I am developing a heart rate monitoring app where I am reading data from BLE device, for all other phones there is no issue but for Samsung mobile like Note 8, which uses Bluetooth version 5.0 It is auto disconnect after some time and I am getting status 8
Code :
For connect
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mGattClient = device.connectGatt(this, false, mGattCallbacks, TRANSPORT_LE)
} else {
mGattClient = device.connectGatt(this, false, mGattCallbacks)
}
// Connection state change
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
when (newState) {
BluetoothProfile.STATE_CONNECTED -> {
// this sleep is here to avoid TONS of problems in BLE, that occur whenever we start
// service discovery immediately after the connection is established
mGattClient?.discoverServices()
}
BluetoothProfile.STATE_DISCONNECTED -> {
Log.d(TAG,"Disconnected status"+ status)
}
}
}
// New services discovered
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
when (status) {
BluetoothGatt.GATT_SUCCESS -> mListener?.deviceConnected(MESSAGE_CONNECTED, status)
else -> Log.w("BLE", "onServicesDiscovered received: $status")
}
}
I have posted this on google issue tracker