Pregunta

AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

switch (am.getRingerMode()) {
case AudioManager.RINGER_MODE_SILENT:
    Log.i("MyApp","Silent mode");
    break;
case AudioManager.RINGER_MODE_VIBRATE:
    Log.i("MyApp","Vibrate mode");
    break;
case AudioManager.RINGER_MODE_NORMAL:
    Log.i("MyApp","Normal mode");
    break;
}

Using the above code, I can successfully find the various AudioManager RINGER_MODE* types, however I can't seem to find an EventListener that catches when the state has changed. The application I am writing runs in the background, so I'd like to know the the most timely fashion of checking the state of the AudioManager.RINGER_MODE.

¿Fue útil?

Solución

You will need to register a BroadcastReceiver in your code that listens for the RINGER_MODE_CHANGED_ACTION intent. This will let you know that the state has changed. Once you receive the intent, you can call getRingerMode() to find out what the current state is.

Otros consejos

did you try listening for AudioManager.RINGER_MODE_CHANGED_ACTION?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top