Use this API to close the Bluetooth adapter and release system resources. Call this when you’re done using Bluetooth.
Parameters
| Property | Type | Required | Description |
|---|
| success | Function | No | Callback on success |
| fail | Function | No | Callback on failure |
| complete | Function | No | Callback 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