我正在开发一个从BLE设备读取数据的android应用程序.我在这里遇到了很多关于如何读取多个特征的解决方案,其中大部分都是建议的队列.
我确实实现了Queue方法,一切都在我的代码中正常工作.我开始这个主题的原因是找到最好的和最有效的解决方案,并清除我对某些BLE服务特性如何工作的疑虑.
我已经将以下两个链接作为参考,这有助于我使我的代码工作.
来源1:
来源2:
我的要求是阅读心率测量和电池水平.最初我尝试将心率和电池特性添加到队列中,然后为每个添加的元素调用读/设置方法.
主要活动:
private void displayGattServices(List gattServices)
{
// get the required service & characteristics
................
................
// add the characteristics via Queue
hRM_characteristicReadQueue.add(characteristics);
// Initiate read/set methods
read_Characteristic();
};
private void read_Characteristic()
{
bluetoothHDPService.read(hRM_characteristicReadQueue.element());
bluetoothHDPService.set(hRM_characteristicReadQueue.element(),true);
hRM_characteristicReadQueue.remove();
};
bl