How to Write consecutive Characteristic fast and stable for BLE in Android?

前端 未结 1 1803
情话喂你
情话喂你 2021-02-07 10:45

I am developing BLE in Android , I can scan, connected and write characteristic to to the BLE device.

I call the following function to pass BluetoothGatt a

相关标签:
1条回答
  • The read/write characteristic system in Android's Bluetooth stack isn't good at queueing up multiple operations. You need to wait for operations to complete before sending along another one. In addition, since your code is using AsyncTask, you will get parallel execution of tasks on some devices, so even the requests aren't being serialized when you repeatedly hit the button.

    To get stable results from the framework, you will need to queue up those requests yourself and wait for BluetoothGattCallback onCharacteristicWrite() to trigger before sending the next command. Your code needs to synchronize all access to the GATT object, so that the next writeCharacteristic() never comes until the completion callback fires for the previous request.

    0 讨论(0)
提交回复
热议问题