在 Android 中手动配对蓝牙设备?

发布于 2024-12-12 08:55:30 字数 540 浏览 0 评论 0原文

我正在读这个 http://developer.android.com/guide/topics/wireless/ bluetooth.html#QueryingPairedDevices

提供有关如何配对、连接到蓝牙设备的帮助。

我遇到过这样的情况:我有几个 BT 设备始终处于非发现模式。我知道这些设备的 MAC 和 PIN。 Android Dev 有没有办法手动将设备添加到配对列表中,这样我就可以将连接用作客户端。 据我所知,本手册是为 V3 编写的。我想我需要在 2.0 上这样做; 2.1-以前有人这样做过吗?

基本上,我想要连接的这些设备都是省电模块,我使用预先构建的 BT 模块来监控日光、另一个湿度等。每 3 小时或在中断时监控一次,并使用单个电池运行数月。因此,关闭服务器上的 divcory 可以节省大量电量,并防止其他人尝试连接并浪费电池。

I was reading this
http://developer.android.com/guide/topics/wireless/bluetooth.html#QueryingPairedDevices

which is allot of help on how to pair,connect to a bluetooth device.

I have a situation where I have several BT devices that are in Non-Discover mode always. I know the MAC and the PIN of these devices. IS there a way in Android Dev to manually add devices to the PAIRED list so i can just use the connect as a client.
I understand this maual is written allot for V3. i think i will need to do this on 2.0 ; 2.1- has anybody done this before?

Basically these devices I want to connect to are power saving modules I used pre built BT modules to monitor daylight, another one humidity, etc.. every 3hrs or when interrupted and runs of a single battery for months. So turning off divcory on server saves immense power and prevents other people trying to connect and waste battery.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏见 2024-12-19 08:55:30

不确定“手动”是什么意思:您的意思是“手动”(如 GUI/用户交互),还是“手动”(如“我在自己的应用程序代码中执行此操作”)?

不过,有一些建议:

如果您可以让您的 BT 设备可被发现,您可以这样做:

  1. 让您的 BT 设备可被发现
  2. 让 Android 搜索并找到设备,然后启动连接
  3. Android 将要求输入 PIN 码以与设备配对设备;输入 PIN 码。
  4. 配对成功后,Android 会存储配对信息以供将来使用,以便您可以
  5. 再次隐藏您的 BT 设备。

从那时起,您的应用程序应该能够随时连接到 BT 设备,而无需进一步的配对操作。

如果上述方法不适合您,也许您想采用另一种方式:

在当前的 Android 版本中,实现了不同的 API 例程,这些例程既没有记录在普通 SDK 中,也没有公开。一种黑客解决方案可能是通过反射或修改 SDK 安装来使用其中一些“隐藏”(“@hide”...)API。

但请注意,这始终是一种黑客行为,它可能会在具有特定 Android 版本的特定设备上运行,并且可能会破坏其他设备和/或任何其他 Android 版本上的应用程序。

话虽如此,这里有一些参考:

如何访问“隐藏”蓝牙的示例API

然后,查看 android.bluetooth.BluetoothDevice 的源代码,例如 这里

在那里,public boolean createBond(){...} 可以做你想做的事。

Not sure what you mean by "manually": Do you mean "manually" as in GUI/user interaction, or "manually" as "I do it in my own application code"?

Some suggestions though:

If you can make your BT devices discoverable at all, you could do it this way:

  1. Make your BT device discoverable
  2. Let Android search for and find the device and then initiate a connection
  3. Android will ask for the PIN for pairing with the device; enter the PIN.
  4. Once pairing was successful, Android stores the pairing information for future use, so that you can
  5. Make your BT device invisible again.

From then on your app should be able to connect to the BT device at any time without further pairing operations.

If the said is not an option for you, maybe you want to go another way:

In current Android versions there are different API routines implemented which are neither documented nor exposed in the normal SDK. A hack kind of solution may be to use some of these "hidden" ("@hide"...) APIs, either via reflection or via modification of your SDK installation.

But be aware that this is always a hack and it may work on a specific device with a specific version of Android and is likely to break your app on another device and/or any other Android version.

Having said that, here comes some reference:

Example of how to access "hidden" bluetooth API.

Then, have a look at the source code for android.bluetooth.BluetoothDevice, e.g. here.

In there, public boolean createBond(){...} may do what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文