提交 d1ee8e93 编写于 作者: X xinking129

add doc

Signed-off-by: Nxinking129 <xinxin13@huawei.com>
上级 d318f2d3
......@@ -1353,4 +1353,79 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
// 处理入参错误异常
console.error('error.code: ${paramError.code}, error.message: ${paramError.message}');
}
```
\ No newline at end of file
```
## ServiceExtensionContext.startAbilityByCallWithAccount
startAbilityByCallWithAccount(want: Want, accountId: number): Promise&lt;Caller&gt;;
根据accountId对指定的Ability进行call调用,并且可以使用返回的Caller通信接口与被调用方进行通信。
使用规则:
- 跨用户场景下,Call调用目标Ability时,调用方应用需同时申请`ohos.permission.ABILITY_BACKGROUND_COMMUNICATION``ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS`权限
- 其他场景下,startAbilityByCallWithAccount接口使用规则与[startAbilityByCall使用规则一致](#serviceextensioncontextstartabilitybycall)
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | 是 | 传入需要启动的Ability的信息,包含abilityName、moduleName、bundleName、deviceId(可选)、parameters(可选),其中deviceId缺省或为空表示启动本地Ability,parameters缺省或为空表示后台启动Ability。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;Caller&gt; | 获取要通讯的caller对象。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | Crowdtest App Expiration. |
| 16000011 | The context does not exist. |
| 16000050 | Internal Error. |
| 16200001 | The caller has been released. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
let caller;
// 系统账号的账号ID, -1表示当前激活用户
let accountId = -1;
// 指定启动的Ability
let want = {
bundleName: 'com.acts.actscalleeabilityrely',
moduleName: 'entry',
abilityName: 'EntryAbility'
deviceId: ''
};
try {
this.context.startAbilityByCallWithAccount(want, accountId)
.then((obj) => {
// 执行正常业务
caller = obj;
console.log('startAbilityByCallWithAccount succeed');
}).catch((error) => {
// 处理业务逻辑错误
console.error('startAbilityByCallWithAccount failed, error.code: ${error.code}, error.message: ${error.message}');
});
} catch (paramError) {
// 处理入参错误异常
console.error('error.code: ${paramError.code}, error.message: ${paramError.message}');
}
```
......@@ -2291,3 +2291,80 @@ try {
console.error(`requestDialogService failed, code is ${err.code}, message is ${err.message}`);
}
```
##
## ServiceExtensionContext.startAbilityByCallWithAccount
startAbilityByCallWithAccount(want: Want, accountId: number): Promise&lt;Caller&gt;;
根据accountId对指定的Ability进行call调用,并且可以使用返回的Caller通信接口与被调用方进行通信。
使用规则:
- 跨用户场景下,Call调用目标Ability时,调用方应用需同时申请`ohos.permission.ABILITY_BACKGROUND_COMMUNICATION``ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS`权限
- 其他场景下,startAbilityByCallWithAccount接口使用规则与[startAbilityByCall使用规则一致](#uiabilitycontextstartabilitybycall)
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | 是 | 传入需要启动的Ability的信息,包含abilityName、moduleName、bundleName、deviceId(可选)、parameters(可选),其中deviceId缺省或为空表示启动本地Ability,parameters缺省或为空表示后台启动Ability。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;Caller&gt; | 获取要通讯的caller对象。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | Crowdtest App Expiration. |
| 16000011 | The context does not exist. |
| 16000050 | Internal Error. |
| 16200001 | The caller has been released. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
let caller;
// 系统账号的账号ID, -1表示当前激活用户
let accountId = -1;
// 指定启动的Ability
let want = {
bundleName: 'com.acts.actscalleeabilityrely',
moduleName: 'entry',
abilityName: 'EntryAbility'
deviceId: ''
};
try {
this.context.startAbilityByCallWithAccount(want, accountId)
.then((obj) => {
// 执行正常业务
caller = obj;
console.log('startAbilityByCallWithAccount succeed');
}).catch((error) => {
// 处理业务逻辑错误
console.error('startAbilityByCallWithAccount failed, error.code: ${error.code}, error.message: ${error.message}');
});
} catch (paramError) {
// 处理入参错误异常
console.error('error.code: ${paramError.code}, error.message: ${paramError.message}');
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册