Reputation: 2839
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
https://issuetracker.google.com/issues/122856771
Upvotes: 8
Views: 6388
Reputation: 18497
This issue has nothing to do with Android OS itself or your software. The error code 8 means Connection Timeout according to the Bluetooth specification. It means the Bluetooth hardware in the phone lost connection to the device. There are mainly three reasons: bad antenna / radio reception, clock drift between the two devices so they lose synchronization, too many scheduling conflicts (if you have multiple connections).
Is you experience that your Note 8 has significantly worse performance than other phones, send an issue report to Samsung.
Upvotes: 9