2015-08-05 4 views
1

когда я проверяю свой код на 5.0.1 андроидной версии метод writeDescriptor всегда возвращает false. Я тестировал его на 4.3 и 4.2.2 устройств, и это всегда возвращается true это мой метод:метод writeDescriptor в android ble всегда возвращает false в lollipop

public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, 
               boolean enabled) { 
     if (mBluetoothAdapter == null || mBluetoothGatt == null) { 
      Log.w(TAG, "BluetoothAdapter not initialized"); 
      return; 
     } 

     mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); 

     // This is specific to Heart Rate Measurement. 
     if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { 
      BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
        UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); 
      descriptor.setValue(new byte[]{0x02}); 
      boolean status = mBluetoothGatt.writeDescriptor(descriptor); 
      if(status) 
       Log.d(TAG,"Client Characteristic Config is changed to 2"); 
      else 
       Log.e(TAG,"Cannot set Client Characteristic Config"); 
     } 
    } 

проблема в методе writeDescriptor, как я сказал

ответ

-1

Пожалуйста, смотрите мой отредактированный ответ.

public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, 
              boolean enabled) { 
    if (mBluetoothAdapter == null || mBluetoothGatt == null) { 
     Log.w(TAG, "BluetoothAdapter not initialized"); 
     return; 
    } 

    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); 

    // This is specific to Heart Rate Measurement. 
    if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { 
     BluetoothGattDescriptor descriptor = characteristic 
       .getDescriptor(GattInfo.CLIENT_CHARACTERISTIC_CONFIG); 


     if(descriptor!=null) 
       { 
      descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); 
     boolean status = mBluetoothGatt.writeDescriptor(descriptor); 
     if(status) 
      Log.d(TAG,"Client Characteristic Config is changed to 2"); 
     else 
      Log.e(TAG,"Cannot set Client Characteristic Config"); 
    } 
    } 
} 
+0

где включено. –

+0

и я вставляю этот код в if (UUID_HEART_RATE_MEASUREMENT.equals (character.getUuid())) statement ??? –

+0

новый байт [] {0x02} - это то, что мне нужно, а не значение BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE. Я работаю на определенном устройстве. –

Смежные вопросы