蓝牙profile4.0有几个profile

蓝牙规范(HSP、HFP、A2DP)、蓝牙版本(1.0、1.2、2.0、3.0、4.0)之间是什么关系?_百度知道
蓝牙规范(HSP、HFP、A2DP)、蓝牙版本(1.0、1.2、2.0、3.0、4.0)之间是什么关系?
提问者采纳
麦芽您解惑楼主您蓝牙耳机现主要三规格———HSP、HFPA2DPHeadsetPro-file(HSP)代表耳机功能提供手机与耳机间通信所需基本功能HandProfile(HFP)则代表免提功能HFPHSP基础增加某些扩展功能 Advanced Audio Distribution Profile(A2DP)指 蓝牙音频传输模型协定HFP格式蓝牙耳机支持手机功能比较完整消费者耳机操作手机设定重拨、电保留、电拒听等免提选项功能A2DP高级音频传送规格允许传输立体声音频信号相比用于 HSP
HFP 单声道加密质量要A2DP能够让两同支持蓝牙音效传输装置互相连接都能输CD音质(16 bits<img class="word-replace" src="/api/getdecpic?picenc=0ad.1 kHz)般音乐假没支持A2DP音效能输Handsfree Profile(8 bits<img class="word-replace" src="/api/getdecpic?picenc=0ad kHz)算耳机采用双耳筒设计能般电单声道音质与真立体声相甚远希望能解除您困惑问题直接问我望采纳~~~想解更蓝牙知识请关注
蓝牙知少 百度知道
但版本呢?
  麦芽为您解惑。楼主,您好。  截止到目前,蓝牙共有六个版本:V1.1 &#47; 1.2 &#47; 2.0 &#47; 2.1 &#47; 3.0 &#47; 4.0,以通讯距离来在不同版本可再分为Class A与Class B,Class A由于成本高主要用于商业特殊用途,我们日常接触的大多是Class B。  (1)V1.1与1.2为最早期的版本,传输速率仅有748~810kb&#47;s,由于是早期设计,通讯质量并不算好,还易受到同频率产品的干扰。  (2)直到蓝牙2.0+EDR标准的推出,蓝牙的实用性得到了大幅的提升,现在市场上能见到的产品也大多是2.0版本以后的,蓝牙2.0+EDR的传输速率达到了2.1Mbps,相对于1.2提升了三倍。  (3)随后蓝牙2.1+EDR的推出增加了Sniff Subrating功能,透过设定在2个装置之间互相确认讯号的发送间隔来达到节省功耗的目的。采用此技术后,让蓝牙2.1+EDR的待机时间可以延长5倍以上,具备了更加的省电效果。  (4)蓝牙3.0的推出,让数据传输速率再次提高到了大约24Mbps,同时还可以调用WiFi功能实现高速数据传输。紧接着蓝牙4.0的推出实现了最远100米的传输距离,同时拥有更低的功耗和3毫秒低延迟。  (5)蓝牙4.0最重要的特性是省电科技,极低的运行和待机功耗可以使一粒纽扣电池连续工作数年之久。此外,低成本和跨厂商互操作性,3毫秒低延迟、100米以上超长距离、AES-128加密等诸多特色,可以用于计步器、心律监视器、智能仪表、传感器物联网等众多领域,大大扩展蓝牙技术的应用范围。  蓝牙4.0依旧向下兼容,包含经典蓝牙技术规范和最高速度24Mbps的蓝牙高速技术规范。三种技术规范可单独使用,也可同时运行,现在的蓝牙4.0已经走向了商用。  希望能解除您的困惑。如果还有问题可以直接问我,望采纳~~~  想了解更多蓝牙知识,请关注 “ 蓝牙知多少 ”。百度一下,你就知道。
提问者评价
来自团队:
其他类似问题
为您推荐:
其他1条回答
蓝牙规范(HSP、HFP、A2DP)种功能蓝牙版本(1.0、1.2、2.0、3.0、4.0)越高越般手机能支持3.0<img class="word-replace" src="/api/getdecpic?picenc=0ad.0要新手机才支持才用
那它们之间有没有关系?
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁蓝牙 Profile_图文_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
蓝牙 Profile
上传于||暂无简介
大小:814.00KB
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢全面揭秘蓝牙4.0技术细节
 &>&&>&&>&&>&正文
  Bluetooth 4.0 双模式组合应用   根据Bluetooth SIG发布的Bluetooth 4.0核心规范白皮书,Bluetooth 4.0低耗电模式有双模式和单模式两种应用。低功耗蓝牙的单模式蓝牙的技术特点技术综述蓝牙(Bluetooth)通过低功率无线电波传输数据,其本质是 一种支持设备短距离通信(一般是10m之内)的无线电技术。其标准是IEEE 802.15,工作在2.402~2.480GHz频率带之间,基础带宽为1Mb/s。和Wi-Fi、WiMAX等用于局域、城域的无线网络规范不同的 是,Bluetooth所定义的应用范围更小一些,它将应用锁定在一个以个人为单位的人域网(PAN)领域,也就是个人起居活动范围的方圆10米之内,却 容纳了包括音频、互联网、移动通信、文件传输等在内的非常多样化的应用取向,加上强调自动化和易操作性,因此在这一领域里很快就得到了普及,虽然在蓝牙的 发展过程中一度曾偏离了这一主旨,但Bluetooth 4.0的出现无疑揭示了Bluetooth对自身核心价值的反思和回归。   调节性跳频与微微网(Piconet)的原理   因为蓝牙所用的频带仍处于应用繁多的2.4G无线电频率范围附近,为达到最大限度地避免设备间的相互干扰的目的,蓝牙从实际的应用出发,将信号功率设计 得非常微弱,仅为手机信号的数千分之一,这样设备间的距离就只能保持在约10米范围内,从而避免了和移动电话、电视机等设备间的相互干扰。   蓝牙协议被设计为同时允许最多八个蓝牙设备互连,因此协议需要解决的另一个问题就是如何处理同在有效传输范围内的这些蓝牙设备之间的相互干扰,这一问题 的解决催生了蓝牙协议最具独创性的通信方式&调节性跳频技术。它定义了79个独立且可随机选择的有效通信频率,每个蓝牙设备都能使用其中任何一个频率,且 能有规律地随时跳往另一个频率,按协议规范,这样的频率跳转每秒钟会发生1600次,因此不太可能出现两个发射器使用相同频率的情况,即使在特定频率下有 任何干扰,其持续时间也仅不到千分之一秒,因此该技术同时还将外界干扰对蓝牙设备间通讯的影响降低到最小。   让我们设想一下两个蓝牙设备 间通讯的过程,当两个蓝牙设备互相靠近时,它们之间会发生电子会话以交流需求,这一会话过程无需用户参与,而一旦需求确认,设备间便会自动确认地址并组成 一个被称为微微网(Piconet)的微型网络,此网络一旦形成,组成网络的设备便可协商好和谐地随机跳频,以确保彼此间的联系,但又不会对其它信号构成 干扰,于是蓝牙&杂技演员手里的一个钢球就这样形成了。   蓝牙的协议组成 蓝牙标准从制定之初便定义成为个人区域内的无线通信制定的协议,它包括两部分:第一部分为协议核心(Core)部分,用来规定诸如射频、基带、链路管理、 服务发现、传输层以及与其他通信协议间的互用、互操作性等基本组件及方法;第二部分为协议子集(Profile)部分,用来以规定不同蓝牙应用(也称使用 模式)所需的协议和过程。
  图4: 共享射频层和独立射频层的双模式低耗电蓝牙设计   如图5,蓝牙标准的设计仍采用从下至上的分层式结构,以人机接口(Host Controller Interface,HCI)为界分为低层和高层协议,其中底层的基带(Baseband)、射频(BluetoothRadio)和链路管理层 (LMP)协议定义了完成数据流的过滤和功能组件是一个高度集成的装置,具备轻量的链路层(Link Layer),能在最低成本的前提下,支持低功耗的待机模式、简易的设备发现、可靠的点对多点的数据传输、安全的加密链接等;位于上述控制器中的链路层, 适用于网络连接传感器,并确保在无线传输中,都能通过低功耗蓝牙传输。在双模式应用中,蓝牙低功耗的功能会整合至现有的传统蓝牙控制器中,共享传统蓝牙技 术已有的射频和功能,相较于传统的蓝牙技术,增加的成本更小;除此之外,制造商可利用升级版蓝牙低功耗技术的功能模块,集成目前的蓝牙3.0高速版本、或 2.1+EDR等传统蓝牙功能组件,从而改善传统蓝牙设备的数据传输效能。图4即为蓝牙低功耗技术的双模式应用功能逻辑拓扑图,图4右边所示即为通过整合原有蓝牙技术的射频降低了升级成本。
图5: 蓝牙标准模块构成   
  低功耗蓝牙为何如此省电?根据SIG官方发布会的资料,它和经典蓝牙技术相比,主要的改变集中体现在待机功耗的减少、高速连接的实现 和峰值功率的降低三个方面。待机功耗的下降 传统蓝牙设备的待机耗电量大一直是为人所诟病的缺陷之一,这与传统蓝牙技术动辄采用16~32个频道进行广播不无关系,而低功耗蓝牙仅使用了3个广播通 道,且每次广播时射频的开启时间也由传统的22.5ms减少到0.6~1.2ms,这两个协议规范上的改变显然大大降低了因为广播数据导致的待机功耗;此 外低功耗蓝牙设计了用深度睡眠状态来替换传统蓝牙的空闲状态,在深度睡眠状态下,主机长时间处于超低的负载循环(DutyCycle)状态,只在需要运作 时由控制器来启动,因主机较控制器消耗更多的能源,因此这样的设计也节省了最多的能源;在深度睡眠状态下,协议也针对此通讯模式进行了优化,数据发送间隔 时间也增加到0.5~4s,传感器类应用程序发送的数据量较平常要少很多,而且所有连接均采用先进的嗅探性次额定(Sn i f f-Subrating)功能模式,因此此时的射频能耗几乎可以忽略不计,综合以上因素,低功耗蓝牙的待机功耗较传统蓝牙大大减少。
&&第2页&&&&http://www.autooo.net/autooo/qianrushixitong/jishu//136532.html当前访客身份:游客 [
归纳总结~~~
:Android 文档特别说明了:Note: You can only sc...
:Android Wear/DuWear/TicWear/TOS/YunOS For Wea...
:Android Wear/DuWear/TicWear/TOS/YunOS For Wea...
:多谢谢分享学习了!
:1元4700套安卓源码+80G安卓学习视频 新店开张 求...
:引用来自“zzqzz”的评论哈哈,没写完呢吧 持续更...
:哈哈,没写完呢吧
:引用来自“FoxHu”的评论怎么不用Android studi...
今日访问:157
昨日访问:145
本周访问:587
本月访问:157
所有访问:96373
低功耗蓝牙(BLE)
发表于2年前( 11:18)&&
阅读(17364)&|&评论()
0人收藏此文章,
Android4.3以上加入了低功耗蓝牙,可以大大节省设备功耗。
& &低功耗蓝牙包括的术语及概念:
如上图所示,使用低功耗蓝牙可以包括多个Profile,一个Profile中有多个Service,一个Service中有多个Characteristic,一个Characteristic中包括一个value和多个Descriptor。
Android中进行蓝牙开发需要使用到的类的执行过程是:
1、使用BluetoothAdapter.startLeScan来扫描低功耗蓝牙设备
2、在扫描到设备的回调函数中会得到BluetoothDevice对象,并使用BluetoothAdapter.stopLeScan停止扫描
3、使用BluetoothDevice.connectGatt来获取到BluetoothGatt对象
4、执行BluetoothGatt.discoverServices,这个方法是异步操作,在回调函数onServicesDiscovered中得到status,通过判断status是否等于BluetoothGatt.GATT_SUCCESS来判断查找Service是否成功
5、如果成功了,则通过BluetoothGatt.getService来获取BluetoothGattService
6、接着通过BluetoothGattService.getCharacteristic获取BluetoothGattCharacteristic
7、然后通过BluetoothGattCharacteristic.getDescriptor获取BluetoothGattDescriptor
Android Bluetooth源码静态类图如下:
使用低功耗蓝牙需要用到的权限:
&uses-permission&android:name="android.permission.BLUETOOTH"/&
&uses-permission&android:name="android.permission.BLUETOOTH_ADMIN"/&
下面介绍怎样使用BLE:
1、准备BLE
& & 1)获取BluetoothAdapter
& & &BluetoothAdapter是从系统服务获取到的,全系统就一个。
//&Initializes&Bluetooth&adapter.
final&BluetoothManager&bluetoothManager&=
&&&&&&&&(BluetoothManager)&getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter&=&bluetoothManager.getAdapter();
& & 2)检测蓝牙是否打开
& & 如果蓝牙未打开,系统会自动打开,会弹出系统框展示打开蓝牙。
private&BluetoothAdapter&mBluetoothA
//&Ensures&Bluetooth&is&available&on&the&device&and&it&is&enabled.&If&not,
//&displays&a&dialog&requesting&user&permission&to&enable&Bluetooth.
if&(mBluetoothAdapter&==&null&||&!mBluetoothAdapter.isEnabled())&{
&&&&Intent&enableBtIntent&=&new&Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
&&&&startActivityForResult(enableBtIntent,&REQUEST_ENABLE_BT);
2、查找BLE设备
& &因为扫描BLE设备是电源密集型操作,浪费电量,因此要保证以下原则:
& & 1)扫描到需要的设备后,马上停止扫描;
& & 2)给扫描一个时间限制
& &扫描示例代码如下:
&*&Activity&for&scanning&and&displaying&available&BLE&devices.
public&class&DeviceScanActivity&extends&ListActivity&{
&&&&private&BluetoothAdapter&mBluetoothA
&&&&private&boolean&mS
&&&&private&Handler&mH
&&&&//&Stops&scanning&after&10&seconds.
&&&&private&static&final&long&SCAN_PERIOD&=&10000;
&&&&private&void&scanLeDevice(final&boolean&enable)&{
&&&&&&&&if&(enable)&{
&&&&&&&&&&&&//&Stops&scanning&after&a&pre-defined&scan&period.
&&&&&&&&&&&&mHandler.postDelayed(new&Runnable()&{
&&&&&&&&&&&&&&&&@Override
&&&&&&&&&&&&&&&&public&void&run()&{
&&&&&&&&&&&&&&&&&&&&mScanning&=&
&&&&&&&&&&&&&&&&&&&&mBluetoothAdapter.stopLeScan(mLeScanCallback);
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&},&SCAN_PERIOD);
&&&&&&&&&&&&mScanning&=&
&&&&&&&&&&&&mBluetoothAdapter.startLeScan(mLeScanCallback);
&&&&&&&&}&else&{
&&&&&&&&&&&&mScanning&=&
&&&&&&&&&&&&mBluetoothAdapter.stopLeScan(mLeScanCallback);
&&&&&&&&...
& & &如果只是要扫描到特定类型的设备,则使用接口&,通过UUID来查找设备。
& & 扫描回调的代码如下所示:
private&LeDeviceListAdapter&mLeDeviceListA
//&Device&scan&callback.
private&BluetoothAdapter.LeScanCallback&mLeScanCallback&=
&&&&&&&&new&BluetoothAdapter.LeScanCallback()&{
&&&&@Override
&&&&public&void&onLeScan(final&BluetoothDevice&device,&int&rssi,
&&&&&&&&&&&&byte[]&scanRecord)&{
&&&&&&&&runOnUiThread(new&Runnable()&{
&&&&&&&&&&&@Override
&&&&&&&&&&&public&void&run()&{
&&&&&&&&&&&&&&&mLeDeviceListAdapter.addDevice(device);
&&&&&&&&&&&&&&&mLeDeviceListAdapter.notifyDataSetChanged();
&&&&&&&&&&&}
&&&&&&&});
注意:我们既可以扫描BLE设备,也可以扫描普通蓝牙设备,也可以同时将BLE设备和普通蓝牙设备一起扫描到。
3、连接到GATT Server
& &获取到BluetoothGatt实例,
mBluetoothGatt&=&device.connectGatt(this,&false,&mGattCallback);
&&&&具体实例如下:
//&A&service&that&interacts&with&the&BLE&device&via&the&Android&BLE&API.
public&class&BluetoothLeService&extends&Service&{
&&&&private&final&static&String&TAG&=&BluetoothLeService.class.getSimpleName();
&&&&private&BluetoothManager&mBluetoothM
&&&&private&BluetoothAdapter&mBluetoothA
&&&&private&String&mBluetoothDeviceA
&&&&private&BluetoothGatt&mBluetoothG
&&&&private&int&mConnectionState&=&STATE_DISCONNECTED;
&&&&private&static&final&int&STATE_DISCONNECTED&=&0;
&&&&private&static&final&int&STATE_CONNECTING&=&1;
&&&&private&static&final&int&STATE_CONNECTED&=&2;
&&&&public&final&static&String&ACTION_GATT_CONNECTED&=
&&&&&&&&&&&&"com.example.bluetooth.le.ACTION_GATT_CONNECTED";
&&&&public&final&static&String&ACTION_GATT_DISCONNECTED&=
&&&&&&&&&&&&"com.example.bluetooth.le.ACTION_GATT_DISCONNECTED";
&&&&public&final&static&String&ACTION_GATT_SERVICES_DISCOVERED&=
&&&&&&&&&&&&"com.example.bluetooth.le.ACTION_GATT_SERVICES_DISCOVERED";
&&&&public&final&static&String&ACTION_DATA_AVAILABLE&=
&&&&&&&&&&&&"com.example.bluetooth.le.ACTION_DATA_AVAILABLE";
&&&&public&final&static&String&EXTRA_DATA&=
&&&&&&&&&&&&"com.example.bluetooth.le.EXTRA_DATA";
&&&&public&final&static&UUID&UUID_HEART_RATE_MEASUREMENT&=
&&&&&&&&&&&&UUID.fromString(SampleGattAttributes.HEART_RATE_MEASUREMENT);
&&&&//&Various&callback&methods&defined&by&the&BLE&API.
&&&&private&final&BluetoothGattCallback&mGattCallback&=
&&&&&&&&&&&&new&BluetoothGattCallback()&{
&&&&&&&&@Override
&&&&&&&&public&void&onConnectionStateChange(BluetoothGatt&gatt,&int&status,
&&&&&&&&&&&&&&&&int&newState)&{
&&&&&&&&&&&&String&intentA
&&&&&&&&&&&&if&(newState&==&BluetoothProfile.STATE_CONNECTED)&{
&&&&&&&&&&&&&&&&intentAction&=&ACTION_GATT_CONNECTED;
&&&&&&&&&&&&&&&&mConnectionState&=&STATE_CONNECTED;
&&&&&&&&&&&&&&&&broadcastUpdate(intentAction);
&&&&&&&&&&&&&&&&Log.i(TAG,&"Connected&to&GATT&server.");
&&&&&&&&&&&&&&&&Log.i(TAG,&"Attempting&to&start&service&discovery:"&+
&&&&&&&&&&&&&&&&&&&&&&&&mBluetoothGatt.discoverServices());
&&&&&&&&&&&&}&else&if&(newState&==&BluetoothProfile.STATE_DISCONNECTED)&{
&&&&&&&&&&&&&&&&intentAction&=&ACTION_GATT_DISCONNECTED;
&&&&&&&&&&&&&&&&mConnectionState&=&STATE_DISCONNECTED;
&&&&&&&&&&&&&&&&Log.i(TAG,&"Disconnected&from&GATT&server.");
&&&&&&&&&&&&&&&&broadcastUpdate(intentAction);
&&&&&&&&&&&&}
&&&&&&&&@Override
&&&&&&&&//&New&services&discovered
&&&&&&&&public&void&onServicesDiscovered(BluetoothGatt&gatt,&int&status)&{
&&&&&&&&&&&&if&(status&==&BluetoothGatt.GATT_SUCCESS)&{
&&&&&&&&&&&&&&&&broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&Log.w(TAG,&"onServicesDiscovered&received:&"&+&status);
&&&&&&&&&&&&}
&&&&&&&&@Override
&&&&&&&&//&Result&of&a&characteristic&read&operation
&&&&&&&&public&void&onCharacteristicRead(BluetoothGatt&gatt,
&&&&&&&&&&&&&&&&BluetoothGattCharacteristic&characteristic,
&&&&&&&&&&&&&&&&int&status)&{
&&&&&&&&&&&&if&(status&==&BluetoothGatt.GATT_SUCCESS)&{
&&&&&&&&&&&&&&&&broadcastUpdate(ACTION_DATA_AVAILABLE,&characteristic);
&&&&&&&&&&&&}
& & 其中,discoverService方式是异步的,它的回调方法是上面代码中的onServiceDiscovered。
private&void&broadcastUpdate(final&String&action)&{
&&&&final&Intent&intent&=&new&Intent(action);
&&&&sendBroadcast(intent);
private&void&broadcastUpdate(final&String&action,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&final&BluetoothGattCharacteristic&characteristic)&{
&&&&final&Intent&intent&=&new&Intent(action);
&&&&//&This&is&special&handling&for&the&Heart&Rate&Measurement&profile.&Data
&&&&//&parsing&is&carried&out&as&per&profile&specifications.
&&&&if&(UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid()))&{
&&&&&&&&int&flag&=&characteristic.getProperties();
&&&&&&&&int&format&=&-1;
&&&&&&&&if&((flag&&&0x01)&!=&0)&{
&&&&&&&&&&&&format&=&BluetoothGattCharacteristic.FORMAT_UINT16;
&&&&&&&&&&&&Log.d(TAG,&"Heart&rate&format&UINT16.");
&&&&&&&&}&else&{
&&&&&&&&&&&&format&=&BluetoothGattCharacteristic.FORMAT_UINT8;
&&&&&&&&&&&&Log.d(TAG,&"Heart&rate&format&UINT8.");
&&&&&&&&final&int&heartRate&=&characteristic.getIntValue(format,&1);
&&&&&&&&Log.d(TAG,&String.format("Received&heart&rate:&%d",&heartRate));
&&&&&&&&intent.putExtra(EXTRA_DATA,&String.valueOf(heartRate));
&&&&}&else&{
&&&&&&&&//&For&all&other&profiles,&writes&the&data&formatted&in&HEX.
&&&&&&&&final&byte[]&data&=&characteristic.getValue();
&&&&&&&&if&(data&!=&null&&&&data.length&&&0)&{
&&&&&&&&&&&&final&StringBuilder&stringBuilder&=&new&StringBuilder(data.length);
&&&&&&&&&&&&for(byte&byteChar&:&data)
&&&&&&&&&&&&&&&&stringBuilder.append(String.format("%02X&",&byteChar));
&&&&&&&&&&&&intent.putExtra(EXTRA_DATA,&new&String(data)&+&"\n"&+
&&&&&&&&&&&&&&&&&&&&stringBuilder.toString());
&&&&sendBroadcast(intent);
//&Handles&various&events&fired&by&the&Service.
//&ACTION_GATT_CONNECTED:&connected&to&a&GATT&server.
//&ACTION_GATT_DISCONNECTED:&disconnected&from&a&GATT&server.
//&ACTION_GATT_SERVICES_DISCOVERED:&discovered&GATT&services.
//&ACTION_DATA_AVAILABLE:&received&data&from&the&device.&This&can&be&a
//&result&of&read&or&notification&operations.
private&final&BroadcastReceiver&mGattUpdateReceiver&=&new&BroadcastReceiver()&{
&&&&@Override
&&&&public&void&onReceive(Context&context,&Intent&intent)&{
&&&&&&&&final&String&action&=&intent.getAction();
&&&&&&&&if&(BluetoothLeService.ACTION_GATT_CONNECTED.equals(action))&{
&&&&&&&&&&&&mConnected&=&
&&&&&&&&&&&&updateConnectionState(R.string.connected);
&&&&&&&&&&&&invalidateOptionsMenu();
&&&&&&&&}&else&if&(BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action))&{
&&&&&&&&&&&&mConnected&=&
&&&&&&&&&&&&updateConnectionState(R.string.disconnected);
&&&&&&&&&&&&invalidateOptionsMenu();
&&&&&&&&&&&&clearUI();
&&&&&&&&}&else&if&(BluetoothLeService.
&&&&&&&&&&&&&&&&ACTION_GATT_SERVICES_DISCOVERED.equals(action))&{
&&&&&&&&&&&&//&Show&all&the&supported&services&and&characteristics&on&the
&&&&&&&&&&&&//&user&interface.
&&&&&&&&&&&&displayGattServices(mBluetoothLeService.getSupportedGattServices());
&&&&&&&&}&else&if&(BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action))&{
&&&&&&&&&&&&displayData(intent.getStringExtra(BluetoothLeService.EXTRA_DATA));
4、读BLE属性
& & 一旦获取到GATT的Services,就可以读写他们的属性了,实例如下:
public&class&DeviceControlActivity&extends&Activity&{
&&&&//&Demonstrates&how&to&iterate&through&the&supported&GATT
&&&&//&Services/Characteristics.
&&&&//&In&this&sample,&we&populate&the&data&structure&that&is&bound&to&the
&&&&//&ExpandableListView&on&the&UI.
&&&&private&void&displayGattServices(List&BluetoothGattService&&gattServices)&{
&&&&&&&&if&(gattServices&==&null)&
&&&&&&&&String&uuid&=&
&&&&&&&&String&unknownServiceString&=&getResources().
&&&&&&&&&&&&&&&&getString(R.string.unknown_service);
&&&&&&&&String&unknownCharaString&=&getResources().
&&&&&&&&&&&&&&&&getString(R.string.unknown_characteristic);
&&&&&&&&ArrayList&HashMap&String,&String&&&gattServiceData&=
&&&&&&&&&&&&&&&&new&ArrayList&HashMap&String,&String&&();
&&&&&&&&ArrayList&ArrayList&HashMap&String,&String&&&&gattCharacteristicData
&&&&&&&&&&&&&&&&=&new&ArrayList&ArrayList&HashMap&String,&String&&&();
&&&&&&&&mGattCharacteristics&=
&&&&&&&&&&&&&&&&new&ArrayList&ArrayList&BluetoothGattCharacteristic&&();
&&&&&&&&//&Loops&through&available&GATT&Services.
&&&&&&&&for&(BluetoothGattService&gattService&:&gattServices)&{
&&&&&&&&&&&&HashMap&String,&String&&currentServiceData&=
&&&&&&&&&&&&&&&&&&&&new&HashMap&String,&String&();
&&&&&&&&&&&&uuid&=&gattService.getUuid().toString();
&&&&&&&&&&&&currentServiceData.put(
&&&&&&&&&&&&&&&&&&&&LIST_NAME,&SampleGattAttributes.
&&&&&&&&&&&&&&&&&&&&&&&&&&&&lookup(uuid,&unknownServiceString));
&&&&&&&&&&&&currentServiceData.put(LIST_UUID,&uuid);
&&&&&&&&&&&&gattServiceData.add(currentServiceData);
&&&&&&&&&&&&ArrayList&HashMap&String,&String&&&gattCharacteristicGroupData&=
&&&&&&&&&&&&&&&&&&&&new&ArrayList&HashMap&String,&String&&();
&&&&&&&&&&&&List&BluetoothGattCharacteristic&&gattCharacteristics&=
&&&&&&&&&&&&&&&&&&&&gattService.getCharacteristics();
&&&&&&&&&&&&ArrayList&BluetoothGattCharacteristic&&charas&=
&&&&&&&&&&&&&&&&&&&&new&ArrayList&BluetoothGattCharacteristic&();
&&&&&&&&&&&//&Loops&through&available&Characteristics.
&&&&&&&&&&&&for&(BluetoothGattCharacteristic&gattCharacteristic&:
&&&&&&&&&&&&&&&&&&&&gattCharacteristics)&{
&&&&&&&&&&&&&&&&charas.add(gattCharacteristic);
&&&&&&&&&&&&&&&&HashMap&String,&String&&currentCharaData&=
&&&&&&&&&&&&&&&&&&&&&&&&new&HashMap&String,&String&();
&&&&&&&&&&&&&&&&uuid&=&gattCharacteristic.getUuid().toString();
&&&&&&&&&&&&&&&&currentCharaData.put(
&&&&&&&&&&&&&&&&&&&&&&&&LIST_NAME,&SampleGattAttributes.lookup(uuid,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&unknownCharaString));
&&&&&&&&&&&&&&&&currentCharaData.put(LIST_UUID,&uuid);
&&&&&&&&&&&&&&&&gattCharacteristicGroupData.add(currentCharaData);
&&&&&&&&&&&&}
&&&&&&&&&&&&mGattCharacteristics.add(charas);
&&&&&&&&&&&&gattCharacteristicData.add(gattCharacteristicGroupData);
&&&&&&&&&}
& 在获取Service的时候,每个蓝牙设备都会有两个默认的Service,它们和对应的UUID分别如下:
Bluetooth Generic Access Profile & &{0-805f9b34fb}
Bluetooth Generic Attribute Profile {0-805F9B34FB}
5、收到GATT通知
& &如果设备主动给手机发信息,则可以通过notification的方式,这种方式不用手机去轮询地读设备上的数据。手机可以用如下方式给设备设置notification功能。
private&BluetoothGatt&mBluetoothG
BluetoothGattCharacteristic&
mBluetoothGatt.setCharacteristicNotification(characteristic,&enabled);
BluetoothGattDescriptor&descriptor&=&characteristic.getDescriptor(
&&&&&&&&UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
& & 如果notificaiton方式对于某个Characteristic是enable的,那么当设备上的这个Characteristic改变时,手机上的&回调就会被促发。如下所示:
//&Characteristic&notification
public&void&onCharacteristicChanged(BluetoothGatt&gatt,
&&&&&&&&BluetoothGattCharacteristic&characteristic)&{
&&&&broadcastUpdate(ACTION_DATA_AVAILABLE,&characteristic);
6、关闭客户端蓝牙
public&void&close()&{
&&&&if&(mBluetoothGatt&==&null)&{
&&&&mBluetoothGatt.close();
&&&&mBluetoothGatt&=&
更多开发者职位上
1)">1)">1" ng-class="{current:{{currentPage==page}}}" ng-repeat="page in pages"><li class='page' ng-if="(endIndex<li class='page next' ng-if="(currentPage
相关文章阅读

我要回帖

更多关于 蓝牙的profile 的文章

 

随机推荐