I asked AI. This is what I get.
In B4X (B4A, B4i, B4J), you can listen to Bluetooth events and media control (AVRCP) button presses, but the method depends on whether you want to:
Stream & Control Media (Play/Pause/Next/Prev)
Connect to a custom Bluetooth device (like OBD or custom module)
Here’s how each is done:
Detect Car Media Button Presses (AVRCP)
When your phone is paired with the car for media playback, the car sends Media Button events (Play/Pause/Next/Prev) to the phone.
On Android (B4A), you can capture these using a BroadcastReceiver that listens for Intent actions.
Example (B4A)
' In Globals
Private br As BroadcastReceiver
Sub Activity_Create(FirstTime As Boolean)
br.Initialize("br")
br.addAction("android.intent.action.MEDIA_BUTTON")
br.SetPriority(1000) 'High priority
br.RegisterReceiver("")
End Sub
Sub br_OnReceive (Action As String, Extras As Object)
Dim jo As JavaObject = Extras
Dim keyEvent As JavaObject = jo.RunMethod("getParcelable", Array("android.intent.extra.KEY_EVENT"))
Dim actionCode As Int = keyEvent.RunMethod("getAction", Null)
Dim keyCode As Int = keyEvent.RunMethod("getKeyCode", Null)
Log($"Media Button: ${keyCode}, Action=${actionCode}"$)
Select keyCode
Case 85 'Play/Pause
Log("Play/Pause Pressed")
Case 87 'Next
Log("Next Pressed")
Case 88 'Previous
Log("Previous Pressed")
End Select
End Sub
'B4A does not have this. Use in if user closed = true in Activity_Pause event
Sub Activity_Destroy
br.UnregisterReceiver
End Sub
How it works
The car sends AVRCP key events → Android generates a MEDIA_BUTTON broadcast → B4A receives it.
Key codes: 85=Play/Pause, 87=Next, 88=Prev, etc
Broadcast library
You can only capture button presses. Can't send media commands.
If you need to send media commands
If your goal is to control playback (e.g., “simulate a play button” in your own player):
Use MediaSessionCompat + MediaControllerCompat.TransportControls
I think you probably played with MediaSessionCompat based on the other thread.