From eea3f5f15cbeee00c3aef581ebc25b7943049e5c Mon Sep 17 00:00:00 2001 From: Gloria Date: Mon, 12 Jun 2023 17:27:56 +0800 Subject: [PATCH] Update docs against 18734 Signed-off-by: wusongqing --- .../application-models/Readme-EN.md | 13 ++++--- .../atomic-services-support-sharing.md | 39 +++++++++++++++++++ .../js-apis-app-ability-abilityManager.md | 31 ++++++++------- .../apis/js-apis-app-ability-uiAbility.md | 2 +- 4 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 en/application-dev/application-models/atomic-services-support-sharing.md diff --git a/en/application-dev/application-models/Readme-EN.md b/en/application-dev/application-models/Readme-EN.md index aca0bbb39f..bdfbb5472e 100644 --- a/en/application-dev/application-models/Readme-EN.md +++ b/en/application-dev/application-models/Readme-EN.md @@ -5,7 +5,7 @@ - [Interpretation of the Application Model](application-model-description.md) - Stage Model Development - [Stage Model Development Overview](stage-model-development-overview.md) - - Stage Mode Application Components + - Stage Model Application Components - [Application- or Component-Level Configuration](application-component-configuration-stage.md) - UIAbility Component - [UIAbility Component Overview](uiability-overview.md) @@ -56,12 +56,13 @@ - [Using Explicit Want to Start an Application Component](ability-startup-with-explicit-want.md) - [Using Implicit Want to Open a Website](ability-startup-with-implicit-want.md) - [Using Want to Share Data Between Applications](data-share-via-want.md) - - [Component Startup Rules](component-startup-rules.md) - - Inter-Device Application Component Interaction (Continuation) + - [Component Startup Rules (Stage Model)](component-startup-rules.md) + - Inter-Device Application Component Interaction (Continuation) - [Continuation Overview](inter-device-interaction-hop-overview.md) - [Cross-Device Migration (for System Applications Only)](hop-cross-device-migration.md) - [Multi-device Collaboration (for System Applications Only)](hop-multi-device-collaboration.md) - [Subscribing to System Environment Variable Changes](subscribe-system-environment-variable-changes.md) + - [Setting Atomic Services to Support Sharing](atomic-services-support-sharing.md) - Process Model - [Process Model Overview](process-model-stage.md) - Common Events @@ -81,12 +82,12 @@ - Mission Management - [Mission Management Scenarios](mission-management-overview.md) - [Mission and Launch Type](mission-management-launch-type.md) - - [Page Stack and MissionList](page-mission-stack.md) + - [Page Stack and Mission List](page-mission-stack.md) - [Setting the Icon and Name of a Mission Snapshot](mission-set-icon-name-for-task-snapshot.md) - [Application Configuration File](config-file-stage.md) - FA Model Development - [FA Model Development Overview](fa-model-development-overview.md) - - FA Mode Application Components + - FA Model Application Components - [Application- or Component-Level Configuration](application-component-configuration-fa.md) - PageAbility Component Development - [PageAbility Component Overview](pageability-overview.md) @@ -119,7 +120,7 @@ - [Widget Development](widget-development-fa.md) - [Context](application-context-fa.md) - [Want](want-fa.md) - - [Component Startup Rules](component-startup-rules-fa.md) + - [Component Startup Rules (FA Model)](component-startup-rules-fa.md) - Process Model - [Process Model Overview](process-model-fa.md) - [Common Events](common-event-fa.md) diff --git a/en/application-dev/application-models/atomic-services-support-sharing.md b/en/application-dev/application-models/atomic-services-support-sharing.md new file mode 100644 index 0000000000..99feea4719 --- /dev/null +++ b/en/application-dev/application-models/atomic-services-support-sharing.md @@ -0,0 +1,39 @@ +# Setting Atomic Services to Support Sharing +By means of sharing, users can quickly access atomic services and use their features. + +## How to Develop +In the sharing scenario, there are two parties involved: a target application that shares data and an application that obtains the shared data. The two can be physically the same. The target application uses the **onShare()** lifecycle callback to set the data to share. After the target application is started, you can run the **hdc shell aa dump -a** command to check the started services and processes and find its mission ID. After the current application is started, call the **abilityManager.acquireShareData()** API with the mission ID passed in to obtain the shared data. +> **NOTE** +> +> The mission ID of the target application can also be obtained by calling [missionManager.getMissionInfos()](../reference/apis/js-apis-app-ability-missionManager.md#getmissioninfos). + +1. The target application calls **UIAbility.onShare()** provided by the UIAbility component to set the data to share. **ohos.extra.param.key.contentTitle** indicates the title of the content to share in the sharing box, **ohos.extra.param.key.shareAbstract** provides an abstract description of the content, and **ohos.extra.param.key.shareUrl** indicates the online address of the service. You need to set these three items as objects, with the key set to **title**, **abstract**, and **url**, respectively. + + ```ts + import AbilityConstant from '@ohos.app.ability.AbilityConstant'; + class MyUIAbility extends UIAbility { + onShare(wantParams) { + console.log('onShare'); + wantParams['ohos.extra.param.key.contentTitle'] = {title: "W3"}; + wantParams['ohos.extra.param.key.shareAbstract'] = {abstract: "communication for huawei employee"}; + wantParams['ohos.extra.param.key.shareUrl'] = {url: "w3.huawei.com"}; + } + } + ``` + +2. The current application calls **abilityManager.acquireShareData()** to obtain the data shared by the target application. **missionId** indicates the target application's mission ID, which can be obtained by running the **hdc shell aa dump -a** command or calling the **missionManager.getMissionInfos()** API after the target application is started. **wantParam** indicates the data shared by the target application through the **UIAbility.onShare()** lifecycle callback. + + ```ts + import abilityManager from '@ohos.app.ability.abilityManager'; + try { + abilityManager.acquireShareData(1, (err, wantParam) => { + if (err) { + console.error(`acquireShareData fail, err: ${JSON.stringify(err)}`); + } else { + console.log(`acquireShareData success, data: ${JSON.stringify(wantParam)}`); + } + }); + } catch (paramError) { + console.error(`error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}`); + } + ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md index c3e24aadaa..ed56fca0dd 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md @@ -143,7 +143,7 @@ try { getAbilityRunningInfos(callback: AsyncCallback\>): void -Obtains the ability running information. This API uses an asynchronous callback to return the result. +Obtains the UIAbility running information. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.GET_RUNNING_INFO @@ -388,7 +388,7 @@ abilityManager.getTopAbility().then((data) => { acquireShareData(missionId: number, callback: AsyncCallback<{[key: string]: Object}>): void; -Acquires the shared data of the target device. This API uses an asynchronous callback to return the result. +Acquires the shared data of the target application. This API uses an asynchronous callback to return the result. **missionId** indicates the target application's mission ID, which can be obtained by running the **hdc shell aa dump -a** command or calling the [missionManager.getMissionInfos()](js-apis-app-ability-missionManager.md#getmissioninfos) API after the target application is started. **callback** indicates the data shared by the target application through the [UIAbility.onShare()](js-apis-app-ability-uiAbility.md#onshare) lifecycle callback. **System capability**: SystemCapability.Ability.AbilityRuntime.Core @@ -396,7 +396,7 @@ Acquires the shared data of the target device. This API uses an asynchronous cal | Name | Type | Mandatory | Description | | --------- | ---------------------------------------- | ---- | -------------- | -| missionId | number | Yes| Mission ID on the target device. The maximum value is 231-1.| +| missionId | number | Yes| Mission ID on the target application. The maximum value is 231-1.| | callback | AsyncCallback<{[key: string]: Object}> | Yes | Callback used to return the API call result and the shared data. You can perform error handling or custom processing in it. | **Error codes** @@ -411,14 +411,17 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ```ts import abilityManager from '@ohos.app.ability.abilityManager'; - -abilityManager.acquireShareData(1, (err, data) => { - if (err) { - console.error(`acquireShareData fail, err: ${JSON.stringify(err)}`); - } else { - console.log(`acquireShareData success, data: ${JSON.stringify(data)}`); - } -}); +try { + abilityManager.acquireShareData(1, (err, wantParam) => { + if (err) { + console.error(`acquireShareData fail, err: ${JSON.stringify(err)}`); + } else { + console.log(`acquireShareData success, data: ${JSON.stringify(wantParam)}`); + } + }); +} catch (paramError) { + console.error(`error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}`); +} ``` @@ -426,7 +429,7 @@ abilityManager.acquireShareData(1, (err, data) => { acquireShareData(missionId: number): Promise<{[key: string]: Object}>; -Acquires the shared data of the target device. This API uses a promise to return the result. +Acquires the shared data of the target application. This API uses a promise to return the result. **missionId** indicates the target application's mission ID, which can be obtained by running the **hdc shell aa dump -a** command or calling the [missionManager.getMissionInfos()](js-apis-app-ability-missionManager.md#getmissioninfos) API after the target application is started. **Promise<{[key: string]: Object}>** indicates the data shared by the target application through the [UIAbility.onShare()](js-apis-app-ability-uiAbility.md#onshare) lifecycle callback. **System capability**: SystemCapability.Ability.AbilityRuntime.Core @@ -449,8 +452,8 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ```ts import abilityManager from '@ohos.app.ability.abilityManager'; try { - abilityManager.acquireShareData(1).then((data) => { - console.log(`acquireShareData success, data: ${JSON.stringify(data)}`); + abilityManager.acquireShareData(1).then((wantParam) => { + console.log(`acquireShareData success, data: ${JSON.stringify(wantParam)}`); }).catch((err) => { console.error(`acquireShareData fail, err: ${JSON.stringify(err)}`); }); diff --git a/en/application-dev/reference/apis/js-apis-app-ability-uiAbility.md b/en/application-dev/reference/apis/js-apis-app-ability-uiAbility.md index cfd08c64b6..572f8909b4 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-uiAbility.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-uiAbility.md @@ -315,7 +315,7 @@ class MyUIAbility extends UIAbility { onShare(wantParam:{ [key: string]: Object }): void; -Called when this UIAbility sets data to share. **ohos.extra.param.key.contentTitle** indicates the title of the content to share in the sharing box, and **ohos.extra.param.key.shareAbstract** provides an abstract description of the content, **ohos.extra.param.key.shareUrl** indicates the online address of the service. You need to set these three items as objects, with the key set to **title**, **abstract**, and **url**, respectively. +Called when this UIAbility sets data to share. **ohos.extra.param.key.contentTitle** indicates the title of the content to share in the sharing box, **ohos.extra.param.key.shareAbstract** provides an abstract description of the content, and **ohos.extra.param.key.shareUrl** indicates the online address of the service. You need to set these three items as objects, with the key set to **title**, **abstract**, and **url**, respectively. **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore -- GitLab