Example for subscribing for BLE indicate in android

核能气质少年 提交于 2019-12-11 03:06:24

问题


I have connected to a bluetooth device. I am able to read charectristic using

mGatt.readCharacteristic(getMiliService().getCharacteristic(uuid));

But I am not able to register indicate for a characteristic.
What I tried

boolean flag1 = m_Gatt.setCharacteristicNotification(bluetoothgattcharacteristic, flag);

BluetoothGattDescriptor descriptor= bluetoothgattcharacteristic.getDescriptor(Helper.UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mGatt.writeDescriptor(descriptor);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
mGatt.writeDescriptor(descriptor);

and waiting for

onCharacteristicChanged(BluetoothGatt bluetoothgatt, final BluetoothGattCharacteristic characteristic)

method getting called. which never happend.
I am not sure what I am missing here.
Can anyone give a working example for indicate?


回答1:


It is important for you to note that Android BLE stack allows you to write characteristics one at a time only.

And this is a working example that helped me a lot:

https://github.com/devunwired/accessory-samples/blob/master/BluetoothGatt/src/com/example/bluetoothgatt/MainActivity.java




回答2:


this project allow you to connect to a BLE device, and contain all the methods of permission: write,read,indicate and notification

for the indication, you must set the CCCD to it's value. you will find this in the project.



来源:https://stackoverflow.com/questions/29073525/example-for-subscribing-for-ble-indicate-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!