簡體   English   中英

未調用Android BLE onCharacteristicChanged()

[英]Android BLE onCharacteristicChanged() not called

我正在研究一個包含Bluegiga BLE113模塊和Android應用程序的項目。 在Bluegiga模塊上,我設置了幾個特征。 對於一個特性,我定義了一個描述符來在enter code here激活提示enter code here nt通知(在我的情況下,客戶端是Android應用。)。 BLE113模塊的特征定義如下所示:

 <characteristic uuid="dcfa2671-974d-4e4a-96cd-6221afeabb62"        id="ez1_flow_data_out">
     <!-- org.bluetooth.descriptor.gatt.characteristic_user_description -->
     <description>Data to transmit to Android device</description>
     <properties write="true" read="true" />
     <value variable_length="true" length="255" type="hex" />
     <!-- org.bluetooth.descriptor.gatt.client_characteristic_configuration -->
     <descriptor uuid="2902">
     <properties write="true" read="true" const="false" />
     <!-- Bit 0 = 1: Notifications enabled -->
    <value type="hex">0001</value>
    </descriptor>


   </characteristic>

在Android方面,我已根據Android藍牙低功耗指南在onServicesDiscovered(...)回調中設置了通知:

characteristic=gatt.getService(BLEuuids.DATAFLOW_SERVICE).getCharacteristic(BLEuuids.DATAFLOW_OUT_CHARACT);
//Enable local notifications
gatt.setCharacteristicNotification(characteristic, true);
//Enabled remote notifications
BluetoothGattDescriptor desc = characteristic.getDescriptor(BLEuuids.DATAFLOW_OUT_DESCRIPT);
boolean test;
test = desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); // return value = true
test = gatt.readDescriptor(desc); // return value = true
test = gatt.writeDescriptor(desc); // return value = true

但是,如果使用Bluegiga模塊的串行接口更改DATAFLOW_OUT_CHARACT特征UUID的值,則MyAndroid應用程序不會觸發預期的onCharacteristicChanged(...)回調。

我是否已正確設置描述符,或者我的Android代碼中的描述符失敗?

現在啟用通知以回調onCharactersticsChanged()並設置屬性ENABLE_NOTIFICATION_VALUE和ENABLE_INDICATION_VALUE

Log.d(TAG, "setCharacteristicNotification");
        if (mBluetoothAdapter == null || customBluetoothGatt == null) {
            Log.d(TAG, "BluetoothAdapter not initialized");
            return;
        }cx
        customBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
        boolean success = customBluetoothGatt.writeDescriptor(descriptor);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM