I was very surprised to find in the app I am currently programming that when I make it play a notification sound, it plays regardless of whether the phone has been set to silent or not!
Surely the phones silent mode should be an overriding feature or am I meant to be checking? I had a quick look at the documentation but did not see anything saying this? Am I missing something?
This is my notification code:
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(300);
Uri alert = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
MediaPlayer mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(this, alert);
final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mMediaPlayer.setLooping(false);
mMediaPlayer.prepare();
mMediaPlayer.start();
}
Thanks for any feedback here!
Bex
Not sure about the documentation you checked, but on Nexus One below Silent mode checkbox it clearly says:
Silence all sounds except media & alarms.
In your example you are playing alarm (not notification), so it is correct.
Based on the testing results it seems that you're the one that needs to check it:
if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
// Play the sound
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With