Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android开发中从蓝牙设置中检索蓝牙设备?_Android_Bluetooth_Android Bluetooth - Fatal编程技术网

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

如何在Android开发中从蓝牙设置中检索蓝牙设备?,android,bluetooth,android-bluetooth,Android,Bluetooth,Android Bluetooth,我正在设计一个应用程序,我希望通过点击按钮打开蓝牙设置。现在,当我进行设置时,我将配对并连接到附近的任何蓝牙设备。当我按下后退按钮并返回应用程序时,我希望能够在我的应用程序中将连接的设备检索为Bluetooth设备,以便我可以从我的应用程序中进一步操作它 现在我知道可以使用BluetoothAdapter、BluetoothSocket和BluetoothDevice从应用程序本身进行搜索、配对和连接,但我想知道是否有任何方法可以使用Bluetooth设置进行配对和连接,然后在我的应用程序中获取

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

现在我知道可以使用BluetoothAdapter、BluetoothSocket和BluetoothDevice从应用程序本身进行搜索、配对和连接,但我想知道是否有任何方法可以使用Bluetooth设置进行配对和连接,然后在我的应用程序中获取连接的设备


谢谢你抽出时间

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

Set<BluetoothDevice> devices = adapter.getBondedDevices();
if (devices != null) {
    for (BluetoothDevice device : devices) {
        if (deviceName.equals(device.getName())) {
            result = device;
            break;
        }
    }
}
Set devices=adapter.getBondedDevices();
如果(设备!=null){
用于(蓝牙设备:设备){
if(deviceName.equals(device.getName())){
结果=设备;
打破
}
}
}
一旦您拥有了设备,就可以envoke
connect