I use the following code in an 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.