未验证 提交 baf94c09 编写于 作者: O openharmony_ci 提交者: Gitee

!21588 update onShare params

Merge pull request !21588 from xieqiongyang/master
......@@ -64,7 +64,6 @@
- [跨端迁移(仅对系统应用开放)](hop-cross-device-migration.md)
- [多端协同(仅对系统应用开放)](hop-multi-device-collaboration.md)
- [订阅系统环境变量的变化](subscribe-system-environment-variable-changes.md)
- [原子化服务支持分享](atomic-services-support-sharing.md)
- 了解进程模型
- [进程模型概述](process-model-stage.md)
- 公共事件
......
# 设置原子化服务支持分享
## 原子化服务分享
1. UIAbility组件提供了[UIAbility.onShare()](../reference/apis/js-apis-app-ability-uiAbility.md#onshare)生命周期方法,应用可通过此方法设置要分享的数据。其中,ohos.extra.param.key.contentTitle表示分享框中对分享内容title的描述,ohos.extra.param.key.shareAbstract表示分享框中对携带内容的摘要描述,ohos.extra.param.key.shareUrl表示服务的在线地址。以上三项分享数据均是开发者填充,且为Object对象,对象的key分别为title,abstract,url。
```ts
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
onShare(wantParams) {
console.log('onShare');
wantParams['ohos.extra.param.key.contentTitle'] = 'shareFeatureAbility';
wantParams['ohos.extra.param.key.shareAbstract'] = 'huawei employee';
wantParams['ohos.extra.param.key.shareUrl'] = 'w3.huawei.com';
}
}
```
2. 系统弹框调用[abilityManager.acquireShareData()](../reference/apis/js-apis-app-ability-abilityManager.md#acquiresharedata)接口发起原子化服务共享,根据missionId找到对应的UIAbility,调用其OnShare生命周期,收到共享数据。
```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)}`);
}
```
......@@ -39,7 +39,7 @@ Ability初次启动原因,该类型为枚举,可配合[Ability](js-apis-app-
| CALL | 2 | 通过[startAbilityByCall](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartabilitybycall)接口启动ability。 |
| CONTINUATION | 3 | 跨端设备迁移启动ability。 |
| APP_RECOVERY | 4 | 设置应用恢复后,应用故障时自动恢复启动ability。 |
| SHARE<sup>10+</sup> | 5 | 通过[acquireShareData](js-apis-app-ability-abilityManager.md#acquiresharedata)接口启动ability。 |
| SHARE<sup>10+</sup> | 5 | 通过原子化服务分享启动ability。 |
**示例:**
......
......@@ -315,7 +315,7 @@ class MyUIAbility extends UIAbility {
onShare(wantParam:{ [key: string]: Object }): void;
ability设置分享数据。其中,ohos.extra.param.key.contentTitle表示分享框中对分享内容title的描述,ohos.extra.param.key.shareAbstract表示分享框中对携带内容的摘要描述,ohos.extra.param.key.shareUrl表示服务的在线地址。以上三项分享数据均是开发者填充,且为Object对象,对象的key分别为title,abstract,url
ability设置分享数据,ohos.extra.param.key.shareUrl表示服务的在线地址
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
......@@ -332,9 +332,7 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
onShare(wantParams) {
console.log('onShare');
wantParams['ohos.extra.param.key.contentTitle'] = 'shareFeatureAbility';
wantParams['ohos.extra.param.key.shareAbstract'] = 'huawei employee';
wantParams['ohos.extra.param.key.shareUrl'] = 'w3.huawei.com';
wantParams['ohos.extra.param.key.shareUrl'] = 'example.com';
}
}
```
......
......@@ -150,7 +150,6 @@
- [跨端迁移(仅对系统应用开放)](application-models/hop-cross-device-migration.md)
- [多端协同(仅对系统应用开放)](application-models/hop-multi-device-collaboration.md)
- [订阅系统环境变量的变化](application-models/subscribe-system-environment-variable-changes.md)
- [原子化服务支持分享](application-models/atomic-services-support-sharing.md)
- 了解进程模型
- [进程模型概述](application-models/process-model-stage.md)
- 公共事件
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册