This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val callback = object : ScanCallback() { | |
override fun onScanResult(callbackType: Int, result: ScanResult?) { | |
super.onScanResult(callbackType, result) | |
result?.device?.connectGatt(context, false, gattCallBack) | |
} | |
} | |
adapter = BluetoothAdapter.getDefaultAdapter() | |
val builder = ScanFilter.Builder() | |
builder.setServiceUuid(ParcelUuid(SERVICE_UUID)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val gattCallBack = object : BluetoothGattCallback() { | |
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) { | |
super.onConnectionStateChange(gatt, status, newState) | |
val isSuccess = status == BluetoothGatt.GATT_SUCCESS | |
val isConnected = newState == BluetoothProfile.STATE_CONNECTED | |
if (isSuccess && isConnected) { | |
// Discover the service on the server on are connected on | |
gatt.discoverServices() | |
} | |
} |