简体   繁体   English

如何用Android BLE“ping”

[英]How to “ping” with Android BLE

Is there any simple way to check if an existing BluetoothDevice object is still reachable without performing a new scan? 有没有简单的方法来检查现有的BluetoothDevice对象是否仍然可以在不执行新扫描的情况下访问?

I am writing an app that scans for devices and goes through connecting to each one at a time to populate a device list with some information about each device, which I acquire while connected to the device. 我正在编写一个扫描设备的应用程序,并一次连接到每个设备,以填充设备列表,其中包含有关每个设备的一些信息,这些信息是我在连接到设备时获取的。 Every now and again, I would like to go through my device list and remove any devices that are no longer active/in range. 我一次又一次地想通过我的设备列表并删除任何不再活动/范围内的设备。 What is the best way to do this? 做这个的最好方式是什么?

You could try to connect to the devices to find out if they are still around, but keep in mind, that devices will change their mac address from time to time. 您可以尝试连接到设备以查明它们是否仍然存在,但请记住,设备将不时更改其mac地址。 I would suggest to use scanning to find out if the devices are still around. 我建议使用扫描来确定设备是否还在。 Also you may want to add an identifier into the advertisement packages, so you don't need to relay on the mac address. 此外,您可能希望在广告包中添加标识符,因此您无需在mac地址上进行中继。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM