【问题标题】:Example for subscribing for BLE indicate in android在android中订阅BLE指示的示例
【发布时间】:2015-09-10 16:02:04
【问题描述】:

我已连接到蓝牙设备。 我可以使用

阅读特征
mGatt.readCharacteristic(getMiliService().getCharacteristic(uuid));

但我无法为某个特征注册指示。
我尝试了什么

boolean flag1 = m_Gatt.setCharacteristicNotification(bluetoothgattcharacteristic, flag);

BluetoothGattDescriptor descriptor= bluetoothgattcharacteristic.getDescriptor(Helper.UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mGatt.writeDescriptor(descriptor);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
mGatt.writeDescriptor(descriptor);

等待

onCharacteristicChanged(BluetoothGatt bluetoothgatt, final BluetoothGattCharacteristic 特征)

方法被调用。这从未发生过。
我不确定我在这里缺少什么。
任何人都可以给出一个指示的工作示例吗?

【问题讨论】:

    标签: android bluetooth bluetooth-lowenergy android-bluetooth


    【解决方案1】:

    请务必注意,Android BLE 堆栈只允许您一次写入一个特征。

    这是一个对我有很大帮助的工作示例:

    https://github.com/devunwired/accessory-samples/blob/master/BluetoothGatt/src/com/example/bluetoothgatt/MainActivity.java

    【讨论】:

    • 我们如何知道之前的特征写入是否完成?
    • android中的通知和指示有什么区别吗?是android直接发送ACK还是我们手动发送?
    • 是的,这取决于蓝牙设备内部的蓝牙配置文件实现。它使用“通知”或“指示”来发布更新。所以你必须找出你的设备使用的是哪一个。
    • 尝试编写一个特征并检查是否调用了回调。然后你应该嵌套调用,只有在上一个完成之后
    • 也试过了。尝试在没有另一个的情况下编写 1。还是一样的问题
    【解决方案2】:

    这个project允许你连接到一个BLE设备,并包含所有的权限方法:write,read,indicatenotification

    对于指示,您必须将CCCD 设置为它的值。你会在项目中找到这个。

    【讨论】:

      猜你喜欢
      • 2015-01-20
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-29
      • 1970-01-01
      相关资源
      最近更新 更多