我正在使用 Android ble 开发应用程序。该应用程序将使用 ble 连接外部设备。外部设备有一个记录数据的传感器,一旦 Android 设备进入范围,数据传输就开始。 Android 应用程序将注册以在特定特征发生变化时收到通知,并且当两个设备都连接时,数据将通过
传输setCharacteristicNoification() --> onCharacteristicChanged()
现在,这对于传感器在 5-10 分钟内收集的数据来说效果很好。但是,如果设备超出范围超过 15 分钟,并且现在必须传输所有这些数据,则应用程序会自行退出。
在几个论坛上阅读有关此内容时,我检查了系统日志并发现了此错误:
BluetoothServiceJni: An exception was thrown by callback 'btgattc_notify_cb'.
BluetoothServiceJni: android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:496)
at android.bluetooth.IBluetoothGattCallback$Stub$Proxy.onNotify(IBluetoothGattCallback.java:840)
at com.android.bluetooth.gatt.GattService.onNotify(GattService.java:838)
此异常消息重复多次后,我收到此消息
BtGatt.AdvertiseManager: stop advertise for client 5
BtGatt.GattService: onAdvertiseInstanceDisabled() - clientIf=5, status=0
BtGatt.GattService: Client app is not null!
BtGatt.AdvertiseManager: failed onAdvertiseInstanceDisabled
android.os.DeadObjectException at
android.os.BinderProxy.transactNative(Native Method) at
android.os.BinderProxy.transact(Binder.java:496) at android.bluetooth.IBluetoothGattCallback$Stub$Proxy.onMultiAdvertiseCallback(IBluetoothGattCallback.java:874)at com.android.bluetooth.gatt.GattService.onAdvertiseInstanceDisabled(GattService.java:1242) at com.android.bluetooth.gatt.AdvertiseManager$AdvertiseNative.stopAdvertising(AdvertiseManager.java:318)at com.android.bluetooth.gatt.AdvertiseManager$ClientHandler.handleStopAdvertising(AdvertiseManager.java:212) at com.android.bluetooth.gatt.AdvertiseManager$ClientHandler.handleMessage(AdvertiseManager.java:175) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.os.HandlerThread.run(HandlerThread.java:61)
BtGatt.AdvertiseManager: app died - unregistering client : 5
最后是这条消息:
BtGatt.ContextMap:找不到 ID 5 的上下文
我不确定我的代码有什么问题以及代码的哪一部分导致了此问题。 谁能解释一下这个问题可能是什么?
最佳答案
在阅读了多个论坛和 StackOverflow 帖子后,我得出的结论是,我的代码没有任何问题可能导致此崩溃。
后台蓝牙服务无法处理正在传输的数据量。由于我们拥有定制硬件,因此我们能够通过降低通知频率来使其正常工作。
之前我们在 7.5 毫秒内发送了 6 个通知(= 96 字节)(Android 的最小连接间隔)。通过将时间间隔增加到 10 毫秒,我们能够稳定应用程序。
如果有人面临类似的问题,您可能需要减少数据传输的频率,因为后台服务无法处理这种类型的吞吐量。
关于java - 蓝牙服务Jni : An exception was thrown by callback 'btgattc_notify_cb' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43800885/