Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
685f4ab1
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
685f4ab1
编写于
8月 01, 2023
作者:
O
openharmony_ci
提交者:
Gitee
8月 01, 2023
浏览文件
操作
浏览文件
下载
差异文件
!21192 新增startAbilityAsCaller接口
Merge pull request !21192 from donglin/caller
上级
52a64452
f37f4885
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
450 addition
and
0 deletion
+450
-0
zh-cn/application-dev/reference/apis/js-apis-inner-application-serviceExtensionContext.md
...apis/js-apis-inner-application-serviceExtensionContext.md
+228
-0
zh-cn/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md
...erence/apis/js-apis-inner-application-uiAbilityContext.md
+222
-0
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-inner-application-serviceExtensionContext.md
浏览文件 @
685f4ab1
...
...
@@ -734,6 +734,234 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
}
```
## ServiceExtensionContext.startAbilityAsCaller<sup>10+<sup>
starAbilityAsCaller(want: Want, callback: AsyncCallback
<void>
): void;
使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用callback异步回调。
使用规则:
-
调用方应用位于后台时,使用该接口启动Ability需申请
`ohos.permission.START_ABILITIES_FROM_BACKGROUND`
权限
-
跨应用场景下,目标Ability的exported属性若配置为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
>
| 是 | 回调函数。当启动Ability成功,err为undefined,否则为错误对象。 |
**错误码:**
| 错误码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
](
../errorcodes/errorcode-ability.md
)
**示例:**
```
ts
import
extension
from
'
@ohos.app.ability.ServiceExtensionAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
EntryAbility
extends
extension
{
onCreate
(
want
,
launchParam
)
{
// want包含启动该应用的Caller信息
let
localWant
:
Want
=
want
;
localWant
.
bundleName
=
'
com.example.demo
'
;
localWant
.
moduleName
=
'
entry
'
;
localWant
.
abilityName
=
'
TestAbility
'
;
// 使用启动方的Caller身份信息启动新Ability
this
.
context
.
startAbilityAsCaller
(
localWant
,
(
err
)
=>
{
if
(
err
&&
err
.
code
!=
0
)
{
console
.
error
(
'
startAbilityAsCaller failed, err:
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
'
startAbilityAsCaller success.
'
);
}
})
}
}
```
## UIAbiliServiceExtensionContexttyContext.startAbilityAsCaller<sup>10+<sup>
startAbilityAsCaller(want: Want, options: StartOptions, callback: AsyncCallback
<void>
): void;
使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用callback异步回调。
使用规则:
-
调用方应用位于后台时,使用该接口启动Ability需申请
`ohos.permission.START_ABILITIES_FROM_BACKGROUND`
权限
-
跨应用场景下,目标Ability的exported属性若配置为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信息。 |
| options |
[
StartOptions
](
js-apis-app-ability-startOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。当启动Ability成功,err为undefined,否则为错误对象。 |
**错误码:**
| 错误码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
](
../errorcodes/errorcode-ability.md
)
**示例:**
```
ts
import
extension
from
'
@ohos.app.ability.ServiceExtensionAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
EntryAbility
extends
extension
{
onCreate
(
want
,
launchParam
)
{
// want包含启动该应用的Caller信息
let
localWant
:
Want
=
want
;
localWant
.
bundleName
=
'
com.example.demo
'
;
localWant
.
moduleName
=
'
entry
'
;
localWant
.
abilityName
=
'
TestAbility
'
;
let
option
:
StartOptions
=
{
displayId
:
0
}
// 使用启动方的Caller身份信息启动新Ability
this
.
context
.
startAbilityAsCaller
(
localWant
,
option
,
(
err
)
=>
{
if
(
err
&&
err
.
code
!=
0
)
{
console
.
error
(
'
startAbilityAsCaller failed, err:
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
'
startAbilityAsCaller success.
'
);
}
})
}
}
```
## ServiceExtensionContext.startAbilityAsCaller<sup>10+<sup>
startAbilityAsCaller(want: Want, options?: StartOptions): Promise
<void>
;
使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用Promise异步回调。
使用规则:
-
调用方应用位于后台时,使用该接口启动Ability需申请
`ohos.permission.START_ABILITIES_FROM_BACKGROUND`
权限
-
跨应用场景下,目标Ability的exported属性若配置为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信息。 |
| options |
[
StartOptions
](
js-apis-app-ability-startOptions.md
)
| 是 | 启动Ability所携带的参数。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| Promise对象。无返回结果的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
](
../errorcodes/errorcode-ability.md
)
**示例:**
```
ts
import
extension
from
'
@ohos.app.ability.ServiceExtensionAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
EntryAbility
extends
extension
{
onCreate
(
want
,
launchParam
)
{
// want包含启动该应用的Caller信息
let
localWant
:
Want
=
want
;
localWant
.
bundleName
=
'
com.example.demo
'
;
localWant
.
moduleName
=
'
entry
'
;
localWant
.
abilityName
=
'
TestAbility
'
;
let
option
:
StartOptions
=
{
displayId
:
0
}
// 使用启动方的Caller身份信息启动新Ability
this
.
context
.
startAbilityAsCaller
(
localWant
,
option
)
.
then
(()
=>
{
console
.
log
(
'
startAbilityAsCaller success.
'
);
})
.
catch
((
err
)
=>
{
console
.
error
(
'
startAbilityAsCaller failed, err:
'
+
JSON
.
stringify
(
err
));
})
}
}
```
## ServiceExtensionContext.stopServiceExtensionAbility
stopServiceExtensionAbility(want: Want, callback: AsyncCallback
\<
void>): void;
...
...
zh-cn/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md
浏览文件 @
685f4ab1
...
...
@@ -2792,6 +2792,228 @@ startAbilityByCallWithAccount(want: Want, accountId: number): Promise<Caller&
}
```
## UIAbilityContext.startAbilityAsCaller<sup>10+<sup>
starAbilityAsCaller(want: Want, callback: AsyncCallback
<void>
): void;
使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用callback异步回调。
使用规则:
-
调用方应用位于后台时,使用该接口启动Ability需申请
`ohos.permission.START_ABILITIES_FROM_BACKGROUND`
权限
-
跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请
`ohos.permission.START_INVISIBLE_ABILITY`
权限
-
组件启动规则详见:
[
组件启动规则(Stage模型)
](
../../application-models/component-startup-rules.md
)
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want |
[
Want
](
js-apis-application-want.md
)
| 是 | 启动Ability的want信息。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。当启动Ability成功,err为undefined,否则为错误对象。 |
**错误码:**
| 错误码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
](
../errorcodes/errorcode-ability.md
)
**示例:**
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
EntryAbility
extends
UIAbility
{
onCreate
(
want
,
launchParam
)
{
// want包含启动该应用的Caller信息
let
localWant
:
Want
=
want
;
localWant
.
bundleName
=
'
com.example.demo
'
;
localWant
.
moduleName
=
'
entry
'
;
localWant
.
abilityName
=
'
TestAbility
'
;
// 使用启动方的Caller身份信息启动新Ability
this
.
context
.
startAbilityAsCaller
(
localWant
,
(
err
)
=>
{
if
(
err
&&
err
.
code
!=
0
)
{
console
.
error
(
'
startAbilityAsCaller failed, err:
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
'
startAbilityAsCaller success.
'
);
}
})
}
}
```
## UIAbilityContext.startAbilityAsCaller<sup>10+<sup>
startAbilityAsCaller(want: Want, options: StartOptions, callback: AsyncCallback
<void>
): void;
使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用callback异步回调。
使用规则:
-
调用方应用位于后台时,使用该接口启动Ability需申请
`ohos.permission.START_ABILITIES_FROM_BACKGROUND`
权限
-
跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请
`ohos.permission.START_INVISIBLE_ABILITY`
权限
-
组件启动规则详见:
[
组件启动规则(Stage模型)
](
../../application-models/component-startup-rules.md
)
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want |
[
Want
](
js-apis-application-want.md
)
| 是 | 启动Ability的want信息。 |
| options |
[
StartOptions
](
js-apis-app-ability-startOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。当启动Ability成功,err为undefined,否则为错误对象。 |
**错误码:**
| 错误码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
](
../errorcodes/errorcode-ability.md
)
**示例:**
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
EntryAbility
extends
UIAbility
{
onCreate
(
want
,
launchParam
)
{
// want包含启动该应用的Caller信息
let
localWant
:
Want
=
want
;
localWant
.
bundleName
=
'
com.example.demo
'
;
localWant
.
moduleName
=
'
entry
'
;
localWant
.
abilityName
=
'
TestAbility
'
;
let
option
:
StartOptions
=
{
displayId
:
0
}
// 使用启动方的Caller身份信息启动新Ability
this
.
context
.
startAbilityAsCaller
(
localWant
,
option
,
(
err
)
=>
{
if
(
err
&&
err
.
code
!=
0
)
{
console
.
error
(
'
startAbilityAsCaller failed, err:
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
'
startAbilityAsCaller success.
'
);
}
})
}
}
```
## UIAbilityContext.startAbilityAsCaller<sup>10+<sup>
startAbilityAsCaller(want: Want, options?: StartOptions): Promise
<void>
;
使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用Promise异步回调。
使用规则:
-
调用方应用位于后台时,使用该接口启动Ability需申请
`ohos.permission.START_ABILITIES_FROM_BACKGROUND`
权限
-
跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请
`ohos.permission.START_INVISIBLE_ABILITY`
权限
-
组件启动规则详见:
[
组件启动规则(Stage模型)
](
../../application-models/component-startup-rules.md
)
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want |
[
Want
](
js-apis-application-want.md
)
| 是 | 启动Ability的want信息。 |
| options |
[
StartOptions
](
js-apis-app-ability-startOptions.md
)
| 是 | 启动Ability所携带的参数。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| Promise对象。无返回结果的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
](
../errorcodes/errorcode-ability.md
)
**示例:**
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
EntryAbility
extends
UIAbility
{
onCreate
(
want
,
launchParam
)
{
// want包含启动该应用的Caller信息
let
localWant
:
Want
=
want
;
localWant
.
bundleName
=
'
com.example.demo
'
;
localWant
.
moduleName
=
'
entry
'
;
localWant
.
abilityName
=
'
TestAbility
'
;
let
option
:
StartOptions
=
{
displayId
:
0
}
// 使用启动方的Caller身份信息启动新Ability
this
.
context
.
startAbilityAsCaller
(
localWant
,
option
)
.
then
(()
=>
{
console
.
log
(
'
startAbilityAsCaller success.
'
);
})
.
catch
((
err
)
=>
{
console
.
error
(
'
startAbilityAsCaller failed, err:
'
+
JSON
.
stringify
(
err
));
})
}
}
```
## UIAbilityContext.reportDrawnCompleted<sup>10+</sup>
reportDrawnCompleted(callback: AsyncCallback
\<
void>): void;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录