# @ohos.application.StaticSubscriberExtensionContext (StaticSubscriberExtensionContext) StaticSubscriberExtensionContext模块是StaticSubscriberExtensionAbility的上下文环境,继承自ExtensionContext。 StaticSubscriberExtensionContext模块提供StaticSubscriberExtensionAbility具有的接口和能力。 > **说明:** > > 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块接口仅可在Stage模型下使用。 ## 导入模块 ```ts import StaticSubscriberExtensionContext from '@ohos.application.StaticSubscriberExtensionContext' ``` ## 使用说明 在使用StaticSubscriberExtensionContext的功能前,需要通过StaticSubscriberExtensionAbility获取。 ```ts import StaticSubscriberExtensionAbility from '@ohos.application.StaticSubscriberExtensionAbility' export default class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { context = this.context; }; ``` ## StaticSubscriberExtensionContext.startAbility startAbility(want: Want, callback: AsyncCallback<void>): void; 拉起一个静态订阅所属的同应用的Ability。使用callback异步回调。 使用规则: - 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限 - 跨应用场景下,目标Ability的visible属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限 **需要权限**:ohos.permission.START_ABILITIES_FROM_BACKGROUND **系统能力**:SystemCapability.Ability.AbilityRuntime.Core **系统API**:该接口为系统接口,三方应用不支持调用。 **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ----------------------------------- | ---- | -------------------------- | | want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 | | callback | AsyncCallback<void> | 是 | callback形式返回启动结果。 | **错误码:** 以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)。 | 错误码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. | | 16000011 | The context does not exist. | | 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. | | 16300003 | The target application is not self application. | **示例:** ```ts let want = { bundleName: "com.example.myapp", abilityName: "MyAbility" }; try { this.context.startAbility(want, (error) => { if (error) { // 处理业务逻辑错误 console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) + ' error.message: ' + JSON.stringify(error.message)); return; } // 执行正常业务 console.log('startAbility succeed'); }); } catch (paramError) { // 处理入参错误异常 console.log('startAbility failed, error.code: ' + JSON.stringify(paramError.code) + ' error.message: ' + JSON.stringify(paramError.message)); } ``` ## StaticSubscriberExtensionContext.startAbility startAbility(want: Want): Promise<void>; 拉起一个静态订阅所属的同应用的Ability。使用Promise异步回调。 使用规则: - 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限 - 跨应用场景下,目标Ability的visible属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限 **需要权限**:ohos.permission.START_ABILITIES_FROM_BACKGROUND **系统能力**:SystemCapability.Ability.AbilityRuntime.Core **系统API**:该接口为系统接口,三方应用不支持调用。 **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ----------------------------------- | ---- | ----------------------- | | want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | Promise形式返回启动结果。 | **错误码:** 以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)。 | 错误码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. | | 16000011 | The context does not exist. | | 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. | | 16300003 | The target application is not self application. | **示例:** ```ts let want = { bundleName: "com.example.myapp", abilityName: "MyAbility" }; try { this.context.startAbility(want) .then(() => { // 执行正常业务 console.log('startAbility succeed'); }) .catch((error) => { // 处理业务逻辑错误 console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) + ' error.message: ' + JSON.stringify(error.message)); }); } catch (paramError) { // 处理入参错误异常 console.log('startAbility failed, error.code: ' + JSON.stringify(paramError.code) + ' error.message: ' + JSON.stringify(paramError.message)); } ```