Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
1829ffc8
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看板
未验证
提交
1829ffc8
编写于
11月 10, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 10, 2022
浏览文件
操作
浏览文件
下载
差异文件
!11150 【元能力】Stage模型ServiceExtensionContext API错误码资料更新
Merge pull request !11150 from HuangXW/ContextErrorCode
上级
0e2d67fe
a224a82f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
2161 addition
and
603 deletion
+2161
-603
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
+1129
-254
zh-cn/application-dev/reference/apis/js-apis-application-ability.md
...ication-dev/reference/apis/js-apis-application-ability.md
+222
-155
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
+803
-187
未找到文件。
zh-cn/application-dev/ability/stage-call.md
浏览文件 @
1829ffc8
...
@@ -40,7 +40,7 @@ Caller及Callee功能如下:具体的API详见[接口文档](../reference/apis
...
@@ -40,7 +40,7 @@ Caller及Callee功能如下:具体的API详见[接口文档](../reference/apis
|call(method: string, data: rpc.Sequenceable): Promise
\<
void>|向通用组件Callee发送约定序列化数据。|
|call(method: string, data: rpc.Sequenceable): Promise
\<
void>|向通用组件Callee发送约定序列化数据。|
|callWithResult(method: string, data: rpc.Sequenceable): Promise
\<
rpc.MessageParcel>|向通用组件Callee发送约定序列化数据, 并将Callee返回的约定序列化数据带回。|
|callWithResult(method: string, data: rpc.Sequenceable): Promise
\<
rpc.MessageParcel>|向通用组件Callee发送约定序列化数据, 并将Callee返回的约定序列化数据带回。|
|release(): void|释放通用组件的Caller通信接口。|
|release(): void|释放通用组件的Caller通信接口。|
|on
Release(callback: OnReleaseCallB
ack): void|注册通用组件通信断开监听通知。|
|on
(type: "release", callback: OnReleaseCallb
ack): void|注册通用组件通信断开监听通知。|
## 开发步骤
## 开发步骤
Call调用的开发步骤:
Call调用的开发步骤:
...
@@ -72,7 +72,7 @@ Ability配置标签示例如下:
...
@@ -72,7 +72,7 @@ Ability配置标签示例如下:
```
```
**2. 导入Ability模块**
**2. 导入Ability模块**
```
ts
```
ts
import
Ability
from
'
@ohos.app
lication.
Ability
'
import
Ability
from
'
@ohos.app
.ability.UI
Ability
'
```
```
**3. 定义约定的序列化数据**
**3. 定义约定的序列化数据**
...
@@ -142,7 +142,7 @@ export default class CalleeAbility extends Ability {
...
@@ -142,7 +142,7 @@ export default class CalleeAbility extends Ability {
### 访问Callee被调用端
### 访问Callee被调用端
**1. 导入Ability模块**
**1. 导入Ability模块**
```
ts
```
ts
import
Ability
from
'
@ohos.app
lication.
Ability
'
import
Ability
from
'
@ohos.app
.ability.UI
Ability
'
```
```
**2. 获取Caller通信接口**
**2. 获取Caller通信接口**
...
@@ -151,7 +151,7 @@ import Ability from '@ohos.application.Ability'
...
@@ -151,7 +151,7 @@ import Ability from '@ohos.application.Ability'
// 注册caller的release监听
// 注册caller的release监听
private
regOnRelease
(
caller
)
{
private
regOnRelease
(
caller
)
{
try
{
try
{
caller
.
on
Release
(
(
msg
)
=>
{
caller
.
on
(
"
release
"
,
(
msg
)
=>
{
console
.
log
(
`caller onRelease is called
${
msg
}
`
)
console
.
log
(
`caller onRelease is called
${
msg
}
`
)
})
})
console
.
log
(
'
caller register OnRelease succeed
'
)
console
.
log
(
'
caller register OnRelease succeed
'
)
...
@@ -192,7 +192,7 @@ async onButtonGetRemoteCaller() {
...
@@ -192,7 +192,7 @@ async onButtonGetRemoteCaller() {
caller
=
data
caller
=
data
console
.
log
(
'
get remote caller success
'
)
console
.
log
(
'
get remote caller success
'
)
// 注册caller的release监听
// 注册caller的release监听
caller
.
on
Release
(
(
msg
)
=>
{
caller
.
on
(
"
release
"
,
(
msg
)
=>
{
console
.
log
(
`remote caller onRelease is called
${
msg
}
`
)
console
.
log
(
`remote caller onRelease is called
${
msg
}
`
)
})
})
console
.
log
(
'
remote caller register OnRelease succeed
'
)
console
.
log
(
'
remote caller register OnRelease succeed
'
)
...
...
zh-cn/application-dev/reference/apis/js-apis-ability-context.md
浏览文件 @
1829ffc8
...
@@ -13,11 +13,13 @@ AbilityContext模块提供允许访问特定Ability的资源的能力,包括
...
@@ -13,11 +13,13 @@ AbilityContext模块提供允许访问特定Ability的资源的能力,包括
在使用AbilityContext的功能前,需要通过Ability子类实例获取。
在使用AbilityContext的功能前,需要通过Ability子类实例获取。
```
js
```
ts
import
Ability
from
'
@ohos.application.Ability
'
;
import
Ability
from
'
@ohos.app.ability.UIAbility
'
;
let
context
=
undefined
;
class
MainAbility
extends
Ability
{
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
onWindowStageCreate
(
windowStage
)
{
let
context
=
this
.
context
;
context
=
this
.
context
;
}
}
}
}
```
```
...
@@ -47,17 +49,54 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
...
@@ -47,17 +49,54 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| callback | AsyncCallback
<
void
>
| 是 | callback形式返回启动结果 |
| callback | AsyncCallback
<
void
>
| 是 | callback形式返回启动结果 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
bundleName
:
"
com.example.myapp
"
,
"
bundleName
"
:
"
com.extreme.test
"
,
abilityName
:
"
MyAbility
"
"
abilityName
"
:
"
MainAbility
"
};
};
this
.
context
.
startAbility
(
want
,
(
error
)
=>
{
console
.
log
(
"
error.code =
"
+
error
.
code
)
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
));
}
```
```
...
@@ -77,22 +116,59 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
...
@@ -77,22 +116,59 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
<
void
>
| 是 | callback形式返回启动结果。 |
| callback | AsyncCallback
<
void
>
| 是 | callback形式返回启动结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
options
=
{
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
};
this
.
context
.
startAbility
(
want
,
options
,
(
error
)
=>
{
console
.
log
(
"
error.code =
"
+
error
.
code
)
})
```
try
{
this
.
context
.
startAbility
(
want
,
options
,
(
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
));
}
```
## AbilityContext.startAbility
## AbilityContext.startAbility
...
@@ -115,23 +191,57 @@ startAbility(want: Want, options?: StartOptions): Promise<void>;
...
@@ -115,23 +191,57 @@ startAbility(want: Want, options?: StartOptions): Promise<void>;
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| Promise形式返回启动结果。 |
| Promise
<
void
>
| Promise形式返回启动结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
bundleName
:
"
com.example.myapp
"
,
"
bundleName
"
:
"
com.extreme.test
"
,
abilityName
:
"
MyAbility
"
"
abilityName
"
:
"
MainAbility
"
};
};
var
options
=
{
var
options
=
{
windowMode
:
0
,
windowMode
:
0
,
};
};
this
.
context
.
startAbility
(
want
,
options
)
.
then
(()
=>
{
try
{
console
.
log
(
'
Operation successful.
'
)
this
.
context
.
startAbility
(
want
,
options
)
}).
catch
((
error
)
=>
{
.
then
((
data
)
=>
{
console
.
log
(
'
Operation failed.
'
);
// 执行正常业务
})
console
.
log
(
'
startAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
...
@@ -139,7 +249,7 @@ startAbility(want: Want, options?: StartOptions): Promise<void>;
...
@@ -139,7 +249,7 @@ startAbility(want: Want, options?: StartOptions): Promise<void>;
startAbilityForResult(want: Want, callback: AsyncCallback
<
AbilityResult
>
): void;
startAbilityForResult(want: Want, callback: AsyncCallback
<
AbilityResult
>
): void;
启动Ability并在
结束
的时候返回执行结果(callback形式)。
启动Ability并在
该Ability退出
的时候返回执行结果(callback形式)。
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
...
@@ -150,24 +260,63 @@ startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>):
...
@@ -150,24 +260,63 @@ startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>):
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| callback | AsyncCallback
<
[AbilityResult](js-apis-featureAbility.md#abilityresult)
>
| 是 | 执行结果回调函数。 |
| callback | AsyncCallback
<
[AbilityResult](js-apis-featureAbility.md#abilityresult)
>
| 是 | 执行结果回调函数。 |
**错误码:**
| 错误码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
```
ts
this
.
context
.
startAbilityForResult
(
var
want
=
{
{
deviceId
:
""
,
bundleName
:
"
com.extreme.myapplication
"
,
abilityName
:
"
MainAbilityDemo2
"
},
deviceId
:
""
,
(
error
,
result
)
=>
{
bundleName
:
"
com.extreme.test
"
,
console
.
log
(
"
startAbilityForResult AsyncCallback is called, error.code =
"
+
error
.
code
)
abilityName
:
"
MainAbility
"
console
.
log
(
"
startAbilityForResult AsyncCallback is called, result.resultCode =
"
+
result
.
resultCode
)
};
}
);
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
## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
<
AbilityResult
>
): void;
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
<
AbilityResult
>
): void;
启动Ability并在
结束
的时候返回执行结果(callback形式)。
启动Ability并在
该Ability退出
的时候返回执行结果(callback形式)。
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
...
@@ -179,20 +328,59 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
...
@@ -179,20 +328,59 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
<
[AbilityResult](js-apis-featureAbility.md#abilityresult)
>
| 是 | 执行结果回调函数。 |
| callback | AsyncCallback
<
[AbilityResult](js-apis-featureAbility.md#abilityresult)
>
| 是 | 执行结果回调函数。 |
**错误码:**
| 错误码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
```
ts
var
want
=
{
deviceId
:
""
,
bundleName
:
"
com.extreme.test
"
,
abilityName
:
"
MainAbility
"
};
var
options
=
{
var
options
=
{
windowMode
:
0
,
windowMode
:
0
,
};
};
this
.
context
.
startAbilityForResult
(
{
deviceId
:
""
,
bundleName
:
"
com.extreme.myapplication
"
,
abilityName
:
"
MainAbilityDemo2
"
},
options
,
try
{
(
error
,
result
)
=>
{
this
.
context
.
startAbilityForResult
(
want
,
options
,
(
error
,
result
)
=>
{
console
.
log
(
"
startAbilityForResult AsyncCallback is called, error.code =
"
+
error
.
code
)
if
(
error
.
code
)
{
console
.
log
(
"
startAbilityForResult AsyncCallback is called, result.resultCode =
"
+
result
.
resultCode
)
// 处理业务逻辑错误
}
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
));
}
```
```
...
@@ -200,7 +388,7 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
...
@@ -200,7 +388,7 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
startAbilityForResult(want: Want, options?: StartOptions): Promise
<
AbilityResult
>
;
startAbilityForResult(want: Want, options?: StartOptions): Promise
<
AbilityResult
>
;
启动Ability并在
结束
的时候返回执行结果(promise形式)。
启动Ability并在
该Ability退出
的时候返回执行结果(promise形式)。
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
**系统能力**
:SystemCapability.Ability.AbilityRuntime.Core
...
@@ -218,17 +406,57 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityRes
...
@@ -218,17 +406,57 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityRes
| -------- | -------- |
| -------- | -------- |
| Promise
<
[AbilityResult](js-apis-featureAbility.md#abilityresult)
>
| Promise形式返回执行结果。 |
| Promise
<
[AbilityResult](js-apis-featureAbility.md#abilityresult)
>
| Promise形式返回执行结果。 |
**错误码:**
| 错误码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
```
ts
var
want
=
{
bundleName
:
"
com.example.myapp
"
,
abilityName
:
"
MyAbility
"
};
var
options
=
{
var
options
=
{
windowMode
:
0
,
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
)
try
{
},
(
error
)
=>
{
this
.
context
.
startAbilityForResult
(
want
,
options
)
console
.
log
(
"
startAbilityForResult Promise.Reject is called, error.code =
"
+
error
.
code
)
.
then
((
result
)
=>
{
})
// 执行正常业务
console
.
log
(
"
startAbilityForResult succeed, result.resultCode =
"
+
result
.
resultCode
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityForResult failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## AbilityContext.startAbilityForResultWithAccount
## AbilityContext.startAbilityForResultWithAccount
...
@@ -251,19 +479,58 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
...
@@ -251,19 +479,58 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
AbilityResult
\>
| 是 | 启动Ability的回调函数,返回Ability结果。 |
| callback | AsyncCallback
\<
AbilityResult
\>
| 是 | 启动Ability的回调函数,返回Ability结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
(
err
,
data
)
=>
{
console
.
log
(
'
---------- startAbilityWithAccount fail, err: -----------
'
,
err
);
try
{
console
.
log
(
'
---------- startAbilityWithAccount success, data: -----------
'
,
data
);
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,21 +555,61 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
...
@@ -288,21 +555,61 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
var
options
=
{
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,25 +639,61 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
...
@@ -332,25 +639,61 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
| -------- | -------- |
| -------- | -------- |
| Promise
<
AbilityResult
>
| 返回一个Promise,包含Ability结果。 |
| Promise
<
AbilityResult
>
| 返回一个Promise,包含Ability结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
var
options
=
{
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
};
this
.
context
.
startAbilityForResultWithAccount
(
want
,
accountId
,
options
)
.
then
((
data
)
=>
{
try
{
console
.
log
(
'
---------- startAbilityForResultWithAccount success, data: -----------
'
,
data
);
this
.
context
.
startAbilityForResultWithAccount
(
want
,
accountId
,
options
)
})
.
then
((
result
)
=>
{
.
catch
((
err
)
=>
{
// 执行正常业务
console
.
log
(
'
---------- startAbilityForResultWithAccount fail, err: -----------
'
,
err
);
console
.
log
(
"
startAbilityForResultWithAccount succeed, result.resultCode =
"
+
})
result
.
resultCode
)
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityForResultWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## AbilityContext.startServiceExtensionAbility
## AbilityContext.startServiceExtensionAbility
...
@@ -369,17 +712,48 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
...
@@ -369,17 +712,48 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
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
## AbilityContext.startServiceExtensionAbility
...
@@ -398,22 +772,50 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
...
@@ -398,22 +772,50 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
this
.
context
.
startServiceExtensionAbility
(
want
)
.
then
(()
=>
{
try
{
console
.
log
(
'
---------- startServiceExtensionAbility success -----------
'
);
this
.
context
.
startServiceExtensionAbility
(
want
)
})
.
then
((
data
)
=>
{
.
catch
((
err
)
=>
{
// 执行正常业务
console
.
log
(
'
---------- startServiceExtensionAbility fail, err: -----------
'
,
err
);
console
.
log
(
'
startServiceExtensionAbility succeed
'
);
})
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## AbilityContext.startServiceExtensionAbilityWithAccount
## AbilityContext.startServiceExtensionAbilityWithAccount
startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback
\<
void>): void;
startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback
\<
void>): void;
...
@@ -434,18 +836,46 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
...
@@ -434,18 +836,46 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
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
## AbilityContext.startServiceExtensionAbilityWithAccount
...
@@ -467,22 +897,50 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
...
@@ -467,22 +897,50 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
(()
=>
{
try
{
console
.
log
(
'
---------- startServiceExtensionAbilityWithAccount success -----------
'
);
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
)
})
.
then
((
data
)
=>
{
.
catch
((
err
)
=>
{
// 执行正常业务
console
.
log
(
'
---------- startServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
console
.
log
(
'
startServiceExtensionAbilityWithAccount succeed
'
);
})
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## AbilityContext.stopServiceExtensionAbility
## AbilityContext.stopServiceExtensionAbility
...
@@ -501,17 +959,45 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
...
@@ -501,17 +959,45 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
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
## AbilityContext.stopServiceExtensionAbility
...
@@ -530,21 +1016,45 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
...
@@ -530,21 +1016,45 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
this
.
context
.
stopServiceExtensionAbility
(
want
)
.
then
(()
=>
{
try
{
console
.
log
(
'
---------- stopServiceExtensionAbility success -----------
'
);
this
.
context
.
stopServiceExtensionAbility
(
want
)
})
.
then
((
data
)
=>
{
.
catch
((
err
)
=>
{
// 执行正常业务
console
.
log
(
'
---------- stopServiceExtensionAbility fail, err: -----------
'
,
err
);
console
.
log
(
'
stopServiceExtensionAbility succeed
'
);
})
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## AbilityContext.stopServiceExtensionAbilityWithAccount
## AbilityContext.stopServiceExtensionAbilityWithAccount
...
@@ -567,18 +1077,47 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
...
@@ -567,18 +1077,47 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
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
## AbilityContext.stopServiceExtensionAbilityWithAccount
...
@@ -600,22 +1139,47 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
...
@@ -600,22 +1139,47 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
(()
=>
{
try
{
console
.
log
(
'
---------- stopServiceExtensionAbilityWithAccount success -----------
'
);
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
)
})
.
then
((
data
)
=>
{
.
catch
((
err
)
=>
{
// 执行正常业务
console
.
log
(
'
---------- stopServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
console
.
log
(
'
stopServiceExtensionAbilityWithAccount succeed
'
);
})
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## AbilityContext.terminateSelf
## AbilityContext.terminateSelf
...
@@ -632,11 +1196,29 @@ terminateSelf(callback: AsyncCallback<void>): void;
...
@@ -632,11 +1196,29 @@ terminateSelf(callback: AsyncCallback<void>): void;
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,返回接口调用是否成功的结果。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,返回接口调用是否成功的结果。 |
**错误码:**
| 错误码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
```
ts
this
.
context
.
terminateSelf
((
err
)
=>
{
this
.
context
.
terminateSelf
((
error
)
=>
{
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringify
(
err
));
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 +1237,27 @@ terminateSelf(): Promise<void>;
...
@@ -655,13 +1237,27 @@ terminateSelf(): Promise<void>;
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
| 错误码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
```
ts
this
.
context
.
terminateSelf
().
then
(()
=>
{
this
.
context
.
terminateSelf
().
then
((
data
)
=>
{
console
.
log
(
'
success
'
);
// 执行正常业务
console
.
log
(
'
terminateSelf succeed
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
// 处理业务逻辑错误
console
.
log
(
'
terminateSelf failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
});
```
```
...
@@ -681,12 +1277,23 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<voi
...
@@ -681,12 +1277,23 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<voi
| parameter |
[
AbilityResult
](
js-apis-featureAbility.md#abilityresult
)
| 是 | 返回给调用startAbilityForResult
接口调用方的相关信息。 |
| parameter |
[
AbilityResult
](
js-apis-featureAbility.md#abilityresult
)
| 是 | 返回给调用startAbilityForResult
接口调用方的相关信息。 |
| callback | AsyncCallback
<
void
>
| 是 | callback形式返回停止结果。 |
| callback | AsyncCallback
<
void
>
| 是 | callback形式返回停止结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
bundleName
"
:
"
com.extreme.myapplication
"
,
bundleName
:
"
com.extreme.myapplication
"
,
"
abilityName
"
:
"
SecondAbility
"
abilityName
:
"
SecondAbility
"
}
}
var
resultCode
=
100
;
var
resultCode
=
100
;
// 返回给接口调用方AbilityResult信息
// 返回给接口调用方AbilityResult信息
...
@@ -694,10 +1301,23 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<voi
...
@@ -694,10 +1301,23 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<voi
want
,
want
,
resultCode
resultCode
}
}
this
.
context
.
terminateSelfWithResult
(
abilityResult
,
(
error
)
=>
{
console
.
log
(
"
terminateSelfWithResult is called =
"
+
error
.
code
)
try
{
this
.
context
.
terminateSelfWithResult
(
abilityResult
,
(
error
)
=>
{
if
(
error
.
code
)
{
// 处理业务逻辑错误
console
.
log
(
'
terminateSelfWithResult failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
return
;
}
}
);
// 执行正常业务
console
.
log
(
'
terminateSelfWithResult succeed
'
);
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
...
@@ -721,12 +1341,24 @@ terminateSelfWithResult(parameter: AbilityResult): Promise<void>;
...
@@ -721,12 +1341,24 @@ terminateSelfWithResult(parameter: AbilityResult): Promise<void>;
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| promise形式返回停止结果。 |
| Promise
<
void
>
| promise形式返回停止结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
bundleName
"
:
"
com.extreme.myapplication
"
,
bundleName
:
"
com.extreme.myapplication
"
,
"
abilityName
"
:
"
SecondAbility
"
abilityName
:
"
SecondAbility
"
}
}
var
resultCode
=
100
;
var
resultCode
=
100
;
// 返回给接口调用方AbilityResult信息
// 返回给接口调用方AbilityResult信息
...
@@ -734,15 +1366,28 @@ terminateSelfWithResult(parameter: AbilityResult): Promise<void>;
...
@@ -734,15 +1366,28 @@ terminateSelfWithResult(parameter: AbilityResult): Promise<void>;
want
,
want
,
resultCode
resultCode
}
}
this
.
context
.
terminateSelfWithResult
(
abilityResult
).
then
((
result
)
=>
{
console
.
log
(
"
terminateSelfWithResult
"
)
try
{
this
.
context
.
terminateSelfWithResult
(
abilityResult
)
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
terminateSelfWithResult succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
terminateSelfWithResult failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
}
)
```
```
## 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。
使用AbilityInfo.AbilityType.SERVICE模板将当前Ability连接到一个Ability。
...
@@ -763,27 +1408,46 @@ connectAbility(want: Want, options: ConnectOptions): number;
...
@@ -763,27 +1408,46 @@ connectAbility(want: Want, options: ConnectOptions): number;
| -------- | -------- |
| -------- | -------- |
| number | 返回Ability连接的结果code。 |
| number | 返回Ability连接的结果code。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
options
=
{
var
options
=
{
onConnect
(
elementName
,
remote
)
{
console
.
log
(
'
----------- onConnect -----------
'
)
},
onConnect
(
elementName
,
remote
)
{
console
.
log
(
'
----------- onConnect -----------
'
)
},
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onFailed
(
code
)
{
console
.
log
(
'
----------- onFailed -----------
'
)
}
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。
使用AbilityInfo.AbilityType.SERVICE模板和account将当前Ability连接到一个Ability。
...
@@ -807,13 +1471,26 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
...
@@ -807,13 +1471,26 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
| -------- | -------- |
| -------- | -------- |
| number | 返回Ability连接的结果code。 |
| number | 返回Ability连接的结果code。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
var
options
=
{
var
options
=
{
...
@@ -821,13 +1498,20 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
...
@@ -821,13 +1498,20 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onFailed
(
code
)
{
console
.
log
(
'
----------- onFailed -----------
'
)
}
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形式)。
断开连接(promise形式)。
...
@@ -847,20 +1531,44 @@ disconnectAbility(connection: number): Promise\<void>;
...
@@ -847,20 +1531,44 @@ disconnectAbility(connection: number): Promise\<void>;
| -------- | -------- |
| -------- | -------- |
| Promise
\<
void> | 返回执行结果。 |
| Promise
\<
void> | 返回执行结果。 |
**错误码:**
| 错误码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
```
ts
var
connectionNumber
=
0
;
// connection为connectAbility中的返回值
this
.
context
.
disconnectAbility
(
connectionNumber
).
then
(()
=>
{
var
connection
=
1
;
console
.
log
(
'
disconnectAbility success
'
);
}).
catch
((
err
)
=>
{
try
{
console
.
log
(
'
disconnectAbility fail, err:
'
,
err
);
this
.
context
.
disconnectServiceExtensionAbility
(
connection
)
});
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
disconnectServiceExtensionAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
disconnectServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
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形式)。
断开连接(callback形式)。
...
@@ -875,13 +1583,39 @@ disconnectAbility(connection: number, callback:AsyncCallback\<void>): void;
...
@@ -875,13 +1583,39 @@ disconnectAbility(connection: number, callback:AsyncCallback\<void>): void;
| connection | number | 是 | 连接的Ability的数字代码。 |
| connection | number | 是 | 连接的Ability的数字代码。 |
| callback | AsyncCallback
\<
void> | 是 | 表示指定的回调方法。 |
| callback | AsyncCallback
\<
void> | 是 | 表示指定的回调方法。 |
**错误码:**
| 错误码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
```
ts
var
connectionNumber
=
0
;
// connection为connectServiceExtensionAbility中的返回值
this
.
context
.
disconnectAbility
(
connectionNumber
,
(
err
)
=>
{
var
connection
=
1
;
console
.
log
(
'
---------- disconnectAbility fail, err: -----------
'
,
err
);
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
## AbilityContext.startAbilityByCall
...
@@ -906,8 +1640,10 @@ startAbilityByCall(want: Want): Promise<Caller>;
...
@@ -906,8 +1640,10 @@ startAbilityByCall(want: Want): Promise<Caller>;
**示例:**
**示例:**
```
js
后台启动:
let
caller
=
undefined
;
```
ts
var
caller
=
undefined
;
// 后台启动Ability,不配置parameters
// 后台启动Ability,不配置parameters
var
wantBackground
=
{
var
wantBackground
=
{
...
@@ -916,13 +1652,29 @@ startAbilityByCall(want: Want): Promise<Caller>;
...
@@ -916,13 +1652,29 @@ startAbilityByCall(want: Want): Promise<Caller>;
abilityName
:
"
MainAbility
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
deviceId
:
""
};
};
this
.
context
.
startAbilityByCall
(
wantBackground
)
.
then
((
obj
)
=>
{
try
{
this
.
context
.
startAbilityByCall
(
wantBackground
)
.
then
((
obj
)
=>
{
// 执行正常业务
caller
=
obj
;
caller
=
obj
;
console
.
log
(
'
GetCaller success
'
);
console
.
log
(
'
startAbilityByCall succeed
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
console
.
log
(
`GetCaller failed with
${
error
}
`
);
// 处理业务逻辑错误
});
console
.
log
(
'
startAbilityByCall failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
前台启动:
```
ts
var
caller
=
undefined
;
// 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true
// 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true
var
wantForeground
=
{
var
wantForeground
=
{
...
@@ -934,13 +1686,23 @@ startAbilityByCall(want: Want): Promise<Caller>;
...
@@ -934,13 +1686,23 @@ startAbilityByCall(want: Want): Promise<Caller>;
"
ohos.aafwk.param.callAbilityToForeground
"
:
true
"
ohos.aafwk.param.callAbilityToForeground
"
:
true
}
}
};
};
this
.
context
.
startAbilityByCall
(
wantForeground
)
.
then
((
obj
)
=>
{
try
{
this
.
context
.
startAbilityByCall
(
wantForeground
)
.
then
((
obj
)
=>
{
// 执行正常业务
caller
=
obj
;
caller
=
obj
;
console
.
log
(
'
GetCaller success
'
);
console
.
log
(
'
startAbilityByCall succeed
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
console
.
log
(
`GetCaller failed with
${
error
}
`
);
// 处理业务逻辑错误
});
console
.
log
(
'
startAbilityByCall failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## AbilityContext.startAbilityWithAccount
## AbilityContext.startAbilityWithAccount
...
@@ -963,18 +1725,57 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
...
@@ -963,18 +1725,57 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
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,21 +1800,60 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
...
@@ -999,21 +1800,60 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 否 | 启动Ability所携带的参数。 |
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 否 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
var
options
=
{
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,25 +1877,60 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
...
@@ -1037,25 +1877,60 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 否 | 启动Ability所携带的参数。 |
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 否 | 启动Ability所携带的参数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
var
options
=
{
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
};
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
options
)
.
then
(()
=>
{
try
{
console
.
log
(
'
---------- startAbilityWithAccount success -----------
'
);
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
options
)
})
.
then
((
data
)
=>
{
.
catch
((
err
)
=>
{
// 执行正常业务
console
.
log
(
'
---------- startAbilityWithAccount fail, err: -----------
'
,
err
);
console
.
log
(
'
startAbilityWithAccount succeed
'
);
})
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## AbilityContext.requestPermissionsFromUser
## AbilityContext.requestPermissionsFromUser
...
@@ -1075,7 +1950,7 @@ requestPermissionsFromUser(permissions: Array<string>, requestCallback: As
...
@@ -1075,7 +1950,7 @@ requestPermissionsFromUser(permissions: Array<string>, requestCallback: As
**示例:**
**示例:**
```
j
s
```
t
s
var
permissions
=
[
'
com.example.permission
'
]
var
permissions
=
[
'
com.example.permission
'
]
this
.
context
.
requestPermissionsFromUser
(
permissions
,(
result
)
=>
{
this
.
context
.
requestPermissionsFromUser
(
permissions
,(
result
)
=>
{
console
.
log
(
'
requestPermissionsFromUserresult:
'
+
JSON
.
stringify
(
result
));
console
.
log
(
'
requestPermissionsFromUserresult:
'
+
JSON
.
stringify
(
result
));
...
@@ -1106,7 +1981,7 @@ requestPermissionsFromUser(permissions: Array<string>) : Promise<Permis
...
@@ -1106,7 +1981,7 @@ requestPermissionsFromUser(permissions: Array<string>) : Promise<Permis
**示例:**
**示例:**
```
j
s
```
t
s
var
permissions
=
[
'
com.example.permission
'
]
var
permissions
=
[
'
com.example.permission
'
]
this
.
context
.
requestPermissionsFromUser
(
permissions
).
then
((
data
)
=>
{
this
.
context
.
requestPermissionsFromUser
(
permissions
).
then
((
data
)
=>
{
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
...
@@ -1134,7 +2009,7 @@ setMissionLabel(label: string, callback:AsyncCallback<void>): void;
...
@@ -1134,7 +2009,7 @@ setMissionLabel(label: string, callback:AsyncCallback<void>): void;
**示例:**
**示例:**
```
j
s
```
t
s
this
.
context
.
setMissionLabel
(
"
test
"
,(
result
)
=>
{
this
.
context
.
setMissionLabel
(
"
test
"
,(
result
)
=>
{
console
.
log
(
'
requestPermissionsFromUserresult:
'
+
JSON
.
stringify
(
result
));
console
.
log
(
'
requestPermissionsFromUserresult:
'
+
JSON
.
stringify
(
result
));
});
});
...
@@ -1163,7 +2038,7 @@ setMissionLabel(label: string): Promise<void>;
...
@@ -1163,7 +2038,7 @@ setMissionLabel(label: string): Promise<void>;
**示例:**
**示例:**
```
j
s
```
t
s
this
.
context
.
setMissionLabel
(
"
test
"
).
then
(()
=>
{
this
.
context
.
setMissionLabel
(
"
test
"
).
then
(()
=>
{
console
.
log
(
'
success
'
);
console
.
log
(
'
success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
...
@@ -1189,7 +2064,7 @@ setMissionIcon(icon: image.PixelMap, callback:AsyncCallback\<void>): void;
...
@@ -1189,7 +2064,7 @@ setMissionIcon(icon: image.PixelMap, callback:AsyncCallback\<void>): void;
**示例:**
**示例:**
```
j
s
```
t
s
import
image
from
'
@ohos.multimedia.image
'
;
import
image
from
'
@ohos.multimedia.image
'
;
var
imagePixelMap
;
var
imagePixelMap
;
var
color
=
new
ArrayBuffer
(
0
);
var
color
=
new
ArrayBuffer
(
0
);
...
@@ -1236,7 +2111,7 @@ setMissionIcon(icon: image.PixelMap): Promise\<void>;
...
@@ -1236,7 +2111,7 @@ setMissionIcon(icon: image.PixelMap): Promise\<void>;
**示例:**
**示例:**
```
j
s
```
t
s
import
image
from
'
@ohos.multimedia.image
'
;
import
image
from
'
@ohos.multimedia.image
'
;
var
imagePixelMap
;
var
imagePixelMap
;
var
color
=
new
ArrayBuffer
(
0
);
var
color
=
new
ArrayBuffer
(
0
);
...
@@ -1277,7 +2152,7 @@ restoreWindowStage(localStorage: LocalStorage) : void;
...
@@ -1277,7 +2152,7 @@ restoreWindowStage(localStorage: LocalStorage) : void;
**示例:**
**示例:**
```
j
s
```
t
s
var
storage
=
new
LocalStorage
();
var
storage
=
new
LocalStorage
();
this
.
context
.
restoreWindowStage
(
storage
);
this
.
context
.
restoreWindowStage
(
storage
);
```
```
...
@@ -1298,7 +2173,7 @@ isTerminating(): boolean;
...
@@ -1298,7 +2173,7 @@ isTerminating(): boolean;
**示例:**
**示例:**
```
j
s
```
t
s
var
isTerminating
=
this
.
context
.
isTerminating
();
var
isTerminating
=
this
.
context
.
isTerminating
();
console
.
log
(
'
ability state :
'
+
isTerminating
);
console
.
log
(
'
ability state :
'
+
isTerminating
);
```
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-application-ability.md
浏览文件 @
1829ffc8
...
@@ -45,8 +45,8 @@ Ability创建时回调,执行初始化业务逻辑操作。
...
@@ -45,8 +45,8 @@ Ability创建时回调,执行初始化业务逻辑操作。
| param | AbilityConstant.LaunchParam | 是 | 创建
ability、上次异常退出的原因信息。 |
| param | AbilityConstant.LaunchParam | 是 | 创建
ability、上次异常退出的原因信息。 |
**示例:**
**示例:**
```
j
s
```
t
s
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
onCreate
(
want
,
param
)
{
onCreate
(
want
,
param
)
{
console
.
log
(
'
onCreate, want:
'
+
want
.
abilityName
);
console
.
log
(
'
onCreate, want:
'
+
want
.
abilityName
);
...
@@ -71,7 +71,7 @@ onWindowStageCreate(windowStage: window.WindowStage): void
...
@@ -71,7 +71,7 @@ onWindowStageCreate(windowStage: window.WindowStage): void
**示例:**
**示例:**
```
j
s
```
t
s
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
onWindowStageCreate
(
windowStage
)
{
console
.
log
(
'
onWindowStageCreate
'
);
console
.
log
(
'
onWindowStageCreate
'
);
...
@@ -90,7 +90,7 @@ onWindowStageDestroy(): void
...
@@ -90,7 +90,7 @@ onWindowStageDestroy(): void
**示例:**
**示例:**
```
j
s
```
t
s
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
onWindowStageDestroy
()
{
onWindowStageDestroy
()
{
console
.
log
(
'
onWindowStageDestroy
'
);
console
.
log
(
'
onWindowStageDestroy
'
);
...
@@ -115,7 +115,7 @@ onWindowStageRestore(windowStage: window.WindowStage): void
...
@@ -115,7 +115,7 @@ onWindowStageRestore(windowStage: window.WindowStage): void
**示例:**
**示例:**
```
j
s
```
t
s
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
onWindowStageRestore
(
windowStage
)
{
onWindowStageRestore
(
windowStage
)
{
console
.
log
(
'
onWindowStageRestore
'
);
console
.
log
(
'
onWindowStageRestore
'
);
...
@@ -134,7 +134,7 @@ Ability生命周期回调,在销毁时回调,执行资源清理等操作。
...
@@ -134,7 +134,7 @@ Ability生命周期回调,在销毁时回调,执行资源清理等操作。
**示例:**
**示例:**
```
j
s
```
t
s
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
onDestroy
()
{
onDestroy
()
{
console
.
log
(
'
onDestroy
'
);
console
.
log
(
'
onDestroy
'
);
...
@@ -153,7 +153,7 @@ Ability生命周期回调,当应用从后台转到前台时触发。
...
@@ -153,7 +153,7 @@ Ability生命周期回调,当应用从后台转到前台时触发。
**示例:**
**示例:**
```
j
s
```
t
s
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
onForeground
()
{
onForeground
()
{
console
.
log
(
'
onForeground
'
);
console
.
log
(
'
onForeground
'
);
...
@@ -172,7 +172,7 @@ Ability生命周期回调,当应用从前台转到后台时触发。
...
@@ -172,7 +172,7 @@ Ability生命周期回调,当应用从前台转到后台时触发。
**示例:**
**示例:**
```
j
s
```
t
s
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
onBackground
()
{
onBackground
()
{
console
.
log
(
'
onBackground
'
);
console
.
log
(
'
onBackground
'
);
...
@@ -203,7 +203,7 @@ onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
...
@@ -203,7 +203,7 @@ onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
**示例:**
**示例:**
```
j
s
```
t
s
import
AbilityConstant
from
"
@ohos.application.AbilityConstant
"
import
AbilityConstant
from
"
@ohos.application.AbilityConstant
"
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
onContinue
(
wantParams
)
{
onContinue
(
wantParams
)
{
...
@@ -232,7 +232,7 @@ onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;
...
@@ -232,7 +232,7 @@ onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;
**示例:**
**示例:**
```
j
s
```
t
s
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
onNewWant
(
want
)
{
onNewWant
(
want
)
{
console
.
log
(
'
onNewWant, want:
'
+
want
.
abilityName
);
console
.
log
(
'
onNewWant, want:
'
+
want
.
abilityName
);
...
@@ -257,7 +257,7 @@ onConfigurationUpdated(config: Configuration): void;
...
@@ -257,7 +257,7 @@ onConfigurationUpdated(config: Configuration): void;
**示例:**
**示例:**
```
j
s
```
t
s
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
onConfigurationUpdated
(
config
)
{
onConfigurationUpdated
(
config
)
{
console
.
log
(
'
onConfigurationUpdated, config:
'
+
JSON
.
stringify
(
config
));
console
.
log
(
'
onConfigurationUpdated, config:
'
+
JSON
.
stringify
(
config
));
...
@@ -281,7 +281,7 @@ dump(params: Array\<string>): Array\<string>;
...
@@ -281,7 +281,7 @@ dump(params: Array\<string>): Array\<string>;
**示例:**
**示例:**
```
j
s
```
t
s
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
dump
(
params
)
{
dump
(
params
)
{
console
.
log
(
'
dump, params:
'
+
JSON
.
stringify
(
params
));
console
.
log
(
'
dump, params:
'
+
JSON
.
stringify
(
params
));
...
@@ -306,7 +306,7 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
...
@@ -306,7 +306,7 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
**示例:**
**示例:**
```
j
s
```
t
s
class
myAbility
extends
Ability
{
class
myAbility
extends
Ability
{
onMemoryLevel
(
level
)
{
onMemoryLevel
(
level
)
{
console
.
log
(
'
onMemoryLevel, level:
'
+
JSON
.
stringify
(
level
));
console
.
log
(
'
onMemoryLevel, level:
'
+
JSON
.
stringify
(
level
));
...
@@ -320,7 +320,6 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
...
@@ -320,7 +320,6 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
通用组件Caller通信客户端调用接口, 用来向通用组件服务端发送约定数据。
通用组件Caller通信客户端调用接口, 用来向通用组件服务端发送约定数据。
## Caller.call
## Caller.call
call(method: string, data: rpc.Sequenceable): Promise
<
void
>
;
call(method: string, data: rpc.Sequenceable): Promise
<
void
>
;
...
@@ -342,54 +341,65 @@ call(method: string, data: rpc.Sequenceable): Promise<void>;
...
@@ -342,54 +341,65 @@ call(method: string, data: rpc.Sequenceable): Promise<void>;
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| Promise形式返回应答。 |
| Promise
<
void
>
| Promise形式返回应答。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
import
Ability
from
'
@ohos.app
lication.
Ability
'
;
import
Ability
from
'
@ohos.app
.ability.UI
Ability
'
;
class
MyMessageAble
{
// 自定义的Sequenceable数据结构
class
MyMessageAble
{
// 自定义的Sequenceable数据结构
name
:
""
name
:
""
str
:
""
str
:
""
num
:
1
num
:
1
constructor
(
name
,
str
)
{
constructor
(
name
,
str
)
{
this
.
name
=
name
;
this
.
name
=
name
;
this
.
str
=
str
;
this
.
str
=
str
;
}
}
marshalling
(
messageParcel
)
{
marshalling
(
messageParcel
)
{
messageParcel
.
writeInt
(
this
.
num
);
messageParcel
.
writeInt
(
this
.
num
);
messageParcel
.
writeString
(
this
.
str
);
messageParcel
.
writeString
(
this
.
str
);
console
.
log
(
'
MyMessageAble marshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
console
.
log
(
'
MyMessageAble marshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
return
true
;
}
}
unmarshalling
(
messageParcel
)
{
unmarshalling
(
messageParcel
)
{
this
.
num
=
messageParcel
.
readInt
();
this
.
num
=
messageParcel
.
readInt
();
this
.
str
=
messageParcel
.
readString
();
this
.
str
=
messageParcel
.
readString
();
console
.
log
(
'
MyMessageAble unmarshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
console
.
log
(
'
MyMessageAble unmarshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
return
true
;
}
}
};
};
var
method
=
'
call_Function
'
;
// 约定的通知消息字符串
var
method
=
'
call_Function
'
;
// 约定的通知消息字符串
var
caller
;
var
caller
;
export
default
class
MainAbility
extends
Ability
{
export
default
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
deviceId
:
""
}).
then
((
obj
)
=>
{
}).
then
((
obj
)
=>
{
caller
=
obj
;
caller
=
obj
;
let
msg
=
new
MyMessageAble
(
1
,
"
world
"
);
// 参考Sequenceable数据定义
let
msg
=
new
MyMessageAble
(
"
msg
"
,
"
world
"
);
// 参考Sequenceable数据定义
caller
.
call
(
method
,
msg
)
caller
.
call
(
method
,
msg
)
.
then
(()
=>
{
.
then
(()
=>
{
console
.
log
(
'
Caller call() called
'
);
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
)
+
console
.
log
(
'
Caller GetCaller Get
'
+
caller
);
'
error.message:
'
+
JSON
.
stringify
(
callErr
.
message
));
}).
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,55 +425,67 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise<rpc.MessagePa
...
@@ -415,55 +425,67 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise<rpc.MessagePa
| -------- | -------- |
| -------- | -------- |
| Promise
<
rpc.MessageParcel
>
| Promise形式返回通用组件服务端应答数据。 |
| Promise
<
rpc.MessageParcel
>
| Promise形式返回通用组件服务端应答数据。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
import
Ability
from
'
@ohos.app
lication.
Ability
'
;
import
Ability
from
'
@ohos.app
.ability.UI
Ability
'
;
class
MyMessageAble
{
class
MyMessageAble
{
name
:
""
name
:
""
str
:
""
str
:
""
num
:
1
num
:
1
constructor
(
name
,
str
)
{
constructor
(
name
,
str
)
{
this
.
name
=
name
;
this
.
name
=
name
;
this
.
str
=
str
;
this
.
str
=
str
;
}
}
marshalling
(
messageParcel
)
{
marshalling
(
messageParcel
)
{
messageParcel
.
writeInt
(
this
.
num
);
messageParcel
.
writeInt
(
this
.
num
);
messageParcel
.
writeString
(
this
.
str
);
messageParcel
.
writeString
(
this
.
str
);
console
.
log
(
'
MyMessageAble marshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
console
.
log
(
'
MyMessageAble marshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
return
true
;
}
}
unmarshalling
(
messageParcel
)
{
unmarshalling
(
messageParcel
)
{
this
.
num
=
messageParcel
.
readInt
();
this
.
num
=
messageParcel
.
readInt
();
this
.
str
=
messageParcel
.
readString
();
this
.
str
=
messageParcel
.
readString
();
console
.
log
(
'
MyMessageAble unmarshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
console
.
log
(
'
MyMessageAble unmarshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
return
true
;
}
}
};
};
var
method
=
'
call_Function
'
;
var
method
=
'
call_Function
'
;
var
caller
;
var
caller
;
export
default
class
MainAbility
extends
Ability
{
export
default
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
deviceId
:
""
}).
then
((
obj
)
=>
{
}).
then
((
obj
)
=>
{
caller
=
obj
;
caller
=
obj
;
let
msg
=
new
MyMessageAble
(
1
,
"
world
"
);
let
msg
=
new
MyMessageAble
(
1
,
"
world
"
);
caller
.
callWithResult
(
method
,
msg
)
caller
.
callWithResult
(
method
,
msg
)
.
then
((
data
)
=>
{
.
then
((
data
)
=>
{
console
.
log
(
'
Caller callWithResult() called
'
);
console
.
log
(
'
Caller callWithResult() called
'
);
let
retmsg
=
new
MyMessageAble
(
0
,
""
);
let
retmsg
=
new
MyMessageAble
(
0
,
""
);
data
.
readSequenceable
(
retmsg
);
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
)
+
console
.
log
(
'
Caller GetCaller Get
'
+
caller
);
'
error.message:
'
+
JSON
.
stringify
(
callErr
.
message
));
}).
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,36 +498,46 @@ release(): void;
...
@@ -476,36 +498,46 @@ release(): void;
**系统能力**
:SystemCapability.Ability.AbilityRuntime.AbilityCore
**系统能力**
:SystemCapability.Ability.AbilityRuntime.AbilityCore
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
**示例:**
**示例:**
```
j
s
```
t
s
import
Ability
from
'
@ohos.app
lication.
Ability
'
;
import
Ability
from
'
@ohos.app
.ability.UI
Ability
'
;
var
caller
;
var
caller
;
export
default
class
MainAbility
extends
Ability
{
export
default
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
deviceId
:
""
}).
then
((
obj
)
=>
{
}).
then
((
obj
)
=>
{
caller
=
obj
;
caller
=
obj
;
try
{
try
{
caller
.
release
();
caller
.
release
();
}
catch
(
e
)
{
}
catch
(
releaseErr
)
{
console
.
log
(
'
Caller Release error
'
+
e
);
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
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
Caller GetCaller error
'
+
e
);
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(桩)断开监听通知。
注册通用组件服务端Stub(桩)断开监听通知。
...
@@ -515,33 +547,43 @@ onRelease(callback: OnReleaseCallBack): void;
...
@@ -515,33 +547,43 @@ onRelease(callback: OnReleaseCallBack): void;
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 监听releaseCall事件,固定为'release'。 |
| callback | OnReleaseCallBack | 是 | 返回onRelease回调结果。 |
| callback | OnReleaseCallBack | 是 | 返回onRelease回调结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
**示例:**
```
j
s
```
t
s
import
Ability
from
'
@ohos.app
lication.
Ability
'
;
import
Ability
from
'
@ohos.app
.ability.UI
Ability
'
;
var
caller
;
var
caller
;
export
default
class
MainAbility
extends
Ability
{
export
default
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
deviceId
:
""
}).
then
((
obj
)
=>
{
}).
then
((
obj
)
=>
{
caller
=
obj
;
caller
=
obj
;
try
{
try
{
caller
.
onRelease
((
str
)
=>
{
caller
.
on
(
"
release
"
,
(
str
)
=>
{
console
.
log
(
'
Caller OnRelease CallBack is called
'
+
str
);
console
.
log
(
'
Caller OnRelease CallBack is called
'
+
str
);
});
});
}
catch
(
e
)
{
}
catch
(
error
)
{
console
.
log
(
'
Caller Release error
'
+
e
);
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
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
Caller GetCaller error
'
+
e
);
console
.
log
(
'
Caller GetCaller error, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
});
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
}
});
}
}
}
```
```
...
@@ -550,7 +592,6 @@ onRelease(callback: OnReleaseCallBack): void;
...
@@ -550,7 +592,6 @@ onRelease(callback: OnReleaseCallBack): void;
通用组件服务端注册和解除客户端caller通知送信的callback接口。
通用组件服务端注册和解除客户端caller通知送信的callback接口。
## Callee.on
## Callee.on
on(method: string, callback: CalleeCallBack): void;
on(method: string, callback: CalleeCallBack): void;
...
@@ -566,10 +607,18 @@ on(method: string, callback: CalleeCallBack): void;
...
@@ -566,10 +607,18 @@ on(method: string, callback: CalleeCallBack): void;
| method | string | 是 | 与客户端约定的通知消息字符串。 |
| method | string | 是 | 与客户端约定的通知消息字符串。 |
| callback | CalleeCallBack | 是 | 一个rpc.MessageParcel类型入参的js通知同步回调函数,
回调函数至少要返回一个空的rpc.Sequenceable数据对象,
其他视为函数执行错误。 |
| callback | CalleeCallBack | 是 | 一个rpc.MessageParcel类型入参的js通知同步回调函数,
回调函数至少要返回一个空的rpc.Sequenceable数据对象,
其他视为函数执行错误。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200004 | Method registered. The method has registered. |
| 16000050 | Internal Error. |
**示例:**
**示例:**
```
j
s
```
t
s
import
Ability
from
'
@ohos.app
lication.
Ability
'
;
import
Ability
from
'
@ohos.app
.ability.UI
Ability
'
;
class
MyMessageAble
{
class
MyMessageAble
{
name
:
""
name
:
""
str
:
""
str
:
""
...
@@ -599,14 +648,18 @@ on(method: string, callback: CalleeCallBack): void;
...
@@ -599,14 +648,18 @@ on(method: string, callback: CalleeCallBack): void;
return
new
MyMessageAble
(
10
,
"
Callee test
"
);
return
new
MyMessageAble
(
10
,
"
Callee test
"
);
}
}
export
default
class
MainAbility
extends
Ability
{
export
default
class
MainAbility
extends
Ability
{
onCreate
(
want
,
launchParam
)
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
Callee onCreate is called
'
);
console
.
log
(
'
Callee onCreate is called
'
);
this
.
callee
.
on
(
method
,
funcCallBack
);
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
## Callee.off
off(method: string): void;
off(method: string): void;
...
@@ -621,20 +674,34 @@ off(method: string): void;
...
@@ -621,20 +674,34 @@ off(method: string): void;
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| method | string | 是 | 已注册的通知事件字符串。 |
| method | string | 是 | 已注册的通知事件字符串。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200005 | Method not registered. The method has not registered. |
| 16000050 | Internal Error. |
**示例:**
**示例:**
```
j
s
```
t
s
import
Ability
from
'
@ohos.app
lication.
Ability
'
;
import
Ability
from
'
@ohos.app
.ability.UI
Ability
'
;
var
method
=
'
call_Function
'
;
var
method
=
'
call_Function
'
;
export
default
class
MainAbility
extends
Ability
{
export
default
class
MainAbility
extends
Ability
{
onCreate
(
want
,
launchParam
)
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
Callee onCreate is called
'
);
console
.
log
(
'
Callee onCreate is called
'
);
this
.
callee
.
off
(
method
);
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;
(msg: string): void;
...
@@ -644,7 +711,7 @@ off(method: string): void;
...
@@ -644,7 +711,7 @@ off(method: string): void;
| -------- | -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- | -------- |
| (msg: string) | function | 是 | 否 | 调用者注册的侦听器函数接口的原型。 |
| (msg: string) | function | 是 | 否 | 调用者注册的侦听器函数接口的原型。 |
## CalleeCall
B
ack
## CalleeCall
b
ack
(indata: rpc.MessageParcel): rpc.Sequenceable;
(indata: rpc.MessageParcel): rpc.Sequenceable;
...
...
zh-cn/application-dev/reference/apis/js-apis-extension-context.md
浏览文件 @
1829ffc8
...
@@ -31,7 +31,7 @@ ExtensionContext主要用于查询所属Extension的信息、Module的配置信
...
@@ -31,7 +31,7 @@ ExtensionContext主要用于查询所属Extension的信息、Module的配置信
三个Module内都定义一个相同名称的ServiceExtension:
三个Module内都定义一个相同名称的ServiceExtension:
```
js
```
js
import
ServiceExtension
from
'
@ohos.app
lication
.ServiceExtensionAbility
'
import
ServiceExtension
from
'
@ohos.app
.ability
.ServiceExtensionAbility
'
import
Want
from
'
@ohos.application.Want
'
import
Want
from
'
@ohos.application.Want
'
export
default
class
TheServiceExtension
extends
ServiceExtension
{
export
default
class
TheServiceExtension
extends
ServiceExtension
{
onCreate
(
want
:
Want
)
{
onCreate
(
want
:
Want
)
{
...
@@ -61,7 +61,7 @@ export default class TheServiceExtension extends ServiceExtension {
...
@@ -61,7 +61,7 @@ export default class TheServiceExtension extends ServiceExtension {
在entry的MainAbility的onCreate回调内启动ServiceExtension
在entry的MainAbility的onCreate回调内启动ServiceExtension
```
js
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
import
Ability
from
'
@ohos.app
.ability
.Ability
'
export
default
class
MainAbility
extends
Ability
{
export
default
class
MainAbility
extends
Ability
{
onCreate
(
want
,
launchParam
)
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
"
[Demo] MainAbility onCreate
"
);
console
.
log
(
"
[Demo] MainAbility onCreate
"
);
...
...
zh-cn/application-dev/reference/apis/js-apis-service-extension-context.md
浏览文件 @
1829ffc8
...
@@ -13,16 +13,18 @@ ServiceExtensionContext模块提供ServiceExtensionAbility具有的能力和接
...
@@ -13,16 +13,18 @@ ServiceExtensionContext模块提供ServiceExtensionAbility具有的能力和接
在使用ServiceExtensionContext的功能前,需要通过ServiceExtensionAbility子类实例获取。
在使用ServiceExtensionContext的功能前,需要通过ServiceExtensionAbility子类实例获取。
```
js
```
ts
import
ServiceExtensionAbility
from
'
@ohos.application.ServiceExtensionAbility
'
;
import
ServiceExtensionAbility
from
'
@ohos.app.ability.ServiceExtensionAbility
'
;
let
context
=
undefined
;
class
MainAbility
extends
ServiceExtensionAbility
{
class
MainAbility
extends
ServiceExtensionAbility
{
onCreate
()
{
onCreate
()
{
let
context
=
this
.
context
;
context
=
this
.
context
;
}
}
}
}
```
```
## startAbility
##
ServiceExtensionContext.
startAbility
startAbility(want: Want, callback: AsyncCallback
<
void
>
): void;
startAbility(want: Want, callback: AsyncCallback
<
void
>
): void;
...
@@ -39,18 +41,57 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
...
@@ -39,18 +41,57 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | Want类型参数,传入需要启动的ability的信息,如ability名称,包名等。 |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | Want类型参数,传入需要启动的ability的信息,如ability名称,包名等。 |
| callback | AsyncCallback
<
void
>
| 否 | 回调函数,返回接口调用是否成功的结果。 |
| callback | AsyncCallback
<
void
>
| 否 | 回调函数,返回接口调用是否成功的结果。 |
**错误码:**
| 错误码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
```
ts
let
want
=
{
var
want
=
{
"
bundleName
"
:
"
com.example.myapp
"
,
bundleName
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
MyAbility
"
};
abilityName
:
"
MyAbility
"
this
.
context
.
startAbility
(
want
,
(
err
)
=>
{
};
console
.
log
(
'
startAbility result:
'
+
JSON
.
stringify
(
err
));
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>;
startAbility(want: Want, options?: StartOptions): Promise
\<
void>;
...
@@ -73,22 +114,60 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>;
...
@@ -73,22 +114,60 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>;
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
| 错误码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
```
ts
let
want
=
{
var
want
=
{
"
bundleName
"
:
"
com.example.myapp
"
,
bundleName
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
MyAbility
"
abilityName
:
"
MyAbility
"
};
};
this
.
context
.
startAbility
(
want
).
then
((
data
)
=>
{
var
options
=
{
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
windowMode
:
0
,
}).
catch
((
error
)
=>
{
};
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
});
try
{
this
.
context
.
startAbility
(
want
,
options
)
.
then
((
data
)
=>
{
// 执行正常业务
console
.
log
(
'
startAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## startAbility
##
ServiceExtensionContext.
startAbility
startAbility(want: Want, options: StartOptions, callback: AsyncCallback
<
void
>
): void
startAbility(want: Want, options: StartOptions, callback: AsyncCallback
<
void
>
): void
...
@@ -106,20 +185,58 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
...
@@ -106,20 +185,58 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 是 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
<
void
>
| 是 | callback形式返回启动结果。 |
| callback | AsyncCallback
<
void
>
| 是 | callback形式返回启动结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
options
=
{
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
};
this
.
context
.
startAbility
(
want
,
options
,
(
error
)
=>
{
console
.
log
(
"
error.code =
"
+
error
.
code
)
try
{
})
this
.
context
.
startAbility
(
want
,
options
,
(
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
));
}
```
```
## ServiceExtensionContext.startAbilityWithAccount
## ServiceExtensionContext.startAbilityWithAccount
...
@@ -140,20 +257,58 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
...
@@ -140,20 +257,58 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
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
## ServiceExtensionContext.startAbilityWithAccount
...
@@ -174,21 +329,60 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
...
@@ -174,21 +329,60 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 否 | 启动Ability所携带的参数。 |
| options |
[
StartOptions
](
js-apis-application-StartOptions.md
)
| 否 | 启动Ability所携带的参数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
var
options
=
{
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,25 +410,60 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
...
@@ -216,25 +410,60 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
var
options
=
{
var
options
=
{
windowMode
:
0
,
windowMode
:
0
};
};
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
options
)
.
then
((
data
)
=>
{
try
{
console
.
log
(
'
---------- startAbilityWithAccount success, data: -----------
'
,
data
);
this
.
context
.
startAbilityWithAccount
(
want
,
accountId
,
options
)
})
.
then
((
data
)
=>
{
.
catch
((
err
)
=>
{
// 执行正常业务
console
.
log
(
'
---------- startAbilityWithAccount fail, err: -----------
'
,
err
);
console
.
log
(
'
startAbilityWithAccount succeed
'
);
})
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## ServiceExtensionContext.startServiceExtensionAbility
## ServiceExtensionContext.startServiceExtensionAbility
...
@@ -254,17 +483,48 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
...
@@ -254,17 +483,48 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 启动Ability的want信息。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
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
## ServiceExtensionContext.startServiceExtensionAbility
...
@@ -289,21 +549,48 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
...
@@ -289,21 +549,48 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
this
.
context
.
startServiceExtensionAbility
(
want
)
.
then
((
data
)
=>
{
try
{
console
.
log
(
'
---------- startServiceExtensionAbility success, data: -----------
'
,
data
);
this
.
context
.
startServiceExtensionAbility
(
want
)
})
.
then
((
data
)
=>
{
.
catch
((
err
)
=>
{
// 执行正常业务
console
.
log
(
'
---------- startServiceExtensionAbility fail, err: -----------
'
,
err
);
console
.
log
(
'
startServiceExtensionAbility succeed
'
);
})
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## ServiceExtensionContext.startServiceExtensionAbilityWithAccount
## ServiceExtensionContext.startServiceExtensionAbilityWithAccount
...
@@ -326,18 +613,51 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
...
@@ -326,18 +613,51 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 启动Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
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
## ServiceExtensionContext.startServiceExtensionAbilityWithAccount
...
@@ -365,22 +685,50 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
...
@@ -365,22 +685,50 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
((
data
)
=>
{
try
{
console
.
log
(
'
---------- startServiceExtensionAbilityWithAccount success, data: -----------
'
,
data
);
this
.
context
.
startServiceExtensionAbilityWithAccount
(
want
,
accountId
)
})
.
then
((
data
)
=>
{
.
catch
((
err
)
=>
{
// 执行正常业务
console
.
log
(
'
---------- startServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
console
.
log
(
'
startServiceExtensionAbilityWithAccount succeed
'
);
})
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
startServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## ServiceExtensionContext.stopServiceExtensionAbility
## ServiceExtensionContext.stopServiceExtensionAbility
...
@@ -400,17 +748,45 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
...
@@ -400,17 +748,45 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 停止Ability的want信息。 |
| want |
[
Want
](
js-apis-application-Want.md
)
| 是 | 停止Ability的want信息。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 停止Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 停止Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
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
## ServiceExtensionContext.stopServiceExtensionAbility
...
@@ -435,21 +811,45 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
...
@@ -435,21 +811,45 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
this
.
context
.
stopServiceExtensionAbility
(
want
)
.
then
((
data
)
=>
{
try
{
console
.
log
(
'
---------- stopServiceExtensionAbility success, data: -----------
'
,
data
);
this
.
context
.
stopServiceExtensionAbility
(
want
)
})
.
then
((
data
)
=>
{
.
catch
((
err
)
=>
{
// 执行正常业务
console
.
log
(
'
---------- stopServiceExtensionAbility fail, err: -----------
'
,
err
);
console
.
log
(
'
stopServiceExtensionAbility succeed
'
);
})
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## ServiceExtensionContext.stopServiceExtensionAbilityWithAccount
## ServiceExtensionContext.stopServiceExtensionAbilityWithAccount
...
@@ -472,18 +872,47 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
...
@@ -472,18 +872,47 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
| accountId | number | 是 | 需要停止的系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| accountId | number | 是 | 需要停止的系统帐号的帐号ID,详情参考
[
getCreatedOsAccountsCount
](
js-apis-osAccount.md#getosaccountlocalidfromprocess
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 停止Ability的回调函数。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 停止Ability的回调函数。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
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
## ServiceExtensionContext.stopServiceExtensionAbilityWithAccount
...
@@ -511,22 +940,47 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
...
@@ -511,22 +940,47 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
)
.
then
((
data
)
=>
{
try
{
console
.
log
(
'
---------- stopServiceExtensionAbilityWithAccount success, data: -----------
'
,
data
);
this
.
context
.
stopServiceExtensionAbilityWithAccount
(
want
,
accountId
)
})
.
then
((
data
)
=>
{
.
catch
((
err
)
=>
{
// 执行正常业务
console
.
log
(
'
---------- stopServiceExtensionAbilityWithAccount fail, err: -----------
'
,
err
);
console
.
log
(
'
stopServiceExtensionAbilityWithAccount succeed
'
);
})
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
stopServiceExtensionAbilityWithAccount failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## ServiceExtensionContext.terminateSelf
## ServiceExtensionContext.terminateSelf
...
@@ -545,11 +999,29 @@ terminateSelf(callback: AsyncCallback<void>): void;
...
@@ -545,11 +999,29 @@ terminateSelf(callback: AsyncCallback<void>): void;
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
void
>
| 否 | 回调函数,返回接口调用是否成功的结果。 |
| callback | AsyncCallback
<
void
>
| 否 | 回调函数,返回接口调用是否成功的结果。 |
**错误码:**
| 错误码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
```
ts
this
.
context
.
terminateSelf
((
err
)
=>
{
this
.
context
.
terminateSelf
((
error
)
=>
{
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringify
(
err
));
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 +1041,33 @@ terminateSelf(): Promise<void>;
...
@@ -569,19 +1041,33 @@ terminateSelf(): Promise<void>;
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
this
.
context
.
terminateSelf
().
then
((
data
)
=>
{
this
.
context
.
terminateSelf
().
then
((
data
)
=>
{
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
// 执行正常业务
console
.
log
(
'
terminateSelf succeed
'
);
}).
catch
((
error
)
=>
{
}).
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绑定。
将一个Ability与服务类型的Ability绑定。
...
@@ -602,24 +1088,44 @@ connectAbility(want: Want, options: ConnectOptions): number;
...
@@ -602,24 +1088,44 @@ connectAbility(want: Want, options: ConnectOptions): number;
| -------- | -------- |
| -------- | -------- |
| number | 返回一个number,后续根据这个number去断开连接。 |
| number | 返回一个number,后续根据这个number去断开连接。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
let
want
=
{
var
want
=
{
"
bundleName
"
:
"
com.example.myapp
"
,
bundleName
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
MyAbility
"
abilityName
:
"
MyAbility
"
};
};
let
options
=
{
var
options
=
{
onConnect
(
elementName
,
remote
)
{
console
.
log
(
'
----------- onConnect -----------
'
)
},
onConnect
(
elementName
,
remote
)
{
console
.
log
(
'
----------- onConnect -----------
'
)
},
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onFailed
(
code
)
{
console
.
log
(
'
----------- onFailed -----------
'
)
}
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将当前能力连接到一个能力。
使用AbilityInfo.AbilityType.SERVICE模板和account将当前能力连接到一个能力。
...
@@ -641,13 +1147,26 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
...
@@ -641,13 +1147,26 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
| -------- | -------- |
| -------- | -------- |
| number | 返回Ability连接的结果code。 |
| number | 返回Ability连接的结果code。 |
**错误码:**
| 错误码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. |
**示例:**
**示例:**
```
j
s
```
t
s
var
want
=
{
var
want
=
{
"
deviceId
"
:
""
,
deviceId
:
""
,
"
bundleName
"
:
"
com.extreme.test
"
,
bundleName
:
"
com.extreme.test
"
,
"
abilityName
"
:
"
MainAbility
"
abilityName
:
"
MainAbility
"
};
};
var
accountId
=
100
;
var
accountId
=
100
;
var
options
=
{
var
options
=
{
...
@@ -655,13 +1174,20 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
...
@@ -655,13 +1174,20 @@ connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onDisconnect
(
elementName
)
{
console
.
log
(
'
----------- onDisconnect -----------
'
)
},
onFailed
(
code
)
{
console
.
log
(
'
----------- onFailed -----------
'
)
}
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解绑。
将一个Ability与绑定的服务类型的Ability解绑。
...
@@ -676,19 +1202,44 @@ disconnectAbility(connection: number, callback:AsyncCallback<void>): void;
...
@@ -676,19 +1202,44 @@ disconnectAbility(connection: number, callback:AsyncCallback<void>): void;
| connection | number | 是 | 在connectAbility中返回的number。 |
| connection | number | 是 | 在connectAbility中返回的number。 |
| callback | AsyncCallback
<
void
>
| 否 | 回调函数,返回接口调用是否成功的结果。 |
| callback | AsyncCallback
<
void
>
| 否 | 回调函数,返回接口调用是否成功的结果。 |
**错误码:**
| 错误码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
```
ts
let
connection
=
1
// connection为connectServiceExtensionAbility中的返回值
this
.
context
.
disconnectAbility
(
connection
,
(
err
)
=>
{
var
connection
=
1
;
// connection为connectAbility中的返回值
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringify
(
err
));
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返回结果。
将一个Ability与绑定的服务类型的Ability解绑。通过Promise返回结果。
...
@@ -707,17 +1258,40 @@ disconnectAbility(connection: number): Promise<void>;
...
@@ -707,17 +1258,40 @@ disconnectAbility(connection: number): Promise<void>;
| 类型 | 说明 |
| 类型 | 说明 |
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
| Promise
<
void
>
| 返回一个Promise,包含接口的结果。 |
**错误码:**
| 错误码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
```
ts
let
connection
=
1
// connection为connectAbility中的返回值
this
.
context
.
disconnectAbility
(
connection
).
then
((
data
)
=>
{
var
connection
=
1
;
// connection为connectAbility中的返回值
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
try
{
}).
catch
((
error
)
=>
{
this
.
context
.
disconnectServiceExtensionAbility
(
connection
)
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
.
then
((
data
)
=>
{
});
// 执行正常业务
console
.
log
(
'
disconnectServiceExtensionAbility succeed
'
);
})
.
catch
((
error
)
=>
{
// 处理业务逻辑错误
console
.
log
(
'
disconnectServiceExtensionAbility failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
```
## ServiceExtensionContext.startAbilityByCall
## ServiceExtensionContext.startAbilityByCall
...
@@ -742,10 +1316,26 @@ startAbilityByCall(want: Want): Promise<Caller>;
...
@@ -742,10 +1316,26 @@ startAbilityByCall(want: Want): Promise<Caller>;
| -------- | -------- |
| -------- | -------- |
| Promise
<
Caller
>
| 获取要通讯的caller对象。 |
| Promise
<
Caller
>
| 获取要通讯的caller对象。 |
**错误码:**
| 错误码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
;
```
ts
var
caller
=
undefined
;
// 后台启动Ability,不配置parameters
// 后台启动Ability,不配置parameters
var
wantBackground
=
{
var
wantBackground
=
{
...
@@ -754,13 +1344,29 @@ startAbilityByCall(want: Want): Promise<Caller>;
...
@@ -754,13 +1344,29 @@ startAbilityByCall(want: Want): Promise<Caller>;
abilityName
:
"
MainAbility
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
deviceId
:
""
};
};
this
.
context
.
startAbilityByCall
(
wantBackground
)
.
then
((
obj
)
=>
{
try
{
this
.
context
.
startAbilityByCall
(
wantBackground
)
.
then
((
obj
)
=>
{
// 执行正常业务
caller
=
obj
;
caller
=
obj
;
console
.
log
(
'
GetCaller Success
'
);
console
.
log
(
'
startAbilityByCall succeed
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
console
.
log
(
`GetCaller failed with
${
error
}
`
);
// 处理业务逻辑错误
});
console
.
log
(
'
startAbilityByCall failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
});
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
log
(
'
error.code:
'
+
JSON
.
stringify
(
paramError
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
paramError
.
message
));
}
```
前台启动:
```
ts
var
caller
=
undefined
;
// 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true
// 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true
var
wantForeground
=
{
var
wantForeground
=
{
...
@@ -772,12 +1378,22 @@ startAbilityByCall(want: Want): Promise<Caller>;
...
@@ -772,12 +1378,22 @@ startAbilityByCall(want: Want): Promise<Caller>;
"
ohos.aafwk.param.callAbilityToForeground
"
:
true
"
ohos.aafwk.param.callAbilityToForeground
"
:
true
}
}
};
};
this
.
context
.
startAbilityByCall
(
wantForeground
)
.
then
((
obj
)
=>
{
try
{
this
.
context
.
startAbilityByCall
(
wantForeground
)
.
then
((
obj
)
=>
{
// 执行正常业务
caller
=
obj
;
caller
=
obj
;
console
.
log
(
'
GetCaller success
'
);
console
.
log
(
'
startAbilityByCall succeed
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
console
.
log
(
`GetCaller failed with
${
error
}
`
);
// 处理业务逻辑错误
});
console
.
log
(
'
startAbilityByCall failed, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录