Original URL: Http://stackoverflow.com/questions/24865120/any-way-to-implement-ble-notifications-in-android-l-preview
This question are not on Android Notificatinos, but BLE notifications (as the title may hint)
I have got basic BLE peripheral mode working on Android-l
Is there an any-to-implement BLE notifications in Android-l preview. I could do some thing like the following to make a charecteritic is able to notify, but trying to listen for
BluetoothGattCharacteristic firstServiceChar = new BluetoothGattCharacteristic( UUID.fromString(serviceOneCharUuid), BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PERMISSION_READ );
But the LightBlue app on IOS I cannot subscribe to this characteristic. apprently There is no API this could be use for respond to the calls when a char was subscribed (like there am in IOS)
Kindly share your code if you had successfully enabled BLE notifications on Android-l
On top of the What OP have done:
BluetoothGattCharacteristic firstServiceChar = new BluetoothGattCharacteristic(UUID.fromString(serviceOneCharUuid), BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PERMISSION_READ )
The next thing is to add a Client characteristic Configuration descriptor (UUID is the-the-bit version of the-the-bit 0x290 2 using the Bluetooth base UUID), so, the connected device can tell yours it wants notifications (or indications) , and then add this descriptor to your characteristic:
BluetoothGattDescriptor gD = new BluetoothGattDescriptor(UUID.fromString("00002902-0000-1000-8000-00805F9B34FB"), BluetoothGattDescriptor.PERMISSION_WRITE | BluetoothGattDescriptor.PERMISSION_READ);firstServiceChar.addDescriptor(gD);
That UUID was from the Bluetooth spec. Apparently a device subscribes to notifications by updating this descriptor ve got to handle the your bluetoothgattservercallback by overriding Ondescriptorwriterequest:
@Overridepublic void onDescriptorWriteRequest (BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) { btClient = device; // perhaps add to some kind of collection of devices to update? // now tell the connected device that this was all successfull btGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, value);}
Now update your value and notify the Connectee:
firstServiceChar.setValue("HI");btGattServer.notifyCharacteristicChanged(btClient, firstServiceChar, false);
Hopefully this quick and dirty code would help, because it is OP's code that I used in the first place to even get basic p Eripheral mode working:)
"Go" any-to-implement BLE notifications in Android-l preview----good