Android examples for android.media:AudioManager
play Key Click Sound
import android.content.Context; import android.media.AudioManager; public class Main { private static final Object mSingletonLock = new Object(); private static AudioManager audioManager; public static void playKeyClickSound(Context context, int volume) { if (volume == 0) return;//w w w . jav a 2s. c o m getInstance(context).playSoundEffect(AudioManager.FX_KEY_CLICK, (float) volume / 100.0f); } private static AudioManager getInstance(Context context) { synchronized (mSingletonLock) { if (audioManager != null) return audioManager; if (context != null) audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); return audioManager; } } }