We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

Querying Connected Wearables

NOTE

To call this API, you need to apply for the basic device information permission on HUAWEI Developers. For details, please refer to Applying for Integrating Wear Engine Kit.

Wear Engine Kit provides the API for querying the list of connected wearables (which are connected to the phone-side HUAWEI Health app and support Wear Engine Kit).

You are advised to implement this API before calling other APIs of Wear Engine Kit.

  1. The app calls the getDeviceClient method of wearEngine to obtain the DeviceClient object.

  2. Call the getConnectedDevices method to query the list of connected wearables.

    // Before using Wear Engine Kit, import wearEngine and related modules.
    import { wearEngine } from '@kit.WearEngine';
    import { BusinessError } from '@kit.BasicServicesKit';
    
    // Step 1: Obtain the DeviceClient object.
    // this.getUIContext().getHostContext() indicates the Context object of the app.
    let deviceClient: wearEngine.DeviceClient = wearEngine.getDeviceClient(this.getUIContext().getHostContext());
    // Create a list to store the returned wearables.
    let deviceList: wearEngine.Device[] = [];
    
    // Step 2: Call the getConnectedDevices method to query whether the user has a connected wearable.
    deviceClient.getConnectedDevices().then(devices => {
      // Process the returned device list.
      deviceList = devices;
      console.info(`Succeeded in getting deviceList, deviceList number is ${deviceList.length}`);
    }).catch((error: BusinessError) => {
      // Process the exception captured if the API call fails.
      console.error(`Failed to get deviceList. Code is ${error.code}, message is ${error.message}`);
    });
Search
Enter a keyword.