When my app or service is running, I can offer a Bluetooth profile (e.g. SPP, DUN, or my own UUID) using BluetoothAdapter.listenUsingRfcommWithServiceRecord(...)
.
Is it possible to instead have this Bluetooth profile visible on the device all the time, even when my app or service is not running, and have Android launch my app or service automatically when someone connects to this Bluetooth profile?
I could envision something like this inside AndroidManifest.xml
:
<receiver android:name="com.example.MyBluetoothReceiver" android:exported="true">
<intent-filter>
<action android:name="android.bluetooth.adapter.action.RFCOMM_ACCEPT" />
<data android:name="My SPP Service"
android:uuid="00001101-0000-1000-8000-00805F9B34FB" />
</intent-filter>
</receiver>
The goal would be for the Android framework to recognize this receiver purely based on AndroidManifest.xml
, automatically offer the Bluetooth profile as specified in the <data ...>
-tag whenever the Bluetooth radio is turned on, and then instantiate and call my intent receiver whenever an actual connection is made. This would be similar to the way custom URL handlers work by registering an ACTION_VIEW
intent with CATEGORY_BROWSABLE
, which the browser then calls to launch my app, even if my app is not currently running.
The closest I could find so far are notifications for general Bluetooth status changes (radio on/off, device paired), e.g. here:
Android Broadcast Receiver bluetooth events catching, or the BluetoothAdapter's ACTION_CONNECTION_STATE_CHANGED
intent, which is called for connection to an existing remote profile, rather than a newly offered local one.