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

时间:2016-08-25 12:47:32

标签: android ios macos

问题:

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

Android外围设备使用属性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吗?

1 个答案:

答案 0 :(得分:0)

在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);
相关问题