How can I avoid or dismiss Android's Bluetooth pairing notification when I am doing programmatic pairing?

前端 未结 3 1799
陌清茗
陌清茗 2020-11-29 16:52

I have an app where I am programmatically controlling Bluetooth pairing and unpairing. I can pair before connection and unpair afterwards. The reason I need to do this is

相关标签:
3条回答
  • 2020-11-29 17:32

    Since Android API 19 Google switched these Methods to public Methods, so there is no need for Reflection any more. :)

    0 讨论(0)
  • 2020-11-29 17:36

    Do this in the PAIRING_REQUEST notification event:

    BluetoothDevice localBluetoothDevice = (BluetoothDevice)intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
    
    Class localClass = localBluetoothDevice.getClass();
    Class[] arrayOfClass = new Class[0];
    localClass.getMethod("cancelPairingUserInput", arrayOfClass).invoke(paramBluetoothDevice, null)).booleanValue();
    

    But you gotta tell me how did you pair your remote device without the user to enter Passkey/PIN? off course, you know the PIN for the remote device which is trying to pair to your device but how did you provide that PIN to the remote device.

    0 讨论(0)
  • 2020-11-29 17:44

    Try setting the confirmation first in the PAIRING_REQUEST

    BluetoothDevice device = intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
    
    device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true);
    device.getClass().getMethod("cancelPairingUserInput").invoke(device);
    

    This worked for me between two Android devices using RFCOMM but I'm not entering any PINs

    0 讨论(0)
提交回复
热议问题