目录

Selecting a Target Device

If the list of connected devices contains more than one device, you need to select the target device as needed.

Selecting a Device Type

The DeviceCategory field in the Device class indicates the device type, and you can use this field to select the target device.

  1. Obtain the list of connected wearable devices by referring to Querying Connected Wearable Devices.

  2. Select the device to communicate with from the list of connected devices based on the device type.

    // Declare the target device.
    let targetDevice: wearEngine.Device;
    for (let index = 0; index < deviceList.length; index++) {
      // Select devices of the watch type.
      if (deviceList[index].category === wearEngine.DeviceCategory.WATCH) {
        targetDevice = deviceList[index];
        break;
      }
      if (index === deviceList.length - 1) {
        // An error is thrown if the target device does not exist.
        throw new Error('cannot find target device');
      }
    }
    // An error is thrown if targetDevice is undefined.
    if (!targetDevice) {
        throw new Error('The value of targetDevice is undefined');
    }

Selecting Devices Supporting Certain Capabilities

Query the capabilities supported by the obtained devices by referring to Querying Wearable Device Information.

[h2]Selecting the Target Device Supporting Certain Wear Engine Capabilities

  1. Obtain the list of connected wearable devices by referring to Querying Connected Wearable Devices.

  2. Select the device to communicate with from the list of connected devices based on the supported Wear Engine capabilities.

    async function fun() {
    // Declare the target device.
      let targetDevice: wearEngine.Device;
      for (let index = 0; index < deviceList.length; index++) {
        // Select devices of the watch type.
        if (await device.isWearEngineCapabilitySupported(wearEngine.WearEngineCapability.MONITOR)) {
          targetDevice = deviceList[index];
          break;
        }
        if (index === deviceList.length - 1) {
        // An error is thrown if the target device does not exist.
          throw new Error('cannot find target device');
        }
      }
      // An error is thrown if targetDevice is undefined.
      if (!targetDevice) {
        throw new Error('The value of targetDevice is undefined.');
      }
    }

[h2]Selecting the Target Device Supporting Certain Device Capabilities

  1. Obtain the list of connected wearable devices by referring to Querying Connected Wearable Devices.

  2. Select the device to communicate with from the list of connected devices based on the supported device capabilities.

    async function fun() {
    // Declare the target device.
      let targetDevice: wearEngine.Device;
      for (let index = 0; index < deviceList.length; index++) {
        // Select devices of the watch type.
        if (await device.isDeviceCapabilitySupported(wearEngine.DeviceCapability.APP_INSTALLATION)) {
          targetDevice = deviceList[index];
          break;
        }
        if (index === deviceList.length - 1) {
        // An error is thrown if the target device does not exist.
          throw new Error('cannot find target device');
        }
      }
      // An error is thrown if targetDevice is undefined.
      if (!targetDevice) {
        throw new Error('The value of targetDevice is undefined.');
      }
    }