1

我在 onItemClickListener 中使用以下代码

            BluetoothDevice device;
        device = btAdapter.getRemoteDevice(address);
        Intent intent1 = new Intent("android.bluetooth.device.action.PAIRING_REQUEST");
        intent1.putExtra("android.bluetooth.device.extra.DEVICE", device);
        intent1.putExtra("android.bluetooth.device.extra.PAIRING_VARIANT", 0);
        intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent1);

它会打开用户输入密码的配对对话框,但实际上并没有配对。

之前有人问过一个非常相似的问题,但没有人回答,希望我能有更多的运气

4

1 回答 1

2

我不知道你是否还有这个问题,因为这个问题真的很老了,但我正在做一个应用程序正是这样做的,所以我将分享我的配对代码:

BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
device = bluetooth.getRemoteDevice(address);

// Opens the pin dialog and then bonds the device
device.createBond();

希望它会帮助某人。

于 2017-04-09T18:22:41.477 回答