harmony 鸿蒙UIExtensionContext
UIExtensionContext
UIExtensionContext是UIExtensionAbility的上下文环境,继承自ExtensionContext,提供UIExtensionAbility的相关配置信息以及操作UIAbility的方法,如启动UIAbility等。
说明:
- 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
- 本模块接口仅可在Stage模型下使用。
导入模块
import common from '@ohos.app.ability.common';
UIExtensionContext.startAbility
startAbility(want: Want, callback: AsyncCallback<void>): void;
启动Ability(callback形式)。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请ohos.permission.START_ABILITIES_FROM_BACKGROUND
权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请ohos.permission.START_INVISIBLE_ABILITY
权限
- 组件启动规则详见:组件启动规则(Stage模型)
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
want | Want | 是 | 启动Ability的want信息。 |
callback | AsyncCallback<void> | 是 | callback形式返回启动结果。 |
错误码:
错误码ID | 错误信息 |
---|---|
16000001 | The specified ability does not exist. |
16000002 | Incorrect ability type. |
16000004 | Can not start invisible component. |
16000005 | The specified process does not have the permission. |
16000006 | Cross-user operations are not allowed. |
16000008 | The crowdtesting application expires. |
16000009 | An ability cannot be started or stopped in Wukong mode. |
16000010 | The call with the continuation flag is forbidden. |
16000011 | The context does not exist. |
16000012 | The application is controlled. |
16000013 | The application is controlled by EDM. |
16000050 | Internal error. |
16000053 | The ability is not on the top of the UI. |
16000055 | Installation-free timed out. |
16200001 | The caller has been released. |
错误码详细介绍请参考errcode-ability
UIExtensionContext.startAbility
startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void;
启动Ability(callback形式)。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请ohos.permission.START_ABILITIES_FROM_BACKGROUND
权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请ohos.permission.START_INVISIBLE_ABILITY
权限
- 组件启动规则详见:组件启动规则(Stage模型)
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
want | Want | 是 | 启动Ability的want信息。 |
options | StartOptions | 是 | 启动Ability所携带的参数。 |
callback | AsyncCallback<void> | 是 | callback形式返回启动结果。 |
错误码:
错误码ID | 错误信息 |
---|---|
16000001 | The specified ability does not exist. |
16000004 | Can not start invisible component. |
16000005 | The specified process does not have the permission. |
16000006 | Cross-user operations are not allowed. |
16000008 | The crowdtesting application expires. |
16000009 | An ability cannot be started or stopped in Wukong mode. |
16000011 | The context does not exist. |
16000012 | The application is controlled. |
16000013 | The application is controlled by EDM. |
16000050 | Internal error. |
16000053 | The ability is not on the top of the UI. |
16000055 | Installation-free timed out. |
16200001 | The caller has been released. |
错误码详细介绍请参考errcode-ability
UIExtensionContext.startAbility
startAbility(want: Want, options?: StartOptions): Promise<void>;
启动Ability(promise形式)。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请ohos.permission.START_ABILITIES_FROM_BACKGROUND
权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请ohos.permission.START_INVISIBLE_ABILITY
权限
- 组件启动规则详见:组件启动规则(Stage模型)
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
want | Want | 是 | 启动Ability的want信息。 |
options | StartOptions | 否 | 启动Ability所携带的参数。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | Promise形式返回启动结果。 |
错误码:
错误码ID | 错误信息 |
---|---|
16000001 | The specified ability does not exist. |
16000002 | Incorrect ability type. |
16000004 | Can not start invisible component. |
16000005 | The specified process does not have the permission. |
16000006 | Cross-user operations are not allowed. |
16000008 | The crowdtesting application expires. |
16000009 | An ability cannot be started or stopped in Wukong mode. |
16000010 | The call with the continuation flag is forbidden. |
16000011 | The context does not exist. |
16000012 | The application is controlled. |
16000013 | The application is controlled by EDM. |
16000050 | Internal error. |
16000053 | The ability is not on the top of the UI. |
16000055 | Installation-free timed out. |
16200001 | The caller has been released. |
错误码详细介绍请参考errcode-ability
UIExtensionContext.startAbilityForResult
startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void;
启动一个Ability。Ability被启动后,有如下情况(callback形式): - 正常情况下可通过调用terminateSelfWithResult接口使之终止并且返回结果给调用方。 - 异常情况下比如杀死Ability会返回异常信息给调用方, 异常信息中resultCode为-1。 - 如果被启动的Ability模式是单实例模式, 不同应用多次调用该接口启动这个Ability,当这个Ability调用terminateSelfWithResult接口使之终止时,只将正常结果返回给最后一个调用方, 其它调用方返回异常信息, 异常信息中resultCode为-1。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请ohos.permission.START_ABILITIES_FROM_BACKGROUND
权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请ohos.permission.START_INVISIBLE_ABILITY
权限
- 组件启动规则详见:组件启动规则(Stage模型)
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
want | Want | 是 | 启动Ability的want信息。 |
callback | AsyncCallback<AbilityResult> | 是 | 执行结果回调函数。 |
错误码:
错误码ID | 错误信息 |
---|---|
16000001 | The specified ability does not exist. |
16000002 | Incorrect ability type. |
16000004 | Can not start invisible component. |
16000005 | The specified process does not have the permission. |
16000006 | Cross-user operations are not allowed. |
16000008 | The crowdtesting application expires. |
16000009 | An ability cannot be started or stopped in Wukong mode. |
16000010 | The call with the continuation flag is forbidden. |
16000011 | The context does not exist. |
16000012 | The application is controlled. |
16000013 | The application is controlled by EDM. |
16000050 | Internal error. |
16000053 | The ability is not on the top of the UI. |
16000055 | Installation-free timed out. |
16200001 | The caller has been released. |
错误码详细介绍请参考errcode-ability
UIExtensionContext.startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): void;
启动一个Ability。Ability被启动后,有如下情况(callback形式): - 正常情况下可通过调用terminateSelfWithResult接口使之终止并且返回结果给调用方。 - 异常情况下比如杀死Ability会返回异常信息给调用方,异常信息中resultCode为-1。 - 如果被启动的Ability模式是单实例模式, 不同应用多次调用该接口启动这个Ability,当这个Ability调用terminateSelfWithResult接口使之终止时,只将正常结果返回给最后一个调用方,其它调用方返回异常信息, 异常信息中resultCode为-1。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请ohos.permission.START_ABILITIES_FROM_BACKGROUND
权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请ohos.permission.START_INVISIBLE_ABILITY
权限
- 组件启动规则详见:组件启动规则(Stage模型)
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
want | Want | 是 | 启动Ability的want信息。 |
options | StartOptions | 是 | 启动Ability所携带的参数。 |
callback | AsyncCallback<AbilityResult> | 是 | 执行结果回调函数。 |
错误码:
错误码ID | 错误信息 |
---|---|
16000001 | The specified ability does not exist. |
16000004 | Can not start invisible component. |
16000005 | The specified process does not have the permission. |
16000006 | Cross-user operations are not allowed. |
16000008 | The crowdtesting application expires. |
16000009 | An ability cannot be started or stopped in Wukong mode. |
16000011 | The context does not exist. |
16000012 | The application is controlled. |
16000013 | The application is controlled by EDM. |
16000050 | Internal error. |
16000053 | The ability is not on the top of the UI. |
16000055 | Installation-free timed out. |
16200001 | The caller has been released. |
错误码详细介绍请参考errcode-ability
UIExtensionContext.startAbilityForResult
startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult>;
启动一个Ability。Ability被启动后,有如下情况(promise形式): - 正常情况下可通过调用terminateSelfWithResult接口使之终止并且返回结果给调用方。 - 异常情况下比如杀死Ability会返回异常信息给调用方, 异常信息中resultCode为-1。 - 如果被启动的Ability模式是单实例模式, 不同应用多次调用该接口启动这个Ability,当这个Ability调用terminateSelfWithResult接口使之终止时,只将正常结果返回给最后一个调用方, 其它调用方返回异常信息, 异常信息中resultCode为-1。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请ohos.permission.START_ABILITIES_FROM_BACKGROUND
权限
- 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请ohos.permission.START_INVISIBLE_ABILITY
权限
- 组件启动规则详见:组件启动规则(Stage模型)
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
want | Want | 是 | 启动Ability的want信息。 |
options | StartOptions | 否 | 启动Ability所携带的参数。 |
返回值:
类型 | 说明 |
---|---|
Promise<AbilityResult> | Promise形式返回执行结果。 |
错误码:
错误码ID | 错误信息 |
---|---|
16000001 | The specified ability does not exist. |
16000002 | Incorrect ability type. |
16000004 | Can not start invisible component. |
16000005 | The specified process does not have the permission. |
16000006 | Cross-user operations are not allowed. |
16000008 | The crowdtesting application expires. |
16000009 | An ability cannot be started or stopped in Wukong mode. |
16000010 | The call with the continuation flag is forbidden. |
16000011 | The context does not exist. |
16000012 | The application is controlled. |
16000013 | The application is controlled by EDM. |
16000050 | Internal error. |
16000053 | The ability is not on the top of the UI. |
16000055 | Installation-free timed out. |
16200001 | The caller has been released. |
错误码详细介绍请参考errcode-ability
UIExtensionContext.connectServiceExtensionAbility
connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
将当前Ability连接到一个使用AbilityInfo.AbilityType.SERVICE模板的Ability。
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
want | Want | 是 | 连接ServiceExtensionAbility的want信息。 |
options | ConnectOptions | 是 | 与ServiceExtensionAbility建立连接后回调函数的实例。 |
返回值:
类型 | 说明 |
---|---|
number | 返回Ability连接的结果code。 |
错误码:
错误码ID | 错误信息 |
---|---|
16000001 | The specified ability does not exist. |
16000002 | Incorrect ability type. |
16000004 | Can not start invisible component. |
16000005 | The specified process does not have the permission. |
16000006 | Cross-user operations are not allowed. |
16000008 | The crowdtesting application expires. |
16000053 | The ability is not on the top of the UI. |
16000055 | Installation-free timed out. |
16000011 | The context does not exist. |
16000050 | Internal error. |
错误码详细介绍请参考errcode-ability
UIExtensionContext.disconnectServiceExtensionAbility
disconnectServiceExtensionAbility(connection: number): Promise<void>;
断开与ServiceExtensionAbility的连接,断开连接之后需要将连接成功时返回的remote对象置空(promise形式)。
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
connection | number | 是 | 连接的ServiceExtensionAbility的数字代码,即connectServiceExtensionAbility返回的connectionId。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 返回执行结果。 |
错误码:
错误码ID | 错误信息 |
---|---|
16000011 | The context does not exist. |
16000050 | Internal error. |
错误码详细介绍请参考errcode-ability
UIExtensionContext.disconnectServiceExtensionAbility
disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback<void>): void;
断开与ServiceExtensionAbility的连接,断开连接之后需要将连接成功时返回的remote对象置空(callback形式)。
系统能力:SystemCapability.Ability.AbilityRuntime.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
connection | number | 是 | 连接的ServiceExtensionAbility的数字代码,即connectServiceExtensionAbility返回的connectionId。 |
callback | AsyncCallback<void> | 是 | callback形式返回断开连接的结果。 |
错误码:
错误码ID | 错误信息 |
---|---|
16000011 | The context does not exist. |
16000050 | Internal error. |
错误码详细介绍请参考errcode-ability
你可能感兴趣的鸿蒙文章
harmony 鸿蒙BundleStatusCallback
harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager模块)
harmony 鸿蒙@ohos.distributedBundle (分布式包管理)
harmony 鸿蒙@ohos.bundle (Bundle模块)
harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (企业设备管理扩展能力)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦