2

I would like to control my app with a headset keys (volume +, middle key, volume -).

I have no problem detecting media keys:

  • play/pause, triggered by click on middle
  • next/previous, triggered by volume buttons long press

I do have a problem detecting (and ideally intercepting) everything else. I am especially interested in volume keys.

!! Solutions with onKeyDown or listening to MEDIA_BUTTON or listening to volume changes (e.g. via AudioService) work with phone volume keys, but not with bluetooth volume keys !!

More info: (just as info) In activity on onKeyDown I do not see headset key presses (it only picks up clicks on phone volume rocker).

I cannot infer clicks from volume changes, as there is no trigger if the device is at max/min volume. Also the volume dialog does not show up if I try to set above max volume with headset, as it does with phone volume buttons.

In debugger, the only thing that happens upon vol+ on max volume is some action reported from avrcp in debug mode:

07:04:08.220 7106-7250/? I/BluetoothAvrcpServiceJni: btavrcp_volume_change_callback
07:04:08.220 7106-30330/? V/Avrcp: MSG_NATIVE_REQ_VOLUME_CHANGE: volume=127 ctype=13
07:04:08.281 5937-13180/? I/EDMNativeHelperService: isAVRCPProfileEnabled
07:04:08.285 7106-7250/? I/BluetoothAvrcpServiceJni: btavrcp_volume_change_callback
07:04:08.285 7106-30330/? V/Avrcp: MSG_NATIVE_REQ_VOLUME_CHANGE: volume=127 ctype=15

How could I get these events with my service? Or is there any useful alternative to detect such headset clicks?

Jure Sencar
  • 554
  • 4
  • 13
  • Possible duplicate of [How to override the behavior of the volume buttons in an Android application?](https://stackoverflow.com/questions/2367484/how-to-override-the-behavior-of-the-volume-buttons-in-an-android-application) – Karan Harsh Wardhan Dec 04 '18 at 08:47
  • see this https://stackoverflow.com/a/17398781/6549598 – nimi0112 Dec 04 '18 at 08:47
  • 1
    I checked both links (and many other) before posting. I wrote in my question that **onKeyDown** or listening to volume changes does not work for me. Both solutions would work (although first one not for Service) for phone volume rocker, but not for bluetooth headset. – Jure Sencar Dec 04 '18 at 12:02
  • @Jure S, any luck? did you found a solution? – snachmsm Apr 28 '20 at 12:25
  • 1
    No. During testing I also realized that overriding volume buttons would not be justified from UX perspective. You'd have to have very strong reasons to go down that way + it does not seem to be (easily) possible. – Jure Sencar Apr 29 '20 at 13:04

0 Answers0