如何获得在该地区的蓝牙配对设备 [英] How to get bluetooth paired devices in the area

查看:316
本文介绍了如何获得在该地区的蓝牙配对设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在该地区的所有设备的列表。

I want to get a list of all the devices in the area.

对于我正在请求与getBondedDevices(),然后进行探索保税设备。但是,这给了我所有绑定设备(在该地区与否)和发现的人的名单。如果我只是让发现(不使用getBondedDevices())我没有得到在该地区的绑定设备。

For that i'm requesting the bonded devices with getBondedDevices() and then making a discovery. But this gives me the list of all bonded devices (in the area or not) and the discoverable ones. And if I just make the discovery (without using getBondedDevices()) I don't get the bonded devices in the area.

所以我想获得与绑定设备列表(但只有那些在该地区)和发现设备。

So I want to get a list with the bonded devices (but only those in the area) and the discoverable devices.

感谢您的帮助。

推荐答案

我解决这个问题的方法是尝试并连接到该设备。它似乎只要工作,因为有问题的设备实际上是侦听连接。如果你不知道你正在处理你的设备的类型必须为扫描提供可用的服务。这是一个有点怪异,因为它似乎你只能通过使用反射调用getUuids。请参见下面code。

The way I solved this was to try and connect to the device. It seems to work as long as the device in question is actually listening for a connection. If you don't know what type of device you're dealing with you have to scan for the available services it provides. This is a bit weird since it seems you can only call the getUuids by using reflection. See code below.

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");
}

这篇关于如何获得在该地区的蓝牙配对设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆