首页 > 解决方案 > Cannot find PairingParams.PAIRING_VARIANT_CONSENT in Xamarin.Android

问题描述

I have faced with issue that when pairing request happens I got the following PairingParams.PAIRING_VARIANT_CONSENT (= 3) pairing variant, but it is absent in ...

object obj = intent.GetParcelableExtra(BluetoothDevice.ExtraDevice);
BluetoothDevice device = (obj as BluetoothDevice)!;
var extraPairingVariant = intent.GetIntExtra(BluetoothDevice.ExtraPairingVariant, 0);
switch (extraPairingVariant)
{
  case BluetoothDevice.PairingVariantPin:
  {
    ...
  }
    break;
  case BluetoothDevice.PairingVariantPasskeyConfirmation:
  {
    ...
  }
    break;
  case \* 3, what constant should be here ?? *\
  {
    ...
  }
    break;
}

... BluetoothDevice do not contain the something like PAIRING_VARIANT_CONSENT ...

Does somebody faced with the same issue ?

标签: xamarin.androidandroid-bluetooth

解决方案


就我而言,我呼吁abortBroadcast()不显示 pin 对话框,但前提是BluetoothDevice.ExtraPairingVariantis not 3。否则,必须显示一个对话框让用户接受配对。当您移除已配对的设备并要求再次配对时,会出现此状态。(https://developer.android.com/reference/com/google/android/things/bluetooth/PairingParams.html#pairing_variant_consent

BluetoothDevice device = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice);
if (action == BluetoothDevice.ActionPairingRequest)
        {
            device.SetPin(System.Text.Encoding.UTF8.GetBytes("####"));
            int exraPairingVariant = intent.GetIntExtra(BluetoothDevice.ExtraPairingVariant, 0);
            if (exraPairingVariant == BluetoothDevice.PairingVariantPasskeyConfirmation || exraPairingVariant == BluetoothDevice.PairingVariantPin)
            {
                InvokeAbortBroadcast();
            }
        }

推荐阅读