1 Star 0 Fork 4.9K

丛林 / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
subsys-remote-start.md 7.17 KB
一键复制 编辑 原始数据 按行查看 历史
wusongqing 提交于 2022-01-30 14:35 . deleted unnecessary links

Distributed Remote Startup

Overview

The Distributed Manager Service sets up a distributed service platform in OpenHarmony by using a proxy between the primary and secondary devices. With the Distributed Manager Service, the primary device (OpenHarmony-powered smart TV) can start a Feature Ability (FA) deployed on the secondary device (a memory-constrained OpenHarmony device such as an IP camera or a lite wearable).

For example, if a user presses the Remind Me button for a TV program on the smart TV, the smart TV will start the corresponding reminder FA on the lite wearable to remind the user when the particular TV program is available.

Basic Concepts

  • FA

    Feature Ability, representing an ability with a UI for interacting with users

  • Remote startup

    Cross-device FA startup, which is the counterpart of local FA startup

Available APIs

The following table describes the API that can be used by smart TVs to remotely start an FA. This API is provided in the AbilitySlice class. For details, see the Java API reference for OpenHarmony application development.

Table 1 API for remotely starting an FA on the distributed network

Method

Description

void startAbility(Want want)

Remotely starts an FA based on the specified Want information. If the name and type of the want parameter are different from those used in the integrated development environment (IDE), use the parameter name and type in the IDE.

Table 2 Description of the want parameter

Parameter

Type

Description

want

ohos.aafwk.content.Want

When you use startAbility(Want want) to remotely start an FA, you must first specify the deviceId, bundleName, and abilityName attributes of the target FA in the Want object.

Limitations and Constraints

  • The primary device can remotely start an FA of the secondary device, but the secondary device cannot remotely start an FA of the primary device.
  • Before the remote startup, ensure that the two OpenHarmony devices are on the same network segment and can ping each other on the distributed network. Otherwise, the remote startup fails.
  • Currently, only the FAs that have the same public key (that is, the same Huawei certificate) can be started between the primary and secondary devices.

How to Develop

To enable the primary device (smart TV) to start an FA of the secondary device (assuming that the target FA has been developed), perform the following steps:

  1. Complete FA development for the smart TV on DevEco Studio.

  2. Obtain the IDs of online secondary devices.

    // Import the header files required for device selection.
    import ohos.distributedschedule.interwork.DeviceInfo;
    import ohos.distributedschedule.interwork.DeviceManager;
    
    // Obtain the online device list.
    List<DeviceInfo> deviceInfoListOnline = DeviceManager.getDmsDeviceList(DeviceInfo.FLAG_GET_ONLINE_DEVICE);
    String remote_device_id;
    if (deviceInfoListOnline.size() > 0)
    {
        remote_device_id = deviceInfoListOnline[0].GetDeviceId(); // Obtain the ID of the first device in the online device list.
    }
  3. Create a Want instance. You should first create an ElementName object with deviceId, bundleName, abilityName specified and add this object to the Want instance. Then, set the multi-device startup flag Want.FLAG_ABILITYSLICE_MULTI_DEVICE to the Want instance to enable remote FA startup.

    // Import related header files.
    import ohos.aafwk.ability.Ability;
    import ohos.aafwk.content.Want;
    import ohos.bundle.ElementName;
    
    // Start the remote FA on the secondary device.
    Want want = new Want(); // Create a Want instance that encapsulates information about the remote FA to start.
    // Use the device ID obtained in step 2 and specify the FA information.
    ElementName name = new ElementName(remote_device_id, "com.huawei.remote_package_name", "remote_class_name"); 
    want.setElement(name); // Add information about the target FA for startup to the Want instance.
    want.setFlags(Want.FLAG_ABILITYSLICE_MULTI_DEVICE); // Set the multi-device startup flag. If this flag is not set, remote FA startup will be unavailable.
    startAbility(want); // Start the specified FA based on the want parameter. If the name and type of the want parameter are different from those used in the IDE, use the parameter name and type in the IDE.
1
https://gitee.com/jungle8023/docs.git
git@gitee.com:jungle8023/docs.git
jungle8023
docs
docs
master

搜索帮助