目录

Querying Wearable Device Information

// Before using Wear Engine, import the wearEngine and related modules.
import { wearEngine } from '@kit.WearEngine';
import { BusinessError } from '@kit.BasicServicesKit';

Querying Whether the Wearable Device Supports Certain Wear Engine Capabilities

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.

Call the isWearEngineCapabilitySupported method in the Device object to query whether the wearable device supports certain Wear Engine capabilities.

  1. Call the getDeviceClient method in wearEngine to obtain the DeviceClient object.

    let deviceClient: wearEngine.DeviceClient = wearEngine.getDeviceClient(this.getUIContext().getHostContext());
  2. Call the getConnectedDevices method to obtain the connected device list.

    let deviceList: wearEngine.Device[] = [];
    deviceClient.getConnectedDevices().then(devices => {
      // Store the list of connected devices.
      deviceList = devices;
      console.info(`Succeeded in getting deviceList, devices 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}`);
    })
  3. Select the target device from the device list.

  4. Call isWearEngineCapabilitySupported in the Device object to query whether this device supports the passed Wear Engine capability (true: supported; false: not supported). The following uses the P2P capability as an example.

    if (deviceList.length > 0) {
      // Step 3 Select the target device from the obtained device list and define it as device. (Assume that there are connected devices in the array and the first one is the target device.)
      let targetDevice: wearEngine.Device = deviceList[0];
    
      // Step 4 Call the method to check whether certain Wear Engine capability is supported (the P2P capability is used as an example).
      targetDevice.isWearEngineCapabilitySupported(wearEngine.WearEngineCapability.P2P_COMMUNICATION).then((isSupportP2P) => {
        console.info(`Succeeded in checking p2p capability, result is ${isSupportP2P}`);
      }).catch((error: BusinessError) => {
        console.error(`Failed to check p2p capability. Code is ${error.code}, message is ${error.message}`);
      })
    }

Querying Whether the Wearable Device Supports Certain Device Capabilities

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.

Call the isDeviceCapabilitySupported method in the Device object to query whether the wearable device supports certain Device capabilities.

  1. Call the getDeviceClient method in wearEngine to obtain the DeviceClient object.

    let deviceClient: wearEngine.DeviceClient = wearEngine.getDeviceClient(this.getUIContext().getHostContext());
  2. Call the getConnectedDevices method to obtain the connected device list.

    let deviceList: wearEngine.Device[] = [];
    deviceClient.getConnectedDevices().then(devices => {
      // Store the list of connected devices.
      deviceList = devices;
      console.info(`Succeeded in getting deviceList, devices 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}`);
    })
  3. Select the target device from the device list.

  4. Call isDeviceCapabilitySupported in the Device object to query whether this device supports the passed device capability (true: supported; false: not supported).

    if (deviceList.length > 0) {
      // Step 3 Select the target device from the obtained device list and define it as device. (Assume that there are connected devices in the array and the first one is the target device.)
      let targetDevice: wearEngine.Device = deviceList[0];
    
      // Step 4 Call the device method to query whether a certain device capability is supported (the app installation capability is used as an example).
      targetDevice.isDeviceCapabilitySupported(wearEngine.DeviceCapability.APP_INSTALLATION).then((isSupportInstall) => {
        console.info(`Succeeded in checking install app capability, result is ${isSupportInstall}`);
      }).catch((error: BusinessError) => {
        console.error(`Failed to check install app capability. Code is ${error.code}, message is ${error.message}`);
      })
    }

Querying the Device SN

To call this API, you need to apply for the device identifier permission (restricted) on HUAWEI Developers and obtain user authorization. For details, please refer to Applying for Integrating Wear Engine.

Call the getSerialNumber method in the Device object to query the SN of the wearable device.

  1. Call the getDeviceClient method in wearEngine to obtain the DeviceClient object.

    let deviceClient: wearEngine.DeviceClient = wearEngine.getDeviceClient(this.getUIContext().getHostContext());
  2. Call the getConnectedDevices method to obtain the connected device list.

    let deviceList: wearEngine.Device[] = [];
    deviceClient.getConnectedDevices().then(devices => {
      // Store the list of connected devices.
      deviceList = devices;
      console.info(`Succeeded in getting deviceList, devices 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}`);
    })
  3. Select the target device from the device list.

  4. Call the getSerialNumber method in the Device object to query the SN of the wearable device.

    if (deviceList.length > 0) {
      // Step 3 Select the target device from the obtained device list and define it as device. (Assume that there are connected devices in the array and the first one is the target device.)
      let targetDevice: wearEngine.Device = deviceList[0];
    
      //Step 4 Call the device method to query the SN.
      targetDevice.getSerialNumber().then((sn) => {
        console.info(`Succeeded in getting device SN, result is ${sn}`);
      }).catch((error: BusinessError) => {
        console.error(`Failed to get device SN. Code is ${error.code}, message is ${error.message}`);
      })
    }