我想得到这个地区所有设备的清单。
为此,我使用getBondedDevices()请求绑定的设备,然后进行一个发现。但这给了我一个列表,列出了所有的保税设备(无论是否在该地区)和可发现的设备。如果我只是发现(不使用getBondedDevices()),就不会得到该区域的绑定设备。
所以我想得到一个列表,上面有绑定的设备(但仅限于区域内的设备)和可发现的设备。
谢谢你的帮助

最佳答案

我解决这个问题的方法是尝试连接到设备。只要所讨论的设备实际上在监听连接,它似乎就可以工作。如果你不知道你要处理的设备类型,你必须扫描它提供的可用服务。这有点奇怪,因为似乎您只能通过使用反射调用getuuid。见下面的代码。

try {
    Method method = device.getClass().getMethod("getUuids"); /// get all services
    ParcelUuid[] parcelUuids = (ParcelUuid[]) method.invoke(device); /// get all services

    BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(parcelUuids[0].getUuid()); ///pick one at random
    socket.connect();
    socket.close();
} catch (Exception e) {
    Log.e("BluetoothPlugin", device.getName() + "Device is not in range");
}

关于android - 如何获得该地区的蓝牙配对设备,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6928595/

10-11 20:09
查看更多