蓝牙解决方案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Device Management设备管理

The Java Bluetooth APIs contain the classes LocalDevice and RemoteDevice, which provide the device-management capabilities defined in the Generic Access Profile. LocalDevice depends on the javax.bluetooth.DeviceClass class to retrieve the device's type and the kinds of services it offers. The RemoteDevice class represents a remote device (a device within a range of reach) and provides methods to retrieve information about the device, including its Bluetooth address and name.

java蓝牙api包含了本地设备和远程设备,这两个类型提供了设备管理能力,这个能力再GAP定义了,本地设备需要javax.bluetooth.DeviceClass类去限定设备的种类和提供的服务种类;远程设备类代表一个远程设备(这个设备在一定范围内,译者说明(下同):蓝牙最多支持传送10米)和提供方法去获得相关设备的信息,包括它自己的蓝牙设备地址和名字(说明:类似PC机的IP和计算机名字).

The following code snippet retrieves that information for the local device: ...

// retrieve the local Bluetooth device object

下面代码片段给出了关于本地设备的相关信息

//获得本地设备对象相关对象:

LocalDevice local = LocalDevice.getLocalDevice();//本地设备实现对象

// retrieve the Bluetooth address of the local device

下面获得蓝牙设备地址

String address = local.getBluetoothAddress();

// retrieve the name of the local Bluetooth device

//下面获得蓝牙设备名字

String name = local.getFriendlyName();

...

You can get the same information about a remote device: ...

你也可以获得远程设备同样的相关信息

// retrieve the device that is at the other end of

// the Bluetooth Serial Port Profile connection,

// L2CAP connection, or OBEX over RFCOMM connection

//获得另一终端设备

RemoteDevice remote =

RemoteDevice.getRemoteDevice(

javax.microedition.io.Connection c);//本地设备实现对象

// retrieve the Bluetooth address of the remote device

//获得远程蓝牙设备的地址

String remoteAddress = remote.getBluetoothAddress();//获得地址方法

// retrieve the name of the remote Bluetooth device

//获得远程设备的名字

String remoteName = local.getFriendlyName(true);//获得名字的方法

...

The RemoteDevice class also provides methods to authenticate,authorize, or encrypt data transferred between local and remote devices.

远程设备类也可以在本地设备与远程设备之间提供方法去验证,授权和加密数据Device Discovery设备发现

Because wireless devices are mobile they need a mechanism that allows them to find other devices and gain access to their capabilities.The core Bluetooth API's DiscoveryAgent class and DiscoveryListener interface provide the necessary discovery services.

因为无线移动设备是移动的他们需要一个机制允许它们发现其它的设备和获得实现它们能力权限,蓝牙核心api的DiscoveryAgent类和DiscoveryListener抽象类提供了必要的发现设备的必要服务.

A Bluetooth device can use a DiscoveryAgent object to obtain a list of accessible devices, in any of three ways:

一个蓝牙设备能够使用一个DiscoveryAgent的对象去获得一个有访问权限设备的类表,在下面三种情况:

The DiscoveryAgent.startInquiry method places the device into an inquiry mode.To take advantage of this mode, the application must specify an event listener that will respond to inquiry-related events. DiscoveryListener.deviceDiscovered is called each time an inquiry finds a device. When the inquiry is completed or canceled, DiscoveryListener.inquiryCompleted is invoked. DiscoveryAgent.startInquiry方法把设备置于查询模式下.为了获得这种模式的优点,应用式必须专门置一个事件侦察器以便可以应答相关的事件, DiscoveryListener.deviceDiscovered方法被称作每次查询发现一个一个设备.当查询完成或者取消, DiscoveryListener.inquiryCompleted将会被调用.

If the device doesn't wish to wait for devices to be discovered,it can use the DiscoveryAgent.retrieveDevices method to retrieve an existing list. Depending on the parameter passed, this method will return either a list of devices that were found in a previous inquiry, or a list of pre-known devices that the local device has told the Bluetooth Control Center it will contact often.

如果设备不希望去等待被发现,他将可能使用DiscoveryAgent.retrieveDevices方法去获得一个存在的列表,依赖于永久通过的,这个方法将返回一个在上次(或者过去)查询被发现设备的列表,或者一个先前已经知道的设备列表,这个本地设备已经通告了蓝牙控制中心(它将频繁的连接)

These three code snippets demonstrate the various approaches: ...

// retrieve the discovery agent

DiscoveryAgent agent = local.getDiscoveryAgent();

// place the device in inquiry mode

boolean complete = agent.startInquiry();

...

这些代码片段实例将给出各种各样的方法案例

//获得发现设备

//把设备置于查询模式下

...

// retrieve the discovery agent

DiscoveryAgent agent = local.getDiscoveryAgent();

相关文档
最新文档