connect

open suspend override fun connect(peripheral: Peripheral)

Establishes Bluetooth LE connection to the peripheral using default connection options.

Parameters

peripheral

The peripheral to connect to.

See also

Throws

If the central manager has been closed.

If Bluetooth is disabled or not available.

If BLUETOOTH_CONNECT permission is denied.

If the Peripheral wasn't acquired from this manager by scanning, ranging, or using methods getPeripheralsById or getBondedPeripherals.

If connection failed. See ConnectionFailedException.reason for a reason.

CancellationException

If the coroutine was canceled.

TimeoutCancellationException

If the connection attempt timed out.


abstract suspend fun connect(peripheral: Peripheral, options: CentralManager.ConnectionOptions)

Establishes Bluetooth LE connection to the peripheral.

This method does nothing if the device is already connected.

Parameters

peripheral

The peripheral to connect to.

options

Connection options.

Throws

If the central manager has been closed.

If Bluetooth is disabled or not available.

If BLUETOOTH_CONNECT permission is denied.

If the Peripheral wasn't acquired from this manager by scanning, getPeripheralsById or getBondedPeripherals.

If connection failed. See ConnectionFailedException.reason for a reason.

CancellationException

If the coroutine was canceled.

TimeoutCancellationException

If the connection attempt timed out.