我正在分析来自android的一个示例,它解释了Android上的蓝牙低能量使用情况。我发现了下面的代码,它设置了一个通知,但是我不能在ifs中使用一个属性整数和条件来获取这里发生的事情。有人能解释一下吗?阅读蓝牙低能耗属性(阅读,通知) - 它是如何工作的?
无论如何,也许你有一些更好的源代码,它可以解释android上的ble概念 - 在这里工作是什么?官方Android教程是真穷,和蓝牙官方页面是给几乎没有...
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) {
if (mGattCharacteristics != null) {
final BluetoothGattCharacteristic characteristic =
mGattCharacteristics.get(groupPosition).get(childPosition);
final int charaProp = characteristic.getProperties();
if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
// If there is an active notification on a characteristic, clear
// it first so it doesn't update the data field on the user interface.
if (mNotifyCharacteristic != null) {
mBluetoothLeService.setCharacteristicNotification(
mNotifyCharacteristic, false);
mNotifyCharacteristic = null;
}
mBluetoothLeService.readCharacteristic(characteristic);
}
if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
mNotifyCharacteristic = characteristic;
mBluetoothLeService.setCharacteristicNotification(
characteristic, true);
}
return true;
}
return false;
}
该样本实际上以各种可能的方式被打破。如果你只是搜索互联网,可能还有很多其他的例子。 – Emil
@Emil,是的,有其他可能的例子,但我试图找到一些 - 他们是复杂的另一种方式。其中很多是用不同的方式写的。我找到的例子/教程都没有解释BLE的一些基础知识,例如从某些位读取等等,或者仅仅从16位创建中解释基本的UUID。 – Krystian