Skip to main content
Use this API to get the current state of the Bluetooth adapter, including whether it’s available and discovering devices.

Parameters

PropertyTypeRequiredDescription
successFunctionNoCallback on success
failFunctionNoCallback on failure
completeFunctionNoCallback that always executes

Success Callback Parameters

PropertyTypeDescription
availableBooleanWhether Bluetooth is available
discoveringBooleanWhether currently discovering devices

Code Example

Basic Usage

my.getBluetoothAdapterState({
  success(res) {
    console.log('Bluetooth available:', res.available);
    console.log('Discovering:', res.discovering);
  }
});

Check Before Operations

Page({
  async checkBluetoothState() {
    my.getBluetoothAdapterState({
      success: (res) => {
        if (!res.available) {
          my.alert({
            title: 'Bluetooth Unavailable',
            content: 'Please enable Bluetooth to continue.'
          });
          return;
        }

        if (res.discovering) {
          console.log('Already scanning...');
        } else {
          this.startDiscovery();
        }
      }
    });
  },

  startDiscovery() {
    my.startBluetoothDevicesDiscovery({
      success: () => console.log('Started scanning')
    });
  }
});

Status Display

Page({
  data: {
    bluetoothStatus: 'unknown'
  },

  updateStatus() {
    my.getBluetoothAdapterState({
      success: (res) => {
        let status = 'Off';
        if (res.available) {
          status = res.discovering ? 'Scanning' : 'Ready';
        }
        this.setData({ bluetoothStatus: status });
      }
    });
  }
});

my.openBluetoothAdapter

Initialize Bluetooth

my.onBluetoothAdapterStateChange

Listen for state changes