实际上,我怎么债券的设备? [英] How do I actually BOND a device?

查看:172
本文介绍了实际上,我怎么债券的设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处看,我觉得这种方法getBondedDevices()我的蓝牙适配器。但是,我有我的平板电脑和其它蓝牙设备坐在我旁边,我想不出如何实际获取设备展现出来绑定设备的清单上。

Everywhere I look I find this method "getBondedDevices()" for my bluetooth adapter. However, I have my tablet and another bluetooth device sitting next to me, and I can't figure out how to actually get the device to show up on the list of bonded devices.

推荐答案

在蓝牙方面,保税和配对基本上是同义词(正式,配对的过程导致了债券,但大多数人使用他们互换) 。为了让您的设备将添加到列表中,你必须经历的过程的搜索,这是怎么一设备搜索并找到另一个,然后点击两在一起。

In Bluetooth terms, "bonded" and "paired" are basically synonyms (officially, the process of pairing leads to a bond, but most people use them interchangeable). In order for your device to be added to that list, you must go through the process of Discovery, which is how one device searches and finds another, and then Pair the two together.

您可以真正做到这一点从设备设置为用户,但如果你正在寻找这样一个让应用程序的范围内,你的过程将可能是这个样子:

You can actually do this from the device settings as a user, but if you are looking to so so within the context of an app, your process will likely look something like this:


  1. 注册一个广播接收器 BluetoothDevice.ACTION_FOUND BluetoothAdapter。 ACTION_DISCOVERY_FINISHED

  2. 通过调用开始发现 BluetoothAdapter.startDiscovery()

  3. 您的接收器将每一个新的设备被发现范围时被调用的第一个动作,你可以检查它,看它是否是你要连接的人。您可以拨打 BluetoothAdapter.cancelDiscovery()一旦你发现它不浪费电池的比必要更多。

  4. 完成发现后,如果您还没有取消它,您的接收器将调用与第二个动作;所以你知道,不要指望任何更多的设备。

  5. 在手设备实例,打开的BluetoothSocket 连接()。如果设备尚未粘合,这将启动配对过程,可能会显示输入PIN code一些系统UI。

  6. 配对后,设备将在保税区的设备列表中显示出来,直到用户进入设置,并删除它。

  7. 连接()方法实际上也打开插座链接,当它返回时没有抛出异常的两个设备连接。

  8. 现在,连接,你可以叫的getInputStream()的getOutputStream()从套接字读取和写入数据

  1. Register a BroadcastReceiver for BluetoothDevice.ACTION_FOUND and BluetoothAdapter. ACTION_DISCOVERY_FINISHED
  2. Start discovery by calling BluetoothAdapter.startDiscovery()
  3. Your receiver will get called with the first action every time a new device is found in range, and you can inspect it to see if it's the one you want to connect with. You can call BluetoothAdapter.cancelDiscovery() once you've found it to not waste the battery any more than necessary.
  4. When discovery is complete, if you haven't canceled it, your receiver will get called with the second action; so you know not to expect any more devices.
  5. With a device instance in hand, open a BluetoothSocket and connect(). If the devices are not already bonded, this will initiate pairing and may show some system UI for a PIN code.
  6. Once paired, your device will show up in the bonded devices list until the user goes into settings and removes it.
  7. The connect() method also actually opens the socket link, and when it returns without throwing an exception the two devices are connected.
  8. Now connected, you can call getInputStream() and getOutputStream() from the socket to read and write data.

基本上,你可以检查绑定设备快速获得访问外部设备的名单,但在大多数应用中,你会做这和真正的发现相结合,以确保可以随时连接到远程设备无需用户做什么。如果一台设备已经粘合,你只是做步骤5-7进行连接和通信。

Basically, you can inspect the list of bonded devices to quickly get access to an external device, but in most applications you will be doing a combination of this and true discovery to make sure you can always connect to the remote device regardless of what the user does. If a device is already bonded, you'd just be doing steps 5-7 to connect and communicate.

有关详细信息和示例code,检查了发现设备和连接设备的 Android SDK中的蓝牙指南

For more information and sample code, check out the "Discovering Devices" and "Connecting Devices" sections of the Android SDK Bluetooth Guide.

心连心

这篇关于实际上,我怎么债券的设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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