0

I use SeekBar for setting volume. I do the following:

  1. I get current volume by getStreamVolume() and pass it to SeekBar element by setProgress().
  2. I listen messages from the SeekBar element by onStopTrackingTouch() and set volume by setStreamVolume(). It works.

But user can change volume by hardware volume controls. I'd like to catch it and change SeekBar pointer position appropriately. How can I do it?

biegleux
  • 13,179
  • 11
  • 45
  • 52
tse
  • 5,769
  • 6
  • 38
  • 58
  • see http://stackoverflow.com/q/7130455/1300995 – biegleux Aug 12 '12 at 20:48
  • I seen it, but it doesn't work for me on my HTC. I tried to do as described in http://android-developers.blogspot.com/2010/06/allowing-applications-to-play-nicer.html – tse Aug 13 '12 at 17:24

1 Answers1

0

Try the following

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
  if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
    //set your SeekBar  
    return true;
  }

 return super.onKeyDown(keyCode, event);
}

The question/answer that biegleux pointed you to is only for the "media keys" on an attached headset, not for the hardware volume up/down keys on the phone itself.

Nick
  • 3,504
  • 2
  • 39
  • 78