I want start a service, when a specific bluetoothdevice is connected and stop this service when it's disconnected. Obviously I don't want to have a background service that is always checking if a BT device is connected, so I want to achieve this with a Receiver.
Is this actually possible? android.bluetooth.device.action.ACL_CONNECTED
is mentioned here, but apparently it didn't work.
Thanks!
There may be too many apps running in the background of the device the Bluetooth is attempting to pair with. Certain applications cause interference with the connection, and some devices are limited in the number of applications that can run concurrently. If in doubt, check with the headset manufacturer.
If possible, restart the Bluetooth device. Then, restart your phone or tablet. This can help fix minor issues and may help the Bluetooth device connect again. On devices with a regular Power key, press and hold the Power key until the Power menu is displayed.
Can someone connect to my Bluetooth without me knowing? Theoretically, anyone can connect to your Bluetooth and gain unauthorized access to your device if the visibility of your Bluetooth device is on.
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
</intent-filter>
These are the filters you have to add with your broadcast receiver.
ACL_CONNECTED
signals when bluetooth is connected and ACL_DISCONNECTED
signals bluetooth disconnection
For specific device you have to check intents/context in broadcast receiver
The two permission you have to add are:
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
I think this should solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With