Dev/Android
Bluetooth 관련 정리
healthyryu
2023. 3. 9. 11:03
1. BluetoothGatt.discoverServices()
연결된 블루투스에 호출할 수 있는 서비스를 호출하는 기능이다. 해당 함수를 호출하면 블루투스 연결을 할때 등록해 놓은 BluetoothGattCallback 콜백 클래스의 onServicesDiscovered() 로 이벤트가 온다.
private val bluetoothGattCallback = object : BluetoothGattCallback() {
override fun onConnectionStateChange(gatt: BluetoothGatt?, status: Int, newState: Int) {
...
}
override fun onServicesDiscovered(gatt: BluetoothGatt?, status: Int) {
// BluetoothGatt.discoverServices() 호출 후, 이벤트가 오는 곳
if (status == BluetoothGatt.GATT_SUCCESS) {
// 정상적으로 연결이 됐다면 status 값이 GATT_SUCCESS 가 온다.
}
...
}
}
참고
반응형