8
votes

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?

3
Would you be happy if you set silent mode for you phone when in important meeting and still get notification sound from one app? It is reasone why user sets silent mode.user123
Yes, because my app will have an option like this: "play sound although silent mode is set", so user can use this feature or not ;)Sergio Viudes
So only solution is change mode to normal, play notification sound and then set silent mode back.user123
There are situations where you still want to override this feature. For example if you want to ping your phone from a bluetooth device to find it. Then you would in 100% of the cases want the phone to sound even if its in silent mode.nilsi

3 Answers

8
votes

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.

6
votes
AudioManager am;
am= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
-2
votes

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"/>