如何获得在Android的访问BluetoothPairingDialog.java? [英] How to get access to the BluetoothPairingDialog.java in android?

查看:282
本文介绍了如何获得在Android的访问BluetoothPairingDialog.java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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).

这篇关于如何获得在Android的访问BluetoothPairingDialog.java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆