BLE

class BLE

Constructors

Link copied to clipboard
constructor(componentActivity: ComponentActivity)

Instantiates a new Bluetooth scanner instance Support for Jetpack Compose

constructor(activity: AppCompatActivity)

Instantiates a new Bluetooth scanner instance

constructor(fragment: Fragment)

Instantiates a new Bluetooth scanner instance

Properties

Link copied to clipboard
Link copied to clipboard

Indicates whether additional information should be logged

Functions

Link copied to clipboard
@RequiresPermission(value = "android.permission.BLUETOOTH_CONNECT")
suspend fun connect(device: BluetoothDevice, priority: Priority = Priority.Balanced): BluetoothConnection?
@RequiresPermission(value = "android.permission.BLUETOOTH_CONNECT")
suspend fun connect(device: BLEDevice, priority: Priority = Priority.Balanced): BluetoothConnection?

Establishes a connection with the specified bluetooth device

Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.BLUETOOTH_ADMIN", "android.permission.BLUETOOTH_SCAN"])
suspend fun scan(filters: List<ScanFilter>? = null, settings: ScanSettings? = null, duration: Long = DEFAULT_TIMEOUT): Array<BLEDevice>

Starts a scan for bluetooth devices Only runs with a duration defined

Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.BLUETOOTH_ADMIN", "android.permission.BLUETOOTH_SCAN"])
fun scanAsync(filters: List<ScanFilter>? = null, settings: ScanSettings? = null, duration: Long = DEFAULT_TIMEOUT, onFinish: Callback<Array<BLEDevice>>? = null, onDiscover: Callback<BLEDevice>? = null, onUpdate: Callback<List<BLEDevice>>? = null, onError: Callback<Int>? = null)

Starts a scan for bluetooth devices Can be used without duration running until stopScan is called.

Link copied to clipboard
suspend fun scanFor(macAddress: String? = null, service: String? = null, name: String? = null, settings: ScanSettings? = null, priority: Priority = Priority.Balanced, timeout: Long = DEFAULT_TIMEOUT): BluetoothConnection?

Scans for a single bluetooth device and automatically connects with it Requires at least one filter being them: macAddress, service and name

Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.BLUETOOTH_ADMIN", "android.permission.BLUETOOTH_SCAN", "android.permission.BLUETOOTH_CONNECT"])
fun scanForAsync(macAddress: String? = null, service: String? = null, name: String? = null, settings: ScanSettings? = null, priority: Priority = Priority.Balanced, timeout: Long = DEFAULT_TIMEOUT, onFinish: Callback<BluetoothConnection?>? = null, onError: Callback<Int>? = null)

Scans for a single bluetooth device and automatically connects with it Requires at least one filter being them: macAddress, service and name

Link copied to clipboard
fun stopScan()

Stops the scan started by scan

Link copied to clipboard
@RequiresPermission(value = "android.permission.BLUETOOTH_ADMIN")
suspend fun verifyBluetoothAdapterState(): Boolean

Checks if the bluetooth adapter is active

Link copied to clipboard
@RequiresPermission(value = "android.permission.BLUETOOTH_ADMIN")
fun verifyBluetoothAdapterStateAsync(callback: PermissionRequestCallback? = null)

Checks if the bluetooth adapter is active

Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"])
suspend fun verifyLocationState(): Boolean

Checks if location services are active

Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"])
fun verifyLocationStateAsync(callback: PermissionRequestCallback? = null)

Checks if location services are active

Link copied to clipboard
@RequiresPermission(allOf = ["android.permission.BLUETOOTH", "android.permission.BLUETOOTH_ADMIN", "android.permission.ACCESS_FINE_LOCATION"])
suspend fun verifyPermissions(rationaleRequestCallback: Callback<EmptyCallback>? = null): Boolean

Checks if the following permissions are granted: permission.BLUETOOTH, permission.BLUETOOTH_ADMIN and permission.ACCESS_FINE_LOCATION

Link copied to clipboard
@RequiresPermission(allOf = ["android.permission.BLUETOOTH", "android.permission.BLUETOOTH_ADMIN", "android.permission.ACCESS_FINE_LOCATION"])
fun verifyPermissionsAsync(rationaleRequestCallback: Callback<EmptyCallback>? = null, callback: PermissionRequestCallback? = null)

Checks if the following permissions are granted: permission.BLUETOOTH, permission.BLUETOOTH_ADMIN and permission.ACCESS_FINE_LOCATION