public class BluetoothGattService
extends Object implements Parcelable
| java.lang.Object | |
| android.bluetooth.BluetoothGattService | |
代表蓝牙GATT服务
盖特服务包含的集合 BluetoothGattCharacteristic ,以及引用服务。
常量(Constants) |
|
|---|---|
int |
SERVICE_TYPE_PRIMARY 主要服务 |
int |
SERVICE_TYPE_SECONDARY 二级服务(包括主要服务) |
Inherited constants |
|---|
android.os.Parcelable
|
Fields |
|
|---|---|
public static final Creator<BluetoothGattService> |
CREATOR |
protected List<BluetoothGattCharacteristic> |
mCharacteristics 此服务中包含的特征列表。 |
protected List<BluetoothGattService> |
mIncludedServices 此服务包含的服务列表。 |
Public constructors |
|
|---|---|
BluetoothGattService(UUID uuid, int serviceType) 创建一个新的BluetoothGattService。 |
|
公共方法(Public methods) |
|
|---|---|
boolean |
addCharacteristic(BluetoothGattCharacteristic characteristic) 为此服务添加一个特征。 |
boolean |
addService(BluetoothGattService service) 为此服务添加一项包含的服务。 |
BluetoothGattCharacteristic |
getCharacteristic(UUID uuid) 返回此服务提供的特征列表中的给定UUID的特征。 |
List<BluetoothGattCharacteristic> |
getCharacteristics() 返回此服务中包含的特征列表。 |
List<BluetoothGattService> |
getIncludedServices() 获取此服务包含的GATT服务列表。 |
int |
getInstanceId() 返回此服务的实例ID 如果远程设备使用相同的UUID提供多个服务(例如, |
int |
getType() 获取此服务的类型(主要/次要) |
UUID |
getUuid() 返回此服务的UUID |
void |
writeToParcel(Parcel out, int flags) 将此对象平铺到一个包裹中。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
android.os.Parcelable
|
|
int SERVICE_TYPE_SECONDARY
二级服务(包括主要服务)
常数值:1(0x00000001)
List<BluetoothGattCharacteristic> mCharacteristics
此服务中包含的特征列表。
BluetoothGattService (UUID uuid, int serviceType)
创建一个新的BluetoothGattService。
需要 BLUETOOTH权限。
| 参数(Parameters) | |
|---|---|
uuid |
UUID: The UUID for this service |
serviceType |
int: The type of this service, SERVICE_TYPE_PRIMARY or SERVICE_TYPE_SECONDARY |
boolean addCharacteristic (BluetoothGattCharacteristic characteristic)
为此服务添加一个特征。
需要 BLUETOOTH权限。
| 参数(Parameters) | |
|---|---|
characteristic |
BluetoothGattCharacteristic: The characteristics to be added |
| 返回(Returns) | |
|---|---|
boolean |
true, if the characteristic was added to the service |
boolean addService (BluetoothGattService service)
为此服务添加一项包含的服务。
需要 BLUETOOTH权限。
| 参数(Parameters) | |
|---|---|
service |
BluetoothGattService: The service to be added |
| 返回(Returns) | |
|---|---|
boolean |
true, if the included service was added to the service |
BluetoothGattCharacteristic getCharacteristic (UUID uuid)
返回此服务提供的特征列表中的给定UUID的特征。
这是一个方便的功能,允许访问给定的特征而不 getCharacteristics()手动列举 getCharacteristics()返回的列表。
如果远程服务提供具有相同UUID的多个特征,则返回具有给定UUID的特征的第一个实例。
| 参数(Parameters) | |
|---|---|
uuid |
UUID
|
| 返回(Returns) | |
|---|---|
BluetoothGattCharacteristic |
GATT characteristic object or null if no characteristic with the given UUID was found. |
List<BluetoothGattCharacteristic> getCharacteristics ()
返回此服务中包含的特征列表。
| 返回(Returns) | |
|---|---|
List<BluetoothGattCharacteristic> |
Characteristics included in this service |
List<BluetoothGattService> getIncludedServices ()
获取此服务包含的GATT服务列表。
| 返回(Returns) | |
|---|---|
List<BluetoothGattService> |
List of included services or empty list if no included services were discovered. |
int getInstanceId ()
返回此服务的实例ID
如果远程设备使用相同的UUID提供多种服务(例如针对不同电池的多种电池服务),则实例ID用于使服务失效。
| 返回(Returns) | |
|---|---|
int |
Instance ID of this service |
void writeToParcel (Parcel out, int flags)
将此对象平铺到一个包裹中。
| 参数(Parameters) | |
|---|---|
out |
Parcel: The Parcel in which the object should be written. |
flags |
int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. |