【问题标题】:BluetoothServiceJni: An exception was thrown by callback 'btgattc_notify_cb'BluetoothServiceJni:回调“btgattc_notify_cb”引发异常
【发布时间】:2017-05-05 09:09:18
【问题描述】:

我正在使用 Android ble 开发应用程序。该应用程序将使用 ble 与外部设备连接。外部设备有一个记录数据的传感器,一旦安卓设备进入范围,数据传输就开始了。 android 应用程序将注册以在特定特征发生变化时得到通知,并且当两个设备连接时,数据通过传输

setCharacteristicNoification() --> onCharactericticChanged()

现在这适用于传感器在 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: Context not found for ID 5

我不确定我的代码有什么问题,以及代码的哪一部分导致了这个问题。 谁能解释一下这个问题可能是什么?

【问题讨论】:

    标签: java android bluetooth bluetooth-lowenergy android-ble


    【解决方案1】:

    在阅读了几个论坛和 StackOverflow 帖子后,我得出结论,我的代码没有任何问题会导致这次崩溃。

    后台蓝牙服务无法处理正在传输的数据量。由于我们拥有定制硬件,因此我们能够通过降低通知频率来使其正常工作。

    之前我们在 7.5 毫秒(Android 的最小连接间隔)内发送 6 个通知(= 96 字节)。通过将时间间隔增加到 10 毫秒,我们能够稳定应用程序。

    如果有人遇到类似问题,您可能希望降低数据传输频率,因为后台服务无法处理这种类型的吞吐量。

    【讨论】:

    • 大声笑。你有什么安卓版本和手机?
    • 我在多个设备上使用 Lollipop 和 Marshmellow。
    • 我只是将字节数组写入 QueueFile 实例。 github.com/square/tape
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 2015-08-14
    • 1970-01-01
    • 2020-04-28
    • 2020-11-07
    相关资源
    最近更新 更多