Public API for the Bluetooth GATT Profile.
适用于GATT协议,实现控制等
This class provides Bluetooth GATT functionality to enable communication with Bluetooth Smart or Smart Ready devices.
To connect to a remote peripheral device, create a BluetoothGattCallback
and call connectGatt(Context, boolean, BluetoothGattCallback)
to get a instance of this class.通过上述两个方法得到这个类的一个实例。 GATT capable能干的 devices can be discovered using the Bluetooth device discovery or BLE scan process.
常量
int CONNECTION_PRIORITY_BALANCED
Connection paramter参数 update - Use the connection paramters recommended推荐,介绍 by the Bluetooth SIG.
int CONNECTION_PRIORITY_HIGH
Connection paramter update - Request a high priority优先级, low latency延迟 connection.
int CONNECTION_PRIORITY_LOW_POWER
Connection paramter update - Request low power, reduced data rate connection parameters.
int GATT_CONNECTION_CONGESTED
远程设备被阻塞
int GATT_FAILURE
A GATT operation failed, errors other than the above
int GATT_INSUFFICIENT_AUTHENTICATION
Insufficient 不足authentication 认证for a given operation
int GATT_INSUFFICIENT_ENCRYPTION
Insufficient encryption加密 for a given operation
int GATT_INVALID_ATTRIBUTE_LENGTH
A write operation exceeds the maximum length of the attribute长度超出限制
int GATT_INVALID_OFFSET
A read or write operation was requested with an invalid无效的 offset补偿抵消
int GATT_READ_NOT_PERMITTED
读的权限不足
int GATT_REQUEST_NOT_SUPPORTED
The given request is not supported
int GATT_SUCCESS
A GATT operation completed successfully
int GATT_WRITE_NOT_PERMITTED
公有方法
void abortReliableWrite()
Cancels a reliable可靠的 write transaction事务 for a given device.
void abortReliableWrite(BluetoothDevice mDevice)
This method was deprecated in API level 19. Use abortReliableWrite()
boolean beginReliableWrite()
Initiates 启用a reliable write transaction for a given remote device.
void close()
关闭GATT客户端
boolean connect();
Connect back to remote device
void disconnect()
Disconnects an established 已建立的connection, or cancels a connection attempt currently in progress.
boolean discoverServices()
Discovers services offered by a remote device as well as their characteristics and descriptors.特征和描述
boolean executeReliableWrite()
Executes a reliable write transaction for a given remote device.执行写的命令
List<BluetoothDevice> getConnectedDevices()
Not supported - please use getConnectedDevices(int)
with GATT
as argument
int getConnectionState( BluetoothDevice device)
Not supported - please use getConnectedDevices(int)
with GATT
as argument论证
BluetoothDevice getDevice ()
return the remote bluetooth device this GATT client targets to
List < BluetoothDevice > getDevicesMatchingConnectionStates(int[] states)
Not supported - please use getDevicesMatchingConnectionStates(int, int[])
with GATT
as first argument
BluetoothGattService getService(UUID uuid)
Returns a BluetoothGattService
, if the requested UUID is supported by the remote device.
List<BluetoothGattService> getServices()
Returns a list of GATT services offered by the remote device.
boolean readCharacteristic(BluetoothGattCharacteristic characteristic)
Reads the requested characteristic from the associated关联的 remote device.
boolean readDescriptor(BluetoothGattDescriptor descriptor)
Reads the value for a given descriptor from the associated remote device.
boolean readRemoteRssi()
Read the RSSI for a connected remote device.
boolean requestConnectionPriority(int connectionPriority)
Request a connection parameter update
boolean requestMtu(int mtu)
Request an MTU size used for a given connection.
boolean setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enable)
Enable or disable notifications/indications for a given characteristic.
boolean writeCharacteristic(BluetoothGattCharacteristic characteristic)
Writes a given characteristic and its values to the associated remote device.
boolean writeDescriptor(BluetoothGattDescriptor descriptor)
Write the value of a given descriptor to the associated remote device.