Parameters
Code Example
Basic Usage
Complete Bluetooth Lifecycle
Related APIs
my.openBluetoothAdapter
Initialize Bluetooth
my.getBluetoothAdapterState
Get adapter state
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Close the Bluetooth adapter.
| Property | Type | Required | Description |
|---|---|---|---|
| success | Function | No | Callback on success |
| fail | Function | No | Callback on failure |
| complete | Function | No | Callback that always executes |
my.closeBluetoothAdapter({
success() {
console.log('Bluetooth adapter closed');
}
});
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();
}
});
onUnload to ensure resources are properly released when leaving the page.