Skip to main content
Use this API to close the Bluetooth adapter and release system resources. Call this when you’re done using Bluetooth.

Parameters

PropertyTypeRequiredDescription
successFunctionNoCallback on success
failFunctionNoCallback on failure
completeFunctionNoCallback that always executes

Code Example

Basic Usage

my.closeBluetoothAdapter({
  success() {
    console.log('Bluetooth adapter closed');
  }
});

Complete Bluetooth Lifecycle

Page({
  onLoad() {
    my.openBluetoothAdapter({
      success: () => {
        this.startScanning();
      }
    });
  },

  startScanning() {
    my.startBluetoothDevicesDiscovery({
      success: () => {
        console.log('Scanning for devices...');
      }
    });
  },

  stopAndCleanup() {
    my.stopBluetoothDevicesDiscovery();
    my.closeBluetoothAdapter({
      success: () => {
        console.log('Bluetooth cleanup complete');
      }
    });
  },

  onUnload() {
    this.stopAndCleanup();
  }
});
Always close the Bluetooth adapter in onUnload to ensure resources are properly released when leaving the page.

my.openBluetoothAdapter

Initialize Bluetooth

my.getBluetoothAdapterState

Get adapter state