Skip to main content
Use this API to stop listening for Bluetooth adapter state changes that were registered with my.onBluetoothAdapterStateChange().

Parameters

PropertyTypeRequiredDescription
callbackFunctionNoThe specific callback to remove. If omitted, all listeners are removed.

Code Example

Remove All Listeners

my.offBluetoothAdapterStateChange();

Remove Specific Listener

Page({
  onLoad() {
    my.onBluetoothAdapterStateChange(this.handleStateChange);
  },

  handleStateChange(res) {
    console.log('State changed:', res.available);
  },

  onUnload() {
    my.offBluetoothAdapterStateChange(this.handleStateChange);
  }
});

Complete Bluetooth Cleanup

function cleanupBluetooth() {
  // Remove all listeners
  my.offBluetoothAdapterStateChange();
  my.offBluetoothDeviceFound();

  // Stop discovery and close adapter
  my.stopBluetoothDevicesDiscovery();
  my.closeBluetoothAdapter();
}

my.onBluetoothAdapterStateChange

Listen for state changes

my.closeBluetoothAdapter

Close adapter