配对时,如何将用户的 pin 码应用于从 android 到外设 BLE 的 setpin 对话框?

问题描述 投票:0回答:1

我对 android 和外围设备 (nrf) 之间的 BLE 配对有一些问题。我通过 nfc(或串行...)从外围设备获取 android 中的 pin 代码,我想使用该 pin 代码与外围设备配对,但每次配对完成时,android 对话框中显示的 pin 代码随机设置为外围设备.

示例:我有从外围设备“112456”发送的密码 but pincode in dialog í random



            final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
            pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
            context.getApplicationContext().registerReceiver(pairingRequestReceiver, pairingRequestFilter);

....
  private final BroadcastReceiver pairingRequestReceiver = new BroadcastReceiver()
    {
        @Override
        public void onReceive(Context context, Intent intent)
        {
            if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(intent.getAction()))
            {
                final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR);
                device.createBond();
                if (type == BluetoothDevice.PAIRING_VARIANT_PIN) {
                    if (device.setPin(Util.parsePinToByteArray(currentPin))) {
                        Log.e("BLE","setPin success " + currentPin);
                    } else {
                        Log.e("BLE", "ERROR: setPin");
                    }
                    if (device.setPairingConfirmation(true)) {
                        Log.e("BLE","setPairingConfirmation success");
                    } else {
                        Log.e("BLE", "ERROR: setPairingConfirmation");
                    }
                    abortBroadcast();
                }
                else {
                    Log.e("BLE","Unexpected pairing type: " + type);
                }
            }
        }
    };

日志猫:return type always 3 而且我不知道如何将配对类型设置为 BluetoothDevice.PAIRING_VARIANT_PIN 因为类型总是返回 3 (PAIRING_VARIANT_CONSENT)

请帮我解决这个问题。非常感谢

java android bluetooth-lowenergy android-bluetooth
1个回答
0
投票

如果我正确理解了你的问题,那么你可以通过更改 nRF 设备上的代码来解决这个问题。具体来说,您需要更改 nRF 设备的 IO 功能,这样配对对话框就不会出现,您要么得到是/否对话框,要么配对就发生了。

具体来说,当你在两个设备之间配对时,配对过程将取决于两个设备的IO能力,IO能力是以下值之一:-

  • 无输入无输出
  • 仅显示
  • 仅键盘
  • 显示是否
  • 键盘显示

Android 的 IO 能力总是在系统级别设置为 KeyboardDisplay。因此,如果远程设备(在您的情况下是 nRF 外围设备)支持 KeyboardDisplay 或 DisplayOnly,那么在 Android 设备上,您将被要求输入与北欧设备上可能显示的内容相匹配的 PIN 码。但是,如果远程设备不支持显示器或键盘,则 Android 设备上的配对提示将简化为简单地接受或拒绝配对。

总而言之,您的解决方案是将 nRF 外围设备上的 IO 功能更改为 NoInputNoOutput。这样,Android 设备上就会显示提示,您应该能够毫无问题地接受配对。

一些相关的有用链接:-

© www.soinside.com 2019 - 2024. All rights reserved.