gpt4 book ai didi

android - 在进行编程配对时,如何避免或关闭 Android 的蓝牙配对通知?

转载 作者:IT王子 更新时间:2023-10-28 23:55:06 24 4
gpt4 key购买 nike

我有一个应用程序,我在其中以编程方式控制蓝牙配对和取消配对。我可以在连接之前配对并在之后取消配对。我需要这样做的原因是特定于我的应用程序,而不是我的问题范围。

基本上我在做的是:

  1. 获取 ibIBluetooth 对象的引用,如 this answer 中所述
  2. android.bluetooth.device.action.PAIRING_REQUEST
  3. 注册一个 BroadcastReceiver
  4. 调用ib.createBond(address)
  5. 等待 BroadcastReceiver 触发
  6. 使用 convertPinToBytes() 将用户 pin 转换为字节
  7. 在 BroadcastReceiver 中调用 ib.setPin(address, pinBytes)

无论如何,这种方法效果很好,除了当我进行配对时,我会在状态栏中收到一条通知,要求用户输入 PIN 码以完成配对。但这实际上是不必要的,因为当用户看到这个时,我的应用程序已经使用了 setPin()。我真的很希望该通知 a) 根本不出现,或者 b) 以某种方式自动关闭。

我知道这甚至不可能,但我想如果有人有创意我会问。

最佳答案

尝试先在PAIRING_REQUEST

中设置确认
BluetoothDevice device = intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");

device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true);
device.getClass().getMethod("cancelPairingUserInput").invoke(device);

这在使用 RFCOMM 的两台 Android 设备之间对我有用,但我没有输入任何 PIN 码

关于android - 在进行编程配对时,如何避免或关闭 Android 的蓝牙配对通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7337032/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com