BluetoothGatt API

punlic final class BluetoothGatt
继承自Object , 实现了BluetoothProfile接口
/**

相关的蓝牙协议可http://www.cnki.net/KCMS/detail/detail.aspx?QueryID=2&CurRec=1&recid=&filename=1013177885.nh&dbname=CMFD201302&dbcode=CMFD&pr=&urlid=&yx=&uid=WEEvREcwSlJHSldTTGJhYlQ4RW9HZzBWckhnY3Z2bTR6VjJ5ZlJsL2FiMkRZcHNnazlOUEJud0pMeW9xLzlycnRqND0=$9A4hF_YAuvQ5obgVAqNKPCYcEjKensW4IQMovwHtwkF4VYPoHbKxJw!!&v=MjQzNTBkdUZ5emdVTHJLVkYyNkhiSy9HZG5FcXBFYlBJUjhlWDFMdXhZUzdEaDFUM3FUcldNMUZyQ1VSTCtmYis=
**/
简述:
提供了BluetoothGATT Profile 的公共API
这个类提供了GATT功能(functionality ) 可以与Bluetooth Smart或者是Smart Ready 设备(devces)进行通信;
要想连接外设(peripheral  device) , 需要创建一个  
BluetoothGattCallback (PS 这个相当于回调函数) ; 
然后调用
BluetoothDevice类的connectGatt(Context, boolean, BluetoothGattCallback)才可以获得该类的实例(instance) ; 具有GATT的设备是可以通过使用 蓝牙设备搜索()或者 低功耗的蓝牙(BLE)搜索到的;
PS : buletooth
ble 概念略有不同 ;

Bluetooth GATT
中的常量:(不全)
GATT_FAILURE : 标识一个失败的GATT操作 这个值是 257 (0x00000101)
GATT_SUCCESS :一个成功的GATT操作 这个值是:0 (0x00000000) PS 符合 "非零即为真 执行成功"

常用函数:
void  close() : 关闭该GATT客户端 ,当与GATT client无关的时候 , 尽可能早的调用这个方法
 boolean
connect()  : 连接到远程设备 , 这个方法用于 当连接断开的时候 , 重新连接一个远程的设备如果这个设备不再范围内. 那么只要这个设备回到覆盖的范围中,就会触发重新连接 PS :这个方法解决了实际生活中的很多问题呀
void disconnect() :
断开建立的连接,或者是终止当前正在适配的连接进程,这个需要权限
discoverServices() :  搜索一个远程设备的服务,以及characteristics descriptors  , 这是一个异步的操作, 一旦搜索服务完成 , 会触发刚才的那个Callback函数的 回调方法:
onServicesDiscovered(BluetoothGatt, int);
如果成功的搜索到服务的话 , 可以使用 
getServices()方法检索
返回true 代表  

getConnectedDevices()  已经不推荐 使用了 ,  BluetoothmanagergetConnectedDevices(int) 方法替代
 -----------------------
与数据交互有关的方法:
 
 
 
BluetoothGattService   getService(UUID uuid)
 
如果远程设备支持UUID的话, 会返回一个 BluetoothGattService对象 , 这个方法需要进行 搜索蓝牙之后给出一个bluetoothDevice对象
如果存在有大量的相同的UUID标识的Service存在的话, 这里只会返回第一个service实例 

List<BluetoothGattService>  getServices() 
返回远程设备提供的所有的服务(Service)   ,返回的结果即为提供的服务,如果是null

boolean   readCharacteristic(BluetoothGattCharacteristic characteristic)
触发回调函数的事件   , 以为读取远程device指定的characteristic  ,
boolean  readDescriptor(BluetoothGattDescriptor descriptor)
读取描述.....



===========================================================================================================
原文:
 http://wear.techbrood.com/reference/android/bluetooth/BluetoothGatt.html#readCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

原文地址:https://www.cnblogs.com/greentomlee/p/4721785.html