简体   繁体   English

Android蓝牙配对意图

[英]Android Bluetooth pairing intent

I use the following code in an onItemClickListener 我在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);

It opens the pairing dialog where the user enters the pin, but it doesn't actually pair. 它会打开配对对话框,用户可以在其中输入图钉,但实际上并没有配对。

A very similar question has been asked before, but nobody answered it, hopefully I'll have more luck 之前有人问过一个非常类似的问题,但没人回答,希望我能有更多的运气

I don't know if you still have this problem since this question is really old, but I'm doing an app which does exactly this, so I'll share my code for pairing: 我不知道您是否仍然有这个问题,因为这个问题确实很老,但是我正在做一个可以完全做到这一点的应用程序,因此,我将分享我的配对代码:

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

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

Hopefully it will help somebody. 希望它将对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM