当我进行编程配对时,如何避免或忽略 Android 的蓝牙配对通知?
我有一个应用程序,可以通过编程方式控制蓝牙配对和取消配对。我可以在连接前配对并在连接后取消配对。我需要这样做的原因是特定于我的应用程序的,而不是在我的问题范围内。
基本上我正在做的是:
- 获取对
IBluetooth
对象的引用ib
,如 这个答案 - 为
android.bluetooth.device.action.PAIRING_REQUEST
调用注册一个 - BroadcastReceiver
ib.createBond(address)
- 等待 BroadcastReceiver 触发 使用
- convertPinToBytes()
- 调用来自 BroadcastReceiver 的 ib.setPin(address, pinBytes)
无论如何,这种方法效果很好,除了当我进行配对时,我在状态栏中收到一条通知,要求用户输入PIN 码以完成配对。但这实际上是不必要的,因为当用户看到这个时,我的应用程序已经使用了 setPin()
。我真的希望该通知要么a)根本不出现,要么b)以某种方式自动消除。
我意识到这甚至可能是不可能的,但我想我会问,以防有人有创意。
I have an app where I am programmatically controlling Bluetooth pairing and unpairing. I can pair before connection and unpair afterwards. The reason I need to do this is specific to my application and not in the scope of my question.
Basically what I am doing is:
- Get a reference
ib
toIBluetooth
object as described in this answer - Register a BroadcastReceiver for
android.bluetooth.device.action.PAIRING_REQUEST
- Call
ib.createBond(address)
- Wait for BroadcastReceiver to trigger
- Convert user pin into bytes with convertPinToBytes()
- Call
ib.setPin(address, pinBytes)
from within BroadcastReceiver
Anyways, this approach works great, except for the fact that when I do the pairing, I get a notification in the Status bar requesting that the user enter a PIN to complete the pairing. But this is in fact unnecessary, because by the time the user sees this, my app has already used setPin()
. I'd really like for that notification to either a) not appear at all, or b) be dismissed automatically somehow.
I realize this may not even be possible, but I thought I would ask in case someone has a creative idea.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试首先在
PAIRING_REQUEST
中设置确认这对我来说在使用 RFCOMM 的两个 Android 设备之间有效,但我没有输入任何 PIN
Try setting the confirmation first in the
PAIRING_REQUEST
This worked for me between two Android devices using RFCOMM but I'm not entering any PINs
从 Android API 19 开始,Google 将这些方法切换为公共方法,因此不再需要反射。 :)
Since Android API 19 Google switched these Methods to public Methods, so there is no need for Reflection any more. :)
在 PAIRING_REQUEST 通知事件中执行此操作:
但是您必须告诉我如何在用户不输入密码/PIN 的情况下配对远程设备?当然,您知道尝试与您的设备配对的远程设备的 PIN,但您如何将该 PIN 提供给远程设备。
Do this in the PAIRING_REQUEST notification event:
But you gotta tell me how did you pair your remote device without the user to enter Passkey/PIN? off course, you know the PIN for the remote device which is trying to pair to your device but how did you provide that PIN to the remote device.