Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Listen for Bluetooth adapter state changes.
my.onBluetoothAdapterStateChange((res) => { console.log('Bluetooth available:', res.available); console.log('Discovering:', res.discovering); });
Page({ onLoad() { my.onBluetoothAdapterStateChange(this.handleStateChange); my.openBluetoothAdapter(); }, handleStateChange(res) { if (!res.available) { my.alert({ title: 'Bluetooth Disabled', content: 'Please enable Bluetooth to continue using this feature.' }); this.setData({ bluetoothEnabled: false }); } else { this.setData({ bluetoothEnabled: true }); } }, onUnload() { my.offBluetoothAdapterStateChange(this.handleStateChange); my.closeBluetoothAdapter(); } });
Page({ data: { shouldBeDiscovering: false }, onLoad() { my.onBluetoothAdapterStateChange((res) => { if (res.available && this.data.shouldBeDiscovering && !res.discovering) { // Bluetooth came back, resume discovery my.startBluetoothDevicesDiscovery(); } }); }, startScan() { this.setData({ shouldBeDiscovering: true }); my.startBluetoothDevicesDiscovery(); } });