2015-12-04 8 views
1

Мой CLIENT_CHARACTERISTIC_CONFIG являетсяBluetoothGattDescriptor всегда NULL

public final static UUID CLIENT_CHARACTERISTIC_CONFIG = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); 

я это изменить Характерный:

  BluetoothGatt mBluetoothGatt = device.connectGatt(this.context, false, mGattCallback); 
      mBluetoothGatt.connect(); 


      BluetoothGattService mCustomService = bleScanner.getBluetoothGatt().getService(UUID.fromString(bleServiceUUID)); 
      if(mCustomService == null){ 
       return; 
      } 

      BluetoothGattCharacteristic mCharacteristic = mCustomService.getCharacteristic(UUID.fromString(bleCharacteristicUUID)); 
      if(mReadCharacteristic == null){ 
       return; 
      } 
      String message = "myMessage"; 
      mCharacteristic.setValue(message.getBytes()); 

      if (!mBluetoothGatt.writeCharacteristic(characteristic)) { 
       Log.e(TAG, "Failed to write characteristic"); 
      } else { 
       Log.e(TAG, "Writed characteristic " + message); 
      } 

После этого characteristic изменяется на датчике, onCharacteristicWrite вызывается в BluetoothGattCallback

@Override 
       public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { 

        if (status == BluetoothGatt.GATT_SUCCESS) { 

         if (!mBluetoothGatt.setCharacteristicNotification(characteristic, true)) { 
          DLog.e(TAG, "Notification Setup failed: "+characteristic.getUuid()); 
         } 

         BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG); 
         if (descriptor!=null){ 
          descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); 
          mBluetoothGatt.writeDescriptor(descriptor1); 
         } 
        } 
       } 

НО descriptor всегда NULL. И onCharacteristicChanged никогда не называется. Почему? и это мой CLIENT_CHARACTERISTIC_CONFIG?

+0

Любая другая информация, которую вы можете поделиться для этой проблемы или вы ее каким-то образом решили? – Harpreet

+0

@Harpreet, см. Ответ ниже – NickUnuchek

ответ

0

это потому, что некоторые из устройств (шахта Samsung E5 Android 4.3-> обновлено до 5.1.1) являются поддержка BLE, но не поддерживает BluetoothGattDescriptor 0x2902 (ссылка)

, чтобы увидеть все дескрипторы, которые поддерживал в вызове устройства следующим образом:

for (BluetoothGattDescriptor descriptor:characteristic.getDescriptors()){ 
        Log.e(TAG, "BluetoothGattDescriptor: "+descriptor.getUuid().toString()); 
       } 

[ОБНОВЛЕНИЕ] Некоторые BLE устройства не поддерживает Writed characteristics, такие как IBeacon

+1

есть ли работа для этого ?? –

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

  • Нет связанных вопросов^_^