public class BluetoothGattService extends Object implements Parcelable
Gatt Service contains a collection of BluetoothGattCharacteristic
,
as well as referenced services.
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<BluetoothGattService> |
CREATOR |
protected List<BluetoothGattCharacteristic> |
mCharacteristics
List of characteristics included in this service.
|
protected BluetoothDevice |
mDevice
The remote device his service is associated with.
|
protected int |
mHandles
Handle counter override (for conformance testing).
|
protected List<BluetoothGattService> |
mIncludedServices
List of included services for this service.
|
protected int |
mInstanceId
Instance ID for this service.
|
protected int |
mServiceType
Service type (Primary/Secondary).
|
protected UUID |
mUuid
The UUID of this service.
|
static int |
SERVICE_TYPE_PRIMARY
Primary service
|
static int |
SERVICE_TYPE_SECONDARY
Secondary service (included by primary services)
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
BluetoothGattService(UUID uuid,
int serviceType)
Create a new BluetoothGattService.
|
BluetoothGattService(UUID uuid,
int instanceId,
int serviceType)
Create a new BluetoothGattService
|
Modifier and Type | Method and Description |
---|---|
boolean |
addCharacteristic(BluetoothGattCharacteristic characteristic)
Add a characteristic to this service.
|
void |
addIncludedService(BluetoothGattService includedService)
Add an included service to the internal map.
|
boolean |
addService(BluetoothGattService service)
Add an included service to this service.
|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
BluetoothGattCharacteristic |
getCharacteristic(UUID uuid)
Returns a characteristic with a given UUID out of the list of
characteristics offered by this service.
|
List<BluetoothGattCharacteristic> |
getCharacteristics()
Returns a list of characteristics included in this service.
|
List<BluetoothGattService> |
getIncludedServices()
Get the list of included GATT services for this service.
|
int |
getInstanceId()
Returns the instance ID for this service
If a remote device offers multiple services with the same UUID
(ex. multiple battery services for different batteries), the instance
ID is used to distuinguish services.
|
int |
getType()
Get the type of this service (primary/secondary)
|
UUID |
getUuid()
Returns the UUID of this service
|
boolean |
isAdvertisePreferred()
Returns whether the uuid of the service should be advertised.
|
void |
setAdvertisePreferred(boolean advertisePreferred)
Set whether the service uuid should be advertised.
|
void |
setHandles(int handles)
Force the number of handles to reserve for this service.
|
void |
setInstanceId(int instanceId)
Force the instance ID.
|
void |
writeToParcel(Parcel out,
int flags)
Flatten this object in to a Parcel.
|
public static final int SERVICE_TYPE_PRIMARY
public static final int SERVICE_TYPE_SECONDARY
protected BluetoothDevice mDevice
protected UUID mUuid
protected int mInstanceId
protected int mHandles
protected int mServiceType
protected List<BluetoothGattCharacteristic> mCharacteristics
protected List<BluetoothGattService> mIncludedServices
public static final Parcelable.Creator<BluetoothGattService> CREATOR
public BluetoothGattService(UUID uuid, int serviceType)
Requires android.Manifest.permission#BLUETOOTH
permission.
uuid
- The UUID for this serviceserviceType
- The type of this service,
SERVICE_TYPE_PRIMARY
or
SERVICE_TYPE_SECONDARY
public BluetoothGattService(UUID uuid, int instanceId, int serviceType)
public int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel out, int flags)
Parcelable
writeToParcel
in interface Parcelable
out
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.public boolean addService(BluetoothGattService service)
Requires android.Manifest.permission#BLUETOOTH
permission.
service
- The service to be addedpublic boolean addCharacteristic(BluetoothGattCharacteristic characteristic)
Requires android.Manifest.permission#BLUETOOTH
permission.
characteristic
- The characteristics to be addedpublic void setInstanceId(int instanceId)
public void setHandles(int handles)
public void addIncludedService(BluetoothGattService includedService)
public UUID getUuid()
public int getInstanceId()
If a remote device offers multiple services with the same UUID (ex. multiple battery services for different batteries), the instance ID is used to distuinguish services.
public int getType()
public List<BluetoothGattService> getIncludedServices()
public List<BluetoothGattCharacteristic> getCharacteristics()
public BluetoothGattCharacteristic getCharacteristic(UUID uuid)
This is a convenience function to allow access to a given characteristic
without enumerating over the list returned by getCharacteristics()
manually.
If a remote service offers multiple characteristics with the same UUID, the first instance of a characteristic with the given UUID is returned.
public boolean isAdvertisePreferred()
public void setAdvertisePreferred(boolean advertisePreferred)