How to Implement Bluetooth Low Energy (BLE) in Ice Cream Sandwich
Bluetooth low energy (BLE) is a feature of Bluetooth 4.0 wireless radio technology, aimed at new, principally low-power and low-latency, applications for wireless devices within a short range. As I discussed in my previous blog about BLE in Android, it has been acknowledged that using this technology in devices will lead to very less power consumption and increase in performance. BLE being a latest technology and in the development mode, is not being used by many devices as of now but this is poised to change soon. It will soon become an essential part of devices that use Bluetooth.
As the Bluetooth Low Energy stack is available with some third party
vendors, they have their own set of APIs for BLE programming. You just
need to include their API add-ons into your Android apps to access the
BLE features.
As we know that in Android, there is no generic API for BLE. Different vendors give their own API's for Android App development.
Here we are going to discuss about Motorola API. The profile
specification allows performing the read and writing operations only
when the Bluetooth Low Energy API's allow connecting with the
remote device.
Some developments have been done with BLE to support the latest Android version ICS (Ice Cream Sandwich) and I have tried to summarize some useful information for you to implement with your latest Motorola device having ICS.
Use this link to download the Add-on for ICS (Ice Cream Sandwich) operating system.
Two libraries, BluetoothGattService.jar and BluetoothGatt.jar are used in Android project.
You need to create two files:
i) android.bluetooth.IBluetoothGattProfile; //This file needs to be created
interface IBluetoothGattProfile {
void onDiscoverCharacteristicsResult(in String path, in boolean result);
void onSetCharacteristicValueResult(in String path, in boolean result);
void onSetCharacteristicCliConfResult(in String path, in boolean result);
void onUpdateCharacteristicValueResult(in String path, in boolean result);
void onValueChanged(in String path, in String value);
}
ii)com.motorola.bluetooth.bluetoothle.IBluetoothGattCallback; //This file needs to be created
/**
* System private API for Bluetooth GATT Service
*
*
*/
oneway interface IBluetoothGattCallback
{
void indicationGattCb (in BluetoothDevice device, String uuid, String char_handle, in String[] data);
void notificationGattCb (in BluetoothDevice device , String uuid, String char_handle, in byte[] data);
}
Now in main activity, initially you have to scan for bluetooth devices and then check for the BLE device by calling function getBluetoothDeviceType(). If it returns LE that means the device you scanned for is a BLE device
After that you need to call getGattServices(uuid, device) for searching the primary device.
private boolean getGattServices(ParcelUuid uuid, BluetoothDevice btDevice)
{
Log.d(TAG, "Calling btDevice.getGattServices");
return btDevice.getGattServices(uuid.getUuid());
}
Parameters
Device: Device address of the GATT server being connected to.
Uuid: UUID of the primary service to which your profile is connecting.
Then you get the broadcast with the action BluetoothDevice.ACTION_GATT and then call the function
getBluetoothGattService(selectedServiceObjPath, uuid);
private void getBluetoothGattService(String objPath, ParcelUuid uuid)
{
if (mDevice != null)
{
BluetoothGattService gattService = new BluetoothGattService(mDevice,uid,objPath,btGattCallback);
if (gattService != null)
{
uuidGattSrvMap.put(uuid, gattService);
return;
}
else
{
Log.e(TAG, "Gatt service is null for UUID");
}
}
else
{
Log.e(TAG, mDevice is null");
}
mLeState = DISCONNECTED;
Toast.makeText(mContext,"Connection Failed", Toast.LENGTH_SHORT).show();
}
Parameters in BluetoothGattService
device: device address of the GATT server being connected to.
Uuid : UUID of the primary service to which your profile is connecting.
Callback: IBluetoothGattProfile.Stub objects that receives user data from the connected service.
Methods used by Bluetooth LE profiles
i) How to read the value of a service
gattService.updateCharacteristicValue(objPath)
objPath is a mapped path for the service you want to read.
ii) How to write a value
gattService.writeCharacteristicRaw(objPath, data, true);
objPath is a mapped path for the service you want to write.
Data is a byte array which you want to write
iii) How to disconnect
gattService.close();
NOTE: You can find the sample inside the Motorola
Add-ons. The above mentioned API is still in development mode and you
might come across with some development issues (bugs) as it is a BETA
Release.
How to Implement Bluetooth Low Energy (BLE) in Ice Cream Sandwich的更多相关文章
- Bluefruit LE Sniffer - Bluetooth Low Energy (BLE 4.0) - nRF51822 驱动安装及使用
BLE Sniffer https://www.adafruit.com/product/2269 Bluefruit LE Sniffer - Bluetooth Low Energy (BLE 4 ...
- Android bluetooth low energy (ble) writeCharacteristic delay callback
I am implementing a application on Android using BLE Api (SDK 18), and I have a issue that the trans ...
- Android Bluetooth Low Energy (BLE)简单方便的蓝牙开源库——EasyBLE
源码传送门 最新版本 功能 支持多设备同时连接 支持广播包解析 支持连接同时配对 支持搜索系统已连接设备 支持搜索器设置 支持自定义搜索过滤条件 支持自动重连.最大重连次数限制.直接重连或搜索到设备再 ...
- Overview and Evaluation of Bluetooth Low Energy: An Emerging Low-Power Wireless Technology
转自:http://www.mdpi.com/1424-8220/12/9/11734/htm Sensors 2012, 12(9), 11734-11753; doi:10.3390/s12091 ...
- Android使用BLE(低功耗蓝牙,Bluetooth Low Energy)
背景 在学习BLE的过程中,积累了一些心得的DEMO,放到Github,形成本文.感兴趣的同学可以下载到源代码. github: https://github.com/vir56k/bluetooth ...
- Bluetooth Low Energy 嗅探
Bluetooth Low Energy 嗅探 路人甲 · 2015/10/16 10:52 0x00 前言 如果你打开这篇文章时期望看到一些新的东西,那么很抱歉这篇文章不是你在找的那篇文章.因为严格 ...
- Bluetooth Low Energy介绍
目录 1. 介绍 2. 协议栈 3. 实现方案 3.1 硬件实现方案 3.2 软件实现方案 1. 介绍 Bluetooth low energy,也称BLE(低功耗蓝牙),在4.0规范中提出 BLE分 ...
- Bluetooth Low Energy 介绍
1.简介 BLE(Bluetooth Low Energy,低功耗蓝牙)是对传统蓝牙BR/EDR技术的补充.尽管BLE和传统蓝牙都称之为蓝牙标准,且共享射频,但是,BLE是一个完全不一样的技术.BLE ...
- Bluetooth® Low Energy Beacons
Bluetooth® Low Energy Beacons ABSTRACT (abstract ) 1.This application report presents the concept of ...
随机推荐
- Application Loader上传app时报错:the bundle identifier cannot be changed from the current value
报错如图: 解决:用info.plist中的bundle identifier生成发布证书(Distribution),如图:
- OGNL 对象视图导航语言
[Object Graphics Navigate Language] 类似于EL(Expression Language)表达式, 可以帮助我们在配置文件.JSP中来获取对象的值 这门语言比EL功能 ...
- 设置WinForm窗体及程序图标
自己留着看,总是用的时候给忘记了,百度来百度去的麻烦. 设置 Ico 图标为 [资源文件] 项目名à右键à属性,在选项卡中选择"资源" 选择 "添加资源"à ...
- 如何下载免费英特尔® 实感™ SDK
英特尔® 实感™ SDK支持的用途包括手/指跟踪.面部分析.语音识别和合成.背景分段.增强现实性等等,给你带来全新的人机交互体验.还不赶紧跟着我们一起免费下载英特尔® 实感™ SDK吧! 1. 输入网 ...
- C# lock用法
当我们使用线程的时候,效率最高的方式当然是异步,即各个线程同时运行,其间不相互依赖和等待.但当不同的线程都需要访问某个资源的时候,就需要同步机制了,也就是说当对同一个资源进行读写的时候,我们要使该资源 ...
- cocos2dx2.2.2登录场景中Checkbox选择框的实现
在前两篇文章中,我们介绍了在注册场景中需要用到的输入框及弹出框的实现方式,这两篇文章中介绍的内容在登录场景同样会用到.而我们经常会在登录场景中见到的另一种元素就是自动登录或者记住密码的Checkbox ...
- 【学习笔记】【C语言】结构体
1.定义结构体变量的3种方式 1> 先定义类型,再定义变量(分开定义) struct Student { int age; }; struct Student stu; 2> 定义 ...
- linux 内核和应用程序区别
应用程序存在于虚拟内存中, 有一个非常大的堆栈区. 堆栈, 当然, 是用来保存函数调用历史以及所有的由当前活跃的函数创建的自动变量. 内核, 相反, 有一个非常小的堆栈; 它可能小到一个, 4096 ...
- iOS ARC基本原理
一.ARC基本简介 ARC:Automatic Reference Counting 自动引用 完全消除了手动管理内存的烦琐,编译器会自动在适当的地方插入适当的retain.release.autor ...
- 【转】CSS实现兼容性的渐变背景(gradient)效果
一.有点俗态的开场白 要是两年前,实现“兼容性的渐变效果”这个说法估计不会被提出来的,那个时候,说起渐变背景,想到的多半是IE的渐变滤镜,其他浏览器尚未支持,但是,在对CSS3支持日趋完善的今天,实现 ...