Advertisement
Guest User

Untitled

a guest
Jan 1st, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
  2. int pin = intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 0);
  3.  
  4. Class<?> btDeviceInstance = Class.forName(BluetoothDevice.class.getCanonicalName());
  5.  
  6. Method convert = btDeviceInstance.getMethod("convertPinToBytes", String.class);
  7.  
  8. byte[] pinBytes = (byte[]) convert.invoke(device, pin);
  9.  
  10. Method setPin = btDeviceInstance.getMethod("setPin", byte[].class);
  11. Boolean success = (Boolean) setPin.invoke(device, pinBytes);
  12. if (success)
  13. Log.d(TAG, "Success to add the PIN.");
  14.  
  15. device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true);
  16.  
  17. setBluetoothPairingPin(device, String.valueOf(pin));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement