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
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 (via requestMtu), or if the peripheral initiates an MTU change. StateFlow's value will be null until MTU is negotiated.

Link copied to clipboard
abstract val name: String?

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 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 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

Return the current ATT MTU size, minus the size of the ATT headers (3 bytes).

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

Observes changes to the specified Characteristic.

Link copied to clipboard
fun CoroutineScope.peripheral(bluetoothDevice: BluetoothDevice, builderAction: PeripheralBuilderAction = {}): Peripheral
fun CoroutineScope.peripheral(identifier: Identifier, builderAction: PeripheralBuilderAction = {}): Peripheral
expect fun CoroutineScope.peripheral(advertisement: Advertisement, builderAction: PeripheralBuilderAction = {}): Peripheral
actual fun CoroutineScope.peripheral(advertisement: Advertisement, builderAction: PeripheralBuilderAction): Peripheral
actual fun CoroutineScope.peripheral(advertisement: Advertisement, builderAction: PeripheralBuilderAction): Peripheral
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
Link copied to clipboard
abstract suspend fun requestMtu(mtu: Int): Int

Requests that the current connection's MTU be changed. Suspends until the MTU changes, or failure occurs. The negotiated MTU value is returned, which may not be mtu value requested if the remote peripheral negotiated an alternate MTU.

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)