Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn to previous RINGER_MODE after ended call
    text
    copied!<p>I have an app that can take you from silent/vibrate and to normal ringer mode, but when i try to put you back in the mode i took you out of, i always end up in the silent mode. Can anyone see why?</p> <p>First i store the current ringstate as an integer with checkCurrentSoundState(), then i try to put the mobile back to the state i saved there when the call is over, but by the time it is over, the value i stored is gone and has been reset to 0. Anyone got some good tips on how to overcome this problem?</p> <pre><code> @Override public void onReceive(Context context, Intent intent) { AudioManager maudio = (AudioManager) context.getSystemService(context.AUDIO_SERVICE); this.context = context; bundle = intent.getExtras(); if (bundle == null) return; state = bundle.getString(TelephonyManager.EXTRA_STATE); Log.i("IncomingCall", "State: " + state); if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING) || TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals("EXTRA_STATE_RINGING")) { checkCurrentSoundState(); setupDatabase(); Bundle bundle = intent.getExtras(); String phoneNr = bundle.getString("incoming_number"); for (int i = 0; i &lt; allowedThrough.size(); i++) { if (PhoneNumberUtils.compare(allowedThrough.get(i), phoneNr)){ goToNormal(); } } } System.out.println("current ringstate is now " + ringcheck); if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_OFFHOOK)) returnToPreviousState(); } private void checkCurrentSoundState() { AudioManager maudio = (AudioManager) context.getSystemService(context.AUDIO_SERVICE); ringcheck = maudio.getRingerMode(); } private void returnToPreviousState() { AudioManager maudio = (AudioManager) context.getSystemService(context.AUDIO_SERVICE); if (ringcheck == AudioManager.RINGER_MODE_SILENT) maudio.setRingerMode(AudioManager.RINGER_MODE_SILENT); else if (ringcheck == AudioManager.RINGER_MODE_NORMAL) maudio.setRingerMode(AudioManager.RINGER_MODE_NORMAL); else if (ringcheck == AudioManager.RINGER_MODE_VIBRATE) maudio.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload