onBluetoothAdapterStateChange(listener: Function)

Requires:
BaseKit≥2.0.1@ray-js/ray≥0.3.23
Platforms:
iOSAndroid
import { onBluetoothAdapterStateChange } from '@ray-js/ray';

// Promise usage
try {
  const res = await onBluetoothAdapterStateChange({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Description

Listen for Bluetooth adapter state changes; Bluetooth permission is required

Parameters

ParameterTypeRequiredDescription
Yes

Return Value

None

Examples

import { onBluetoothAdapterStateChange } from '@ray-js/ray'

// Listen for Bluetooth adapter state changes; the callback indicates availability when toggling Bluetooth on the phone
onBluetoothAdapterStateChange(e => {
  console.log("Bluetooth adapter available:", e.available);
});
// State changes require toggling Bluetooth; keep listening for a while
await new Promise(resolve => setTimeout(resolve, 8000));