Reputation: 11
I got Mac book (OS X 10.11.6) acts as BLE Central device and Android Phone (Os 6.0) acts as Peripheral device.
Android Peripheral advertises characteristic-1 with properties BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_NOTIFY
Mac book(BLE Central) discovers Android Peripheral successfully with characteristic-1. However, when BLE Central tries to do setNotifyValue:YES for this characteristic fails with below error.
Error changing notification state:Error Domain=CBErrorDomain Code=0 "Unknown error." UserInfo={NSLocalizedDescription=Unknown error.}
Incase, if the Peripheral device is an iPhone(iOS) which has similar characteristic then setNotifyValue:YES gets succeeded.
I tried the below combinations for the characteristic-1 with
1- BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_INDICATE
2- BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY
3- BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_INDICATE
But unfortunately none of them worked.
Can some one help me in setting notifiable to YES on Mac OS X Central for Android Peripheral characteristic ?
Upvotes: 1
Views: 1242
Reputation: 1
On android, you need set descriptor to enable notification.
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);
Upvotes: 0