0
我在我的應用程序中遇到了藍牙問題。我有很多特徵,只能讀取2.當我嘗試閱讀更多時,我沒有得到任何回調。我讀到我應該創建隊列,但不知道如何去做。請幫忙嗎?藍牙沒有讀取每個特徵
這是我的特點:
private void registerParametersCharacteristics(List<BluetoothGattCharacteristic> characteristics) {
for (BluetoothGattCharacteristic characteristic : characteristics) {
UUID characteristicUuid = characteristic.getUuid();
if (Characteristics.EON_PARAMS_EDDYSTONE_UID_CHAR.equals(characteristicUuid)) {
euidCharacteristic = characteristic;
Log.e(TAG, "registerParametersCharacteristics: EUID");
}
else if (Characteristics.EON_PARAMS_EDDYSTONE_EID_CHAR.equals(characteristicUuid)) {
eeidCharacteristic = characteristic;}
else if (Characteristics.EON_PARAMS_EDDYSTONE_URL_CHAR.equals(characteristicUuid)) {
eurlCharacteristic = characteristic;}
else if (Characteristics.EON_PARAMS_EDDYSTONE_TLM_CHAR.equals(characteristicUuid)) {
etlmCharacteristic = characteristic;}
else if (Characteristics.EON_PARAMS_EDDYSTONE_UID_UUID.equals(characteristicUuid)) {
eUidUUidCharacteristic = characteristic;}
else if (Characteristics.EON_PARAMS_EDDYSTONE_URL_UUID.equals(characteristicUuid)) {
eUrlUuidCharacteristic = characteristic;
Log.e(TAG, "registerParametersCharacteristics: EurlUUID");
}
else if (Characteristics.MINOR_CHARACTERISTIC_UUID.equals(characteristicUuid)) {
minorCharacteristic = characteristic;}
else if (Characteristics.MAJOR_CHARACTERISTIC_UUID.equals(characteristicUuid)) {
majorCharacteristic = characteristic;
}
else if (Characteristics.UUID_CHARACTERISTIC_UUID.equals(characteristicUuid)){
uuidCharacteristic = characteristic;
}
else if (Characteristics.INTERVAL_CHARACTERISTIC_UUID.equals(characteristicUuid)) {
intervalCharacteristic = characteristic;
}
else if (Characteristics.TX_CHARACTERISTIC_UUID.equals(characteristicUuid)) {
txCharacteristic = characteristic;
}
else if (Characteristics.BATTERY_CHARACTERISTIC_UUID.equals(characteristicUuid)) {
batteryCharacteristic = characteristic;
Log.e(TAG, "registerParametersCharacteristics: BAT");
}
Log.e(TAG, "registerParametersCharacteristics: " + characteristic.getUuid().toString());
}
}
,這是我onServicediscovered方法:
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
super.onServicesDiscovered(gatt, status);
if (status == BluetoothGatt.GATT_SUCCESS) {
List<BluetoothGattService> services = gatt.getServices();
for (BluetoothGattService service : services) {
registerService(service);
Log.e(TAG, "onServicesDiscovered: " + service.getUuid().toString());
}
callback.connectedStateChanged(true);
} else
disconnect();
}
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicRead(gatt, characteristic, status);
characteristicValueRead(characteristic);
BluetoothCommunicationManager.getInstance().processNext();
}
我失去了兩天寫這個隊列,並不能做到這一點。在此先感謝您的幫助。
亞歷任何例子嗎? – Bartos
當然,https://en.wikipedia.org/wiki/Command_pattern#Java –