Bluetooth disconnects when calling writeCharacteristic on Android 13
See original GitHub issueWhen I call BleManager.writeCharacteristic where the data has 543 bytes in the array, the call succeeds on Android 12. However, on Android 13 the bluetooth disconnects with the following logs:
2022-09-15 12:59:30.850 V/Android-BLE-Library: Writing characteristic <custom characteristic UUID> (WRITE REQUEST)
2022-09-15 12:59:30.850 D/Android-BLE-Library: gatt.writeCharacteristic(<custom characteristic UUID>)
2022-09-15 12:59:31.685 D/BluetoothAdapter: onBluetoothServiceDown
2022-09-15 12:59:31.692 D/BluetoothAdapter: onBluetoothServiceDown
2022-09-15 12:59:31.695 D/Android-BLE-Library: [Broadcast] Action received: android.bluetooth.adapter.action.STATE_CHANGED, state changed to TURNING OFF
2022-09-15 12:59:31.696 I/Android-BLE-Library: Disconnected
2022-09-15 12:59:31.712 D/Android-BLE-Library: gatt.close()
2022-09-15 12:59:31.712 D/BluetoothGatt: close()
2022-09-15 12:59:31.712 D/BluetoothGatt: unregisterApp() - mClientIf=6
2022-09-15 12:59:31.714 E/BluetoothGatt: android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(BinderProxy.java:584)
at android.bluetooth.IBluetoothGatt$Stub$Proxy.unregisterClient(IBluetoothGatt.java:1506)
at android.bluetooth.BluetoothGatt.unregisterApp(BluetoothGatt.java:941)
at android.bluetooth.BluetoothGatt.close(BluetoothGatt.java:799)
at no.nordicsemi.android.ble.BleManagerHandler.close(BleManagerHandler.java:472)
at no.nordicsemi.android.ble.BleManagerHandler.notifyDeviceDisconnected(BleManagerHandler.java:1633)
at no.nordicsemi.android.ble.BleManagerHandler.access$900(BleManagerHandler.java:59)
at no.nordicsemi.android.ble.BleManagerHandler$1.onReceive(BleManagerHandler.java:279)
at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$android-app-LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1790)
at android.app.LoadedApk$ReceiverDispatcher$Args$$ExternalSyntheticLambda0.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
2022-09-15 12:59:31.714 D/BleManagerGattCallback: onServicesInvalidated
2022-09-15 12:59:31.714 D/BleManagerGattCallback: onDeviceDisconnected
2022-09-15 12:59:31.995 D/BluetoothAdapter: onBluetoothServiceUp: android.bluetooth.IBluetooth$Stub$Proxy@868fc9d
There are a few earlier calls to writeCharacteristic with 1-2 bytes that succeed, it’s only the call with the larger amount of data that fails due to the bluetooth disconnecting.
For reference, I’m targeting API 32 and using the following library versions:
implementation 'no.nordicsemi.android.support.v18:scanner:1.6.0'
implementation "no.nordicsemi.android:ble:2.5.1"
implementation "no.nordicsemi.android:ble-livedata:2.5.1"
Has anyone else run into this issue on Android 13?
Issue Analytics
- State:
- Created a year ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
BluetoothGattCharacteristic > write crashes with Android 13
If the Bluetooth service is crashing when you write a characteristic, it's a bug in the Bluetooth stack which you should report to...
Read more >BluetoothGatt - Android Developers
The application will receive a BluetoothGattCallback#onCharacteristicWrite callback in response to every writeCharacteristic(android.bluetooth.
Read more >About the problem with Bluetooth connection disconnecting by ...
Currently, a cellphone bug with the OS version Android 13 is causing many SwitchBot Bluetooth devices to disconnect themselves.
Read more >BLE: GATT writes sometimes stop working if peripheral is ...
If the device disconnects and reconnects and you start a new write operation, the onCharacteristicWrite is still never called. The only possible workaround...
Read more >Android 13 on P6P broke bluetooth, everything disconnects ...
Same issue, Bluetooth disconnecting randomly. Headset will drop mid call, galaxy watch 4 drops so often its battery life is down from 2...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks a lot @philips77, that was very helpful.
Hi @philips77
Do you know if the first
write()
is guaranteed to be fully sent as-is even if it’s very small (let’s say 4 bytes)? Is there a risk for it to be sent with subsequent data, when the send buffer is big enough? Basically what I’m asking is if aflush()
automatically occurs after everywrite()
.