Example for subscribing for BLE indicate in android

匿名 (未验证) 提交于 2019-12-03 00:59:01

问题:

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.



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