• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.AtomicServiceOptions (AtomicServiceOptions)
2<!--Kit: Ability Kit-->
3<!--Subsystem: Ability-->
4<!--Owner: @littlejerry1; @wendel; @Luobniz21-->
5<!--Designer: @ccllee1-->
6<!--Tester: @lixueqing513-->
7<!--Adviser: @huipeizi-->
8
9AtomicServiceOptions可以作为[openAtomicService()](js-apis-inner-application-uiAbilityContext.md#openatomicservice12)的入参,用于携带参数。继承于[StartOptions](js-apis-app-ability-startOptions.md)。
10
11> **说明:**
12>
13> 本模块首批接口从API version 12 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14>
15> 本模块接口仅可在Stage模型下使用。
16
17## 导入模块
18
19```ts
20import { AtomicServiceOptions } from '@kit.AbilityKit';
21```
22
23## AtomicServiceOptions
24
25**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
26
27**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
28
29| 名称 | 类型 | 只读 | 可选 | 说明 |
30| -------- | -------- | -------- | -------- | -------- |
31| [flags](js-apis-app-ability-wantConstant.md#flags) | number | 否 |  是 | 系统处理该次启动的方式。<br />例如通过wantConstant.Flags.FLAG_INSTALL_ON_DEMAND表示使用免安装能力。 |
32| parameters | Record\<string, Object> | 否 |  是 | 表示额外参数描述。具体描述参考[Want](js-apis-app-ability-want.md)中parameters字段描述。 |
33| completionHandlerForAtomicService<sup>20+</sup> | [CompletionHandlerForAtomicService](./js-apis-app-ability-CompletionHandlerForAtomicService.md) | 否 |  是 | 打开原子化服务结果的操作类,用于接收打开原子化服务的结果。<br/>**原子化服务API**:从API version 20开始,该接口支持在原子化服务中使用。 |
34
35**示例:**
36
37```ts
38import { UIAbility, AtomicServiceOptions, common, wantConstant, CompletionHandlerForAtomicService } from '@kit.AbilityKit';
39import { BusinessError } from '@kit.BasicServicesKit';
40import { FailureCode } from '@ohos.app.ability.CompletionHandlerForAtomicService';
41import { hilog } from '@kit.PerformanceAnalysisKit';
42
43export default class EntryAbility extends UIAbility {
44  onForeground() {
45    let completionHandler: CompletionHandlerForAtomicService = {
46      onAtomicServiceRequestSuccess(appId: string) {
47        hilog.info(0x0000, 'testTag', `appId:${appId}`);
48      },
49      onAtomicServiceRequestFailure(appId: string, failureCode: FailureCode, failureMessage: string) {
50        hilog.info(0x0000, 'testTag', `appId:${appId}, failureCode:${failureCode}, failureMessage:${failureMessage}`);
51      }
52    };
53
54    let options: AtomicServiceOptions = {
55      flags: wantConstant.Flags.FLAG_INSTALL_ON_DEMAND,
56      parameters: {
57        'demo.result': 123456
58      },
59      completionHandlerForAtomicService: completionHandler
60    };
61
62    try {
63      let appId: string = '6918661953712445909'; // 根据实际appId修改此值
64      this.context.openAtomicService(appId, options)
65        .then((result: common.AbilityResult) => {
66          // 执行正常业务
67          console.info('openAtomicService succeed');
68        })
69        .catch((err: BusinessError) => {
70          // 处理业务逻辑错误
71          console.error(`openAtomicService failed, code is ${err.code}, message is ${err.message}`);
72        });
73    } catch (err) {
74      // 处理入参错误异常
75      let code = (err as BusinessError).code;
76      let message = (err as BusinessError).message;
77      console.error(`openAtomicService failed, code is ${code}, message is ${message}`);
78    }
79  }
80}
81```
82