gpt4 book ai didi

java - 安卓蓝牙 : descriptor/characteristic write fails with GATT_WRITE_NOT_PERMITTED

转载 作者:行者123 更新时间:2023-11-30 10:39:28 25 4
gpt4 key购买 nike

我正在尝试从我的移动设备(扫描仪)写入已连接的可穿戴设备(广播设备)中的描述符。

在可穿戴设备上,我将描述符定义为

readCharacteristic = new BluetoothGattCharacteristic(Constants.READ_CHAR_UUID,
BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY,
BluetoothGattCharacteristic.PERMISSION_READ);
readCharacteristic.addDescriptor(new BluetoothGattDescriptor(Constants.NOTIFY_DESC_UUID,
BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_WRITE));

在移动设备上,我尝试用

写入特性
BluetoothGattDescriptor descriptor = readCharacteristic.getDescriptor(Constants.NOTIFY_DESC_UUID);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)

不幸的是,这失败了,状态为 GATT_WRITE_NOT_PERMITTED

@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {

}

在可穿戴 logcat 中,我看到 gatts_write_attr_perm_check - GATT_WRITE_NOT_PERMIT。

当我尝试写入特征时,同样的事情发生了。

奇怪的是,使用 iOS 扫描仪时写入成功。这意味着可穿戴部分是正确的。

我在 list 中有权限:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

使用的设备:联系 5x 6.0.1 API 23,摩托 360 5.1.1 API 22

有谁知道如何解决这个描述符/特征写入问题?

最佳答案

From my mobile device(scanner) I am trying to write to a descriptor in a connected wearable(broadcaster).

在这种情况下,它应该是移动设备(中央)和连接的可穿戴设备(外围设备)。 scanner和broadcaster实际上并没有建立BLE连接。

关于写入失败,当应用程序尝试将数据写入数据库时​​,在函数 gatts_write_attr_perm_check 处被拒绝。代码如下:

else if (!(perm & GATT_WRITE_ALLOWED))
{
status = GATT_WRITE_NOT_PERMIT;
GATT_TRACE_ERROR( "gatts_write_attr_perm_check -GATT_WRITE_NOT_PERMIT");
}

所以,问题是记录的 perm 不符合 GATT_WRITE_ALLOWED,即

> (GATT_PERM_WRITE | GATT_PERM_WRITE_ENCRYPTED |\
> GATT_PERM_WRITE_ENC_MITM | GATT_PERM_WRITE_SIGNED |\
> GATT_PERM_WRITE_SIGNED_MITM)

那么,你能不能试一下:1) 取消配对设备并重新配对设备。2)启用高安全级别,例如启用 MITM。

我假设您想要启用通知,对吗?我无法获得您拥有的所有代码,但您也可以试试这个(引用自 Android 网站):

private BluetoothGatt mBluetoothGatt;
BluetoothGattCharacteristic characteristic;
boolean enabled;
...
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
...
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);

关于java - 安卓蓝牙 : descriptor/characteristic write fails with GATT_WRITE_NOT_PERMITTED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39289594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com