我试着写一个BLE设备的特性。根据文档,它的特点是能够读写,有不同的用法。我已经成功地阅读了它,但我在写作方面遇到了一些问题。每次我试图写入它时,onWriteCharacterstic函数都会带有一个状态代码6,它应该是GATT_REQUEST_NOT_SUPPORTED。
我不太确定是什么引起的。我向我的应用程序添加了所有必要的蓝牙权限,文档表明它能够编写。
我的代码看起来有点像(简化):
@Override
public void onServicesDiscovered( BluetoothGatt gatt, int status ){
if( status == BluetoothGatt.GATT_SUCCESS ){
mGatt = gatt;
mService= gatt.getService(UUID_SERVICE);
mChar = mService.getCharacteristic(UUID_CHAR);
byte[] value = {...}
mChar.setValue(value);
boolean retval = mGatt.writeCharacteristic(mChar); //retval is true
}
}
@Override
public void onCharacteristicWrite (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)
{
... //status here is 6
}我还检查了函数getProperties()和getPermissions()的特性。getPermissions()函数返回0,我无法与android文档中的任何内容相匹配,而getProperties()返回10,这也很奇怪。有了属性,就意味着它支持通知,而它不支持通知。
发布于 2017-07-25 08:17:43
好像是手机出了问题。当它关掉蓝牙几个小时后,它就正常工作了。
https://stackoverflow.com/questions/45280830
复制相似问题