Separate headset long press from media button

124 views
Skip to first unread message

Trapier Marshall

unread,
Oct 31, 2023, 12:51:28 PM10/31/23
to Automate for Android
Please consider separating headset "long press" detection from the media button receiver.  On my device (Android 13) the android.intent.action.VOICE_COMMAND action is triggered by headset long press and can be consumed independently from other media buttons. I've experimented with "headset hook" in the "media button" block but have found the block has a couple undesirable side effects, and in this case I've no use for the other buttons (play/pause/next/prev):

  * Causes a brief silent sound to be played (on the notification audio stream?) when re-acquiring focus.  This produces an unpleasant popping sound on connected bluetooth devices between audio tracks and very briefly misdirects any volume changes by hardware button to the notification stream.  This is particularly noticeable when using Voice Aloud Reader, a text-to-speech app that "plays" sentences in series.
  * Tends to mask or be masked by other media players depending on who started most recently.  That could be interesting for some use cases but not interesting here.  "Media playing?" provides more explicit logic.

The app picker happend to suggest that Tasker also handles android.intent.action.VOICE_COMMAND, and its manifest indicates it has no media button receiver.  One scenic route to the desired effect is to set Tasker as the default for android.intent.action.VOICE_COMMAND and bounce the event to Automate via broadcast.

Headset "long press" is implemented by most hardware and rarely used by media players.  It's an ideal automation target.  Please consider exposing it without the overheads currently associated with the "media button" block.

Henrik "The Developer" Lindqvist

unread,
Nov 1, 2023, 2:20:09 PM11/1/23
to Automate for Android
In its manifest, Automate is already registered to handle the "android.intent.action.VOICE_COMMAND" action, that's what's reported as the "Headset hook" button presses. The proper Media button API doesn't support it.
A audio playback is needed on Android 8+ otherwise the app wont get media button events, i.e. only most recent/current audio player does, hence the silent sample. That's not really needed for the VOICE_COMMAND action, but since the Media button block can't handle any button dynamically, it's always played.
Reply all
Reply to author
Forward
0 new messages