Most visited

Recently visited

Added in API level 18

BluetoothGattService

public class BluetoothGattService
extends Object implements Parcelable

java.lang.Object
    android.bluetooth.BluetoothGattService


代表蓝牙GATT服务

盖特服务包含的集合 BluetoothGattCharacteristic ,以及引用服务。

摘要(Summary)

常量(Constants)

int SERVICE_TYPE_PRIMARY

主要服务

int SERVICE_TYPE_SECONDARY

二级服务(包括主要服务)

Inherited constants

From interface 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)

From class java.lang.Object
From interface android.os.Parcelable

常量(Constants)

SERVICE_TYPE_PRIMARY

Added in API level 18
int SERVICE_TYPE_PRIMARY

主要服务

常量值:0(0x00000000)

SERVICE_TYPE_SECONDARY

Added in API level 18
int SERVICE_TYPE_SECONDARY

二级服务(包括主要服务)

常数值:1(0x00000001)

Fields

CREATOR

Added in API level 24
Creator<BluetoothGattService> CREATOR

mCharacteristics

Added in API level 18
List<BluetoothGattCharacteristic> mCharacteristics

此服务中包含的特征列表。

mIncludedServices

Added in API level 18
List<BluetoothGattService> mIncludedServices

此服务包含的服务列表。

Public constructors

BluetoothGattService

Added in API level 18
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

公共方法(Public methods)

addCharacteristic

Added in API level 18
boolean addCharacteristic (BluetoothGattCharacteristic characteristic)

为此服务添加一个特征。

需要 BLUETOOTH权限。

参数(Parameters)
characteristic BluetoothGattCharacteristic: The characteristics to be added
返回(Returns)
boolean true, if the characteristic was added to the service

addService

Added in API level 18
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

getCharacteristic

Added in API level 18
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.

getCharacteristics

Added in API level 18
List<BluetoothGattCharacteristic> getCharacteristics ()

返回此服务中包含的特征列表。

返回(Returns)
List<BluetoothGattCharacteristic> Characteristics included in this service

getIncludedServices

Added in API level 18
List<BluetoothGattService> getIncludedServices ()

获取此服务包含的GATT服务列表。

返回(Returns)
List<BluetoothGattService> List of included services or empty list if no included services were discovered.

getInstanceId

Added in API level 18
int getInstanceId ()

返回此服务的实例ID

如果远程设备使用相同的UUID提供多种服务(例如针对不同电池的多种电池服务),则实例ID用于使服务失效。

返回(Returns)
int Instance ID of this service

getType

Added in API level 18
int getType ()

获取此服务的类型(主要/次要)

返回(Returns)
int

getUuid

Added in API level 18
UUID getUuid ()

返回此服务的UUID

返回(Returns)
UUID UUID of this service

writeToParcel

Added in API level 24
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.

Hooray!