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 Type | System 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
Traditional Bluetooth
API List
Bluetooth Type | API | Description |
BLE | my.connectBLEDevice | Connect to low energy bluetooth devices. |
BLE | my.disconnectBLEDevice | Disconnect to low energy bluetooth devices. |
BLE | my.getBLEDeviceCharacteristics | Get the characteristics of low energy bluetooth devices. |
BLE | my.getBLEDeviceServices | Get all the low energy bluetooth devices that are discovered, including the connected devices. |
BLE | my.notifyBLECharacteristicValueChange | Enable the function to notify changes to the characteristic value. |
BLE | my.offBLECharacteristicValueChange | Disable the function to notify changes to the characteristic value. |
BLE | my.offBLEConnectionStateChanged | Disable the the event listener for the connection status. |
BLE | my.onBLECharacteristicValueChange | Enable the event listener for changes to the characteristic value. |
BLE | my.onBLEConnectionStateChanged | Enable the the event listener for changes to the connection status , such as device lost and device disconnected. |
BLE | my.readBLECharacteristicValue | Read the characteristic value. |
BLE | my.writeBLECharacteristicValue | Write data to the characteristic value. |
Bluetooth | my.openBluetoothAdapter | Use this API to initialize the Bluetooth module in the mini program. |
Bluetooth | my.closeBluetoothAdapter | Use this API to close the Bluetooth module in the mini program. |
Bluetooth | my.getBluetoothAdapterState | Use this API to check the Bluetooth adapter status in the mini program. |
Bluetooth | my.startBluetoothDevicesDiscovery | Use this API to start discovering bluetooth devices. |
Bluetooth | my.stopBluetoothDevicesDiscovery | Use this API to stop discovering bluetooth devices. |
Bluetooth | my.getBluetoothDevices | Use this API to get all the bluetooth devices that are discovered, including those that are connected to the current device. |
Bluetooth | my.getConnectedBluetoothDevices | Use this API to get the bluetooth devices that are connected. |
Bluetooth | my.onBluetoothDeviceFound | Use this API when a new Bluetooth device is found. |
Bluetooth | my.offBluetoothDeviceFound | Use this API to remove the bluetooth devices that are found. |
Bluetooth | my.onBluetoothAdapterStateChange | Use this API to monitor the bluetooth adapter state changes. |
Bluetooth | my.offBluetoothAdapterStateChange | Use this API to remove the bluetooth adapter with a state change. |