Android: BLE how to read multiple Characteristics?

前端 未结 3 771
予麋鹿
予麋鹿 2020-12-05 01:24

Android BLE API methods for reading some characteristics are Asynchronous in nature and when you request some value, your GATT callback method is called.

If you requ

相关标签:
3条回答
  • 2020-12-05 01:32

    Possible Solution #6: try the Task feature provided by https://github.com/BoltsFramework/Bolts-Android :-)

    0 讨论(0)
  • 2020-12-05 01:33

    Pseudo code:

    1) Use a FIFO Queue or Priority Queue depends upon your business logic

    2) insert all the characteristics you want to read

    3) call your requestCharacteristics method so that it can start consuming your Queue

    4) from your onCharacteristicsRead call see if the size of the queue is greater than Zero request one more.. be sure to peek() from here

    5) now on your requestCharacteristics method do the poll() and request BLE GATT for characteristic.

    0 讨论(0)
  • 2020-12-05 01:34

    You might have discovered it yourself already, but it might be useful for others.

    I didn't understand if that so why they made methods Async.

    They probably did it because sending a read-request to another device in synchronous execution would mean you cannot do anything with your app until an answer is received. By making it Async you can do other stuff, but no other bluetooth requests.

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