2
votes

I am working on BLE,

i would like to know how to programmatically pair Bluetooth without entering PIN manually the following code i am using with that it opens pairing dialog asking pin but i want direct pairing without entering pin

public void pairDevice2(BluetoothDevice device)
{
    String ACTION_PAIRING_REQUEST = "android.bluetooth.device.action.PAIRING_REQUEST";
    Intent intent = new Intent(ACTION_PAIRING_REQUEST);
    String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
    intent.putExtra(EXTRA_DEVICE, device);
    String EXTRA_PAIRING_VARIANT = "android.bluetooth.device.extra.PAIRING_VARIANT";
    int PAIRING_VARIANT_PIN = 0;
    intent.putExtra(EXTRA_PAIRING_VARIANT, PAIRING_VARIANT_PIN);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

I want to pair it automatically when it is scanned.

1

1 Answers

1
votes

Look at insecure Bluetooth sockets, e.g. createInsecureRfcommSocketToServiceRecord. That way you can establish connection without pairing process.