Android BLE 蓝牙低功耗教程,中央和周边的实现
来源:互联网 发布:申请域名多少钱 编辑:程序博客网 时间:2024/04/30 01:00
Android4.3 规范了BLE的API,但是直到目前的4.4,还有些功能不完善。
在BLE协议中,有两个角色,周边(Periphery)和中央(Central);周边是数据提供者,中央是数据使用/处理者;在iOS SDK里面,可以把一个iOS设备作为一个周边,也可以作为一个中央;但是在Android SDK里面,直到目前最新的Android4.4.2,Android手机只能作为中央来使用和处理数据;那数据从哪儿来?从BLE设备来,现在的很多可穿戴设备都是用BLE来提供数据的。
一个中央可以同时连接多个周边,但是一个周边某一时刻只能连接一个中央。
大概了解了概念后,看看Android BLE SDK的四个关键类(class):
a) BluetoothGattServer作为周边来提供数据;BluetoothGattServerCallback返回周边的状态。
b) BluetoothGatt作为中央来使用和处理数据;BluetoothGattCallback返回中央的状态和周边提供的数据。
因为我们讨论的是Android的BLE SDK,下面所有的BluetoothGattServer代表周边,BluetoothGatt代表中央。
一.创建一个周边(虽然目前周边API在Android手机上不工作,但还是看看)
a)先看看周边用到的class,蓝色椭圆
b)说明:
每一个周边BluetoothGattServer,包含多个服务Service,每一个Service包含多个特征Characteristic。
1.new一个特征:character = new BluetoothGattCharacteristic(
UUID.fromString(characteristicUUID),
BluetoothGattCharacteristic.PROPERTY_NOTIFY,
BluetoothGattCharacteristic.PERMISSION_READ);
2.new一个服务:service = new BluetoothGattService(UUID.fromString(serviceUUID),
BluetoothGattService.SERVICE_TYPE_PRIMARY);
3.把特征添加到服务:service.addCharacteristic(character);
4.获取BluetoothManager:manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
5.获取/打开周边:BluetoothGattServer server = manager.openGattServer(this,
new BluetoothGattServerCallback(){...});
6.把service添加到周边:server.addService(service);
7.开始广播service:Google还没有广播Service的API,等吧!!!!!所以目前我们还不能让一个Android手机作为周边来提供数据。
二.创建一个中央(这次不会让你失望,可以成功创建并且连接到周边的)
a)先看看中央用到的class,蓝色椭圆
下载地址:http://download.csdn.net/detail/jimoduwu/7072515
- Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现
- Android BLE 蓝牙低功耗教程,中央和周边的实现
- Android BLE 蓝牙低功耗教程,中央和周边的实现
- Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现
- Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现
- Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现
- Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现
- Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现
- Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现
- Android BLE 蓝牙低功耗教程,中央和周边的实现
- Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现
- Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现
- android 低功耗蓝牙BLE的春天
- Android蓝牙开发教程:中央BluetoothGatt和周边BluetoothGattServer的实现
- Android BLE低功耗蓝牙开发(下) BLE客户端(中央设备)与GATT服务的通讯
- android 蓝牙4.0 ble 低功耗蓝牙
- 低功耗蓝牙BLE
- 蓝牙低功耗(BLE)
- Ip camera(网络摄像头)试用
- 融系统中PBOC/EMV的TLV的算法实现(含C++/C#)
- wave文件 wav格式
- 或许是好文章,先记录下,有时间看下
- wso2 Carbon在eclipse上运行
- Android BLE 蓝牙低功耗教程,中央和周边的实现
- SDK manager显示不全的问题
- 动态规划3:合唱队形
- 进程与线程及其区别
- 图片转base64串及反转回图片
- 数组指针和指针数组的区别
- xml的一个内部透明,带边框的背景,可用于按钮之类
- 源码剖析Iterator接口遍历和直接for-get组合遍历的区别
- Linux下SCP命令不输入密码(免密码)备份