Code example for AudioManager

Methods: getRingerModesetRingerMode

0
 
                final AudioManager am = (AudioManager) context 
                        .getSystemService(Context.AUDIO_SERVICE); 
 
                if (state == 1) { 
                    // plugged in 
                    if (am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) { 
                        mShouldSwitchBack = true; 
                        am.setRingerMode(userPreferenceAudioMode); 
                        log("plugged in"); 
                    } 
                } else { 
                    // unplugged 
                    if (mShouldSwitchBack && 
                            am.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) { 
                        mShouldSwitchBack = false; 
                        am.setRingerMode(AudioManager.RINGER_MODE_NORMAL); 
                        log("unplugged"); 
                    } 
                } 
                mRunningOwnRingerModeChange = true;