提交 74984930 编写于 作者: H HuangXW

Context错误码整改

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