Code example for AudioManager

Methods: getModegetRingerModesetRingerMode

    private void toggleAudioMute() { 
        if (mAudioManager == null) {
            mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
        // We only act in normal mode (rings, calls, ... are handled by aosp) 
        if (mAudioManager.getMode() == AudioManager.MODE_NORMAL) {
            // TODO: If an alarm is sound then don't toggle the volume mute. In this case, 
            // is better to ignore the key event and let the alarm app to handle it. 
            // Just toggle between normal and silent (by now we are not going to handle 
            // vibration here) 
            int newValue =
                    mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL ?
                    AudioManager.RINGER_MODE_NORMAL :
            int status = newValue == AudioManager.RINGER_MODE_NORMAL ?
                    ASUSDEC_STATUS_OFF :
            notifyKey(ASUSDEC_VOLUME_MUTE, status);