1

I know this question has already been asked but It does not work for me. I want to automatically pair 2 devices without having a pairing notification on my device. I followed the instruction here: How to pair Bluetooth device programmatically Android but it does not work. Indeed, I still have a pairing notification. Here is my code:

IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
    final BroadcastReceiver mReceiver2 = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)) {
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    int pin=intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 0);
                    byte[]  pinBytes = Integer.toString(pin).getBytes();
                    device.setPin(pinBytes);
                    boolean b = device.createBond();
                }
            }
        }
    };
    registerReceiver(mReceiver2, filter2);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Bazouk55555
  • 557
  • 6
  • 24

0 Answers0