提交 bb338067 编写于 作者: X xinking129

add docs about staticSubscriberExtensinContext

Signed-off-by: Nxinking129 <xinxin13@huawei.com>
上级 e5c83149
# @ohos.application.StaticSubscriberExtensionContext (StaticSubscriberExtensionContext)
StaticSubscriberExtensionContext模块是StaticSubscriberExtensionAbility的上下文环境,继承自ExtensionContext。
StaticSubscriberExtensionContext模块提供StaticSubscriberExtensionAbility具有的接口和能力。
> **说明:**
>
> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。
## 使用说明
在使用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&lt;void&gt;): void;
启动Ability(callback形式)。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限
- 跨应用场景下,目标Ability的visible属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限
- 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**:该接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------- | ---- | -------------------------- |
| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 |
| callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回启动结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 201 | The application does not have permission to call the interface. |
| 202 | The application is not system-app, can not use system-api. |
| 401 | If the input parameter is not valid parameter. |
| 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.code) {
// 处理业务逻辑错误
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&lt;void&gt;;
启动Ability(promise形式)。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限
- 跨应用场景下,目标Ability的visible属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限
- 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**:该接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------------------- | ---- | ----------------------- |
| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise形式返回启动结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 201 | The application does not have permission to call the interface. |
| 202 | The application is not system-app, can not use system-api. |
| 401 | If the input parameter is not valid parameter. |
| 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));
}
```
\ No newline at end of file
......@@ -12,6 +12,14 @@ StaticSubscriberExtensionAbility模块提供静态订阅者ExtensionAbility的
import StaticSubscriberExtensionAbility from '@ohos.application.StaticSubscriberExtensionAbility';
```
## 属性
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.AbilityCore
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------- | ------------------------------------------------------------ | ---- | ---- | -------- |
| context | [StaticSubscriberExtensionContext](js-apis-application-StaticSubscriberExtensionContext.md) | 是 | 否 | 上下文。 |
## StaticSubscriberExtensionAbility.onReceiveEvent
onReceiveEvent(event: CommonEventData): void;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册