相关疑难解决方法(0)

Android BLE API:未收到GATT通知

用于测试的设备:Nexus 4,Android 4.3

连接工作正常,但onCharacteristicChanged我的回调方法永远不会被调用.但是我正在使用setCharacteristicNotification(char, true)inside 注册通知onServicesDiscovered,该函数甚至返回true.

设备日志(当通知应该出现/通过蓝牙设备发送时,实际上根本没有消息):

07-28 18:15:06.936  16777-16809/de.ffuf.leica.sketch D/BluetoothGatt: setCharacteristicNotification() - uuid: 3ab10101-f831-4395-b29d-570977d5bf94 enable: true
07-28 18:15:06.936    4372-7645/com.android.bluetooth D/BtGatt.GattService: registerForNotification() - address=C9:79:25:34:19:6C enable: true
07-28 18:15:06.936    4372-7645/com.android.bluetooth D/BtGatt.btif: btif_gattc_reg_for_notification
07-28 18:15:06.946    4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1018
07-28 18:15:06.946    4372-7645/com.android.bluetooth D/BtGatt.GattService: onRegisterForNotifications() - address=null, status=0, registered=1, charUuid=3ab10101-f831-4395-b29d-570977d5bf94
07-28 18:15:06.946    4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1016
07-28 18:15:06.946    4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1018
07-28 18:15:06.946    4372-7645/com.android.bluetooth D/BtGatt.GattService: onRegisterForNotifications() - address=null, status=0, …
Run Code Online (Sandbox Code Playgroud)

android bluetooth bluetooth-lowenergy gatt android-4.3-jelly-bean

68
推荐指数
5
解决办法
7万
查看次数

Android:BLE如何读取多个特征?

用于读取某些特征的Android BLE API方法本质上是异步的,当您请求某些值时,将调用您的GATT回调方法.

如果您请求多个读取特征值,它只会丢弃其他值,直到它不接受第一个请求为止.

我不明白是否这样,为什么他们制作方法Async.如果有人知道我们应该采用哪种设计模式来解决这个问题,请分享.

如果你想阅读一些特征,那么你必须要求它.

// new value available will be notified in Callback Object
        mBluetoothGatt.readCharacteristic(ch);
Run Code Online (Sandbox Code Playgroud)

GATT回调

public void onCharacteristicRead(BluetoothGatt gatt, android.bluetooth.BluetoothGattCharacteristic characteristic, int status)
Run Code Online (Sandbox Code Playgroud)

可能的解决方案#1

https://code.google.com/p/guava-libraries/wiki/ListenableFutureExplained

任何人都可以解释如何使用它.我认为这将有助于这种情况,但我仍然在寻找如何使用它.

可能的解决方案#2

https://code.google.com/p/mobility-rpc/source/browse/mobility-rpc/trunk/src/main/java/com/googlecode/mobilityrpc/session/impl/MobilitySessionImpl.java#395

可能的解决方案#3

http://tutorials.jenkov.com/java-util-concurrent/synchronousqueue.html

可能的解决方案#4

http://examples.javacodegeeks.com/core-java/util/concurrent/synchronous-queue-example-to-execute-commands/

可能的解决方案#5

/sf/answers/1107159651/

更新

我已经成功地使用Queue更好的SynchronousQueue,但我会在测试后分享我的最终解决方案.指定超时,否则它将被卡住或者您请求读取不支持读取操作的特性.

您可以看到哪些特性是可读写的,请参阅此帖子

android asynchronous bluetooth-lowenergy

22
推荐指数
1
解决办法
1万
查看次数