AndroidPeripheral

Types

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Represents possible write operation results, as defined by Android's WriteOperationReturnValues IntDef.

Properties

Link copied to clipboard
abstract val address: String

Returns the hardware address of this AndroidPeripheral.

Link copied to clipboard

This is an internal API and may be removed from a future release. If you are using it, please open an issue and report your use case.

Link copied to clipboard
abstract val identifier: Identifier

Platform specific identifier for the remote peripheral. On some platforms, this can be used to "restore" a previously known peripheral for reconnection.

Link copied to clipboard
abstract val mtu: StateFlow<Int?>

StateFlow of the most recently negotiated MTU. The MTU will change upon a successful request to change the MTU (as configured via the PeripheralBuilder.mtu property), or if the peripheral initiates an MTU change. StateFlow's value will be null until MTU is negotiated.

Link copied to clipboard

The peripheral name, as provided by the underlying bluetooth system. This value is system dependent and is not necessarily the Generic Access Profile (GAP) device name.

Link copied to clipboard
abstract val scope: CoroutineScope

CoroutineScope tied to the lifecycle of this Peripheral (is cancelled upon Peripheral being disposed via close).

Link copied to clipboard
abstract val services: StateFlow<List<DiscoveredService>?>

The list of services (GATT profile) which have been discovered on the remote peripheral.

Link copied to clipboard
abstract val state: StateFlow<State>

Provides a conflated Flow of the Peripheral's State.

Link copied to clipboard
@get:RequiresPermission(anyOf = ["android.permission.BLUETOOTH", "android.permission.BLUETOOTH_CONNECT"])
abstract val type: AndroidPeripheral.Type

Get the type of the peripheral.

Functions

Link copied to clipboard
abstract fun close()
Link copied to clipboard
abstract suspend fun connect(): CoroutineScope

Initiates a connection, suspending until connected, or failure occurs. Multiple concurrent invocations will all suspend until connected (or failure occurs). If already connected, then returns immediately.

Link copied to clipboard
abstract suspend fun disconnect()

Disconnects the active connection, or cancels an in-flight connection attempt, suspending until Peripheral has settled on a disconnected state.

Link copied to clipboard
abstract suspend fun maximumWriteValueLengthForType(writeType: WriteType): Int

The maximum amount of data, in bytes, you can send in a single write operation.

Link copied to clipboard
abstract fun observe(characteristic: Characteristic, onSubscription: OnSubscriptionAction = {}): Flow<ByteArray>

Observes changes to the specified Characteristic.

Link copied to clipboard
abstract suspend fun read(characteristic: Characteristic): ByteArray

Reads data from characteristic.

abstract suspend fun read(descriptor: Descriptor): ByteArray

Reads data from descriptor.

Link copied to clipboard

Clears Android's cached GATT database for this peripheral, so that the next service discovery reads the services from the remote device instead of the cache. Useful when a peripheral changes its attribute table (e.g. after a firmware update) without the stack noticing.

Link copied to clipboard
Link copied to clipboard
abstract suspend fun rssi(): Int

On JavaScript, requires Chrome 79+ with the chrome://flags/#enable-experimental-web-platform-features flag enabled.

Link copied to clipboard
abstract suspend override fun write(descriptor: Descriptor, data: ByteArray)
abstract suspend override fun write(characteristic: Characteristic, data: ByteArray, writeType: WriteType = WithoutResponse)