我正在分析來自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