Android: Detect volume button presses to change media volume instead of ringer volume

Man, this one was bloody hard to find. Couldn't find it in the docs for the life of me.

Luckily, StackOverflow came to the rescue.

Normally when your app starts, people expect to be able to change the volume when they press the volume buttons. Surely enough, the Android platform shows the the volume level and it changes accordingly.

Sadly, it is the RINGER volume which they are changing and not your MEDIA volume (the volume level which your app uses!).

Because of this, they'll think you're stupid (but really its not your fault!)

To prevent this, during the Activity.onCreate() phase, paste in this line.


That's it! Now the app will respond to the volume button by changing the media volume rather than ringtone volume.

[ Source ]

Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog