Code example for AudioManager

Methods: getRingerModeplaySoundEffect

0
    private void updateRingerMode() { 
        if (mAudioManager == null) {
            mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        } 
        if (mAudioManager != null) {
            mSilentMode = (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL);
        } 
    } 
 
    public void playKeyClick(int primaryCode) {
        // if mAudioManager is null, we don't have the ringer state yet 
        // mAudioManager will be set by updateRingerMode 
        if (mAudioManager == null) {
            if (getInputView() != null) { 
                updateRingerMode(); 
            } 
        } 
        if (mSoundOn && !mSilentMode) {
            // FIXME: Volume and enable should come from UI settings 
            // FIXME: These should be triggered after auto-repeat logic 
            int sound = AudioManager.FX_KEYPRESS_STANDARD;
            switch (primaryCode) {
                case Keyboard.KEYCODE_DELETE:
                    sound = AudioManager.FX_KEYPRESS_DELETE;
                    break; 
                case KEYCODE_ENTER:
                    sound = AudioManager.FX_KEYPRESS_RETURN;
                    break; 
                case KEYCODE_SPACE:
                    sound = AudioManager.FX_KEYPRESS_SPACEBAR;
                    break; 
            } 
            mAudioManager.playSoundEffect(sound, FX_VOLUME);
        } 
    } 
 
    public void vibrate() { 
        if (!mVibrateOn) {