title: How to programmatically pair a bluetooth device on Android
body: <p>For my application I'm trying to programmatically pair a bluetooth device. I'm able to show the pairing dialog for the device I want to pair and I can enter a pincode. When I press "Pair" the dialog is removed and nothing happens.</p>
  
  <p>I only need to support devices with Android 2.0 and newer.</p>
  
  <p>Currently I am using the following code to start the pairing progress:</p>
  
  <pre><code>
  public void pairDevice(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);
          context.startActivity(intent);
      }
  </code></pre>
  
  <p>Before starting a pairing request I stop scanning for new devices.</p>
  
  <p>My application has the following bluetooth permissions:</p>
  
  <ul>
  <li>android.permission.BLUETOOTH_ADMIN</li>
  <li>android.permission.BLUETOOTH</li>
  </ul>