Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/bluetooth/BluetoothGattService#constants) \| [Inherited Constants](https://developer.android.com/reference/android/bluetooth/BluetoothGattService#inhconstants) \| [Fields](https://developer.android.com/reference/android/bluetooth/BluetoothGattService#lfields) \| [Ctors](https://developer.android.com/reference/android/bluetooth/BluetoothGattService#pubctors) \| [Methods](https://developer.android.com/reference/android/bluetooth/BluetoothGattService#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/bluetooth/BluetoothGattService#inhmethods)

# BluetoothGattService

*** ** * ** ***

` public class BluetoothGattService `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/os/Parcelable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.bluetooth.BluetoothGattService |

<br />

*** ** * ** ***

Represents a Bluetooth GATT Service

Gatt Service contains a collection of `https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic`, as well as referenced services.

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/bluetooth/BluetoothGattService#SERVICE_TYPE_PRIMARY` Primary service |
| `int` | `https://developer.android.com/reference/android/bluetooth/BluetoothGattService#SERVICE_TYPE_SECONDARY` Secondary service (included by primary services) |

### Inherited constants

From interface `https://developer.android.com/reference/android/os/Parcelable` `int` `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR`

Descriptor bit used with `https://developer.android.com/reference/android/os/Parcelable#describeContents()`: indicates that the Parcelable object's flattened representation includes a file descriptor.
`int` `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`

Flag for use with `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`: the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`".

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/os/Parcelable.Creator<https://developer.android.com/reference/android/bluetooth/BluetoothGattService>` | `https://developer.android.com/reference/android/bluetooth/BluetoothGattService#CREATOR` <br /> |
| ` protected https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic>` | `https://developer.android.com/reference/android/bluetooth/BluetoothGattService#mCharacteristics` List of characteristics included in this service. |
| ` protected https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/bluetooth/BluetoothGattService>` | `https://developer.android.com/reference/android/bluetooth/BluetoothGattService#mIncludedServices` List of included services for this service. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/bluetooth/BluetoothGattService#BluetoothGattService(java.util.UUID,%20int)(https://developer.android.com/reference/java/util/UUID uuid, int serviceType) ` Create a new BluetoothGattService. |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/android/bluetooth/BluetoothGattService#addCharacteristic(android.bluetooth.BluetoothGattCharacteristic)(https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic characteristic) ` Add a characteristic to this service. |
| ` boolean` | ` https://developer.android.com/reference/android/bluetooth/BluetoothGattService#addService(android.bluetooth.BluetoothGattService)(https://developer.android.com/reference/android/bluetooth/BluetoothGattService service) ` Add an included service to this service. |
| ` int` | ` https://developer.android.com/reference/android/bluetooth/BluetoothGattService#describeContents()() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
| ` https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic` | ` https://developer.android.com/reference/android/bluetooth/BluetoothGattService#getCharacteristic(java.util.UUID)(https://developer.android.com/reference/java/util/UUID uuid) ` Returns a characteristic with a given UUID out of the list of characteristics offered by this service. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic>` | ` https://developer.android.com/reference/android/bluetooth/BluetoothGattService#getCharacteristics()() ` Returns a list of characteristics included in this service. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/bluetooth/BluetoothGattService>` | ` https://developer.android.com/reference/android/bluetooth/BluetoothGattService#getIncludedServices()() ` Get the list of included GATT services for this service. |
| ` int` | ` https://developer.android.com/reference/android/bluetooth/BluetoothGattService#getInstanceId()() ` Returns the instance ID for this service If a remote device offers multiple services with the same UUID (ex. |
| ` int` | ` https://developer.android.com/reference/android/bluetooth/BluetoothGattService#getType()() ` Get the type of this service (primary/secondary) |
| ` https://developer.android.com/reference/java/util/UUID` | ` https://developer.android.com/reference/android/bluetooth/BluetoothGattService#getUuid()() ` Returns the UUID of this service |
| ` void` | ` https://developer.android.com/reference/android/bluetooth/BluetoothGattService#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel out, int flags) ` Flatten this object in to a Parcel. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/android/os/Parcelable ` ` abstract int` ` https://developer.android.com/reference/android/os/Parcelable#describeContents()() `

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
` abstract void` ` https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) `

Flatten this object in to a Parcel.

## Constants

### SERVICE_TYPE_PRIMARY

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SERVICE_TYPE_PRIMARY
```

Primary service

<br />

Constant Value: 0 (0x00000000)

### SERVICE_TYPE_SECONDARY

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SERVICE_TYPE_SECONDARY
```

Secondary service (included by primary services)

<br />

Constant Value: 1 (0x00000001)

## Fields

### CREATOR

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final Creator<BluetoothGattService> CREATOR
```

<br />

<br />

### mCharacteristics

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected List<BluetoothGattCharacteristic> mCharacteristics
```

List of characteristics included in this service.

<br />

### mIncludedServices

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected List<BluetoothGattService> mIncludedServices
```

List of included services for this service.

<br />

## Public constructors

### BluetoothGattService

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BluetoothGattService (UUID uuid, 
                int serviceType)
```

Create a new BluetoothGattService.

<br />

| Parameters ||
|---|---|
| `uuid` | `UUID`: The UUID for this service <br /> |
| `serviceType` | `int`: The type of this service, `https://developer.android.com/reference/android/bluetooth/BluetoothGattService#SERVICE_TYPE_PRIMARY` or `https://developer.android.com/reference/android/bluetooth/BluetoothGattService#SERVICE_TYPE_SECONDARY` <br /> |

## Public methods

### addCharacteristic

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean addCharacteristic (BluetoothGattCharacteristic characteristic)
```

Add a characteristic to this service.

<br />

| Parameters ||
|---|---|
| `characteristic` | `BluetoothGattCharacteristic`: The characteristics to be added <br /> |

| Returns ||
|---|---|
| `boolean` | true, if the characteristic was added to the service <br /> |

### addService

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean addService (BluetoothGattService service)
```

Add an included service to this service.

<br />

| Parameters ||
|---|---|
| `service` | `BluetoothGattService`: The service to be added <br /> |

| Returns ||
|---|---|
| `boolean` | true, if the included service was added to the service <br /> |

### describeContents

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int describeContents ()
```

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`, the return value of this method must include the `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` bit.

<br />

| Returns ||
|---|---|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either `0` or - `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` |

### getCharacteristic

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BluetoothGattCharacteristic getCharacteristic (UUID uuid)
```

Returns a characteristic with a given UUID out of the list of characteristics offered by this service.

This is a convenience function to allow access to a given characteristic without enumerating over the list returned by `https://developer.android.com/reference/android/bluetooth/BluetoothGattService#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.

<br />

| Parameters ||
|---|---|
| `uuid` | `UUID` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic` | GATT characteristic object or null if no characteristic with the given UUID was found. <br /> |

### getCharacteristics

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<BluetoothGattCharacteristic> getCharacteristics ()
```

Returns a list of characteristics included in this service.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic>` | Characteristics included in this service <br /> |

### getIncludedServices

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<BluetoothGattService> getIncludedServices ()
```

Get the list of included GATT services for this service.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/bluetooth/BluetoothGattService>` | List of included services or empty list if no included services were discovered. <br /> |

### getInstanceId

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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 distinguish services.

<br />

| Returns ||
|---|---|
| `int` | Instance ID of this service <br /> |

### getType

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getType ()
```

Get the type of this service (primary/secondary)

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getUuid

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public UUID getUuid ()
```

Returns the UUID of this service

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/UUID` | UUID of this service <br /> |

### writeToParcel

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void writeToParcel (Parcel out, 
                int flags)
```

Flatten this object in to a Parcel.

<br />

| Parameters ||
|---|---|
| `out` | `Parcel`: The Parcel in which the object should be written. This value cannot be `null`. <br /> |
| `flags` | `int`: Additional flags about how the object should be written. May be 0 or `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE` |