1.2K Star 6.4K Fork 5.4K

OpenHarmony/docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
js-apis-app-ability-atomicServiceOptions.md 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
xuzhihao 提交于 2024-06-26 17:17 . Bugfix: 元能力Vod单处理。

@ohos.app.ability.AtomicServiceOptions (AtomicServiceOptions)

AtomicServiceOptions可以作为openAtomicService()的入参,用于携带参数。继承于StartOptions

说明:

本模块首批接口从API version 12 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

本模块接口仅可在Stage模型下使用。

导入模块

import { AtomicServiceOptions } from '@kit.AbilityKit';

属性

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 必填 说明
flags number 系统处理该次启动的方式。
例如通过wantConstant.Flags.FLAG_INSTALL_ON_DEMAND表示使用免安装能力。
parameters Record<string, Object> 表示额外参数描述。具体描述参考Want中parameters字段描述。

示例:

import { UIAbility, AtomicServiceOptions, common, wantConstant } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  onForeground() {
    let appId: string = '6918661953712445909';
    let options: AtomicServiceOptions = {
      flags: wantConstant.Flags.FLAG_INSTALL_ON_DEMAND,
      parameters: {
        "demo.result": 123456
      }
    };

    try {
      this.context.openAtomicService(appId, options)
        .then((result: common.AbilityResult) => {
          // 执行正常业务
          console.info('openAtomicService succeed');
        })
        .catch((err: BusinessError) => {
          // 处理业务逻辑错误
          console.error(`openAtomicService failed, code is ${err.code}, message is ${err.message}`);
        });
    } catch (err) {
      // 处理入参错误异常
      let code = (err as BusinessError).code;
      let message = (err as BusinessError).message;
      console.error(`openAtomicService failed, code is ${code}, message is ${message}`);
    }
  }
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
其他
1
https://gitee.com/openharmony/docs.git
git@gitee.com:openharmony/docs.git
openharmony
docs
docs
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891