同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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.
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
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. |
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.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。