【问题标题】:How do I suppress the bluetooth pairing request dialog in Android(api 19)?如何抑制 Android(api 19)中的蓝牙配对请求对话框?
【发布时间】:2014-03-22 21:33:10
【问题描述】:

我正在使用 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);
            }
        }
    }
    };

【问题讨论】:

    标签: android bluetooth


    【解决方案1】:

    你有什么运气吗? 我也做过同样的事情...下面应该会有所帮助....

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

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

    垫子

    【讨论】:

    • 我们实际上转向了蓝牙 4.0 和一系列全新的问题。我从来没有让配对被抑制。
    【解决方案2】:

    我使用Xamarin,但应该有一个 java 等价物。

    我在设置 pin 后调用方法InvokeAbortBroadcast()

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多