Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
bb338067
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
bb338067
编写于
5月 09, 2023
作者:
X
xinking129
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add docs about staticSubscriberExtensinContext
Signed-off-by:
N
xinking129
<
xinxin13@huawei.com
>
上级
e5c83149
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
173 addition
and
0 deletion
+173
-0
zh-cn/application-dev/reference/apis/js-apis-application-StaticSubscriberExtensionContext.md
...s/js-apis-application-StaticSubscriberExtensionContext.md
+165
-0
zh-cn/application-dev/reference/apis/js-apis-application-staticSubscriberExtensionAbility.md
...s/js-apis-application-staticSubscriberExtensionAbility.md
+8
-0
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-application-StaticSubscriberExtensionContext.md
0 → 100644
浏览文件 @
bb338067
# @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
<
void
>
): 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
<
void
>
| 是 | 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
<
void
>
;
启动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
<
void
>
| 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
zh-cn/application-dev/reference/apis/js-apis-application-staticSubscriberExtensionAbility.md
浏览文件 @
bb338067
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录