Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.media.AudioManager; public class Main { private static final Object lock = new Object(); private static AudioManager audioManager; public static void playKeyClickSound(Context context, int volume) { if (volume == 0) return; getInstance(context).playSoundEffect(AudioManager.FX_KEY_CLICK, (float) volume / 100.0f); } private static AudioManager getInstance(Context context) { synchronized (lock) { if (audioManager != null) return audioManager; if (context != null) audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); return audioManager; } } }