title: android bluetooth pairing programmatically with pin without user pin input
body: <p>I looking to pair my android device to an arduino bluetooth shield, I managed to connect to it but it keeps asking me to put in the pincode manualy. </p>
  
  <p>My question is how do i make it so the app does this (fill in the pincode and connect with bluetooth) automatically? </p>
  
  <p>my code    </p>
  
  <pre><code>private byte[] convertPinToBytes(String s)
  {
      byte[] pin = s.getBytes();
      return pin;
  }
  
  byte[] pinBytes = convertPinToBytes("0000");
  
  try 
  {
       Log.d(TAG, "Try to set the PIN");
       m = device.getClass().getMethod("setPin", byte[].class);
       m.invoke(device, pinBytes);
       Log.d(TAG, "Success to add the PIN.");
       Toast.makeText(this, "Success to add the PIN", Toast.LENGTH_LONG).show();
  } 
  catch (Exception e) 
  {
       Log.e(TAG, e.getMessage());
       e.printStackTrace();
       Toast.makeText(this, "add pin failed. " + e.getMessage(), Toast.LENGTH_LONG).show();
  }
  </code></pre>
  
  <p>I need this for a project and I'm stuck for 2 days already,
  if someone could help me with this problem that would be awesome!</p>