Wednesday, January 29, 2014

Listening to bluetooth connections




In this quick tutorial I'm going to lead you through creating a BroadcastReceiver that will listening for bluetooth device connections and disconnections.



Permissions

The first though we'll do is add a few permissions in the AndroidManifest, we need both the Bluetooth and the Bluetooth Admin permission for listening to connections/disconnections.




BroadcastReceiver

The next step is to create a BroadcastReceiver that receives ACL_CONNECTED and ACL_DISCONNECTED broadcast actions.



Registration

The last step is to register the BroadcastReceiver in the AndroidManifest so it can start receiving the broadcasts automatically. Alternatively you can handle this by registering the receiver in an Activity or Fragment when needed.


No comments:

Post a Comment