GattClientScope


public interface GattClientScope


Scope for operations as a GATT client role.

See also
connectGatt

Summary

Public methods

abstract GattService

Gets the service of the remote device by UUID.

default @NonNull List<@NonNull GattService>

GATT services recently discovered from the remote device.

abstract @NonNull StateFlow<@NonNull List<@NonNull GattService>>

A flow of GATT services discovered from the remote device.

abstract @NonNull Result<@NonNull byte[]>

Reads the characteristic value from the server.

abstract @NonNull Flow<@NonNull byte[]>

Returns a cold Flow that contains the indicated value of the given characteristic.

abstract @NonNull Result<Unit>
writeCharacteristic(
    @NonNull GattCharacteristic characteristic,
    @NonNull byte[] value
)

Writes the characteristic value to the server.

Public methods

getService

Added in 1.0.0-alpha02
abstract GattService getService(@NonNull UUID uuid)

Gets the service of the remote device by UUID.

If multiple instances of the same service exist, the first instance of the services is returned.

getServices

Added in 1.0.0-alpha02
default @NonNull List<@NonNull GattServicegetServices()

GATT services recently discovered from the remote device.

Note that this can be changed, subscribe to servicesFlow to get notified of services changes.

getServicesFlow

Added in 1.0.0-alpha02
abstract @NonNull StateFlow<@NonNull List<@NonNull GattService>> getServicesFlow()

A flow of GATT services discovered from the remote device.

If the services of the remote device has changed, the new services will be discovered and emitted automatically.

readCharacteristic

abstract @NonNull Result<@NonNull byte[]> readCharacteristic(@NonNull GattCharacteristic characteristic)

Reads the characteristic value from the server.

Parameters
@NonNull GattCharacteristic characteristic

a remote GattCharacteristic to read

Returns
@NonNull Result<@NonNull byte[]>

the value of the characteristic

subscribeToCharacteristic

Added in 1.0.0-alpha02
abstract @NonNull Flow<@NonNull byte[]> subscribeToCharacteristic(@NonNull GattCharacteristic characteristic)

Returns a cold Flow that contains the indicated value of the given characteristic.

writeCharacteristic

abstract @NonNull Result<UnitwriteCharacteristic(
    @NonNull GattCharacteristic characteristic,
    @NonNull byte[] value
)

Writes the characteristic value to the server.

Parameters
@NonNull GattCharacteristic characteristic

a remote GattCharacteristic to write

@NonNull byte[] value

a value to be written.

Returns
@NonNull Result<Unit>

the result of the write operation

Throws
kotlin.IllegalArgumentException

if the characteristic doesn't have the write property or the length of the value is greater than the maximum attribute length (512)