- Add Permissions in
AndroidManifest.xml. - Enable Bluetooth using
BluetoothAdapter. - Check if Bluetooth is supported.
- Find Bluetooth devices using
BluetoothDevice&BroadcastReceiver. - Pair Bluetooth devices using
BluetoothDevice. - Establish connection with Bluetooth devices using
BluetoothSocket. - Transfer Bluetooth data using
BluetoothSocket. - Close connection using
BluetoothSocket.
Note to clarify here between points 5 and 6, as they are closely related. There is a difference between being paired and being connected:
- To be paired means that two devices are aware of each other's existence, have a shared link-key that can be used for authentication, and are capable of establishing an encrypted connection with each other.
- To be connected means that the devices currently share an RFCOMM channel and are able to transmit data with each other. The current Bluetooth APIs require devices to be paired before an RFCOMM connection can be established. Pairing is automatically performed when you initiate an encrypted connection with the Bluetooth APIs.
- Koin for dependency injection