Handling headset buttons before Voice Search on Jelly Bean
Asked Answered
D

1

8

Android Jelly Bean introduced a voice search which activates with a long-press on the play/pause button of a headset. As my app requires being able to utilise these long-presses, I was wondering if there is any way to either disable the voice search or make Android play fair with the button events.

Denominationalism answered 12/7, 2012 at 12:3 Comment(0)
H
1

I have not tried it myself, but you may be able to get this to work using the AudioManager's registerMediaButtonEventReceiver method, as the volume buttons are media buttons.

The AOSP music app has a MediaButtonIntentReceiver that responds to volume button presses.

Credit for this solution belongs to this answer.

Havildar answered 17/7, 2012 at 4:20 Comment(2)
I'm afraid not. In Android 4.0+, all media button receivers have to use registerMediaButtonEventReceiver to receive button clicks. This part still works, but sadly doesn't make Android give the intent to third party apps before handling Voice Search.Denominationalism
The Pressy app is able to hook a long press of the headset button (even on Lollipop). Pressy has a specific interface with a 'go' button which presumably fires some intent and forces the system to ask if you want to make Pressy or Google Search the default. I would love to know how it achieves it.Gulgee

© 2022 - 2024 — McMap. All rights reserved.