my.getBLEDeviceServices

Use this API to obtain all services of Bluetooth devices that are connected to the native.

Note:
Currently simulation in IDE is not supported. Please debug in production environment.

Sample Code

copy
 //Obtain the services of the connected device
  getBLEDeviceServices() {
    my.getConnectedBluetoothDevices({
      success: res => {
        if (res.devices.length === 0) {
          my.alert({ content: 'No connected devices' });
          return;
        }
        my.getBLEDeviceServices({
          deviceId: this.data.devid,
          success: res => {
            my.alert({ content: JSON.stringify(res) });
            this.setData({
              serid: res.services[0].serviceId,
            });
          },
          fail: error => {
            my.alert({ content: JSON.stringify(error) });
          },
        });
      },
    });
  },

Return Value Sample

copy
{
    "services": [{
        "isPrimary": true,
        "serviceId": "00001800-0000-1000-8000-00805f9b34fb"
    }, {
        "isPrimary": true,
        "serviceId": "00001801-0000-1000-8000-00805f9b34fb"
    }, {
        "isPrimary": true,
        "serviceId": "d0611e78-bbb4-4591-a5f8-487910ae4366"
    }, {
        "isPrimary": true,
        "serviceId": "9fa480e0-4967-4542-9390-d343dc5d04ae"
    }]
}

Parameters

PropertyType

Required

Description
deviceIdStringYesThe Bluetooth device ID.
successFunctionNoThe callback function for a successful API call.
failFunctionNoThe callback function for a failed API call.
completeFunctionNoThe callback function used when the API call is completed. This function is always executed no matter the call succeeds or fails.

Success return value

PropertyTypeDescription
servicesArrayList of discovered device services

services

PropertyTypeDescription
isPrimaryBoolean

This field indicates whether the service is the main service. Valid values are:

true: The service is the main service.
false: The service is not the main service.

serviceIdStringThe UUID of the service corresponding to a Bluetooth characteristic.