Some Android programs trigger the "media volume" slider when the hardware volume up/down buttons are pressed. My application seems to set the ringer volume when the hardware buttons are pressed.
How would I enable the media volume slider?
I would hate for users to have to go into their settings to change the media volume when they use my application.
Just grab a copy of Slider Widget - Volume & more for your Android device and you're ready to start customizing. Press and hold on one of your Android Home screens and then choose the size widget you want to get started with. After the widget appears, just tap on one of the icons for the sliding bar to pop up.
The app also has a widget that does allow you to adjust the volume directly from the widget. To find the widget long-press on an empty space on your home screen and swipe until you see the Volume Control options. Choose the large widget and drag it to where you want to place it.
Just call Activity.setVolumeControlStream(AudioManager.STREAM_MUSIC)
in your Activity's onCreate
method.
private AudioManager audio;
Inside onCreate:
audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Override onKeyDown:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
return true;
default:
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With