小编Kir*_*415的帖子

在 Android Studio 中配对蓝牙设备

我正在创建一个应通过蓝牙连接到特定设备的应用程序。

我希望我的应用程序与此设备连接,无论它是否已配对。

现在我有这个

private void findDevice() {
    Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            if (device.getName().equals(DEVICE_NAME)) {
                bluetoothDevice = device;
                deviceFound = true;
                break;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但此功能仅连接到配对设备。如果我的设备尚未配对,我想配对它。不知道该怎么做。

有人可以给我任何建议吗?

java android bluetooth

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

bluetooth ×1

java ×1