title: Android pairing bluetooth devices without dialog with pin
body: <p>I want pairing my android cellphone and SPP bluetooth without dialog with pin and confirmation. I have this code, register <code>BroadcastReceiver</code>:
  </p>
  
  <pre class="lang-java prettyprint-override"><code>IntentFilter filter = new IntentFilter(ACTION_PAIRING_REQUEST);
                  registerReceiver(mPairReceiver, filter); 
                  pairDevice(device);
  </code></pre>
  
  <p><strong>pairDevice</strong> method:</p>
  
  <pre class="lang-java prettyprint-override"><code> private void pairDevice(BluetoothDevice device) {
      try {
  
          Method method = device.getClass().getMethod("createBond", (Class[]) null);
          method.invoke(device, (Object[]) null);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p><strong>BroadcastReceiver</strong>:</p>
  
  <pre class="lang-java prettyprint-override"><code>private final BroadcastReceiver mPairReceiver = new BroadcastReceiver() {
      public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          if (ACTION_PAIRING_REQUEST.equals(action)) {    
              System.out.println("ACTION_PAIRING_REQUEST");
              setBluetoothPairingPin(device);
          } 
      }
  };
  </code></pre>
  
  <p><strong>setBluetoothPairingPin</strong> method:</p>
  
  <pre class="lang-java prettyprint-override"><code>public void setBluetoothPairingPin(BluetoothDevice device)
  {
      byte[] pinBytes = convertPinToBytes("0000");
      try {
          Log.d(TAG, "Try to set the PIN");
          Method m = device.getClass().getMethod("setPin", byte[].class);
          m.invoke(device, pinBytes);
          Log.d(TAG, "Success to add the PIN.");
          try {
              device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, false);
              Log.d(TAG, "Success to setPairingConfirmation.");
          } catch (Exception e) {
              // TODO Auto-generated catch block
              Log.e(TAG, e.getMessage());
              e.printStackTrace();
          } 
      } catch (Exception e) {
          Log.e(TAG, e.getMessage());
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>but always show dialog with pin and confirmation.</p>