harmony 鸿蒙Distributed Remote Startup
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
Table 2 Description of the want parameter
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:
Complete FA development for the smart TV on DevEco Studio.
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. }
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.
你可能感兴趣的鸿蒙文章
harmony 鸿蒙AI Framework Development
harmony 鸿蒙Application Privilege Configuration
harmony 鸿蒙Setting Up a Development Environment
harmony 鸿蒙Development Guidelines
harmony 鸿蒙Application Framework Overview
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦