ShareThis

- By Vikas Verma

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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Android Bluetooth Low Energy (BLE)简单方便的蓝牙开源库——EasyBLE

    源码传送门 最新版本 功能 支持多设备同时连接 支持广播包解析 支持连接同时配对 支持搜索系统已连接设备 支持搜索器设置 支持自定义搜索过滤条件 支持自动重连.最大重连次数限制.直接重连或搜索到设备再 ...

  4. 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 ...

  5. Android使用BLE(低功耗蓝牙,Bluetooth Low Energy)

    背景 在学习BLE的过程中,积累了一些心得的DEMO,放到Github,形成本文.感兴趣的同学可以下载到源代码. github: https://github.com/vir56k/bluetooth ...

  6. Bluetooth Low Energy 嗅探

    Bluetooth Low Energy 嗅探 路人甲 · 2015/10/16 10:52 0x00 前言 如果你打开这篇文章时期望看到一些新的东西,那么很抱歉这篇文章不是你在找的那篇文章.因为严格 ...

  7. Bluetooth Low Energy介绍

    目录 1. 介绍 2. 协议栈 3. 实现方案 3.1 硬件实现方案 3.2 软件实现方案 1. 介绍 Bluetooth low energy,也称BLE(低功耗蓝牙),在4.0规范中提出 BLE分 ...

  8. Bluetooth Low Energy 介绍

    1.简介 BLE(Bluetooth Low Energy,低功耗蓝牙)是对传统蓝牙BR/EDR技术的补充.尽管BLE和传统蓝牙都称之为蓝牙标准,且共享射频,但是,BLE是一个完全不一样的技术.BLE ...

  9. Bluetooth® Low Energy Beacons

    Bluetooth® Low Energy Beacons ABSTRACT (abstract ) 1.This application report presents the concept of ...

随机推荐

  1. sharepoint 2013 "The module ... owssvr.dll could not be loaded due to a configuration problem"

    打开sharepoint站点可以看到这个503的错误, 在event viewer中查看如下: The Module DLL 'C:\Program Files\Common Files\Micros ...

  2. asp.net mvc @RenderBody()的问题

    在使用.net mvc 母版页布局时如果是进行上中下三块布局的话,那么就会像下面的图那样: 在上面的div 和下面的div之间会出现4cm的间隔, 解决如下: 给包裹@RenderBody()的div ...

  3. Android之画廊点击内容显示

    package com.example.Gallery; import com.example.Gallery.R; import android.os.Bundle; import android. ...

  4. jquery更改Reaper某一列的值

    一.实现效果:通过Jquery实现点击repeater中的按钮循环修改快递专线的线路状态 1.初始效果图 2.点击关闭专线按钮之后的效果图 二.MVC模式实现上述效果 SQLServerDAL层 #r ...

  5. 关于Windows® API Code Pack for Microsoft® .NET Framework

    相比之前的操作系统,Window 7(or Vista)提供了很多新特性,我们在应用实现中可以利用这些特性来提升用户体验. 这些特性主要包括以下几个方面: Shell Enhancements Dir ...

  6. C# 四舍五入

    1,国外的标准具体是四舍六入 Math.Round(1.267,2)     //Returns   1.27 参数1是需要处理的值; 参数2是小数点后保留几位   2,中国的标准 Math.Roun ...

  7. (转)hessian源码分析(一)------架构

    在计费中心的对外交互这块采用了hessian,有必要对hessian的运行机理和源码做一定的解析. 大致翻了翻源码后,发现hessian的主要结构分客户端与服务端,中间基于http传输.客户端主要做的 ...

  8. 原生js实现addClass,removeClass,hasClass方法

    function hasClass(elem, cls) { cls = cls || ''; if (cls.replace(/\s/g, '').length == 0) return false ...

  9. 济南学习 Day 4 T1 am

    完美的序列(sequence)Time Limit:1000ms Memory Limit:64MB题目描述LYK 认为一个完美的序列要满足这样的条件:对于任意两个位置上的数都不相同.然而并不是所有的 ...

  10. C++ Vector 动态数组

    Vectors 包含着一系列连续存储的元素,其行为和数组类似.访问Vector中的任意元素或从末尾添加元素都可以在常量级时间复杂度内完成,而查找特定值的元素所处的位置或是在Vector中插入元素则是线 ...