想问一下,我的300A连接蓝牙耳机怎么连接手机后为什么不能控

查看: 18148|回复: 22
索尼ZX300A——4.4平衡的普及者
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
感谢关注耳机俱乐部网站,注册后有更多权限。
才可以下载或查看,没有帐号?
本帖最后由 tommyclerk 于
10:28 编辑
& && & 十月份的时候,索尼发布了新的播放器,ZX300A,外形和ZX100很像,这次最大的变化是增加了4.4mm平衡口,能让更低价的机器用上平衡口,带给烧油平衡的音质和乐趣,3千不到的价位也是备受关注。
正面除了zx300a图,小金标更容易吸引眼球
背面写着支持的系统,还印有aptX标
打开盒子,黑色的机身的好处是整体感很棒,一眼望去一片黑
说明书、保修证等。索尼家说明书有个好处,一张简洁图文并茂为了快速上手用的,一般大家来到新东西,都想迫不及待地体验;当玩了一会了,可以详细看下具体说明书。不过这次zx300a操作和索尼黑砖、金砖差不多,不看说明书基本没问题。
“大家都黑,做个朋友吧”zx300a正面仔细看能发现屏幕不到下巴,留着一块,感觉有点可惜,如果像A系列播放器那样,会更好看。
背部材质是类皮肤的材质,有支持NFC的小标,下面的文字表明了马来西亚产的。
机身左侧面是索尼标志性的按键组合,从一回归的zx、砖系列都是这样布局的,按键排列顺序也是为了操作便捷和人性化,比如音量+和开始暂停按键上有盲操凸点,这次hold键相比黑砖移到了同侧。
机身右侧只有简单的一个TF卡扩展槽
机身顶部就是耳机接口了3.5和4.4的平衡口,平衡口旁边还有英文balanced表明;底部就一个自家的数据线接口和挂绳处
自家接口数据线
重量和手机差不多
总得来说,磨砂金属机身加上类皮肤后盖,冰冷中有着一丝温暖,圆弧边框正好吻合左手虎口处,单手操作全在掌握之中,可以说是真正的便携了,不再是砖头了。
Ⅲ音质& && &
& && &&&这款定位便携的小播放器一出,加上3千不到的价格,很多人都不是很好看。但是它又有4.4mm平衡口,是索尼连接低价位和高价位的一款机器。
& && & 先说下操作,开机用时不到30s,虽然有点慢,但是不关机不怎么费电。触摸屏操作比我玩过的金砖黑砖流畅多了,以前金砖点下一首曲子总得卡一下,有延迟(现在最新固件不知道怎么样了,按理说应该没问题了)。还有些快捷操作,通过拖动屏幕(向左拖是歌曲列表,向右拖是书签列表,向上拖是音效设置,向下拖是主界面音乐分类还有最上角的USB DAC选项)。支持格式挺全,还有新增的ape和mqa,还可以把非hi-res音源提升到高解析,效果还是有的。无线方面,支持LDAC,传输速度快,配合自家无线产品效果更好,试过和狗圈的配对,用LDAC比aptX更稳当,NFC方便连接。
& && & ZX300A搭配黑武士+黑光剑线,一套黑装。试听卢冠廷的《一生所爱》,这套搭配下,声音非常通透,人声清晰有种缥缈的感觉,宛转悠扬,没有那种干涩的感觉,第二段的女声和声,定位非常准,能清楚的感受到方位。低频的氛围感很真实,但完全不影响人声。
搭配指数:★★★★☆
& && & ZX300A和hifiman re600s,又是黑色装。一首梁静茹的《会呼吸的痛》,ZX300A基本能把re600s的声音表现出来,人声比较润、滑,但是也稍微有点厚,ZX300A并没有改变原来耳塞的人声厚度,算是忠于原味的表达。还有点比较难能可贵,就是ZX300A能把re600s的低频推得像模像样,我印象中的re600s虽然是单动圈耳塞,低频并不是很强,而ZX300A下,低频的下潜和量感都不错。
搭配指数:★★★☆☆
& && &&&ZX300A和歌德gr10,gr10人声以结像清晰出名,但是以牺牲人声厚度为代价的,人声偏薄,听女声会好点。我胆战兢兢地试了下这套搭配,特意挑战下,选了手梁静茹的《勇气》(梁阿姨给我的勇气)。开始还没事,继续听,到高潮时,“爱真的需要勇气”,竟然也没有齿音,只会感受到人声是很薄、很近,感觉就快贴过来似的。人声为主,其他为辅的感觉,这种只为人声的塞子,不时听下这种极端耳塞,也别有一番味道。可见ZX300A高频控制力还是可以的,如果稍微过一点,齿音就要爆发出来了。
搭配指数:★★★★☆
& && &&&ZX300A和索尼的N3耳塞,自家的西装。有升级线,当然得先试下原配线,才能知道提升幅度。原线比较柔软,还有mic,采用mmxc接口。初听霉霉的《Blank Space》,又让我想起了索尼以前的耳塞,z5,低频有z5那种下潜深的感觉,但是没z5那么过,很多人都觉得z5低频太过了,n3的低频下潜和质感非常棒,拳拳到肉,虽然是圈铁,但是还是得看后期调试。再听人声,厚度适中,距离也适中,并不像z5那样直白,有点a3的流行味,平淡中带着些味道,不会感到无聊。唯一明显的缺点就是横向声场有点窄,跟纵向声场比差远了,还有就是通透度稍微差点。
& && & 然后换上升级线,还是4.4平衡口的,4.4的是索尼主推的标准,我感觉比2.5好些,主要是粗了,不容易断,给人安全感。升级线下的低频简直脱胎换骨,最明显的变化就是低频的弹性好很多,以前原线下基本没有回弹,低频的残响也很明显,有种黑云压城的气势。升级线下人声也更加清晰,整体感觉就是全面提升1档,低频提升2档。不过这升级线也不便宜,1499元的价格快赶上n3本身了。
搭配指数:★★★★★
& && & ZX300A作为便携播放器,还带4.4平衡口,可以让更多的人来感受平衡口的提升,可以把n3以及4.4平衡升级线作为套装来卖,省去了烧友折腾搭配的过程。除了平衡玩法,ZX300A还可以配合出街使用的蓝牙耳机。小巧的体积还可以作为捆绑解码使用。最后这张图,大家猜下是黑白的还是彩色的?
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
楼主认为N3的4.4比Z5表现更好一些吗?是买的大法原配升级线?谢谢。
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
楼主认为N3的4.4比Z5表现更好一些吗?是买的大法原配升级线?谢谢。
平衡下的n3官升线比z5更适合听流行
主题帖子积分
初级会员, 积分 1, 距离下一级还需 9 积分
初级会员, 积分 1, 距离下一级还需 9 积分
感受完全一样啊
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
感受完全一样啊
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
看着还不错呀
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
看着还不错呀
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
听港台老歌,欧美乡村音乐更合适
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
听港台老歌,欧美乡村音乐更合适
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
用转接头对声音有影响吗
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
用转接头对声音有影响吗
主题帖子积分
新手上路, 积分 0, 距离下一级还需 1 积分
新手上路, 积分 0, 距离下一级还需 1 积分
平衡下的n3官升线比z5更适合听流行
谢谢楼主,我试听过Z5,单端的,觉得低音偏重了一点点,所以对N3AP或者N3BP抱有期望,当然最好是改平衡线的。
我用WM1A,我想应该与ZX-300听感类似。
Powered by好记性不如烂笔头
[Andriod官方API指南]连接之蓝牙
Bluetooth —— 蓝牙
The Android platform includes support for the Bluetooth network stack, which allows a device to wirelessly exchange data with other Bluetooth devices. The application framework provides access to the Bluetooth functionality through the Android
Bluetooth APIs. These APIs let applications wirelessly connect to other Bluetooth devices, enabling point-to-point and multipoint wireless features.
Android平台包含了对蓝牙网络栈的支持,它允许一个设备与其他蓝牙设备进行无线数据传输。该应用程序框架通过Android Bluetooth APIs提供了一个蓝牙编程接口。这些接口使得应用可以与其他蓝牙设备进行无线连接,完成点对点以及多点的无线特点。
Using the Bluetooth APIs, an Android application can perform the following:
Scan for other Bluetooth devicesQuery the local Bluetooth adapter for paired Bluetooth devicesEstablish RFCOMM channelsConnect to other devices through service discoveryTransfer data to and from other devicesManage multiple connections
使用蓝牙接口,一个Android应用可以执行以下功能:
扫描其他蓝牙设备为配对的蓝牙设备查询本地蓝牙适配器建立RFCOMM串口通过服务发现连接到其他设备和其他设备之间进行数据传输控制多重连接
The Basics —— 基础
This document describes how to use the Android Bluetooth APIs to accomplish the four major tasks necessary to communicate using Bluetooth: setting up Bluetooth, finding devices that are either paired or available in the local area, connecting devices, and
transferring data between devices.
本文档描述了怎样使用Android Bluetooth APIs来完成以下使用蓝牙进行交互的所必要的四个主要任务:建立蓝牙,查找设备(配对的或是在当前区域可用的),连接设备,以及在设备间传输数据。
All of the Bluetooth APIs are available in the package. Here's a summary of the classes and interfaces you will need to create Bluetooth
connections:
所有的蓝牙接口在包内都是可用的。对于你将要需要创建的蓝牙连接,下面展示了一些类和接口的总结:
Represents the local Bluetooth adapter (Bluetooth radio). The is the entry-point for all Bluetooth interaction. Using this, you can
discover other Bluetooth devices, query a list of bonded (paired) devices, instantiate a using a known MAC address, and create a
to listen for communications from other devices.代表本地蓝牙适配器(蓝牙无线电)。是所有蓝牙交互的入口。使用这个你可以发现其他蓝牙设备,查询已配对的设备列表,使用一个已知的MAC地址来实例化一个,以及创建一个来为监听与其他设备的通信。Represents a remote Bluetooth device. Use this to request a connection with a remote device through a or query information about the
device such as its name, address, class, and bonding state.代表一个远程蓝牙设备,使用这个来请求一个与远程设备的连接,或者查询关于设备名称、地址、类和连接状态等设备信息。Represents the interface for a Bluetooth socket (similar to a TCP). This is the connection point that allows an application to exchange data with another Bluetooth
device via InputStream and OutputStream.代表一个蓝牙socket的接口(和TCP Socket类似)。这是一个连接点,它允许一个应用与其他蓝牙设备通过InputStream和OutputStream交换数据。Represents an open server socket that listens for incoming requests (similar to a TCP). In order to connect two Android devices, one device must open
a server socket with this class. When a remote Bluetooth device makes a connection request to the this device, the will return
a connected when the connection is accepted.代表一个开放的服务器socket,它监听接受的请求(与TCP ServerSocket类似)。为了连接两台Android设备,一个设备必须使用这个类开启一个服务器socket。当一个远程蓝牙设备开始一个和该设备的连接请求,将会返回一个已连接的,接受该连接。Describes the general characteristics and capabilities of a Bluetooth device. This is a read-only set of properties that define the device's major and minor device classes and its services. However, this does not reliably describe all Bluetooth profiles
and services supported by the device, but is useful as a hint to the device type.描述一个蓝牙设备的基本特性和性能。这是一个只读的属性集合,它定义了设备的主要和次要的设备类以及它的服务。但是,它没有描述所有的蓝牙配置和设备支持的服务,它只是暗示了设备的类型。An interface that represents a Bluetooth profile. A Bluetooth profile is a wireless interface specification for Bluetooth-based communication between devices. An example is the Hands-Free profile.
For more discussion of profiles, see一个表示蓝牙配置文件的接口。一个Bluetooth profile是一个基于蓝牙的通信无线接口定义。一个例子是Hands-Free profile。更多的讨论请见。Provides support for Bluetooth headsets to be used with mobile phones. This includes both
Bluetooth Headset and Hands-Free (v1.5) profiles.提供对移动手机使用的蓝牙耳机的支持。它包含了Headset and Hands-Free (v1.5)配置文件。Defines how high quality audio can be streamed from one device to another over a Bluetooth connection. "A2DP" stands for Advanced Audio Distribution Profile.定义高品质的音频如何通过蓝牙连接从一个设备传输到另一个设备。”A2DP“是Advanced Audio Distribution Profile的缩写。Represents a Health Device Profile proxy that controls the Bluetooth service.表示一个Health Device Profile代理,它控制蓝牙服务。An abstract class that you use to implement
callbacks. You must extend this class and implement the callback methods to receive updates
about changes in the application’s registration state and Bluetooth channel state.一个抽象类,你可以使用它来实现的回调函数。你必须扩展这个类并实现回调函数方法来接收应用程序的注册状态改变以及蓝牙串口状态的更新。Represents an application configuration that the Bluetooth Health third-party
application registers to communicate with a remote Bluetooth health device.表示一个应用程序配置,Bluetooth Health第三方应用程序注册和一个远程Bluetooth Health设备通信。An interface that notifies
IPC clients when they have
been connected to or disconnected from the service (that is, the internal service
that runs a particular profile). 一个接口,当 IPC客户端从服务器上建立连接或断开连接时,它负责通知它们(也就是,运行在特性配置的内部服务)。Bluetooth Permissions —— 蓝牙权限
In order to use Bluetooth features in your application, you need to declare at least one of two Bluetooth permissions: and.
为了在你的应用中使用蓝牙特性,你需要至少声明一种蓝牙权限: 和。
You must request the
permission in order to perform any Bluetooth communication, such as requesting a connection, accepting a connection,
and transferring data.
为了执行任何蓝牙通信,例如请求一个连接、接受一个连接以及传输数据,你必须请求 权限。
You must request the permission in order to initiate device discovery or manipulate Bluetooth settings. Most applications need
this permission solely for the ability to discover local Bluetooth devices. The other abilities granted by this permission should not be used, unless the application is a "power manager" that will modify Bluetooth settings upon user request.Note:
If you use
permission, then must also have the
permission.
为了初始化设备查找或控制蓝牙设置,你必须请求权限。大多数应用需要这个权限,仅仅是为了可以发现本地蓝牙设备。这个权限授权的其他功能不应该被使用,除非该应用是一个“强大的控制器”,来通过用户请求修改蓝牙设置。注意:如果你使用权限,那么必须拥有权限。
Declare the Bluetooth permission(s) in your application manifest file. For example:
在你的应用程序清单文件中声明蓝牙权限。例如:
&manifest ... &
&uses-permission android:name="android.permission.BLUETOOTH" /&
&/manifest&
reference for more information about declaring application permissions.
更多关于声明应用程序权限的信息请见参考。
Setting Up Bluetooth —— 建立蓝牙
Figure 1: The enabling Bluetooth dialog.
图1:开启蓝牙对话框
Before your application can communicate over Bluetooth, you need to verify that Bluetooth is supported on the device, and if so, ensure that it is enabled.
在你的应用可以通过蓝牙进行通信之前,你需要验证该设备是否支持蓝牙,如果支持,确保它被打开了。
If Bluetooth is not supported, then you should gracefully disable any Bluetooth features. If Bluetooth is supported, but disabled, then you can request that the user enable Bluetooth without leaving your application. This setup is accomplished in two steps,
using the .
如果不支持蓝牙,那么你应该优雅地关掉所有蓝牙特性,如果支持蓝牙,但是没有开启,那么你可以请求用户在不离开你的应用前提下开启蓝牙。这个过程使用用两步完成。
is required for any and all Bluetooth activity. To get the,
call the static method. This returns a
that represents the device's own Bluetooth adapter (the Bluetooth radio). There's one Bluetooth adapter for the entire system, and your application can interact with it using this object. If
returns null, then the device does not support Bluetooth and your story ends here. For example:
所有的蓝牙活动都需要请求。为了得到,调用静态的方法。它返回一个,代表设备本身的蓝牙适配器(蓝牙无线电)。一个完整的系统只有一个蓝牙适配器,而且你的应用可以使用与它进行交互。如果返回为null,那么设备不支持蓝牙而你的故事将在此结束。例如:
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
Enable Bluetooth 开启蓝牙
Next, you need to ensure that Bluetooth is enabled. Call
to check whether Bluetooth is currently enable. If this method returns
false, then Bluetooth is disabled. To request that Bluetooth be enabled, call
action Intent. This will issue a request to enable Bluetooth through the system settings (without stopping your application). For example:
接下来,你需要保证蓝牙是开启的。调用来检查蓝牙最近是否是开启的。如果这个方法返回false,那么蓝牙没有开启。为了请求开启蓝牙,调用并使用方法Intent。这将发出一个请求来利用系统设置开启蓝牙(不需要停止你的应用)。例如:
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
A dialog will appear requesting user permission to enable Bluetooth, as shown in Figure 1. If the user responds "Yes," the system will begin to enable Bluetooth and focus will return to your application once the process completes (or fails).
一个对话框将会出现,请求用户开启蓝牙,像在图1中展示的那样。如果用户相应”是“,系统将会开启蓝牙,而且一旦完成进程(或失败)就返回你的应用。
The REQUEST_ENABLE_BT constant passed to
is a locally defined integer (which
must be greater than 0), that the system passes back to you in your implementation as therequestCode
parameter.
传给的REQUEST_ENABLE_BT常量是一个本地定义的整型(必须大于0),系统在你的实现中返回给你作为requestCode参数。
If enabling Bluetooth succeeds, your activity receives the
result code in thecallback.
If Bluetooth was not enabled due to an error (or the user responded "No") then the result code is.
如果开启蓝牙成功,你的activity在回调函数中接受一个结果代码。如果蓝牙因为一个错误(或者用户相应”否“)没有开启,那么结果代码就是。
Optionally, your application can also listen for the broadcast Intent, which the system will broadcast whenever
the Bluetooth state has changed. This broadcast contains the extra fields
containing the new and old Bluetooth states, respectively. Possible values for these extra fields are,,,
and. Listening for this broadcast can be useful to detect changes made to the Bluetooth state while your app is running.
可选的,你的应用也可以监听广播Intent,任何时候蓝牙状态改变了系统将会广播该Intent。这个广播包含了额外的变量
和,分别包含了新的和老的蓝牙状态。这些额外的变量可能值是,,和。监听这个广播对于检测你的应用运行时蓝牙状态的变化是非常有用的。
Tip: Enabling discoverability will automatically enable Bluetooth. If you plan to consistently enable device discoverability before performing Bluetooth activity, you can skip step 2 above. Read about, below.
提示:开启可发现性将会自动开启蓝牙。如果你打算在执行蓝牙activity之前长期开启设备的可发现性,你可以跳过上面的第二步。阅读下面的。
Finding Devices
Using the , you can find remote Bluetooth devices either through device discovery or by querying the list of paired (bonded) devices.
使用,你可以通过设备检测或者查询已配对的设备来找到远程蓝牙设备。
Device discovery is a scanning procedure that searches the local area for Bluetooth enabled devices and then requesting some information about each one (this is sometimes referred to as "discovering," "inquiring" or "scanning"). However, a Bluetooth device
within the local area will respond to a discovery request only if it is currently enabled to be discoverable. If a device is discoverable, it will respond to the discovery request by sharing some information, such as the device name, class, and its unique
MAC address. Using this information, the device performing discovery can then choose to initiate a connection to the discovered device.
设备检测是一个浏览流程,它查找附近的蓝牙可用设备,然后请求每个设备的相关信息(这有时被称为“检测”“查询”或“浏览”等)。虽然,附近的蓝牙设备仅在它目前是可被检测的状态下时才会回应发现请求。如果一个设备是可被检测的,它将通过分享一些数据来相应检测请求,例如设备名称,类,以及他的唯一的MAC地址。使用这个信息,进行检测的设备可以选择和检测到的的设备初始化一个连接。
Once a connection is made with a remote device for the first time, a pairing request is automatically presented to the user. When a device is paired, the basic information about that device (such as the device name, class, and MAC address) is saved and can
be read using the Bluetooth APIs. Using the known MAC address for a remote device, a connection can be initiated with it at any time without performing discovery (assuming the device is within range).
一旦一个连接第一次和一个远程设备进行连接,一个匹配的请求会自动呈现在用户面前。当一个设备配对后,设备的基本信息(例如设备名称、类、MAC地址)将被保存,并且可以使用蓝牙接口进行访问。使用已知的MAC地址,一个连接可以在任何时间被初始化,而不需要执行检测(假设设备在可检测范围内)。
Remember there is a difference between being paired and being connected. To be paired means that two devices are aware of each other's existence, have a shared link-key that can be used for authentication, and are capable of establishing an encrypted connection
with each other. To be connected means that the devices currently share an RFCOMM channel and are able to transmit data with each other. The current Android Bluetooth API's require devices to be paired before an RFCOMM connection can be established. (Pairing
is automatically performed when you initiate an encrypted connection with the Bluetooth APIs.)
记住,配对和连接之间有一点是不同的。配对以为着两台设备是知道彼此的存在的,它们有一个共享的链接密匙,可以用于授权以及建立一个加密的连接。而连接意味着设备目前共享一个RFCOMM通道,并且可以彼此传输数据。目前的安卓蓝牙接口要求设备在建立一个RFCOMM连接之前先进行配对。(当你使用蓝牙接口初始化一个加密的连接时,配对是自动执行的)。
The following sections describe how to find devices that have been paired, or discover new devices using device discovery.
下面的章节描述了如何查找已配对的设备,或者使用设备检测找到新的设备。
Note: Android-powered devices are not discoverable by default. A user can make the device discoverable for a limited time through the system settings, or an application can request that the user enable discoverability without
leaving the application. How to
is discussed below.
注意:安卓设备默认是不可检测的。一个用户可以通过系统设置使设备在一定时间内是可检测的,或者一个应用可以请求用户开启可检测功能而不需要离开应用。下面描述了怎样开启可检测功能。
Querying paired devices —— 查询已配对的设备
Before performing device discovery, its worth querying the set of paired devices to see if the desired device is already known. To do so, call.
This will return a Set ofs representing paired devices. For example, you can query all paired devices and then show the name of each device
to the user, using an ArrayAdapter:
Set&BluetoothDevice& pairedDevices = mBluetoothAdapter.getBondedDevices();
// If there are paired devices
if (pairedDevices.size() & 0) {
// Loop through paired devices
for (BluetoothDevice device : pairedDevices) {
// Add the name and address to an array adapter to show in a ListView
mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}All that's needed from the
object in order to initiate a connection is the MAC address. In this example, it's saved as a part of an ArrayAdapter
that's shown to the user. The MAC address can later be extracted in order to initiate the connection. You can learn more about creating a connection in the section about.
Discovering devices
To start discovering devices, simply call . The process is asynchronous and the method will immediately return with
a boolean indicating whether discovery has successfully started. The discovery process usually involves an inquiry scan of about 12 seconds, followed by a page scan of each found device to retrieve its Bluetooth name.
Your application must register a BroadcastReceiver for the Intent in order to receive information about each device discovered.
For each device, the system will broadcast the Intent. This Intent carries the extra fields
and, containing a
and a , respectively. For example, here's how you can register to handle the broadcast when devices are discovered:
// Create a BroadcastReceiver for ACTION_FOUND
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Add the name and address to an array adapter to show in a ListView
mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
// Register the BroadcastReceiver
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroyAll that's needed from the
object in order to initiate a connection is the MAC address. In this example, it's saved as a part of an ArrayAdapter
that's shown to the user. The MAC address can later be extracted in order to initiate the connection. You can learn more about creating a connection in the section about.
Caution: Performing device discovery is a heavy procedure for the Bluetooth adapter and will consume a lot of its resources. Once you have found a device to connect, be certain that you always stop discovery with
before attempting a connection. Also, if you already hold a connection with a device, then performing discovery can significantly reduce the bandwidth available for the connection, so you should not perform discovery while connected.
Enabling discoverability
If you would like to make the local device discoverable to other devices, call
with the action Intent. This will issue a request to enable discoverable mode through the system
settings (without stopping your application). By default, the device will become discoverable for 120 seconds. You can define a different duration by adding the
Intent extra. The maximum duration an app can set is 3600 seconds, and a value of 0 means the device is always discoverable. Any value below 0 or above 3600 is automatically set to 120 secs). For example, this snippet sets the duration to 300:
Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
Figure 2: The enabling discoverability dialog.
A dialog will be displayed, requesting user permission to make the device discoverable, as shown in Figure 2. If the user responds "Yes," then the device will become discoverable for the specified amount of time. Your activity will then receive a call to
callback, with the result code equal to the duration that the device is discoverable. If
the user responded "No" or if an error occurred, the result code will be .
Note: If Bluetooth has not been enabled on the device, then enabling device discoverability will automatically enable Bluetooth.
The device will silently remain in discoverable mode for the allotted time. If you would like to be notified when the discoverable mode has changed, you can register a BroadcastReceiver for theIntent.
This will contain the extra fields and,
which tell you the new and old scan mode, respectively. Possible values for each are,,
or , which indicate that the device is either in discoverable mode, not in discoverable mode but still able to receive connections,
or not in discoverable mode and unable to receive connections, respectively.
You do not need to enable device discoverability if you will be initiating the connection to a remote device. Enabling discoverability is only necessary when you want your application to host a server socket that will accept incoming connections, because
the remote devices must be able to discover the device before it can initiate the connection.
Connecting Devices —— 连接设备
In order to create a connection between your application on two devices, you must implement both the server-side and client-side mechanisms, because one device must open a server socket and the other one must initiate the connection (using the server device's
MAC address to initiate a connection). The server and client are considered connected to each other when they each have a connected
the same RFCOMM channel. At this point, each device can obtain input and output streams and data transfer can begin, which is discussed in the section about . This section describes how to initiate the connection between two devices.
为了在两台设备上创建一个连接,你必须实现服务器端和客户端两头的机制,因为一个设备必须打开一个服务器socket,而另一个设备初始化创建(使用服务器设备的MAC地址来初始化一个连接)。当他们在相同的RFCOMM通道上有一个已连接的
时,服务器和客户被认为是互相连接了。这时,每一个设备可以包含输入和输出流,而且可以开始数据传输,这在课程中将会讨论。本节课描述了怎样在两台设备之间初始化连接。
The server device and the client device each obtain the required
in different ways. The server will receive it when an incoming connection
is accepted. The client will receive it when it opens an RFCOMM channel to the server.
服务器设备和客户端设备使用不同的方法来得到需要的
。服务器在接受外来的连接的将会接收到它。客户端在向服务器端打开一个RFCOMM通道时会接收到它。
Figure 3: The Bluetooth pairing dialog.
图3:蓝牙配对对话框
One implementation technique is to automatically prepare each device as a server, so that each one has a server socket open and listening for connections. Then either device can initiate a connection with the other and become the client. Alternatively, one
device can explicitly "host" the connection and open a server socket on demand and the other device can simply initiate the connection.
一种实现技术使得每一个设备都可以成为一个服务器,因此每一个都有一个打开的服务器socket,并且随时监听连接。然后另一个设备可以初始化连接,并且成为客户端。对应的,一个设备可以显式地“发起”连接,并且在需要时打开一个服务器socket,而另一个设备可以简单地初始化连接即可。
Note: If the two devices have not been previously paired, then the Android framework will automatically show a pairing request notification or dialog to the user during the connection procedure, as shown in Figure 3. So when
attempting to connect devices, your application does not need to be concerned about whether or not the devices are paired. Your RFCOMM connection attempt will block until the user has successfully paired, or will fail if the user rejects pairing, or if pairing
fails or times out.
注意:如果两台设备之前没有配对过,那么Android框架将会自动显示一个请求配对的通知或对话框,正如图3中显示的那样。因此,当尝试连接设备时,你的应用不需要考虑设备是否配对过。你的RFCOMM连接尝试将会阻塞,知道用户成功配对,或者用户拒绝失败时,或者配对失败,或者超时。
Connecting as a server —— 作为服务器端连接
When you want to connect two devices, one must act as a server by holding an open . The purpose of the server socket is to
listen for incoming connection requests and when one is accepted, provide a connected . When the
is acquired from the , the
can (and should) be discarded, unless you want to accept more connections.
当你想要连接两台设备时,一个必须通过持有一个打开的
来作为服务器端。服务器socket的目的是为了监听外来的连接请求,当一个请求被接受后,提供一个连接的。当该被请求时, 可以(而且应当)被舍弃,除非你想要接收更多的连接。
Here's the basic procedure to set up a server socket and accept a connection:
下面是创建一个服务器socket并且接受一个连接的基本过程:
by calling the . 通过调用 得到一个。
The string is an identifiable name of your service, which the system will automatically write to a new Service Discovery Protocol (SDP) database entry on the device (the name is arbitrary and can simply be your application name). The UUID is also included
in the SDP entry and will be the basis for the connection agreement with the client device. That is, when the client attempts to connect with this device, it will carry a UUID that uniquely identifies the service with which it wants to connect. These UUIDs
must match in order for the connection to be accepted (in the next step).
这个String是你的服务的标志名称,系统将会把它写入设备中的一个新的服务发现协议(SDP)数据库条目中(名字是任意的,并且可以只是你应用的名字)。UUID同样被包含在SDP条目中,并且将会成为和客户端设备连接协议的基础。也就是说,当客户端尝试连接这个设备时,它将会携带一个UUID用于唯一指定它想要连接的服务器。这些UUIDs必须匹配以便该连接可以被接受(在下一步中)。
Start listening for connection requests by calling . 通过调用开始监听连接请求。
This is a blocking call. It will return when either a connection has been accepted or an exception has occurred. A connection is accepted only when a remote device has sent a connection request with a UUID matching the one registered with this listening
server socket. When successful,
will return a connected .
这一个阻塞调用。在一个连接被接受或一个异常出现时,它将会返回。只有当一个远程设备使用一个UUID发送了一个连接请求,并且该UUID和正在监听的服务器socket注册的UUID相匹配时,一个连接才会被接受。成功后, 将会返回一个已连接的 。
Unless you want to accept additional connections, call . 调用,除非你想要接受更多的连接。
This releases the server socket and all its resources, but does not close the connected
that's been returned by .
Unlike TCP/IP, RFCOMM only allows one connected client per channel at a time, so in most cases it makes sense to call
immediately after accepting a connected socket.
这将释放服务器socket和它所有的资源,但是不会关闭 返回的已连接的 。不同于TCP/IP,RFCOMM仅仅允许每一个通道上在某一时刻只有一个已连接的客户端,因此在大多数情况下在接受一个已连接的socket后,在上调用
是非常必要的。
call should not be executed in the main activity UI thread because it is a blocking call and will prevent any other interaction
with the application. It usually makes sense to do all work with a
in a new thread managed by your application. To abort a blocked call such as , call
from another thread and the blocked call will immediately return. Note that all methods on a
thread-safe.
不应该再主活动UI线程上执行,因为它是一个阻塞调用,并且将会阻止任何与应用的交互行为。它通常在你的应用管理的一个新的线程中使用一个 或
来完成所有工作。为了中止一个阻塞调用,例如,从你的其他线程里在 (或 )
,然后阻塞调用就会立即返回。注意在
上所有的方法都是线程安全的。
Example —— 例子
Here's a simplified thread for the server component that accepts incoming connections:
下面是一个简单的线程,用于服务器端接受外来的连接:
private class AcceptThread extends Thread {
private final BluetoothServerSocket mmServerS
public AcceptThread() {
// Use a temporary object that is later assigned to mmServerSocket,
// because mmServerSocket is final
BluetoothServerSocket tmp =
// MY_UUID is the app's UUID string, also used by the client code
tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
} catch (IOException e) { }
mmServerSocket =
public void run() {
BluetoothSocket socket =
// Keep listening until exception occurs or a socket is returned
while (true) {
socket = mmServerSocket.accept();
} catch (IOException e) {
// If a connection was accepted
if (socket != null) {
// Do work to manage the connection (in a separate thread)
manageConnectedSocket(socket);
mmServerSocket.close();
/** Will cancel the listening socket, and cause the thread to finish */
public void cancel() {
mmServerSocket.close();
} catch (IOException e) { }
In this example, only one incoming connection is desired, so as soon as a connection is accepted and the
is acquired, the application
sends the acquired
to a separate thread, closes the
and breaks the loop.
在这个例子里,只接受一个外来的连接,因此一旦一个连接被接受了并且需要一个 ,应用将会发送需要的
给另一个线程,关闭
然后打破循环。
Note that when returns the ,
the socket is already connected, so you should not call
(as you do from the client-side).
注意当返回一个 是,该socket已经被连接了,因此你不应该调用(正如你在客户端里所做的)。
manageConnectedSocket() is a fictional method in the application that will initiate the thread for transferring data, which is discussed in the section about .
manageConnectedSocket()是一个虚构的方法,它将会初始化线程来传输数据,这在
中将会讨论。
You should usually close your
as soon as you are done listening for incoming connections. In this example,
is called as soon as the
is acquired. You may also want to provide a public method in your thread that can close the private
in the event that you need to stop listening on the server socket.
你通常应该关闭你的 ,一旦你已经监听到了外来的连接。在这个例子里, 一旦得到了
就会调用。你也可能想要在你的线程中提供一个公共的方法来关闭事件中私有的
,以便你需要停止在服务器socket上监听。
Connecting as a client —— 作为客户端连接
In order to initiate a connection with a remote device (a device holding an open server socket), you must first obtain a
object that
represents the remote device. (Getting a
is covered in the above section about .) You must then use the
to acquire a
and initiate the connection.
为了和一个远程设备(一个持有服务器socket的设备)初始化一个连接,你必须首先得到一个
对象来表示这个远程设备。(上面的课程讲述了如何得到一个
)。然后你必须使用来得到一个
,然后初始化该连接。
Here's the basic procedure: 下面是基本的过程:
Using the , get a
by calling .
使用 ,通过调用来得到一个
This initializes a
that will connect to the .
The UUID passed here must match the UUID used by the server device when it opened its
(with). Using the same UUID is simply a matter of hard-coding the UUID string into your application and then referencing it from both the server and client code.
这将初始化一个,它连接到该。这里传递的UUID必须和服务器设备开启它的 时使用的UUID相匹配。
Initiate the connection by calling . 通过调用初始化一个连接。
Upon this call, the system will perform an SDP lookup on the remote device in order to match the UUID. If the lookup is successful and the remote device accepts the connection, it will share the RFCOMM channel to use during the connection and
will return. This method is a blocking call. If, for any reason, the connection fails or the
method times out (after about 12 seconds),
then it will throw an exception.
执行这个调用时,系统将会在远程设备上执行一个SDP查找工作,来匹配UUID。如果查找成功,并且远程设备接受了连接,它将会在连接过程中分享RFCOMM通道,而
将会返回。这个方法是阻塞的。如果,处于任何原因,该连接失败了或者超时了(大约12秒以后),那么它将会抛出一个异常。
is a blocking call, this connection procedure should always be performed in a thread separate from the main activity thread.
因为是一个阻塞调用,这个连接过程应该总是在一个单独的线程中执行。
Note: You should always ensure that the device is not performing device discovery when you call. If discovery is in progress,
then the connection attempt will be significantly slowed and is more likely to fail.
注意:你应该总是确保在你调用时设备没有执行设备查找工作。如果正在查找设备,那么连接尝试将会很大程度的减缓,并且很有可能会失败。
Example —— 例子
Here is a basic example of a thread that initiates a Bluetooth connection:
下面是初始化一个蓝牙连接的基本例子:
private class ConnectThread extends Thread {
private final BluetoothSocket mmS
private final BluetoothDevice mmD
public ConnectThread(BluetoothDevice device) {
// Use a temporary object that is later assigned to mmSocket,
// because mmSocket is final
BluetoothSocket tmp =
mmDevice =
// Get a BluetoothSocket to connect with the given BluetoothDevice
// MY_UUID is the app's UUID string, also used by the server code
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) { }
mmSocket =
public void run() {
// Cancel discovery because it will slow down the connection
mBluetoothAdapter.cancelDiscovery();
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
mmSocket.connect();
} catch (IOException connectException) {
// U close the socket and get out
mmSocket.close();
} catch (IOException closeException) { }
// Do work to manage the connection (in a separate thread)
manageConnectedSocket(mmSocket);
/** Will cancel an in-progress connection, and close the socket */
public void cancel() {
mmSocket.close();
} catch (IOException e) { }
Notice that
is called before the connection is made. You should always do this before connecting and it is safe
to call without actually checking whether it is running or not (but if you do want to check, call ).
manageConnectedSocket() is a fictional method in the application that will initiate the thread for transferring data, which is discussed in the section about .
注意到在创建一个连接之前调用了。你应该在连接前总是这样做,而不需要考虑是否真的有在执行查询任务(但是如果你想要检查,调用 )。manageConnectedSocket()是一个虚拟的方法,它将会初始化一个线程用于传输数据,这在课程中将会讨论。
When you're done with your , always call
to clean up. Doing so will immediately close the connected socket and clean up all internal resources.
当你使用完你的 后,总是调用来清除资源。这样做将会立即关闭已连接的socket,然后清除所有的内部资源。
Managing a Connection —— 管理一个连接
When you have successfully connected two (or more) devices, each one will have a connected . This is where the fun begins because you
can share data between devices. Using the , the general procedure to transfer arbitrary data is simple:
当你成功连接两个(或更多)设备后,每一个都将有一个已连接的 。这就是乐趣开始的地方,因为你可以在不同的设备之间共享数据了!使用 ,常见的二进制数据传输是很简单的:
that handle transmissions through
the socket, via
respectively.
分别通过 和 来得到
来控制socket之间的传输。Read and write data to the streams with
和 来向数据流中读取和写入数据。That's it.
就是这样啦!
There are, of course, implementation details to consider. First and foremost, you should use a dedicated thread for all stream reading and writing. This is important because both
methods are blocking calls.
will block until there is something to read from the stream.
does not usually block, but can block for flow control if the remote device
is not calling
quickly enough and the intermediate buffers are full. So, your main loop in the thread should be dedicated to reading from the .
A separate public method in the thread can be used to initiate writes to the .
当然,实现的细节需要考虑。首先并且最重要的是,你应该为所有输入和输出的数据流使用一个专属的线程。这是十分重要的,因为 和 方法都是阻塞调用。 将会发生阻塞知道送数据流中读取到了一些东西。 不经常发生阻塞,但是当远程设备没有足够迅速地调用 而中间缓冲区已经负载时可以阻塞。因此,你的线程中的主要循环应该是专门从中读取数据的。一个单独的公共方法可以被用于初始化向
中写入数据。
Example —— 例子
Here's an example of how this might look:
它看起来可能像下面这个例子,:
private class ConnectedThread extends Thread {
private final BluetoothSocket mmS
private final InputStream mmInS
private final OutputStream mmOutS
public ConnectedThread(BluetoothSocket socket) {
mmSocket =
InputStream tmpIn =
OutputStream tmpOut =
// Get the input and output streams, using temp objects because
// member streams are final
tmpIn = socket.getInputStream();
tmpOut = socket.getOutputStream();
} catch (IOException e) { }
mmInStream = tmpIn;
mmOutStream = tmpO
public void run() {
byte[] buffer = new byte[1024];
// buffer store for the stream
// bytes returned from read()
// Keep listening to the InputStream until an exception occurs
while (true) {
// Read from the InputStream
bytes = mmInStream.read(buffer);
// Send the obtained bytes to the UI activity
mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)
.sendToTarget();
} catch (IOException e) {
/* Call this from the main activity to send data to the remote device */
public void write(byte[] bytes) {
mmOutStream.write(bytes);
} catch (IOException e) { }
/* Call this from the main activity to shutdown the connection */
public void cancel() {
mmSocket.close();
} catch (IOException e) { }
The constructor acquires the necessary streams and once executed, the thread will wait for data to come through the InputStream. When
with bytes from the stream, the data is sent to the main activity using a member Handler from the parent class. Then it goes back and waits for more bytes from the stream.
构造器需要必须的数据流,并且一旦执行,线程将会等待InputStream 中来的数据。当
返回一些数值时,数据将会使用一个父类的一个成员变量句柄发送给主活动。然后它返回并继续等待更多的数据。
Sending outgoing data is as simple as calling the thread's write() method from the main activity and passing in the bytes to be sent. This method then simply calls
to send the data to the remote device.
发送数据只需要在主活动中调用线程的 write()方法,并将需要发送数据传递给它即可。这个方法然后调用 来向远程设备发送数据。
The thread's cancel() method is important so that the connection can be terminated at any time by closing the . This should
always be called when you're done using the Bluetooth connection.
线程的cancel() 方法是重要的,以便连接可以在任何时间被中断(通过关闭)。这个方法应该在你完成蓝牙连接后总是被调用。
demonstration of using the Bluetooth APIs, see the .
使用蓝牙APIs的更多例子,详见。
Working with Profiles —— 使用配置文件
Starting in Android 3.0, the Bluetooth API includes support for working with Bluetooth profiles. A Bluetooth profile is a wireless interface specification for Bluetooth-based communication between devices. An example is the Hands-Free profile. For
a mobile phone to connect to a wireless headset, both devices must support the Hands-Free profile.
从Android 3.0开始,蓝牙API包含了对蓝牙配置文件的支持。一个蓝牙配置文件是一个对设备之间依赖蓝牙交互的无线接口定义。一个例子是Hands-Free 配置文件。对于一个和蓝牙耳机相连接的移动电话,两个设备都必须支持Hands-Free 配置文件。
You can implement the interface
to write your own classes to support a particular Bluetooth profile. The Android Bluetooth API provides
implementations for the following Bluetooth profiles:
你可以实现接口来定义你自己的类,以便支持特定的蓝牙配置文件。Android蓝牙API提供了以下蓝牙配置文件的实现:
Headset. The Headset profile provides support for Bluetooth headsets to be used with mobile phones. Android provides the
class, which is a proxy for controlling the Bluetooth Headset Service via interprocess communication (). This includes both
Bluetooth Headset and Hands-Free (v1.5)
profiles. The
class in cludes support for AT commands. For more discussion of this topic, see
耳机:耳机配置文件提供了对于移动设备使用的蓝牙耳机的支持。Android提供了
类,它是一个通过进程间的交互(IPC)来控制蓝牙耳机服务的代理。它包含了 Bluetooth Headset
Hands-Free (v1.5) 配置文件。 类包含了对AT命令的支持。更多的信息,详见
A2DP. The Advanced Audio Distribution Profile (A2DP) profile defines how high quality audio can be streamed from one device to another over a Bluetooth connection. Android provides the
class, which is a proxy for controlling the Bluetooth A2DP
Service via IPC.
A2DP:Advanced Audio Distribution Profile (A2DP)配置文件定义了高质量的音频可以如何通过蓝牙连接从一台设备上传输到另一台设备上。Android提供了
类,它是一个通过IPC管理蓝牙A2DP服务的代理。
Health Device. Android 4.0 (API level 14) introduces support for the Bluetooth Health Device Profile (HDP). This lets you create applications that use Bluetooth to communicate with health devices that support Bluetooth, such as heart-rate
monitors, blood meters, thermometers, scales, and so on. For a list of supported devices and their corresponding device data specialization codes, refer to Bluetooth Assigned Numbers at .
Note that these values are also referenced in the ISO/IEEE
[7] specification as MDC_DEV_SPEC_PROFILE_* in the Nomenclature Codes Annex. For more discussion of HDP, see .
保健设备:Android 4.0(API level 14)介绍了对于蓝牙保健设备配置文件(HDP)。它允许你使用蓝牙和支持蓝牙的保健设备进行交互来创建应用,例如心跳监控器,血压,温度计,直尺等。参见Bluetooth Assigned Numbers at得到支持设备的列表和它们对应的设备数据定义代码。注意,这些值也可以在 ISO/IEEE
[7] 定义中查找。更多关于HDP的讨论,详见 。
Here are the basic steps for working with a profile:
下面是操作一个配置文件的基本步骤:
Get the default adapter, as described in
得到默认的适配器,正如 描述的那样。Use
to establish a connection to
the profile proxy object associated with the profile. In the example below, the profile proxy object is an instance of . 使用
来建立一个和配置代理对象的连接。这下面的实例代码中,配置代理对象是一个 的实例。Set up a
. This listener notifies
IPC clients when they have been connected to or disconnected from the service.
建立一个 。这个监听器通知
IPC客户端,当它们已经和服务器连接或取消连接时。In , get a handle to the profile proxy object. 在 里,得到一个配置代理对象的句柄。Once you have the profile proxy object, you can use it to monitor the state of the connection and perform other operations that are relevant to that profile.
一旦你有了配置代理对象,你可以使用它来监视连接状态,并且执行和配置文件相关的其他操作。For example, this code snippet shows how to connect to a
proxy object so that you can control the Headset profile:
例如,下面的代码片段展示了如何和一个代理进行连接,以便你可以控制 Headset profile:
BluetoothHeadset mBluetoothH
// Get the default adapter
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// Establish connection to the proxy.
mBluetoothAdapter.getProfileProxy(context, mProfileListener, BluetoothProfile.HEADSET);
private BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset = (BluetoothHeadset)
public void onServiceDisconnected(int profile) {
if (profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset =
// ... call functions on mBluetoothHeadset
// Close proxy connection after use.
mBluetoothAdapter.closeProfileProxy(mBluetoothHeadset);
Vendor-specific AT commands —— 厂商特定的AT命令
Starting in Android 3.0, applications can register to receive system broadcasts of pre-defined vendor-specific AT commands sent by headsets (such as a Plantronics +XEVENT command). For example, an application could receive broadcasts that indicate a connected
device's battery level and could notify the user or take other action as needed. Create a broadcast receiver for the
intent to handle vendor-specific AT commands for the headset.
从Android 3.0开始,应用可以注册来接收系统广播的、耳机发送的、预定义的、厂商特定的AT命令(例如一个Plantronics +XEVENT 命令)。例如,一个应用可以接收广播,来表明一个已连接的设备的电池等级,并且可以告知用于或者采取其他需要的动作。为
Intent 创建一个广播接收器来为耳机控制厂商特定的AT命令。
Health Device Profile —— 保健设备配置文件
Android 4.0 (API level 14) introduces support for the Bluetooth Health Device Profile (HDP). This lets you create applications that use Bluetooth to communicate with health devices that support Bluetooth, such as heart-rate monitors, blood meters, thermometers,
and scales. The Bluetooth Health API includes the classes ,,
and, which are described in .
Android 4.0(API level 14) 介绍了对蓝牙保健设备配置文件(HDP)的支持。它允许你使用蓝牙和支持蓝牙的保健设备进行交互来创建应用,例如心跳监控器,血压,温度计,直尺等。蓝牙保健设备API包含了, 和
类,.描述了它们。
In using the Bluetooth Health API, it's helpful to understand these key HDP concepts:
为了使用Bluetooth Health API,理解下面这些关键的HDP概念是有用的:
Description
A role defined in HDP. A source is a
health device that transmits medical data (weight scale, glucose meter, thermometer, etc.) to a smart device such as an Android phone or tablet.
A role defined in HDP. In HDP, a sink is the smart device that receives the medical data. In an Android HDP application, the sink is represented by aobject.
Registration
Refers to registering a sink for a particular health device.
Connection
Refers to opening a channel between a health device and a smart device such as an Android phone or tablet.
Creating an HDP Application —— 创建一个HDP应用
Here are the basic steps involved in creating an Android HDP application:
下面是创建一个Android HDP应用的基本步骤:
Get a reference to the
proxy object.
得到代理对象的引用。
Similar to regular headset and A2DP profile devices, you must call with
profile type to establish a connection with the profile proxy object.
和通常的耳机和A2DP配置文件设备类似,你必须使用和 配置文件类型来调用,以建立一个和配置代理对象的连接。
and register an application configuration
that acts as a health sink.
创建一个 ,然后注册一个应用配置()来作为一个health
sink。Establish a connection to a health device.
Some devices will initiate the connection.
It is unnecessary to carry out this step for those devices. 建立一个和保健设备的连接,一些设备将会初始化连接。对于这些设备来说,这一步是不需要的。When connected successfully to a health device, read/write to the health device using the file descriptor.
当成功建立和保健设备的连接后,使用 file descriptor来向保健设备读取/写入数据。
The received data needs to be interpreted using a health manager which implements the IEEE 11073-xxxxx specifications.
接收到的数据需要使用保健管理器(实现了 IEEE 11073-xxxxx定义)来解读。
When done, close the health channel and unregister the application.
The channel also closes when there is extended inactivity.
完成以后,关闭保健通道,然后注销应用。通道也会在静止时关闭。For a complete code sample that illustrates these steps, see .
完整的实例这些步骤的代码,请见。
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!}

我要回帖

更多关于 华为mate蓝牙连接问题 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信