Search code examples
androidaudionotificationmanager

How do you change the output volume of a sound?


I'm using this code to play a sound.

I would like to give the user the ability to alter the volume of the sound. Can you tell me how to do this?

NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification();
notification.sound = Uri.parse("android.resource://emad/raw/quarter");

Thanks.

Truly, Emad


Solution

  • use

      notification.audioStreamType = AudioManager.STREAM_MUSIC;
    
      context.setVolumeControlStream(AudioManager.STREAM_MUSIC);