如何阅读BluetoothGattCharacteristic
属性如特征Readable
,Writable
或Notifiable
。Android如何阅读BLE属性Readable可写的应具备的GATT特征
8
A
回答
12
/**
* @return Returns <b>true</b> if property is writable
*/
public static boolean isCharacteristicWriteable(BluetoothGattCharacteristic pChar) {
return (pChar.getProperties() & (BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) != 0;
}
/**
* @return Returns <b>true</b> if property is Readable
*/
public static boolean isCharacterisitcReadable(BluetoothGattCharacteristic pChar) {
return ((pChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) != 0);
}
/**
* @return Returns <b>true</b> if property is supports notification
*/
public boolean isCharacterisiticNotifiable(BluetoothGattCharacteristic pChar) {
return (pChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0;
}
0
我遇到了类似的问题,其中示例代码只有在因操作符“|”而导致特征为READ时才起作用。如果特性属于其他类型,如通知或写入,则代码将始终将其设置为READ。正确的代码应该如下所示:
if((charaProp & BluetoothGattCharacteristic.PROPERTY_READ) > 0){
} else if(charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFICATION) > 0){
}
(......与其他案件继续)
同样,谷歌的代码示例是不正确的。
大卫
+0
你的意思是“charaProp&BluetoothGattCharacteristic.PROPERTY_NOTIFICATION”,对吧? – Emil
相关问题
- 1. Android Ble在BLE设备的GATT服务中找不到特征
- 2. Android BLE阅读GAT特性
- 3. 如何知道BLE设备何时订阅Android上的特征?
- 4. 获得Android BLE响应写入特征
- 5. Android BLE GATT多写入 - 写入特性失败
- 6. Android,蓝牙,BTLE,GATT阅读特征失败?
- 7. 无法读取特征。的Android BLE
- 8. GATT工具无法读取/写入特征
- 9. BLE Android中写入GATT后的答案
- 10. 如何将READ,NOTIFY属性添加到Android BLE GATT Server中的自定义特征?
- 11. Android 4.3的BLE如何写特性
- 12. BLE Android,无法启用超过1通知阅读特征
- 13. 无法从Android读取BLE特征
- 14. 具有属性的特征
- 15. android | BLE将值写入特征
- 16. 阅读Android上的GATT属性问题蓝牙低功耗
- 17. BLE GATT服务器特性定义
- 18. BLE更改要写入的UUID特征
- 19. Android如何通过PriorityQueue读取多个BLE特征
- 20. 发送Android BLE GATT通知
- 21. BLE GATT上传数据 - Android
- 22. Ble Beacon Gpio阅读/写作
- 23. 通过GATT(UWP)发送给BLE设备的写请求
- 24. 阅读特征错误BLE与evothings和rPi
- 25. NFC或BLE阅读的设备
- 26. 如何从BLE设备的Arraybuffer中获取值读取特征值
- 27. BLE写入特性的ios
- 28. 读取/写入设备iOS 7中BLE设备的名称特性
- 29. iOS swift BLE读取多个特征
- 30. 定位Ble设备GATT服务推荐
我真的不知道为什么,但Android的官方样品中是 “如果((charaProp | BluetoothGattCharacteristic.PROPERTY_READ)> 0)” 使用 '&' 在我看来是正确的,但“| '正在为我工作。无论如何,你能解释一下,为什么这个BluetoothGattCharacteristic属性有它们的值?例如对于PROPERTY_READ 0x02。在任何服务中,Read是我的第一个属性。 – Krystian
这些是服务地址,您在设备上运行的每项服务都有不同的地址。 –