如何在Android(api 19)中禁止蓝牙配对请求对话框?

时间:2014-03-22 21:33:11

标签: android bluetooth

我使用api 19中的setPin()自动与蓝牙设备配对。我通过广播接收器...检查配对请求,然后自动配对。这样做的原因是,一旦用户在我的应用中更改了它,就不会让用户重新输入。

有没有办法抑制蓝牙配对请求的通知/对话框?我的代码正确更改了手机上的PIN并连接到设备,因此该部分不是问题。我只是想摆脱对话框/弹出窗口,这样用户就不会感到困惑。如果它弹出一秒钟,我不介意,只要它自动关闭。

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        // Get the BluetoothDevice object from the Intent
        if (btDevice.ACTION_PAIRING_REQUEST.equals(action)) {
            Log.i(TAG, "XXXXXXXXXXXXXX PAIRING REQUEST RECEIVED XXXXXXXXXXXXXXXX");

            int bondState = btDevice.getBondState();

            if (bondState == BluetoothDevice.BOND_NONE || bondState == BluetoothDevice.BOND_BONDING) {                  
                String pinString = settings.getString("com.hiqautomation.iopener.pin", null);

                byte[] pinBytes = pinString.getBytes();
                btDevice.setPin(pinBytes);
            }
        }
    }
    };

2 个答案:

答案 0 :(得分:0)

你有运气吗? 我做了同样的事......下面应该有所帮助......

    Method m = bt_device.getClass().getMethod("cancelBondProcess", (Class[]) null);
    m.invoke(bt_device, (Object[]) null);

出于兴趣,你是如何在输入引脚时隐藏软键盘的。这是我目前在https://stackoverflow.com/questions/25290319/android-how-to-disable-soft-keyboard-during-bluetooth-pairing

播放的问题

答案 1 :(得分:0)

我使用Xamarin,但应该有一个Java等效项。

设置引脚后,我调用方法InvokeAbortBroadcast()

 Device.SetPin(Encoding.ASCII.GetBytes(pin));
 InvokeAbortBroadcast();