Unfortunately, I haven't found anything and I can't even create one, but I'd like to find an extension that handles the Bluetooth AVRCP commands received from the car stereo so I can start and stop my app's media player directly from the car stereo controls. Can anyone help me?
1 Like
What you can use already
- Thereâs the Bluetooth Classic Extension from Pura Vida Apps (Bluetooth SDK) for AI2 which supports classic Bluetooth functions. Pura Vida Apps+1
- Thereâs the builtâin/official BLE (Bluetooth Low Energy) extension: BluetoothLE Extension by MIT. MIT CML+2MIT App Inventor Community+2
- There are community extensions for pairing asynchronously, scanning, etc. MIT App Inventor Community+1
Why AVRCP is a special case
- AVRCP (Audio/Video Remote Control Profile) is part of Bluetooth Classic profiles (not BLE) and is used for media controls (play/pause/next).
- Handling AVRCP means your app has to listen for the Bluetooth media control commands sent by the head-unit (car stereo) and map them into actions in your app.
- AI2 and typical Bluetooth extensions are more oriented to device connection/data exchange, not automatically hooking into OSâlevel media control events from the car head unit.
- Also Androidâs handling of media sessions, remote controls, Bluetooth metadata, etc., is more complex, and may require native code or special permissions
What approach would work for you
Since thereâs no plugâandâplay extension I found, you have two main paths:
- Create or adapt an extension yourself
- Write an AI2 extension (.aix) in Java that listens for Bluetooth AVRCP commands and raises events for your AI2 app (e.g., âOnPlayPressedâ, âOnPausePressedâ).
- Youâll need to use Androidâs Bluetooth API for AVRCP (e.g.,
BluetoothA2dp,MediaSession,MediaBrowser,BluetoothDevice.ACTION_MEDIA_BUTTON, etc.). - Then expose blocks in AI2 so you can link those events to your media player in your app.
- This requires Java/Android development skills (or you hire someone/participate in community extension creation).
- Youâll also need to consider Android permissions, handling of media button intents, Bluetooth profile connection, etc.
- Workaround inside AI2 (limited but possible)
- Instead of directly catching AVRCP commands, you might intercept media button events in Android (if your app becomes a media player and registers a
MediaSessionand receives media button intents). - In your AI2 app, you can use the âActivityStarterâ or an extension to register for media button intents, then map those to your appâs Play/Pause control.
- This isnât purely AVRCP at the Bluetooth layer, but often when a headâunit sends Play/Pause, Android generates a mediaâbutton event.
- So you might build this in AI2 with an extension or (if there is one) via an existing extension that handles mediaâbutton events.
My recommendation for your next steps
- Check in the AI2 community forums (e.g., âMedia buttonâ, âAVRCPâ, âCar stereo controlsâ) to see if anyone has shared an extension for media button/AVRCP.
- If you are comfortable or willing to learn, plan to create your own extension:
- Research how to detect media button events in Android (e.g., via
AudioManager,MediaSessionCompat,BroadcastReceiverforIntent.ACTION_MEDIA_BUTTON). - Expose those as events in an AI2 extension.
- Research how to detect media button events in Android (e.g., via
- Alternatively, see if you can re-purposing a âmedia button listenerâ extension (if one exists) rather than a full Bluetooth AVRCP extension.
Hi Sriram,
Sorry for the delay in replying.
Thank you so much for your help and advice. I'll try to figure out how to intercept and manage the play and pause button events. Obviously, if I could find a ready-made extension, it would be easier, especially considering my limited time for testing, as I have a family with a small child.
In any case, thank you again. If I discover anything more, I'll share it here. In any case, I invite anyone who reads this post to help out further.
Have a good day.
Marco
1 Like
Have a nice day to and may you and your famaily be happy
1 Like