Android 以编程方式蓝牙配对 [英] Android Programmatically Bluetooth Pairing

查看:25
本文介绍了Android 以编程方式蓝牙配对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用蓝牙接口以编程方式将我的手机与医疗传感器配对.我有连接设备所需的地址和 PIN 码,但我想避免用户交互(配对过程 - 传感器配置等)

I would like to programmatically pair my mobile phone with medical sensor using Bluetooth interface. I have address and PIN necessary for connecting to device but I would like to avoid user interaction (pairing process - sensor configuration etc.)

我尝试使用非官方蓝牙 API (http://code.google.com/p/android-bluetooth/) 但似乎这不适用于 Android 2.1 及更高版本(我的 LocalBluetoothDevice 始终为 NULL,并且人们在他们的论坛说这仅适用于 1.X 版本)

I tried using unofficial Bluetooth API (http://code.google.com/p/android-bluetooth/) but it seems that this doesn't for Android 2.1 and above (I got LocalBluetoothDevice allways NULL, and people on their forum said that this is only for 1.X versions)

我看到 Android API 具有在后台执行此配对的方法,但它们标有 @hide 注释.我如何访问它?

I saw that Android API has methods that do this pairing in background but they are labeled with @hide annotation. How do I access this?

有人成功了吗?(以编程方式配对)有什么例子吗?

Did anyone succeeded in this? (programmatically pairing) Any example?

谢谢!

推荐答案

我认为你需要使用 API 10 中引入的 createInsecureRfcommSocketToServiceRecord().我必须让它在 Android 上运行2.2,所以我使用反射按照 这个方法&有效.我通过友好名称识别我连接的蓝牙设备将其设置为不需要 PIN 绑定,我的 Android 应用程序现在可以连接到它,而无需绑定设备或任何 PIN 输入,因此这是一个安全问题.

I think you need to use createInsecureRfcommSocketToServiceRecord() which is introduced in API 10. I've got to get this working on Android 2.2, so I used reflection to call the method as per this method & it worked. I am identifying the Bluetooth device I connect to by its friendly name & setting it to not require PIN bonding, my Android APP now connects to it without the device having to be bonded or any PIN input, so its a security concern.

这篇关于Android 以编程方式蓝牙配对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆