如何从Android开发中的蓝牙设置中检索蓝牙设备?

时间:2016-03-19 01:47:04

标签: android bluetooth android-bluetooth

我正在设计一个应用程序,我只需点击一下按钮即可打开蓝牙设置。现在,当我进行设置时,我将配对并连接到附近的任何蓝牙设备。当我按下后退按钮&回到应用程序,我希望能够在我的应用程序中将该连接的设备检索为BluetoothDevice,以便我可以从我的应用程序进一步操作它。

现在我知道搜索,配对和可以使用BluetoothAdapter,BluetoothSocket& amp;蓝牙设备,但我想知道是否有任何方式配对&使用蓝牙设置连接然后在我的应用程序中获取连接的设备。

感谢您的时间!

1 个答案:

答案 0 :(得分:0)

您可能需要查询已绑定的设备。但您需要知道UUID或设备名称,以便获得正确的配对设备

Set<BluetoothDevice> devices = adapter.getBondedDevices();
if (devices != null) {
    for (BluetoothDevice device : devices) {
        if (deviceName.equals(device.getName())) {
            result = device;
            break;
        }
    }
}

拥有设备后,您可以调出connect

相关问题