Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
74984930
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
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看板
提交
74984930
编写于
10月 22, 2022
作者:
H
HuangXW
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Context错误码整改
Signed-off-by:
N
HuangXW
<
huangxinwei4@huawei.com
>
上级
0e327401
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
2001 addition
and
414 deletion
+2001
-414
zh-cn/application-dev/ability/stage-call.md
zh-cn/application-dev/ability/stage-call.md
+5
-5
zh-cn/application-dev/reference/apis/js-apis-ability-context.md
...application-dev/reference/apis/js-apis-ability-context.md
+993
-143
zh-cn/application-dev/reference/apis/js-apis-application-ability.md
...ication-dev/reference/apis/js-apis-application-ability.md
+216
-137
zh-cn/application-dev/reference/apis/js-apis-extension-context.md
...plication-dev/reference/apis/js-apis-extension-context.md
+2
-2
zh-cn/application-dev/reference/apis/js-apis-service-extension-context.md
...n-dev/reference/apis/js-apis-service-extension-context.md
+785
-127
未找到文件。
zh-cn/application-dev/ability/stage-call.md
浏览文件 @
74984930
...
...
@@ -40,7 +40,7 @@ Caller及Callee功能如下:具体的API详见[接口文档](../reference/apis
|call(method: string, data: rpc.Sequenceable): Promise
\<
void>|向通用组件Callee发送约定序列化数据。|
|callWithResult(method: string, data: rpc.Sequenceable): Promise
\<
rpc.MessageParcel>|向通用组件Callee发送约定序列化数据, 并将Callee返回的约定序列化数据带回。|
|release(): void|释放通用组件的Caller通信接口。|
|on
Release(callback: OnReleaseCallB
ack): void|注册通用组件通信断开监听通知。|
|on
(type: "release", callback: OnReleaseCallb
ack): void|注册通用组件通信断开监听通知。|
## 开发步骤
Call调用的开发步骤:
...
...
@@ -72,7 +72,7 @@ Ability配置标签示例如下:
```
**2. 导入Ability模块**
```
ts
import
Ability
from
'
@ohos.app
lication
.Ability
'
import
Ability
from
'
@ohos.app
.ability
.Ability
'
```
**3. 定义约定的序列化数据**
...
...
@@ -142,7 +142,7 @@ export default class CalleeAbility extends Ability {
### 访问Callee被调用端
**1. 导入Ability模块**
```
ts
import
Ability
from
'
@ohos.app
lication
.Ability
'
import
Ability
from
'
@ohos.app
.ability
.Ability
'
```
**2. 获取Caller通信接口**
...
...
@@ -151,7 +151,7 @@ import Ability from '@ohos.application.Ability'
// 注册caller的release监听
private
regOnRelease
(
caller
)
{
try
{
caller
.
on
Release
(
(
msg
)
=>
{
caller
.
on
(
"
release
"
,
(
msg
)
=>
{
console
.
log
(
`caller onRelease is called
${
msg
}
`
)
})
console
.
log
(
'
caller register OnRelease succeed
'
)
...
...
@@ -192,7 +192,7 @@ async onButtonGetRemoteCaller() {
caller
=
data
console
.
log
(
'
get remote caller success
'
)
// 注册caller的release监听
caller
.
on
Release
(
(
msg
)
=>
{
caller
.
on
(
"
release
"
,
(
msg
)
=>
{
console
.
log
(
`remote caller onRelease is called
${
msg
}
`
)
})
console
.
log
(
'
remote caller register OnRelease succeed
'
)
...
...
zh-cn/application-dev/reference/apis/js-apis-ability-context.md
浏览文件 @
74984930
...
...
@@ -14,10 +14,12 @@ AbilityContext模块提供允许访问特定Ability的资源的能力,包括
在使用AbilityContext的功能前,需要通过Ability子类实例获取。
```
js
import
Ability
from
'
@ohos.application.Ability
'
;
import
Ability
from
'
@ohos.app.ability.Ability
'
;
let
context
=
undefined
;
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
let
context
=
this
.
context
;
context
=
this
.
context
;
}
}
```
...
...
@@ -47,17 +49,56 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| callback | AsyncCallback
<
void
>
| 是 | callback形式返回启动结果 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
var
want
=
{
"
deviceId
"
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
"
bundleName
"
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
MyAbility
"
};
try
{
this
.
context
.
startAbility
(
want
,
(
error
)
=>
{
console
.
log
(
"
error.code =
"
+
error
.
code
)
})
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
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
...
...
@@ -77,6 +118,32 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
<
void
>
| 是 | callback形式返回启动结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -86,14 +153,27 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
"
abilityName
"
:
"
MainAbility
"
};
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
try
{
this
.
context
.
startAbility
(
want
,
options
,
(
error
)
=>
{
console
.
log
(
"
error.code =
"
+
error
.
code
)
})
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
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.startAbility
startAbility(want: Want, options?: StartOptions): Promise
<
void
>
;
...
...
@@ -115,23 +195,59 @@ startAbility(want: Want, options?: StartOptions): Promise<void>;
| -------- | -------- |
| Promise
<
void
>
| Promise形式返回启动结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
var
want
=
{
"
deviceId
"
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
"
bundleName
"
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
MyAbility
"
};
var
options
=
{
windowMode
:
0
,
};
try
{
this
.
context
.
startAbility
(
want
,
options
)
.
then
(()
=>
{
console
.
log
(
'
Operation successful.
'
)
}).
catch
((
error
)
=>
{
console
.
log
(
'
Operation failed.
'
);
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
startAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbility failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
...
...
@@ -150,17 +266,58 @@ startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>):
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| callback | AsyncCallback
<
[AbilityResult](js-apis-featureAbility.md#abilityresult)
>
| 是 | 执行结果回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
this
.
context
.
startAbilityForResult
(
{
deviceId
:
""
,
bundleName
:
"
com.extreme.myapplication
"
,
abilityName
:
"
MainAbilityDemo2
"
},
(
error
,
result
)
=>
{
console
.
log
(
"
startAbilityForResult AsyncCallback is called, error.code =
"
+
error
.
code
)
console
.
log
(
"
startAbilityForResult AsyncCallback is called, result.resultCode =
"
+
result
.
resultCode
)
var
want
=
{
"
deviceId
"
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
};
try
{
this
.
context
.
startAbilityForResult
(
want
,
(
error
,
result
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityForResult failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
"
startAbilityForResult succeed, result.resultCode =
"
+
result
.
resultCode
)
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
);
```
## AbilityContext.startAbilityForResult
...
...
@@ -179,20 +336,61 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
<
[AbilityResult](js-apis-featureAbility.md#abilityresult)
>
| 是 | 执行结果回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
var
want
=
{
"
deviceId
"
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
};
var
options
=
{
windowMode
:
0
,
};
this
.
context
.
startAbilityForResult
(
{
deviceId
:
""
,
bundleName
:
"
com.extreme.myapplication
"
,
abilityName
:
"
MainAbilityDemo2
"
},
options
,
(
error
,
result
)
=>
{
console
.
log
(
"
startAbilityForResult AsyncCallback is called, error.code =
"
+
error
.
code
)
console
.
log
(
"
startAbilityForResult AsyncCallback is called, result.resultCode =
"
+
result
.
resultCode
)
try
{
this
.
context
.
startAbilityForResult
(
want
,
options
,
(
error
,
result
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityForResult failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
"
startAbilityForResult succeed, result.resultCode =
"
+
result
.
resultCode
)
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
);
```
...
...
@@ -218,17 +416,59 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityRes
| -------- | -------- |
| Promise
<
[AbilityResult](js-apis-featureAbility.md#abilityresult)
>
| Promise形式返回执行结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
var
want
=
{
"
bundleName
"
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
MyAbility
"
};
var
options
=
{
windowMode
:
0
,
};
this
.
context
.
startAbilityForResult
({
deviceId
:
""
,
bundleName
:
"
com.extreme.myapplication
"
,
abilityName
:
"
MainAbilityDemo2
"
},
options
).
then
((
result
)
=>
{
console
.
log
(
"
startAbilityForResult Promise.resolve is called, result.resultCode =
"
+
result
.
resultCode
)
},
(
error
)
=>
{
console
.
log
(
"
startAbilityForResult Promise.Reject is called, error.code =
"
+
error
.
code
)
try
{
this
.
context
.
startAbilityForResult
(
want
,
options
)
.
then
((
result
)
=>
{
// 执行正常业务
console
.
log
(
"
startAbilityForResult succeed, result.resultCode =
"
+
result
.
resultCode
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityForResult failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.startAbilityForResultWithAccount
...
...
@@ -251,6 +491,33 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
AbilityResult
\>
| 是 | 启动Ability的回调函数,返回Ability结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -260,10 +527,24 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
"
abilityName
"
:
"
MainAbility
"
};
var
accountId
=
100
;
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
(
err
,
data
)
=>
{
console
.
log
(
'
---------- startAbilityWithAccount fail, err: -----------
'
,
err
);
console
.
log
(
'
---------- startAbilityWithAccount success, data: -----------
'
,
data
);
try
{
this
.
context
.
startAbilityForResultWithAccount
(
want
,
accountId
,
(
error
,
result
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityForResultWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
"
startAbilityForResultWithAccount succeed, result.resultCode =
"
+
result
.
resultCode
)
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
...
...
@@ -288,6 +569,33 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -298,11 +606,26 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
};
var
accountId
=
100
;
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
this
.
context
.
startAbilityForResultWithAccount
(
want
,
accountId
,
options
,
(
err
)
=>
{
console
.
log
(
'
---------- startAbilityForResultWithAccount fail, err: -----------
'
,
err
);
try
{
this
.
context
.
startAbilityForResultWithAccount
(
want
,
accountId
,
options
,
(
error
,
result
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityForResultWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
"
startAbilityForResultWithAccount succeed, result.resultCode =
"
+
result
.
resultCode
)
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
...
...
@@ -332,6 +655,33 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
| -------- | -------- |
| Promise
<
AbilityResult
>
| 返回一个Promise,包含Ability结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -342,15 +692,26 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
};
var
accountId
=
100
;
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
try
{
this
.
context
.
startAbilityForResultWithAccount
(
want
,
accountId
,
options
)
.
then
((
data
)
=>
{
console
.
log
(
'
---------- startAbilityForResultWithAccount success, data: -----------
'
,
data
);
})
.
catch
((
err
)
=>
{
console
.
log
(
'
---------- startAbilityForResultWithAccount fail, err: -----------
'
,
err
);
.
then
((
result
)
=>
{
// 执行正常业务
console
.
log
(
"
startAbilityForResultWithAccount succeed, result.resultCode =
"
+
result
.
resultCode
)
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityForResultWithAccount failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.startServiceExtensionAbility
...
...
@@ -369,6 +730,25 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -377,9 +757,23 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
};
this
.
context
.
startServiceExtensionAbility
(
want
,
(
err
)
=>
{
console
.
log
(
'
---------- startServiceExtensionAbility fail, err: -----------
'
,
err
);
try
{
this
.
context
.
startServiceExtensionAbility
(
want
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
startServiceExtensionAbility succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.startServiceExtensionAbility
...
...
@@ -398,6 +792,25 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
| -------- | -------- | -------- | -------- |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -406,14 +819,25 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
};
try
{
this
.
context
.
startServiceExtensionAbility
(
want
)
.
then
(()
=>
{
console
.
log
(
'
---------- startServiceExtensionAbility success -----------
'
);
})
.
catch
((
err
)
=>
{
console
.
log
(
'
---------- startServiceExtensionAbility fail, err: -----------
'
,
err
);
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
startServiceExtensionAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.startServiceExtensionAbilityWithAccount
startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback
\<
void>): void;
...
...
@@ -434,6 +858,22 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -443,9 +883,23 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
"
abilityName
"
:
"
MainAbility
"
};
var
accountId
=
100
;
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
,
(
err
)
=>
{
console
.
log
(
'
---------- startServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
try
{
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
startServiceExtensionAbilityWithAccount succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.startServiceExtensionAbilityWithAccount
...
...
@@ -467,6 +921,26 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -476,13 +950,23 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
"
abilityName
"
:
"
MainAbility
"
};
var
accountId
=
100
;
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
(()
=>
{
console
.
log
(
'
---------- startServiceExtensionAbilityWithAccount success -----------
'
);
})
.
catch
((
err
)
=>
{
console
.
log
(
'
---------- startServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
try
{
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
startServiceExtensionAbilityWithAccount succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.stopServiceExtensionAbility
...
...
@@ -501,6 +985,22 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -509,9 +1009,23 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
};
this
.
context
.
stopServiceExtensionAbility
(
want
,
(
err
)
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbility fail, err: -----------
'
,
err
);
try
{
this
.
context
.
stopServiceExtensionAbility
(
want
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
stopServiceExtensionAbility succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.stopServiceExtensionAbility
...
...
@@ -530,6 +1044,22 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
| -------- | -------- | -------- | -------- |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -538,13 +1068,23 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
};
try
{
this
.
context
.
stopServiceExtensionAbility
(
want
)
.
then
(()
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbility success -----------
'
);
})
.
catch
((
err
)
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbility fail, err: -----------
'
,
err
);
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
stopServiceExtensionAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.stopServiceExtensionAbilityWithAccount
...
...
@@ -567,6 +1107,23 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -576,9 +1133,23 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
"
abilityName
"
:
"
MainAbility
"
};
var
accountId
=
100
;
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
,
(
err
)
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
try
{
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
stopServiceExtensionAbilityWithAccount succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.stopServiceExtensionAbilityWithAccount
...
...
@@ -600,6 +1171,23 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -609,13 +1197,23 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
"
abilityName
"
:
"
MainAbility
"
};
var
accountId
=
100
;
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
(()
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbilityWithAccount success -----------
'
);
})
.
catch
((
err
)
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
try
{
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
stopServiceExtensionAbilityWithAccount succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.terminateSelf
...
...
@@ -632,11 +1230,31 @@ terminateSelf(callback: AsyncCallback<void>): void;
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,返回接口调用是否成功的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
this
.
context
.
terminateSelf
((
err
)
=>
{
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringify
(
err
));
this
.
context
.
terminateSelf
((
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
terminateSelf failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
terminateSelf succeed
'
);
});
```
...
...
@@ -655,13 +1273,29 @@ terminateSelf(): Promise<void>;
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
this
.
context
.
terminateSelf
().
then
(()
=>
{
console
.
log
(
'
success
'
);
this
.
context
.
terminateSelf
().
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
terminateSelf succeed
'
);
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
// 处理业务逻辑错误
console
.
log
(
'
terminateSelf failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
```
...
...
@@ -740,9 +1374,9 @@ terminateSelfWithResult(parameter: AbilityResult): Promise<void>;
)
```
## AbilityContext.connectAbility
## AbilityContext.connect
ServiceExtension
Ability
connectAbility(want: Want, options: ConnectOptions): number;
connect
ServiceExtension
Ability(want: Want, options: ConnectOptions): number;
使用AbilityInfo.AbilityType.SERVICE模板将当前Ability连接到一个Ability。
...
...
@@ -763,6 +1397,20 @@ connectAbility(want: Want, options: ConnectOptions): number;
| -------- | -------- |
| number | 返回Ability连接的结果code。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -776,14 +1424,21 @@ connectAbility(want: Want, options: ConnectOptions): number;
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onFailed
(
code
)
{
console
.
log
(
'
----------- onFailed -----------
'
)
}
}
const
result
=
this
.
context
.
connectAbility
(
want
,
options
);
console
.
log
(
'
----------- connectAbilityResult: ------------
'
,
result
);
var
connection
=
null
;
try
{
connection
=
this
.
context
.
connectServiceExtensionAbility
(
want
,
options
);
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.connectAbilityWithAccount
## AbilityContext.connect
ServiceExtension
AbilityWithAccount
connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number;
connect
ServiceExtension
AbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number;
使用AbilityInfo.AbilityType.SERVICE模板和account将当前Ability连接到一个Ability。
...
...
@@ -807,6 +1462,21 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
| -------- | -------- |
| number | 返回Ability连接的结果code。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000006 | Can not cross user operations. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -821,13 +1491,20 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onFailed
(
code
)
{
console
.
log
(
'
----------- onFailed -----------
'
)
}
}
const
result
=
this
.
context
.
connectAbilityWithAccount
(
want
,
accountId
,
options
);
console
.
log
(
'
----------- connectAbilityResult: ------------
'
,
result
);
var
connection
=
null
;
try
{
connection
=
this
.
context
.
connectServiceExtensionAbilityWithAccount
(
want
,
accountId
,
options
);
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.disconnectAbility
## AbilityContext.disconnect
ServiceExtension
Ability
disconnectAbility(connection: number): Promise
\<
void>;
disconnect
ServiceExtension
Ability(connection: number): Promise
\<
void>;
断开连接(promise形式)。
...
...
@@ -847,20 +1524,46 @@ disconnectAbility(connection: number): Promise\<void>;
| -------- | -------- |
| Promise
\<
void> | 返回执行结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000003 | Input error. The specified id does not exist. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
var
connectionNumber
=
0
;
this
.
context
.
disconnectAbility
(
connectionNumber
).
then
(()
=>
{
console
.
log
(
'
disconnectAbility success
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
disconnectAbility fail, err:
'
,
err
);
// connection为connectAbility中的返回值
var
connection
=
1
;
try
{
this
.
context
.
disconnectServiceExtensionAbility
(
connection
)
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
disconnectServiceExtensionAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
disconnectServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.disconnectAbility
## AbilityContext.disconnect
ServiceExtension
Ability
disconnectAbility(connection: number, callback:AsyncCallback
\<
void>): void;
disconnect
ServiceExtension
Ability(connection: number, callback:AsyncCallback
\<
void>): void;
断开连接(callback形式)。
...
...
@@ -875,13 +1578,41 @@ disconnectAbility(connection: number, callback:AsyncCallback\<void>): void;
| connection | number | 是 | 连接的Ability的数字代码。 |
| callback | AsyncCallback
\<
void> | 是 | 表示指定的回调方法。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000003 | Input error. The specified id does not exist. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
var
connectionNumber
=
0
;
this
.
context
.
disconnectAbility
(
connectionNumber
,
(
err
)
=>
{
console
.
log
(
'
---------- disconnectAbility fail, err: -----------
'
,
err
);
// connection为connectServiceExtensionAbility中的返回值
var
connection
=
1
;
try
{
this
.
context
.
disconnectServiceExtensionAbility
(
connection
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
disconnectServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
disconnectServiceExtensionAbility succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.startAbilityByCall
...
...
@@ -907,7 +1638,7 @@ startAbilityByCall(want: Want): Promise<Caller>;
**示例:**
```
js
let
caller
=
undefined
;
var
caller
=
undefined
;
// 后台启动Ability,不配置parameters
var
wantBackground
=
{
...
...
@@ -963,6 +1694,33 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -972,9 +1730,23 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
"
abilityName
"
:
"
MainAbility
"
};
var
accountId
=
100
;
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
(
err
)
=>
{
console
.
log
(
'
---------- startAbilityWithAccount fail, err: -----------
'
,
err
);
try
{
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
startAbilityWithAccount succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
...
...
@@ -999,6 +1771,33 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 否 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -1009,11 +1808,25 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
};
var
accountId
=
100
;
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
options
,
(
err
)
=>
{
console
.
log
(
'
---------- startAbilityWithAccount fail, err: -----------
'
,
err
);
try
{
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
options
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
startAbilityWithAccount succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
...
...
@@ -1037,6 +1850,33 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 否 | 启动Ability所携带的参数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -1047,15 +1887,25 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
};
var
accountId
=
100
;
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
try
{
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
options
)
.
then
(()
=>
{
console
.
log
(
'
---------- startAbilityWithAccount success -----------
'
);
})
.
catch
((
err
)
=>
{
console
.
log
(
'
---------- startAbilityWithAccount fail, err: -----------
'
,
err
);
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
startAbilityWithAccount succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## AbilityContext.requestPermissionsFromUser
...
...
zh-cn/application-dev/reference/apis/js-apis-application-ability.md
浏览文件 @
74984930
...
...
@@ -320,7 +320,6 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
通用组件Caller通信客户端调用接口, 用来向通用组件服务端发送约定数据。
## Caller.call
call(method: string, data: rpc.Sequenceable): Promise
<
void
>
;
...
...
@@ -342,10 +341,22 @@ call(method: string, data: rpc.Sequenceable): Promise<void>;
| -------- | -------- |
| Promise
<
void
>
| Promise形式返回应答。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
class
MyMessageAble
{
// 自定义的Sequenceable数据结构
name
:
""
str
:
""
...
...
@@ -381,15 +392,16 @@ call(method: string, data: rpc.Sequenceable): Promise<void>;
caller
.
call
(
method
,
msg
)
.
then
(()
=>
{
console
.
log
(
'
Caller call() called
'
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller call() catch error
'
+
e
);
})
.
catch
((
callErr
)
=>
{
console
.
log
(
'
Caller.call catch error, error.code:
'
+
JSON
.
stringify
(
callErr
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
callErr
.
message
));
});
console
.
log
(
'
Caller GetCaller Get
'
+
caller
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller GetCaller error
'
+
e
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
Caller GetCaller error, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
)
);
});
}
}
```
...
...
@@ -415,10 +427,22 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise<rpc.MessagePa
| -------- | -------- |
| Promise
<
rpc.MessageParcel
>
| Promise形式返回通用组件服务端应答数据。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
class
MyMessageAble
{
name
:
""
str
:
""
...
...
@@ -456,12 +480,14 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise<rpc.MessagePa
console
.
log
(
'
Caller callWithResult() called
'
);
let
retmsg
=
new
MyMessageAble
(
0
,
""
);
data
.
readSequenceable
(
retmsg
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller callWithResult() catch error
'
+
e
);
})
.
catch
((
callErr
)
=>
{
console
.
log
(
'
Caller.callWithResult catch error, error.code:
'
+
JSON
.
stringify
(
callErr
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
callErr
.
message
));
});
console
.
log
(
'
Caller GetCaller Get
'
+
caller
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller GetCaller error
'
+
e
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
Caller GetCaller error, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
)
);
});
}
}
...
...
@@ -476,10 +502,21 @@ release(): void;
**系统能力**
:SystemCapability.Ability.AbilityRuntime.AbilityCore
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
var
caller
;
export
default
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
...
...
@@ -491,21 +528,22 @@ release(): void;
caller
=
obj
;
try
{
caller
.
release
();
}
catch
(
e
)
{
console
.
log
(
'
Caller Release error
'
+
e
);
}
catch
(
releaseErr
)
{
console
.
log
(
'
Caller.release catch error, error.code:
'
+
JSON
.
stringify
(
releaseErr
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
releaseErr
.
message
));
}
console
.
log
(
'
Caller GetCaller Get
'
+
caller
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller GetCaller error
'
+
e
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
Caller GetCaller error, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
)
);
});
}
}
```
## Caller.on
Release
## Caller.on
onRelease(callback: OnReleaseCallB
ack): void;
on(type: "release", callback: OnReleaseCallb
ack): void;
注册通用组件服务端Stub(桩)断开监听通知。
...
...
@@ -515,12 +553,23 @@ onRelease(callback: OnReleaseCallBack): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 监听releaseCall事件,固定为'release'。 |
| callback | OnReleaseCallBack | 是 | 返回onRelease回调结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
var
caller
;
export
default
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
...
...
@@ -531,15 +580,16 @@ onRelease(callback: OnReleaseCallBack): void;
}).
then
((
obj
)
=>
{
caller
=
obj
;
try
{
caller
.
onRelease
(
(
str
)
=>
{
caller
.
on
(
"
release
"
,
(
str
)
=>
{
console
.
log
(
'
Caller OnRelease CallBack is called
'
+
str
);
});
}
catch
(
e
)
{
console
.
log
(
'
Caller Release error
'
+
e
);
}
catch
(
error
)
{
console
.
log
(
'
Caller.on catch error, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
}
console
.
log
(
'
Caller GetCaller Get
'
+
caller
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller GetCaller error
'
+
e
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
Caller GetCaller error, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
)
);
});
}
}
...
...
@@ -550,7 +600,6 @@ onRelease(callback: OnReleaseCallBack): void;
通用组件服务端注册和解除客户端caller通知送信的callback接口。
## Callee.on
on(method: string, callback: CalleeCallBack): void;
...
...
@@ -566,10 +615,20 @@ on(method: string, callback: CalleeCallBack): void;
| method | string | 是 | 与客户端约定的通知消息字符串。 |
| callback | CalleeCallBack | 是 | 一个rpc.MessageParcel类型入参的js通知同步回调函数,
回调函数至少要返回一个空的rpc.Sequenceable数据对象,
其他视为函数执行错误。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200004 | Method registered. The method has registered. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
class
MyMessageAble
{
name
:
""
str
:
""
...
...
@@ -601,12 +660,16 @@ on(method: string, callback: CalleeCallBack): void;
export
default
class
MainAbility
extends
Ability
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
Callee onCreate is called
'
);
try
{
this
.
callee
.
on
(
method
,
funcCallBack
);
}
catch
(
error
)
{
console
.
log
(
'
Callee.on catch error, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
}
}
}
```
## Callee.off
off(method: string): void;
...
...
@@ -621,20 +684,36 @@ off(method: string): void;
| -------- | -------- | -------- | -------- |
| method | string | 是 | 已注册的通知事件字符串。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200005 | Method not registered. The method has not registered. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
var
method
=
'
call_Function
'
;
export
default
class
MainAbility
extends
Ability
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
Callee onCreate is called
'
);
try
{
this
.
callee
.
off
(
method
);
}
catch
(
error
)
{
console
.
log
(
'
Callee.off catch error, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
}
}
}
```
## OnReleaseCall
B
ack
## OnReleaseCall
b
ack
(msg: string): void;
...
...
@@ -644,7 +723,7 @@ off(method: string): void;
| -------- | -------- | -------- | -------- | -------- |
| (msg: string) | function | 是 | 否 | 调用者注册的侦听器函数接口的原型。 |
## CalleeCall
B
ack
## CalleeCall
b
ack
(indata: rpc.MessageParcel): rpc.Sequenceable;
...
...
zh-cn/application-dev/reference/apis/js-apis-extension-context.md
浏览文件 @
74984930
...
...
@@ -31,7 +31,7 @@ ExtensionContext主要用于查询所属Extension的信息、Module的配置信
三个Module内都定义一个相同名称的ServiceExtension:
```
js
import
ServiceExtension
from
'
@ohos.app
lication
.ServiceExtensionAbility
'
import
ServiceExtension
from
'
@ohos.app
.ability
.ServiceExtensionAbility
'
import
Want
from
'
@ohos.application.Want
'
export
default
class
TheServiceExtension
extends
ServiceExtension
{
onCreate
(
want
:
Want
)
{
...
...
@@ -61,7 +61,7 @@ export default class TheServiceExtension extends ServiceExtension {
在entry的MainAbility的onCreate回调内启动ServiceExtension
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
import
Ability
from
'
@ohos.app
.ability
.Ability
'
export
default
class
MainAbility
extends
Ability
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
"
[Demo] MainAbility onCreate
"
);
...
...
zh-cn/application-dev/reference/apis/js-apis-service-extension-context.md
浏览文件 @
74984930
...
...
@@ -14,15 +14,17 @@ ServiceExtensionContext模块提供ServiceExtensionAbility具有的能力和接
在使用ServiceExtensionContext的功能前,需要通过ServiceExtensionAbility子类实例获取。
```
js
import
ServiceExtensionAbility
from
'
@ohos.application.ServiceExtensionAbility
'
;
import
ServiceExtensionAbility
from
'
@ohos.app.ability.ServiceExtensionAbility
'
;
let
context
=
undefined
;
class
MainAbility
extends
ServiceExtensionAbility
{
onCreate
()
{
let
context
=
this
.
context
;
context
=
this
.
context
;
}
}
```
## startAbility
##
ServiceExtensionContext.
startAbility
startAbility(want: Want, callback: AsyncCallback
<
void
>
): void;
...
...
@@ -39,18 +41,59 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | Want类型参数,传入需要启动的ability的信息,如ability名称,包名等。 |
| callback | AsyncCallback
<
void
>
| 否 | 回调函数,返回接口调用是否成功的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
let
want
=
{
var
want
=
{
"
bundleName
"
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
MyAbility
"
};
this
.
context
.
startAbility
(
want
,
(
err
)
=>
{
console
.
log
(
'
startAbility result:
'
+
JSON
.
stringify
(
err
));
"
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
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## startAbility
##
ServiceExtensionContext.
startAbility
startAbility(want: Want, options?: StartOptions): Promise
\<
void>;
...
...
@@ -73,22 +116,62 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>;
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
let
want
=
{
var
want
=
{
"
bundleName
"
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
MyAbility
"
};
this
.
context
.
startAbility
(
want
).
then
((
data
)
=>
{
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
});
var
options
=
{
windowMode
:
0
,
};
try
{
this
.
context
.
startAbility
(
want
,
options
)
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
startAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbility failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## startAbility
##
ServiceExtensionContext.
startAbility
startAbility(want: Want, options: StartOptions, callback: AsyncCallback
<
void
>
): void
...
...
@@ -106,6 +189,32 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
<
void
>
| 是 | callback形式返回启动结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -115,11 +224,25 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
"
abilityName
"
:
"
MainAbility
"
};
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
try
{
this
.
context
.
startAbility
(
want
,
options
,
(
error
)
=>
{
console
.
log
(
"
error.code =
"
+
error
.
code
)
})
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
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.startAbilityWithAccount
...
...
@@ -140,6 +263,33 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -149,12 +299,25 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
"
abilityName
"
:
"
MainAbility
"
};
var
accountId
=
100
;
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
(
err
)
=>
{
console
.
log
(
'
---------- startAbilityWithAccount fail, err: -----------
'
,
err
);
try
{
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
startAbilityWithAccount succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.startAbilityWithAccount
startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback
\<
void
\>
): void;
...
...
@@ -174,6 +337,33 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 否 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -184,11 +374,25 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
};
var
accountId
=
100
;
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
options
,
(
err
)
=>
{
console
.
log
(
'
---------- startAbilityWithAccount fail, err: -----------
'
,
err
);
try
{
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
options
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
startAbilityWithAccount succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
...
...
@@ -216,6 +420,33 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000010 | Can not operation with continue flag. |
| 16000011 | Context does not exist. |
| 16000051 | Network error. The network is abnormal. |
| 16000052 | Free install not support. The application does not support freeinstall |
| 16000053 | Not top ability. The application is not top ability. |
| 16000054 | Free install busyness. There are concurrent tasks, waiting for retry. |
| 16000055 | Free install timeout. |
| 16000056 | Can not free install other ability. |
| 16000057 | Not support cross device free install. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -226,15 +457,25 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
};
var
accountId
=
100
;
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
try
{
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
options
)
.
then
((
data
)
=>
{
console
.
log
(
'
---------- startAbilityWithAccount success, data: -----------
'
,
data
);
})
.
catch
((
err
)
=>
{
console
.
log
(
'
---------- startAbilityWithAccount fail, err: -----------
'
,
err
);
// 执行正常业务
console
.
log
(
'
startAbilityWithAccount succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.startServiceExtensionAbility
...
...
@@ -254,6 +495,25 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -262,9 +522,23 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
};
this
.
context
.
startServiceExtensionAbility
(
want
,
(
err
)
=>
{
console
.
log
(
'
---------- startServiceExtensionAbility fail, err: -----------
'
,
err
);
try
{
this
.
context
.
startServiceExtensionAbility
(
want
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
startServiceExtensionAbility succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.startServiceExtensionAbility
...
...
@@ -289,6 +563,25 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -297,13 +590,23 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
};
try
{
this
.
context
.
startServiceExtensionAbility
(
want
)
.
then
((
data
)
=>
{
console
.
log
(
'
---------- startServiceExtensionAbility success, data: -----------
'
,
data
);
})
.
catch
((
err
)
=>
{
console
.
log
(
'
---------- startServiceExtensionAbility fail, err: -----------
'
,
err
);
// 执行正常业务
console
.
log
(
'
startServiceExtensionAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.startServiceExtensionAbilityWithAccount
...
...
@@ -326,6 +629,27 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -335,9 +659,23 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
"
abilityName
"
:
"
MainAbility
"
};
var
accountId
=
100
;
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
,
(
err
)
=>
{
console
.
log
(
'
---------- startServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
try
{
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
startServiceExtensionAbilityWithAccount succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.startServiceExtensionAbilityWithAccount
...
...
@@ -365,6 +703,26 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -374,13 +732,23 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
"
abilityName
"
:
"
MainAbility
"
};
var
accountId
=
100
;
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
)
try
{
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
((
data
)
=>
{
console
.
log
(
'
---------- startServiceExtensionAbilityWithAccount success, data: -----------
'
,
data
);
})
.
catch
((
err
)
=>
{
console
.
log
(
'
---------- startServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
// 执行正常业务
console
.
log
(
'
startServiceExtensionAbilityWithAccount succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.stopServiceExtensionAbility
...
...
@@ -400,6 +768,22 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 停止Ability的want信息。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 停止Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -408,9 +792,23 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
};
this
.
context
.
stopServiceExtensionAbility
(
want
,
(
err
)
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbility fail, err: -----------
'
,
err
);
try
{
this
.
context
.
stopServiceExtensionAbility
(
want
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
stopServiceExtensionAbility succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.stopServiceExtensionAbility
...
...
@@ -435,6 +833,22 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -443,13 +857,23 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
"
bundleName
"
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
};
try
{
this
.
context
.
stopServiceExtensionAbility
(
want
)
.
then
((
data
)
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbility success, data: -----------
'
,
data
);
})
.
catch
((
err
)
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbility fail, err: -----------
'
,
err
);
// 执行正常业务
console
.
log
(
'
stopServiceExtensionAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.stopServiceExtensionAbilityWithAccount
...
...
@@ -472,6 +896,23 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
| accountId | number | 是 | 需要停止的系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 停止Ability的回调函数。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -481,9 +922,23 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
"
abilityName
"
:
"
MainAbility
"
};
var
accountId
=
100
;
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
,
(
err
)
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
try
{
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
stopServiceExtensionAbilityWithAccount succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.stopServiceExtensionAbilityWithAccount
...
...
@@ -511,6 +966,23 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000006 | Can not cross user operations. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -520,13 +992,23 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
"
abilityName
"
:
"
MainAbility
"
};
var
accountId
=
100
;
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
)
try
{
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
((
data
)
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbilityWithAccount success, data: -----------
'
,
data
);
})
.
catch
((
err
)
=>
{
console
.
log
(
'
---------- stopServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
// 执行正常业务
console
.
log
(
'
stopServiceExtensionAbilityWithAccount succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.terminateSelf
...
...
@@ -545,11 +1027,31 @@ terminateSelf(callback: AsyncCallback<void>): void;
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
void
>
| 否 | 回调函数,返回接口调用是否成功的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
this
.
context
.
terminateSelf
((
err
)
=>
{
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringify
(
err
));
this
.
context
.
terminateSelf
((
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
terminateSelf failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
terminateSelf succeed
'
);
});
```
...
...
@@ -569,19 +1071,35 @@ terminateSelf(): Promise<void>;
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
this
.
context
.
terminateSelf
().
then
((
data
)
=>
{
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
// 执行正常业务
console
.
log
(
'
terminateSelf succeed
'
);
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
// 处理业务逻辑错误
console
.
log
(
'
terminateSelf failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
```
## ServiceExtensionContext.connectAbility
## ServiceExtensionContext.connect
ServiceExtension
Ability
connectAbility(want: Want, options: ConnectOptions): number;
connect
ServiceExtension
Ability(want: Want, options: ConnectOptions): number;
将一个Ability与服务类型的Ability绑定。
...
...
@@ -602,24 +1120,46 @@ connectAbility(want: Want, options: ConnectOptions): number;
| -------- | -------- |
| number | 返回一个number,后续根据这个number去断开连接。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
let
want
=
{
var
want
=
{
"
bundleName
"
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
MyAbility
"
};
let
options
=
{
var
options
=
{
onConnect
(
elementName
,
remote
)
{
console
.
log
(
'
----------- onConnect -----------
'
)
},
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onFailed
(
code
)
{
console
.
log
(
'
----------- onFailed -----------
'
)
}
}
let
connection
=
this
.
context
.
connectAbility
(
want
,
options
);
var
connection
=
null
;
try
{
connection
=
this
.
context
.
connectServiceExtensionAbility
(
want
,
options
);
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.connectAbilityWithAccount
## ServiceExtensionContext.connect
ServiceExtension
AbilityWithAccount
connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number;
connect
ServiceExtension
AbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number;
使用AbilityInfo.AbilityType.SERVICE模板和account将当前能力连接到一个能力。
...
...
@@ -641,6 +1181,21 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
| -------- | -------- |
| number | 返回Ability连接的结果code。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. |
| 16000004 | Visibility verification failed. |
| 16000006 | Can not cross user operations. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
...
...
@@ -655,13 +1210,20 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onFailed
(
code
)
{
console
.
log
(
'
----------- onFailed -----------
'
)
}
}
const
result
=
this
.
context
.
connectAbilityWithAccount
(
want
,
accountId
,
options
);
console
.
log
(
'
----------- connectAbilityResult: ------------
'
,
result
);
var
connection
=
null
;
try
{
connection
=
this
.
context
.
connectServiceExtensionAbilityWithAccount
(
want
,
accountId
,
options
);
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.disconnectAbility
## ServiceExtensionContext.disconnect
ServiceExtension
Ability
disconnectAbility(connection: number, callback:AsyncCallback
<
void
>
): void;
disconnect
ServiceExtension
Ability(connection: number, callback:AsyncCallback
<
void
>
): void;
将一个Ability与绑定的服务类型的Ability解绑。
...
...
@@ -676,19 +1238,46 @@ disconnectAbility(connection: number, callback:AsyncCallback<void>): void;
| connection | number | 是 | 在connectAbility中返回的number。 |
| callback | AsyncCallback
<
void
>
| 否 | 回调函数,返回接口调用是否成功的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000003 | Input error. The specified id does not exist. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
let
connection
=
1
this
.
context
.
disconnectAbility
(
connection
,
(
err
)
=>
{
// connection为connectAbility中的返回值
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringify
(
err
));
// connection为connectServiceExtensionAbility中的返回值
var
connection
=
1
;
try
{
this
.
context
.
disconnectServiceExtensionAbility
(
connection
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
disconnectServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
// 执行正常业务
console
.
log
(
'
disconnectServiceExtensionAbility succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.disconnectAbility
## ServiceExtensionContext.disconnect
ServiceExtension
Ability
disconnectAbility(connection: number): Promise
<
void
>
;
disconnect
ServiceExtension
Ability(connection: number): Promise
<
void
>
;
将一个Ability与绑定的服务类型的Ability解绑。通过Promise返回结果。
...
...
@@ -708,16 +1297,41 @@ disconnectAbility(connection: number): Promise<void>;
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000003 | Input error. The specified id does not exist. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
let
connection
=
1
this
.
context
.
disconnectAbility
(
connection
).
then
((
data
)
=>
{
// connection为connectAbility中的返回值
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
var
connection
=
1
;
try
{
this
.
context
.
disconnectServiceExtensionAbility
(
connection
)
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
disconnectServiceExtensionAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
disconnectServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
## ServiceExtensionContext.startAbilityByCall
...
...
@@ -742,10 +1356,28 @@ startAbilityByCall(want: Want): Promise<Caller>;
| -------- | -------- |
| Promise
<
Caller
>
| 获取要通讯的caller对象。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000004 | Visibility verification failed. |
| 16000005 | Static permission denied. The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000008 | Crowdtest App Expiration. |
| 16000009 | Can not start ability in wukong mode. |
| 16000050 | Internal Error. |
**示例:**
前台启动:
```
js
let
caller
=
undefined
;
var
caller
=
undefined
;
// 后台启动Ability,不配置parameters
var
wantBackground
=
{
...
...
@@ -754,13 +1386,29 @@ startAbilityByCall(want: Want): Promise<Caller>;
abilityName
:
"
MainAbility
"
,
deviceId
:
""
};
try
{
this
.
context
.
startAbilityByCall
(
wantBackground
)
.
then
((
obj
)
=>
{
// 执行正常业务
caller
=
obj
;
console
.
log
(
'
GetCaller Success
'
);
console
.
log
(
'
startAbilityByCall succeed
'
);
}).
catch
((
error
)
=>
{
console
.
log
(
`GetCaller failed with
${
error
}
`
);
// 处理业务逻辑错误
console
.
log
(
'
startAbilityByCall failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
前台启动:
```
js
var
caller
=
undefined
;
// 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true
var
wantForeground
=
{
...
...
@@ -772,12 +1420,22 @@ startAbilityByCall(want: Want): Promise<Caller>;
"
ohos.aafwk.param.callAbilityToForeground
"
:
true
}
};
this
.
context
.
startAbilityByCall
(
wantForeground
)
try
{
this
.
context
.
startAbilityByCall
(
wantBackground
)
.
then
((
obj
)
=>
{
// 执行正常业务
caller
=
obj
;
console
.
log
(
'
GetCaller success
'
);
console
.
log
(
'
startAbilityByCall succeed
'
);
}).
catch
((
error
)
=>
{
console
.
log
(
`GetCaller failed with
${
error
}
`
);
// 处理业务逻辑错误
console
.
log
(
'
startAbilityByCall failed, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录