How to make my Android app play sound even in Do Not Disturb Mode
You can enable ringer mode in the following way:
- AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
- mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); /* set ringer mode */
or increase up the volume of media player and play the desired tone:
- MediaPlayer player = MediaPlayer.create(context, R.raw.xyz); /* set tone or use setDataSource method */
- final AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
- final int originalVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
- mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
- player.setVolume(100, 100);
- player.prepare();
- player.start();
- player.setOnCompletionListener(new OnCompletionListener(){
- @Override
- public void onCompletion(MediaPlayer player){
- mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, originalVolume, 0);
- player.release();
- player.stop(); }
- });
Artigos semelhantes
- Why am I not able to make a super chat on YouTube? Why does it say this feature isn’t available yet in your region?
- How to make the background image of a button disappear when we click it, and make it appear on another button when we click it in Visual Studio
- What changes did Gmail make to their latest Android app?
- Why is the CBS Sports app not working on Xbox?