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;
}
使用上面的代碼,我可以成功找到各種AudioManager RINGER_MODE *類型,但是我似乎無法找到狀態發生變化時捕獲的EventListener。我正在編寫的應用程序在後臺運行,因此我想知道檢查AudioManager.RINGER_MODE狀態的最及時方式。Android AudioManager事件監聽器?