In this quick tutorial I'm going to lead you through creating a BroadcastReceiver that will listening for bluetooth device connections and disconnections.
PermissionsThe 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.
The next step is to create a BroadcastReceiver that receives ACL_CONNECTED and ACL_DISCONNECTED broadcast actions.
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.