在Mac BLE Central上设置特征通知Android(6.0)BLE外围设备特性失败

问题:

我得到了Mac书(OS X 10.11.6)作为BLE Central设备,而Android Phone(Os 6.0)作为外围设备。

Android Peripheral通过属性BluetoothGattCharacteristic.PROPERTY_WRITE |来宣传特征-1 BluetoothGattCharacteristic.PROPERTY_NOTIFY

Mac book(BLE Central)使用特征-1成功发现Android外设。 但是,当BLE Central尝试执行setNotifyValue:YES时 ,此特性会失败并出现以下错误。

更改通知状态时出错:错误域= CBErrorDomain代码= 0“未知错误”。 UserInfo = {NSLocalizedDescription =未知错误。}

如果外围设备是具有类似特征的iPhone(iOS) ,那么setNotifyValue:YES会成功。

我尝试了以下组合的特征-1

1- BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_INDICATE

2- BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY

3- BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_INDICATE

但不幸的是,他们都没有工作。

有人可以帮我在Mac OS X Central上设置适用于Android周边特性的YES吗?

在android上,你需要设置描述符来启用通知。

BluetoothGattService gattService = new BluetoothGattService(YOUR_SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY); BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(YOUR_CHARACTERISTIC_UUID, BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_INDICATE, BluetoothGattCharacteristic.PERMISSION_WRITE); BluetoothGattDescriptor descriptor = new BluetoothGattDescriptor(UUID.fromString("00002902-0000-1000-8000-00805F9B34FB"), BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_WRITE); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); characteristic.addDescriptor(descriptor); gattService.addCharacteristic(characteristic);