Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- int pin = intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 0);
- Class<?> btDeviceInstance = Class.forName(BluetoothDevice.class.getCanonicalName());
- Method convert = btDeviceInstance.getMethod("convertPinToBytes", String.class);
- byte[] pinBytes = (byte[]) convert.invoke(device, pin);
- Method setPin = btDeviceInstance.getMethod("setPin", byte[].class);
- Boolean success = (Boolean) setPin.invoke(device, pinBytes);
- if (success)
- Log.d(TAG, "Success to add the PIN.");
- device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true);
- setBluetoothPairingPin(device, String.valueOf(pin));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement