Android:以编程方式配对蓝牙设备

时间:2015-02-03 23:40:30

标签: android bluetooth android-bluetooth pairing

我正在尝试以编程方式将手机与蓝牙设备配对。虽然我能够这样做,但仍会弹出一个窗口,要求用户输入PIN码。 有没有办法隐藏这个窗口?

我在做什么:

获取目标的BluetoothDevice个对象;

尝试创建债券:

 Class class1 = Class.forName("android.bluetooth.BluetoothDevice");
 Method createBondMethod = class1.getMethod("createBond");
 createBondMethod.invoke(device);

聆听BluetoothDevice.ACTION_PAIRING_REQUEST我尝试设置Pin:

Method m = device.getClass().getMethod("setPin", byte[].class);
m.invoke(device, pin);
device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true);

虽然我知道Android可能由于恶意软件而无法给我们这个选项,但我非常想隐藏要求输入PIN码的窗口(这是不必要的,因为即使用户不这样做,绑定也已完成将任何数据输入该窗口)由于我的应用程序针对孩子,他们可能无法自己完成配对。

0 个答案:

没有答案