QNA > H > How To Make My Android App Play Sound Even In Do Not Disturb Mode

How to make my Android app play sound even in Do Not Disturb Mode

You can enable ringer mode in the following way:

  1. AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); 
  2. mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); /* set ringer mode */ 

or increase up the volume of media player and play the desired tone:

  1. MediaPlayer player = MediaPlayer.create(context, R.raw.xyz); /* set tone or use setDataSource method */ 
  2. final AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); 
  3. final int originalVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
  4. mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0); 
  5. player.setVolume(100, 100); 
  6. player.prepare(); 
  7. player.start(); 
  8.  
  9. player.setOnCompletionListener(new OnCompletionListener(){ 
  10. @Override 
  11. public void onCompletion(MediaPlayer player){ 
  12. mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, originalVolume, 0); 
  13. player.release(); 
  14. player.stop(); } 
  15. }); 

Di Lamoree Stonebrakerjr

Photoshop è obsoleto? :: Quali sono le domande più seguite su Quora?
Link utili