How to tell android which volume (media/ringtone etc.) should be controlled by your app
In my android apps I was getting annoying problems that whilst playing sound the volume buttons would control the media volume, but when no sound was playing they would control the ringtone volume. I found the following by trial and error, hopefully this post will help people with the same problem.
This is done by placing a call of setVolumeControlStream in the onCreate part of your activity which takes on of the following values
- AudioManager.STREAM_MUSIC
- AudioManager.STREAM_RING
- AudioManager.STREAM_ALARM
- AudioManager.STREAM_NOTIFICATION
- AudioManager.STREAM_SYSTEM
- AudioManager.STREAM_VOICECALL
Below shows the code required to set your applications default volume control to any of the above values:
Media Volume
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
Ringtone Volume
this.setVolumeControlStream(AudioManager.STREAM_RING);
Alarm Volume
this.setVolumeControlStream(AudioManager.STREAM_ALARM);
Notification Volume
this.setVolumeControlStream(AudioManager.STREAM_NOTIFICATION);
System Volume
this.setVolumeControlStream(AudioManager.STREAM_SYSTEM);
Voicecall Volume
this.setVolumeControlStream(AudioManager.STREAM_VOICECALL);
I imagine this is also possible via and XML settings, if anyone knows of this I’d be very grateful to know how!




thx
Thanks. That’s been bugging me for a while. Play testers kept saying “It doesn’t make sense!!!! Volume this, volume that.”
Not much on-line to help with this issue either.