Bluetooth API Overview

Before you get started, you can see the system requirement as a prerequisite and then see the process flow on how the bluetooth APIs work. You can then find an overview of all the bluetooth APIs and a sample of code snippet. In addition, you can refer to the FAQ and error code table for more details.

System Requirement

Bluetooth TypeSystem Requirement
Bluetooth Low Energy (BLE)Android: 5.0 and upper versions
iOS: no requirements

Process Flow

The following diagram illustrates how the bluetooth function is enabled with APIs. You can see the details on how each API works.

BLE

Bluetooth API Overview

Traditional Bluetooth

Bluetooth API Overview

API List

Bluetooth TypeAPIDescription
BLEmy.connectBLEDeviceConnect to low energy bluetooth devices.
BLEmy.disconnectBLEDeviceDisconnect to low energy bluetooth devices.
BLEmy.getBLEDeviceCharacteristicsGet the characteristics of low energy bluetooth devices.
BLEmy.getBLEDeviceServicesGet all the low energy bluetooth devices that are discovered, including the connected devices.
BLEmy.notifyBLECharacteristicValueChangeEnable the function to notify changes to the characteristic value.
BLEmy.offBLECharacteristicValueChangeDisable the function to notify changes to the characteristic value.
BLEmy.offBLEConnectionStateChangedDisable the the event listener for the connection status.
BLEmy.onBLECharacteristicValueChangeEnable the event listener for changes to the characteristic value.
BLEmy.onBLEConnectionStateChangedEnable the the event listener for changes to the connection status , such as device lost and device disconnected.
BLEmy.readBLECharacteristicValueRead the characteristic value.
BLEmy.writeBLECharacteristicValueWrite data to the characteristic value.
Bluetoothmy.openBluetoothAdapterUse this API to initialize the Bluetooth module in the mini program.
Bluetoothmy.closeBluetoothAdapterUse this API to close the Bluetooth module in the mini program.
Bluetoothmy.getBluetoothAdapterStateUse this API to check the Bluetooth adapter status in the mini program.
Bluetoothmy.startBluetoothDevicesDiscoveryUse this API to start discovering bluetooth devices.
Bluetoothmy.stopBluetoothDevicesDiscoveryUse this API to stop discovering bluetooth devices.
Bluetoothmy.getBluetoothDevicesUse this API to get all the bluetooth devices that are discovered, including those that are connected to the current device.
Bluetoothmy.getConnectedBluetoothDevicesUse this API to get the bluetooth devices that are connected.
Bluetoothmy.onBluetoothDeviceFoundUse this API when a new Bluetooth device is found.
Bluetoothmy.offBluetoothDeviceFoundUse this API to remove the bluetooth devices that are found.
Bluetoothmy.onBluetoothAdapterStateChangeUse this API to monitor the bluetooth adapter state changes.
Bluetoothmy.offBluetoothAdapterStateChangeUse this API to remove the bluetooth adapter with a state change.