【问题标题】:How to retrieve Bluetooth device from Bluetooth Settings in Android development?如何在 Android 开发中从蓝牙设置中检索蓝牙设备?
【发布时间】:2016-07-05 22:44:24
【问题描述】:

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

现在我知道可以使用蓝牙适配器、蓝牙套接字和蓝牙设备从应用程序本身完成搜索、配对和连接,但我想知道是否有任何方法可以使用蓝牙设置进行配对和连接,然后将连接的设备放入我的应用程序。

感谢您的宝贵时间!

【问题讨论】:

    标签: android bluetooth android-bluetooth


    【解决方案1】:

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

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

    一旦你有了你的设备,你就可以调用connect

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 2023-03-23
      • 1970-01-01
      相关资源
      最近更新 更多