Reputation: 2854
My app is showing notifications, and when a notification is shown, a sound is played. But when my phone is on "silent mode" the notification is not played. I want to "override" volume settings, and play a sound although silent mode is set. There is a way to do it?
Upvotes: 13
Views: 15778
Reputation: 8995
Hi you can use MediaPlayer as the notification sound, by starting a Service that play's the MediaPlayer when the notification is shown.
To make the sound stop, stop the service in the BroadCastReceiver of the notification's PendingIntent.
Also, don't forget to stop the sound when the notification cancels.
Upvotes: 8
Reputation: 12201
use this to enable notification sound -
Settings.System.putInt(getContentResolver(),android.provider.Settings.System.NOTIFICATION_SOUND, 1);
Dont forget give permission in manifest -
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
Upvotes: -3
Reputation: 1092
AudioManager am;
am= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Upvotes: 7