下面的代码在Android 12及更低版本上运行得很好,但在Android 13上却毫无原因地崩溃了。
我正在实现ObservableBleManager并调用:
writeCharacteristic(characteristic, data)
.done {
// emit success
}
.fail { _, _ ->
// emit error
}
.enqueue()但它像这样崩溃了:
2022-09-13 11:30:54.265 23853-23853/com V/Android-BLE-Library: Writing characteristic <custom characteristic> (WRITE REQUEST)
2022-09-13 11:30:54.265 23853-23853/com D/Android-BLE-Library: gatt.writeCharacteristic(<custom characteristic>)
2022-09-13 11:30:55.003 23853-23867/com D/BluetoothAdapter: onBluetoothServiceDown
2022-09-13 11:30:55.007 23853-23869/com D/BluetoothAdapter: onBluetoothServiceDown
2022-09-13 11:30:55.013 23853-23853/com D/Android-BLE-Library: [Broadcast] Action received: android.bluetooth.adapter.action.STATE_CHANGED, state changed to TURNING OFF
2022-09-13 11:30:55.013 23853-23853/com I/Android-BLE-Library: Disconnected
2022-09-13 11:30:55.035 23853-23853/com D/Android-BLE-Library: gatt.close()
2022-09-13 11:30:55.035 23853-23853/com D/BluetoothGatt: close()
2022-09-13 11:30:55.035 23853-23853/com D/BluetoothGatt: unregisterApp() - mClientIf=6
2022-09-13 11:30:55.036 23853-23853/com 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:422)
at no.nordicsemi.android.ble.BleManagerHandler.notifyDeviceDisconnected(BleManagerHandler.java:1520)请注意,相反,阅读是好的。我们发现有一个带有此错误消息的崩溃:
A/libc: FORTIFY: memcpy: prevented 546-byte write into 513-byte buffer
看来有效载荷太大了。然而,我不明白为什么Android 13这么小,而Android 12和更低的版本却能工作:
发布于 2022-10-17 14:46:11
直到Android 12,我们允许长写超过512字节,但在Android 13 (Android的新的Gabeldorsche蓝牙堆栈)中,由于某种原因,它是有限的。不管是哪种方式,它似乎都不像是可以在这个库中修复的东西。
这对我来说很管用:
val writeType = if (VERSION.SDK_INT >= 33) BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE else BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT
val writeData = writeCharacteristic(rxCharacteristic, payload, writeType)
writeData.with(rxCallback)
if (VERSION.SDK_INT >= 33) writeData.split()https://stackoverflow.com/questions/73772158
复制相似问题