my.onBluetoothAdapterStateChange().
Parameters
Code Example
Remove All Listeners
Remove Specific Listener
Complete Bluetooth Cleanup
Related APIs
my.onBluetoothAdapterStateChange
Listen for state changes
my.closeBluetoothAdapter
Close adapter
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Stop listening for Bluetooth adapter state changes.
my.onBluetoothAdapterStateChange().
| Property | Type | Required | Description |
|---|---|---|---|
| callback | Function | No | The specific callback to remove. If omitted, all listeners are removed. |
my.offBluetoothAdapterStateChange();
Page({
onLoad() {
my.onBluetoothAdapterStateChange(this.handleStateChange);
},
handleStateChange(res) {
console.log('State changed:', res.available);
},
onUnload() {
my.offBluetoothAdapterStateChange(this.handleStateChange);
}
});
function cleanupBluetooth() {
// Remove all listeners
my.offBluetoothAdapterStateChange();
my.offBluetoothDeviceFound();
// Stop discovery and close adapter
my.stopBluetoothDevicesDiscovery();
my.closeBluetoothAdapter();
}