How to set what the volume control actually controls in your Android app

I was recently working on an Android application  and found that when debugging the volume was to low. Using the volume control on the phone would only increase the ringer volume. By accident I found that if a media sound was playing then the volume controls would control the media volume,which indicated that the default action for the volume control is to adjust the ringer volume. So all I needed to do was work out how to change the default volume control action, and as it turns out it’s quite easy.

The Activity class has a public method called setVolumeControlStream which description is “Suggests an audio stream whose volume should be changed by the hardware volume controls.” Bingo that sounds the ticket. The method takes an int StreamType as input. The AudioManager class defines the different stream types.

So in the onCreate method for your activity add something like this:

this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Twitter
  • Google Bookmarks

2 thoughts on “How to set what the volume control actually controls in your Android app

Leave a Reply

Your email address will not be published. Required fields are marked *

*