如何获得在Android的访问BluetoothPairingDialog.java?如何获得、Android、java、BluetoothPairingDialog

2023-09-07 23:11:55 作者:小三落伍了闺蜜走你

有没有什么办法可以有力地点击配对键,每当出现蓝牙配对对话框?

Is there any way to forcefully click on "pair button" whenever the Bluetooth pairing dialog appears?

推荐答案

我不知道怎么去进入配对对话框,但是我能够通过以下方式逼配对:

I don't know how to get access to the pairing dialog, but I was able to "force" pairing in the following way:

1)注册一个BroadcastReceiver的行动:

1) register a BroadcastReceiver for the action:

android.bluetooth.device.action.PAIRING_REQUEST

2)一旦接收到的动作,逼PIN码使用反射:

2) once the action is received, "force" the PIN using reflection:

String DEVICE_PIN = "12345";

final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

if (intent.getAction().equals("android.bluetooth.device.action.PAIRING_REQUEST")) {
    byte[] pin = (byte[]) BluetoothDevice.class.getMethod("convertPinToBytes", String.class).invoke(BluetoothDevice.class, ARDUINO_PIN);
    BluetoothDevice.class.getMethod("setPin", byte[].class).invoke(device, pin); 
}

它为我的GB和ICS(不知道这是否适用于更新的版本)。

It worked for me on GB and ICS (don't know if it works on newer releases).