代码之家  ›  专栏  ›  技术社区  ›  Master Crouch

Android BLE:成功将ENABLE\u NOTIFICATION\u VALUE写入BluetoothGattDescriptor,但onCharacteristicChanged从未触发

  •  1
  • Master Crouch  · 技术社区  · 7 年前

        boolean success = mBluetoothGatt.setCharacteristicNotification(characteristic, true);
        Log.e(TAG, "set char notification = " + (success ? "It worked :)" : "It did not work :("));
    
        if (UUID_DATA_PACKET.equals(characteristic.getUuid())) {
            BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
                    UUID.fromString(EkoCoreGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
    
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    
            success = mBluetoothGatt.writeDescriptor(descriptor);
            Log.e(TAG, "set descriptor = " + descriptor.getCharacteristic().getWriteType() + ", success = " + (success ? "It worked :)" : "It did not work :("));
        }
    

    1 回复  |  直到 7 年前
        1
  •  1
  •   Master Crouch    7 年前

    在编写描述符之前添加以下内容修复了我的问题:

    characteristic.setWriteType(BluetoothGattCharacteristic.WRIT‌​E_TYPE_DEFAULT);