Характеристики Android BLE GetValue — нет ли какого-либо ответа?

#android #bluetooth-lowenergy

#Android #bluetooth-lowenergy

Вопрос:

Я пытаюсь настроить характеристику чтения с атрибутом уведомления. На данный момент я вижу эту характеристику в приложении для Android со свойствами ЧТЕНИЯ и УВЕДОМЛЕНИЯ.

вот информация о uuid моего устройства :

Информация о UUID

ДА, сначала мне нужен атрибут уведомления, затем, во-вторых, я отправляю команду, которая будет получать значение, но, на самом деле, я не получаю никакого значения, я даже не знаю, что не так, вот мой код :

      public void onServicesDiscovered(BluetoothGatt gatt, int status){

          if (status == gatt.GATT_SUCCESS){ 

              runOnUiThread(new Runnable(){

                  public void run() {
                      BluetoothGattService gattService = gatt.getService(SERVICE_UUID);

                      if(gattService != null){
                        BluetoothGattCharacteristic gattCharacteristic = gattService.getCharacteristic(NOTIF_UUID);
                        if (gattCharacteristic != null ){
                           for (BluetoothGattDescriptor descriptor : gattCharacteristic.getDescriptors()){
                              descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
                              boolean sucess = gatt.writeDescriptor(descriptor);
                           }
                        gatt.setCharacteristicNotification(gattCharacteristic, true);  

                       }
                characteristic = gattService.getCharacteristic(WRITE_DATA); 
                if (characteristic != null){
                   sendCommand(characteristic, gatt); //send command
                }     
                    
now , I have already send command , and it's return success , because onCharacteristicWrite() has response,
but onCharacteristicRead() and onCharacteristicChanged() is not any response? Why ?

which part I missing?
 

Ответ №1:

   descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
 

вместо

   descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);