2017-03-19 5 views
0

Android 4.3では 'onCharacteristicChanged'というコールバックですが、上記のAndroid 5.0ではコールされません。 'WriteCharacteristic'と 'setCharaceristicNotification'は成功し、 'onCharacteristicWrite'コールバックはまだ成功しています。Android5.0やAndroid 6.0では呼び出されません。onCharacteristicChangedはAndroid 5.0のコールバックではありません

この私の通知コードさ:

private void notification(BluetoothGattCharacteristic gattCharacteristic, String tag) { 
    boolean success = mBluetoothGatt.setCharacteristicNotification(gattCharacteristic, true); 
    if (success) { 
     for (BluetoothGattDescriptor dp : gattCharacteristic.getDescriptors()) { 
      if (dp != null) { 
       if ((gattCharacteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) { 
        dp.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); 
        Log.i(TAG,"notification NOTIFICATION value = "+ Arrays.toString(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)); 
       } else if ((gattCharacteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) { 
        dp.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); 
        Log.i(TAG,"notification INDICATION value = "+ Arrays.toString(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)); 

       } 
       mBluetoothGatt.writeDescriptor(dp); 
       Log.i(TAG, tag + " notification successful"); 
      } 
     } 
    } 
} 

答えて

0

"BluetoothGatt.writeDescriptor(DP)は、" 失敗した、そしてそれは、非同期スレッドです。スレッドがビジー状態になったときにディスクリプタを書き込むのは停止します。そこで私はディスクリプタを一つずつ書きます。大丈夫です。

関連する問題