提交 a224a82f 编写于 作者: H HuangXW

删除错误码汇总文档的链接,修改示例代码

Signed-off-by: NHuangXW <huangxinwei4@huawei.com>
上级 74984930
...@@ -72,7 +72,7 @@ Ability配置标签示例如下: ...@@ -72,7 +72,7 @@ Ability配置标签示例如下:
``` ```
**2. 导入Ability模块** **2. 导入Ability模块**
```ts ```ts
import Ability from '@ohos.app.ability.Ability' import Ability from '@ohos.app.ability.UIAbility'
``` ```
**3. 定义约定的序列化数据** **3. 定义约定的序列化数据**
...@@ -142,7 +142,7 @@ export default class CalleeAbility extends Ability { ...@@ -142,7 +142,7 @@ export default class CalleeAbility extends Ability {
### 访问Callee被调用端 ### 访问Callee被调用端
**1. 导入Ability模块** **1. 导入Ability模块**
```ts ```ts
import Ability from '@ohos.app.ability.Ability' import Ability from '@ohos.app.ability.UIAbility'
``` ```
**2. 获取Caller通信接口** **2. 获取Caller通信接口**
......
...@@ -13,8 +13,8 @@ AbilityContext模块提供允许访问特定Ability的资源的能力,包括 ...@@ -13,8 +13,8 @@ AbilityContext模块提供允许访问特定Ability的资源的能力,包括
在使用AbilityContext的功能前,需要通过Ability子类实例获取。 在使用AbilityContext的功能前,需要通过Ability子类实例获取。
```js ```ts
import Ability from '@ohos.app.ability.Ability'; import Ability from '@ohos.app.ability.UIAbility';
let context = undefined; let context = undefined;
class MainAbility extends Ability { class MainAbility extends Ability {
...@@ -51,8 +51,6 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void; ...@@ -51,8 +51,6 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -77,10 +75,10 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void; ...@@ -77,10 +75,10 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"bundleName": "com.example.myapp", bundleName: "com.example.myapp",
"abilityName": "MyAbility" abilityName: "MyAbility"
}; };
try { try {
...@@ -120,9 +118,7 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void& ...@@ -120,9 +118,7 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md) | 错误码ID | 错误信息
| 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. | | 401 | Invalid input parameter. |
...@@ -146,11 +142,11 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void& ...@@ -146,11 +142,11 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var options = { var options = {
windowMode: 0 windowMode: 0
...@@ -197,8 +193,6 @@ startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;; ...@@ -197,8 +193,6 @@ startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -223,10 +217,10 @@ startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;; ...@@ -223,10 +217,10 @@ startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"bundleName": "com.example.myapp", bundleName: "com.example.myapp",
"abilityName": "MyAbility" abilityName: "MyAbility"
}; };
var options = { var options = {
windowMode: 0, windowMode: 0,
...@@ -240,8 +234,8 @@ startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;; ...@@ -240,8 +234,8 @@ startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startAbility failed, error.code: ' + JSON.stringify(err.code) + console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -255,7 +249,7 @@ startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;; ...@@ -255,7 +249,7 @@ startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): void; startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): void;
启动Ability并在结束的时候返回执行结果(callback形式)。 启动Ability并在该Ability退出的时候返回执行结果(callback形式)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
...@@ -268,8 +262,6 @@ startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): ...@@ -268,8 +262,6 @@ startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;):
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -294,11 +286,11 @@ startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): ...@@ -294,11 +286,11 @@ startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;):
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
try { try {
...@@ -324,7 +316,7 @@ startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): ...@@ -324,7 +316,7 @@ startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;):
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void; startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void;
启动Ability并在结束的时候返回执行结果(callback形式)。 启动Ability并在该Ability退出的时候返回执行结果(callback形式)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
...@@ -338,8 +330,6 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback ...@@ -338,8 +330,6 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -364,11 +354,11 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback ...@@ -364,11 +354,11 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var options = { var options = {
windowMode: 0, windowMode: 0,
...@@ -398,7 +388,7 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback ...@@ -398,7 +388,7 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityResult&gt;; startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityResult&gt;;
启动Ability并在结束的时候返回执行结果(promise形式)。 启动Ability并在该Ability退出的时候返回执行结果(promise形式)。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
...@@ -418,8 +408,6 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityRes ...@@ -418,8 +408,6 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityRes
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -444,10 +432,10 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityRes ...@@ -444,10 +432,10 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityRes
**示例:** **示例:**
```js ```ts
var want = { var want = {
"bundleName": "com.example.myapp", bundleName: "com.example.myapp",
"abilityName": "MyAbility" abilityName: "MyAbility"
}; };
var options = { var options = {
windowMode: 0, windowMode: 0,
...@@ -461,8 +449,8 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityRes ...@@ -461,8 +449,8 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityRes
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(err.code) + console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -493,8 +481,6 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC ...@@ -493,8 +481,6 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -520,11 +506,11 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC ...@@ -520,11 +506,11 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
...@@ -571,8 +557,6 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp ...@@ -571,8 +557,6 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -598,11 +582,11 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp ...@@ -598,11 +582,11 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
var options = { var options = {
...@@ -657,8 +641,6 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO ...@@ -657,8 +641,6 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -684,11 +666,11 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO ...@@ -684,11 +666,11 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
var options = { var options = {
...@@ -704,8 +686,8 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO ...@@ -704,8 +686,8 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startAbilityForResultWithAccount failed, error.code: ' + JSON.stringify(err.code) + console.log('startAbilityForResultWithAccount failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -732,8 +714,6 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void; ...@@ -732,8 +714,6 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -751,11 +731,11 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void; ...@@ -751,11 +731,11 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
try { try {
...@@ -794,8 +774,6 @@ startServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -794,8 +774,6 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -813,11 +791,11 @@ startServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -813,11 +791,11 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
try { try {
...@@ -828,8 +806,8 @@ startServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -828,8 +806,8 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startServiceExtensionAbility failed, error.code: ' + JSON.stringify(err.code) + console.log('startServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -860,8 +838,6 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: ...@@ -860,8 +838,6 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -876,11 +852,11 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: ...@@ -876,11 +852,11 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
...@@ -923,8 +899,6 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\ ...@@ -923,8 +899,6 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -943,11 +917,11 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\ ...@@ -943,11 +917,11 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
...@@ -959,8 +933,8 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\ ...@@ -959,8 +933,8 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(err.code) + console.log('startServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -987,8 +961,6 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void; ...@@ -987,8 +961,6 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1003,11 +975,11 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void; ...@@ -1003,11 +975,11 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
try { try {
...@@ -1046,8 +1018,6 @@ stopServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -1046,8 +1018,6 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1062,11 +1032,11 @@ stopServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -1062,11 +1032,11 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
try { try {
...@@ -1077,8 +1047,8 @@ stopServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -1077,8 +1047,8 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(err.code) + console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -1109,8 +1079,6 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: ...@@ -1109,8 +1079,6 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1126,11 +1094,11 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: ...@@ -1126,11 +1094,11 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
...@@ -1173,8 +1141,6 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\< ...@@ -1173,8 +1141,6 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1190,11 +1156,11 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\< ...@@ -1190,11 +1156,11 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
...@@ -1206,8 +1172,8 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\< ...@@ -1206,8 +1172,8 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('stopServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(err.code) + console.log('stopServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -1232,8 +1198,6 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void; ...@@ -1232,8 +1198,6 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1245,7 +1209,7 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void; ...@@ -1245,7 +1209,7 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
**示例:** **示例:**
```js ```ts
this.context.terminateSelf((error) => { this.context.terminateSelf((error) => {
if (error.code) { if (error.code) {
// 处理业务逻辑错误 // 处理业务逻辑错误
...@@ -1275,8 +1239,6 @@ terminateSelf(): Promise&lt;void&gt;; ...@@ -1275,8 +1239,6 @@ terminateSelf(): Promise&lt;void&gt;;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1288,7 +1250,7 @@ terminateSelf(): Promise&lt;void&gt;; ...@@ -1288,7 +1250,7 @@ terminateSelf(): Promise&lt;void&gt;;
**示例:** **示例:**
```js ```ts
this.context.terminateSelf().then((data) => { this.context.terminateSelf().then((data) => {
// 执行正常业务 // 执行正常业务
console.log('terminateSelf succeed'); console.log('terminateSelf succeed');
...@@ -1315,12 +1277,23 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;voi ...@@ -1315,12 +1277,23 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;voi
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | 是 | 返回给调用startAbilityForResult&nbsp;接口调用方的相关信息。 | | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | 是 | 返回给调用startAbilityForResult&nbsp;接口调用方的相关信息。 |
| callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回停止结果。 | | callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回停止结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:** **示例:**
```js ```ts
var want = { var want = {
"bundleName": "com.extreme.myapplication", bundleName: "com.extreme.myapplication",
"abilityName": "SecondAbility" abilityName: "SecondAbility"
} }
var resultCode = 100; var resultCode = 100;
// 返回给接口调用方AbilityResult信息 // 返回给接口调用方AbilityResult信息
...@@ -1328,10 +1301,23 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;voi ...@@ -1328,10 +1301,23 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;voi
want, want,
resultCode resultCode
} }
this.context.terminateSelfWithResult(abilityResult, (error) => {
console.log("terminateSelfWithResult is called = " + error.code) try {
this.context.terminateSelfWithResult(abilityResult, (error) => {
if (error.code) {
// 处理业务逻辑错误
console.log('terminateSelfWithResult failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
return;
} }
); // 执行正常业务
console.log('terminateSelfWithResult succeed');
});
} catch (paramError) {
// 处理入参错误异常
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
...@@ -1355,12 +1341,24 @@ terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;; ...@@ -1355,12 +1341,24 @@ terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | promise形式返回停止结果。 | | Promise&lt;void&gt; | promise形式返回停止结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16000001 | Input error. The specified ability name does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**示例:** **示例:**
```js ```ts
var want = { var want = {
"bundleName": "com.extreme.myapplication", bundleName: "com.extreme.myapplication",
"abilityName": "SecondAbility" abilityName: "SecondAbility"
} }
var resultCode = 100; var resultCode = 100;
// 返回给接口调用方AbilityResult信息 // 返回给接口调用方AbilityResult信息
...@@ -1368,10 +1366,23 @@ terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;; ...@@ -1368,10 +1366,23 @@ terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
want, want,
resultCode resultCode
} }
this.context.terminateSelfWithResult(abilityResult).then((result) => {
console.log("terminateSelfWithResult") try {
this.context.terminateSelfWithResult(abilityResult)
.then((data) => {
// 执行正常业务
console.log('terminateSelfWithResult succeed');
})
.catch((error) => {
// 处理业务逻辑错误
console.log('terminateSelfWithResult failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
});
} catch (paramError) {
// 处理入参错误异常
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
} }
)
``` ```
## AbilityContext.connectServiceExtensionAbility ## AbilityContext.connectServiceExtensionAbility
...@@ -1399,8 +1410,6 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number; ...@@ -1399,8 +1410,6 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1413,11 +1422,11 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number; ...@@ -1413,11 +1422,11 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var options = { var options = {
onConnect(elementName, remote) { console.log('----------- onConnect -----------') }, onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
...@@ -1464,8 +1473,6 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options ...@@ -1464,8 +1473,6 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1479,11 +1486,11 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options ...@@ -1479,11 +1486,11 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
var options = { var options = {
...@@ -1526,8 +1533,6 @@ disconnectServiceExtensionAbility(connection: number): Promise\<void>; ...@@ -1526,8 +1533,6 @@ disconnectServiceExtensionAbility(connection: number): Promise\<void>;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1539,7 +1544,7 @@ disconnectServiceExtensionAbility(connection: number): Promise\<void>; ...@@ -1539,7 +1544,7 @@ disconnectServiceExtensionAbility(connection: number): Promise\<void>;
**示例:** **示例:**
```js ```ts
// connection为connectAbility中的返回值 // connection为connectAbility中的返回值
var connection = 1; var connection = 1;
...@@ -1551,8 +1556,8 @@ disconnectServiceExtensionAbility(connection: number): Promise\<void>; ...@@ -1551,8 +1556,8 @@ disconnectServiceExtensionAbility(connection: number): Promise\<void>;
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('disconnectServiceExtensionAbility failed, error.code: ' + JSON.stringify(err.code) + console.log('disconnectServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -1580,8 +1585,6 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback\<vo ...@@ -1580,8 +1585,6 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback\<vo
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1593,7 +1596,7 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback\<vo ...@@ -1593,7 +1596,7 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback\<vo
**示例:** **示例:**
```js ```ts
// connection为connectServiceExtensionAbility中的返回值 // connection为connectServiceExtensionAbility中的返回值
var connection = 1; var connection = 1;
...@@ -1637,7 +1640,9 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;; ...@@ -1637,7 +1640,9 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
**示例:** **示例:**
```js 后台启动:
```ts
var caller = undefined; var caller = undefined;
// 后台启动Ability,不配置parameters // 后台启动Ability,不配置parameters
...@@ -1647,13 +1652,29 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;; ...@@ -1647,13 +1652,29 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
abilityName: "MainAbility", abilityName: "MainAbility",
deviceId: "" deviceId: ""
}; };
this.context.startAbilityByCall(wantBackground)
.then((obj) => { try {
this.context.startAbilityByCall(wantBackground)
.then((obj) => {
// 执行正常业务
caller = obj; caller = obj;
console.log('GetCaller success'); console.log('startAbilityByCall succeed');
}).catch((error) => { }).catch((error) => {
console.log(`GetCaller failed with ${error}`); // 处理业务逻辑错误
}); console.log('startAbilityByCall failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
});
} catch (paramError) {
// 处理入参错误异常
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
前台启动:
```ts
var caller = undefined;
// 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true // 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true
var wantForeground = { var wantForeground = {
...@@ -1665,13 +1686,23 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;; ...@@ -1665,13 +1686,23 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
"ohos.aafwk.param.callAbilityToForeground": true "ohos.aafwk.param.callAbilityToForeground": true
} }
}; };
this.context.startAbilityByCall(wantForeground)
.then((obj) => { try {
this.context.startAbilityByCall(wantForeground)
.then((obj) => {
// 执行正常业务
caller = obj; caller = obj;
console.log('GetCaller success'); console.log('startAbilityByCall succeed');
}).catch((error) => { }).catch((error) => {
console.log(`GetCaller failed with ${error}`); // 处理业务逻辑错误
}); console.log('startAbilityByCall failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
});
} catch (paramError) {
// 处理入参错误异常
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## AbilityContext.startAbilityWithAccount ## AbilityContext.startAbilityWithAccount
...@@ -1696,8 +1727,6 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\< ...@@ -1696,8 +1727,6 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1723,11 +1752,11 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\< ...@@ -1723,11 +1752,11 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
...@@ -1773,8 +1802,6 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca ...@@ -1773,8 +1802,6 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1800,11 +1827,11 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca ...@@ -1800,11 +1827,11 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
var options = { var options = {
...@@ -1852,8 +1879,6 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): ...@@ -1852,8 +1879,6 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1879,11 +1904,11 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): ...@@ -1879,11 +1904,11 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
var options = { var options = {
...@@ -1898,8 +1923,8 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): ...@@ -1898,8 +1923,8 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(err.code) + console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -1925,7 +1950,7 @@ requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: As ...@@ -1925,7 +1950,7 @@ requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: As
**示例:** **示例:**
```js ```ts
var permissions=['com.example.permission'] var permissions=['com.example.permission']
this.context.requestPermissionsFromUser(permissions,(result) => { this.context.requestPermissionsFromUser(permissions,(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringify(result)); console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
...@@ -1956,7 +1981,7 @@ requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;Permis ...@@ -1956,7 +1981,7 @@ requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;Permis
**示例:** **示例:**
```js ```ts
var permissions=['com.example.permission'] var permissions=['com.example.permission']
this.context.requestPermissionsFromUser(permissions).then((data) => { this.context.requestPermissionsFromUser(permissions).then((data) => {
console.log('success:' + JSON.stringify(data)); console.log('success:' + JSON.stringify(data));
...@@ -1984,7 +2009,7 @@ setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void; ...@@ -1984,7 +2009,7 @@ setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void;
**示例:** **示例:**
```js ```ts
this.context.setMissionLabel("test",(result) => { this.context.setMissionLabel("test",(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringify(result)); console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
}); });
...@@ -2013,7 +2038,7 @@ setMissionLabel(label: string): Promise&lt;void&gt;; ...@@ -2013,7 +2038,7 @@ setMissionLabel(label: string): Promise&lt;void&gt;;
**示例:** **示例:**
```js ```ts
this.context.setMissionLabel("test").then(() => { this.context.setMissionLabel("test").then(() => {
console.log('success'); console.log('success');
}).catch((error) => { }).catch((error) => {
...@@ -2039,7 +2064,7 @@ setMissionIcon(icon: image.PixelMap, callback:AsyncCallback\<void>): void; ...@@ -2039,7 +2064,7 @@ setMissionIcon(icon: image.PixelMap, callback:AsyncCallback\<void>): void;
**示例:** **示例:**
```js ```ts
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
var imagePixelMap; var imagePixelMap;
var color = new ArrayBuffer(0); var color = new ArrayBuffer(0);
...@@ -2086,7 +2111,7 @@ setMissionIcon(icon: image.PixelMap): Promise\<void>; ...@@ -2086,7 +2111,7 @@ setMissionIcon(icon: image.PixelMap): Promise\<void>;
**示例:** **示例:**
```js ```ts
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
var imagePixelMap; var imagePixelMap;
var color = new ArrayBuffer(0); var color = new ArrayBuffer(0);
...@@ -2127,7 +2152,7 @@ restoreWindowStage(localStorage: LocalStorage) : void; ...@@ -2127,7 +2152,7 @@ restoreWindowStage(localStorage: LocalStorage) : void;
**示例:** **示例:**
```js ```ts
var storage = new LocalStorage(); var storage = new LocalStorage();
this.context.restoreWindowStage(storage); this.context.restoreWindowStage(storage);
``` ```
...@@ -2148,7 +2173,7 @@ isTerminating(): boolean; ...@@ -2148,7 +2173,7 @@ isTerminating(): boolean;
**示例:** **示例:**
```js ```ts
var isTerminating = this.context.isTerminating(); var isTerminating = this.context.isTerminating();
console.log('ability state :' + isTerminating); console.log('ability state :' + isTerminating);
``` ```
\ No newline at end of file
...@@ -46,7 +46,7 @@ Ability创建时回调,执行初始化业务逻辑操作。 ...@@ -46,7 +46,7 @@ Ability创建时回调,执行初始化业务逻辑操作。
**示例:** **示例:**
```js ```ts
class myAbility extends Ability { class myAbility extends Ability {
onCreate(want, param) { onCreate(want, param) {
console.log('onCreate, want:' + want.abilityName); console.log('onCreate, want:' + want.abilityName);
...@@ -71,7 +71,7 @@ onWindowStageCreate(windowStage: window.WindowStage): void ...@@ -71,7 +71,7 @@ onWindowStageCreate(windowStage: window.WindowStage): void
**示例:** **示例:**
```js ```ts
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
...@@ -90,7 +90,7 @@ onWindowStageDestroy(): void ...@@ -90,7 +90,7 @@ onWindowStageDestroy(): void
**示例:** **示例:**
```js ```ts
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageDestroy() { onWindowStageDestroy() {
console.log('onWindowStageDestroy'); console.log('onWindowStageDestroy');
...@@ -115,7 +115,7 @@ onWindowStageRestore(windowStage: window.WindowStage): void ...@@ -115,7 +115,7 @@ onWindowStageRestore(windowStage: window.WindowStage): void
**示例:** **示例:**
```js ```ts
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageRestore(windowStage) { onWindowStageRestore(windowStage) {
console.log('onWindowStageRestore'); console.log('onWindowStageRestore');
...@@ -134,7 +134,7 @@ Ability生命周期回调,在销毁时回调,执行资源清理等操作。 ...@@ -134,7 +134,7 @@ Ability生命周期回调,在销毁时回调,执行资源清理等操作。
**示例:** **示例:**
```js ```ts
class myAbility extends Ability { class myAbility extends Ability {
onDestroy() { onDestroy() {
console.log('onDestroy'); console.log('onDestroy');
...@@ -153,7 +153,7 @@ Ability生命周期回调,当应用从后台转到前台时触发。 ...@@ -153,7 +153,7 @@ Ability生命周期回调,当应用从后台转到前台时触发。
**示例:** **示例:**
```js ```ts
class myAbility extends Ability { class myAbility extends Ability {
onForeground() { onForeground() {
console.log('onForeground'); console.log('onForeground');
...@@ -172,7 +172,7 @@ Ability生命周期回调,当应用从前台转到后台时触发。 ...@@ -172,7 +172,7 @@ Ability生命周期回调,当应用从前台转到后台时触发。
**示例:** **示例:**
```js ```ts
class myAbility extends Ability { class myAbility extends Ability {
onBackground() { onBackground() {
console.log('onBackground'); console.log('onBackground');
...@@ -203,7 +203,7 @@ onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult; ...@@ -203,7 +203,7 @@ onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
**示例:** **示例:**
```js ```ts
import AbilityConstant from "@ohos.application.AbilityConstant" import AbilityConstant from "@ohos.application.AbilityConstant"
class myAbility extends Ability { class myAbility extends Ability {
onContinue(wantParams) { onContinue(wantParams) {
...@@ -232,7 +232,7 @@ onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void; ...@@ -232,7 +232,7 @@ onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;
**示例:** **示例:**
```js ```ts
class myAbility extends Ability { class myAbility extends Ability {
onNewWant(want) { onNewWant(want) {
console.log('onNewWant, want:' + want.abilityName); console.log('onNewWant, want:' + want.abilityName);
...@@ -257,7 +257,7 @@ onConfigurationUpdated(config: Configuration): void; ...@@ -257,7 +257,7 @@ onConfigurationUpdated(config: Configuration): void;
**示例:** **示例:**
```js ```ts
class myAbility extends Ability { class myAbility extends Ability {
onConfigurationUpdated(config) { onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, config:' + JSON.stringify(config)); console.log('onConfigurationUpdated, config:' + JSON.stringify(config));
...@@ -281,7 +281,7 @@ dump(params: Array\<string>): Array\<string>; ...@@ -281,7 +281,7 @@ dump(params: Array\<string>): Array\<string>;
**示例:** **示例:**
```js ```ts
class myAbility extends Ability { class myAbility extends Ability {
dump(params) { dump(params) {
console.log('dump, params:' + JSON.stringify(params)); console.log('dump, params:' + JSON.stringify(params));
...@@ -306,7 +306,7 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void; ...@@ -306,7 +306,7 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
**示例:** **示例:**
```js ```ts
class myAbility extends Ability { class myAbility extends Ability {
onMemoryLevel(level) { onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level)); console.log('onMemoryLevel, level:' + JSON.stringify(level));
...@@ -343,8 +343,6 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;; ...@@ -343,8 +343,6 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -355,8 +353,8 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;; ...@@ -355,8 +353,8 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
**示例:** **示例:**
```js ```ts
import Ability from '@ohos.app.ability.Ability'; import Ability from '@ohos.app.ability.UIAbility';
class MyMessageAble{ // 自定义的Sequenceable数据结构 class MyMessageAble{ // 自定义的Sequenceable数据结构
name:"" name:""
str:"" str:""
...@@ -388,7 +386,7 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;; ...@@ -388,7 +386,7 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
deviceId: "" deviceId: ""
}).then((obj) => { }).then((obj) => {
caller = obj; caller = obj;
let msg = new MyMessageAble(1, "world"); // 参考Sequenceable数据定义 let msg = new MyMessageAble("msg", "world"); // 参考Sequenceable数据定义
caller.call(method, msg) caller.call(method, msg)
.then(() => { .then(() => {
console.log('Caller call() called'); console.log('Caller call() called');
...@@ -429,8 +427,6 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessagePa ...@@ -429,8 +427,6 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessagePa
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -441,8 +437,8 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessagePa ...@@ -441,8 +437,8 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessagePa
**示例:** **示例:**
```js ```ts
import Ability from '@ohos.app.ability.Ability'; import Ability from '@ohos.app.ability.UIAbility';
class MyMessageAble{ class MyMessageAble{
name:"" name:""
str:"" str:""
...@@ -504,8 +500,6 @@ release(): void; ...@@ -504,8 +500,6 @@ release(): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 401 | Invalid input parameter. | | 401 | Invalid input parameter. |
...@@ -515,8 +509,8 @@ release(): void; ...@@ -515,8 +509,8 @@ release(): void;
**示例:** **示例:**
```js ```ts
import Ability from '@ohos.app.ability.Ability'; import Ability from '@ohos.app.ability.UIAbility';
var caller; var caller;
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
...@@ -558,8 +552,6 @@ release(): void; ...@@ -558,8 +552,6 @@ release(): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 401 | Invalid input parameter. | | 401 | Invalid input parameter. |
...@@ -568,8 +560,8 @@ release(): void; ...@@ -568,8 +560,8 @@ release(): void;
**示例:** **示例:**
```js ```ts
import Ability from '@ohos.app.ability.Ability'; import Ability from '@ohos.app.ability.UIAbility';
var caller; var caller;
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
...@@ -617,8 +609,6 @@ on(method: string, callback: CalleeCallBack): void; ...@@ -617,8 +609,6 @@ on(method: string, callback: CalleeCallBack): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 401 | Invalid input parameter. | | 401 | Invalid input parameter. |
...@@ -627,8 +617,8 @@ on(method: string, callback: CalleeCallBack): void; ...@@ -627,8 +617,8 @@ on(method: string, callback: CalleeCallBack): void;
**示例:** **示例:**
```js ```ts
import Ability from '@ohos.app.ability.Ability'; import Ability from '@ohos.app.ability.UIAbility';
class MyMessageAble{ class MyMessageAble{
name:"" name:""
str:"" str:""
...@@ -686,8 +676,6 @@ off(method: string): void; ...@@ -686,8 +676,6 @@ off(method: string): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 401 | Invalid input parameter. | | 401 | Invalid input parameter. |
...@@ -697,8 +685,8 @@ off(method: string): void; ...@@ -697,8 +685,8 @@ off(method: string): void;
**示例:** **示例:**
```js ```ts
import Ability from '@ohos.app.ability.Ability'; import Ability from '@ohos.app.ability.UIAbility';
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) {
......
...@@ -13,7 +13,7 @@ ServiceExtensionContext模块提供ServiceExtensionAbility具有的能力和接 ...@@ -13,7 +13,7 @@ ServiceExtensionContext模块提供ServiceExtensionAbility具有的能力和接
在使用ServiceExtensionContext的功能前,需要通过ServiceExtensionAbility子类实例获取。 在使用ServiceExtensionContext的功能前,需要通过ServiceExtensionAbility子类实例获取。
```js ```ts
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
let context = undefined; let context = undefined;
...@@ -43,8 +43,6 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void; ...@@ -43,8 +43,6 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -69,10 +67,10 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void; ...@@ -69,10 +67,10 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"bundleName": "com.example.myapp", bundleName: "com.example.myapp",
"abilityName": "MyAbility" abilityName: "MyAbility"
}; };
try { try {
...@@ -118,8 +116,6 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>; ...@@ -118,8 +116,6 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -144,10 +140,10 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>; ...@@ -144,10 +140,10 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"bundleName": "com.example.myapp", bundleName: "com.example.myapp",
"abilityName": "MyAbility" abilityName: "MyAbility"
}; };
var options = { var options = {
windowMode: 0, windowMode: 0,
...@@ -161,8 +157,8 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>; ...@@ -161,8 +157,8 @@ startAbility(want: Want, options?: StartOptions): Promise\<void>;
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startAbility failed, error.code: ' + JSON.stringify(err.code) + console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -191,8 +187,6 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void& ...@@ -191,8 +187,6 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -217,11 +211,11 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void& ...@@ -217,11 +211,11 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var options = { var options = {
windowMode: 0 windowMode: 0
...@@ -265,8 +259,6 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\< ...@@ -265,8 +259,6 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -292,11 +284,11 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\< ...@@ -292,11 +284,11 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
...@@ -339,8 +331,6 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca ...@@ -339,8 +331,6 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -366,11 +356,11 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca ...@@ -366,11 +356,11 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
var options = { var options = {
...@@ -422,8 +412,6 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): ...@@ -422,8 +412,6 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -449,11 +437,11 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): ...@@ -449,11 +437,11 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
var options = { var options = {
...@@ -468,8 +456,8 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): ...@@ -468,8 +456,8 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(err.code) + console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -497,8 +485,6 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void; ...@@ -497,8 +485,6 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -516,11 +502,11 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void; ...@@ -516,11 +502,11 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
try { try {
...@@ -565,8 +551,6 @@ startServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -565,8 +551,6 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -584,11 +568,11 @@ startServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -584,11 +568,11 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
try { try {
...@@ -599,8 +583,8 @@ startServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -599,8 +583,8 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startServiceExtensionAbility failed, error.code: ' + JSON.stringify(err.code) + console.log('startServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -631,8 +615,6 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: ...@@ -631,8 +615,6 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -652,11 +634,11 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: ...@@ -652,11 +634,11 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
...@@ -705,8 +687,6 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\ ...@@ -705,8 +687,6 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -725,11 +705,11 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\ ...@@ -725,11 +705,11 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
...@@ -741,8 +721,8 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\ ...@@ -741,8 +721,8 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(err.code) + console.log('startServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -770,8 +750,6 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void; ...@@ -770,8 +750,6 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -786,11 +764,11 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void; ...@@ -786,11 +764,11 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
try { try {
...@@ -835,8 +813,6 @@ stopServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -835,8 +813,6 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -851,11 +827,11 @@ stopServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -851,11 +827,11 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
try { try {
...@@ -866,8 +842,8 @@ stopServiceExtensionAbility(want: Want): Promise\<void>; ...@@ -866,8 +842,8 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(err.code) + console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -898,8 +874,6 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: ...@@ -898,8 +874,6 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -915,11 +889,11 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: ...@@ -915,11 +889,11 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
...@@ -968,8 +942,6 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\< ...@@ -968,8 +942,6 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -985,11 +957,11 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\< ...@@ -985,11 +957,11 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
...@@ -1001,8 +973,8 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\< ...@@ -1001,8 +973,8 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('stopServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(err.code) + console.log('stopServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -1029,8 +1001,6 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void; ...@@ -1029,8 +1001,6 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1042,7 +1012,7 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void; ...@@ -1042,7 +1012,7 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
**示例:** **示例:**
```js ```ts
this.context.terminateSelf((error) => { this.context.terminateSelf((error) => {
if (error.code) { if (error.code) {
// 处理业务逻辑错误 // 处理业务逻辑错误
...@@ -1073,8 +1043,6 @@ terminateSelf(): Promise&lt;void&gt;; ...@@ -1073,8 +1043,6 @@ terminateSelf(): Promise&lt;void&gt;;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1086,7 +1054,7 @@ terminateSelf(): Promise&lt;void&gt;; ...@@ -1086,7 +1054,7 @@ terminateSelf(): Promise&lt;void&gt;;
**示例:** **示例:**
```js ```ts
this.context.terminateSelf().then((data) => { this.context.terminateSelf().then((data) => {
// 执行正常业务 // 执行正常业务
console.log('terminateSelf succeed'); console.log('terminateSelf succeed');
...@@ -1122,8 +1090,6 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number; ...@@ -1122,8 +1090,6 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1136,10 +1102,10 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number; ...@@ -1136,10 +1102,10 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
**示例:** **示例:**
```js ```ts
var want = { var want = {
"bundleName": "com.example.myapp", bundleName: "com.example.myapp",
"abilityName": "MyAbility" abilityName: "MyAbility"
}; };
var options = { var options = {
onConnect(elementName, remote) { console.log('----------- onConnect -----------') }, onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
...@@ -1183,8 +1149,6 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options ...@@ -1183,8 +1149,6 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1198,11 +1162,11 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options ...@@ -1198,11 +1162,11 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
**示例:** **示例:**
```js ```ts
var want = { var want = {
"deviceId": "", deviceId: "",
"bundleName": "com.extreme.test", bundleName: "com.extreme.test",
"abilityName": "MainAbility" abilityName: "MainAbility"
}; };
var accountId = 100; var accountId = 100;
var options = { var options = {
...@@ -1240,8 +1204,6 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback&lt; ...@@ -1240,8 +1204,6 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback&lt;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1253,7 +1215,7 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback&lt; ...@@ -1253,7 +1215,7 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback&lt;
**示例:** **示例:**
```js ```ts
// connection为connectServiceExtensionAbility中的返回值 // connection为connectServiceExtensionAbility中的返回值
var connection = 1; var connection = 1;
...@@ -1299,8 +1261,6 @@ disconnectServiceExtensionAbility(connection: number): Promise&lt;void&gt;; ...@@ -1299,8 +1261,6 @@ disconnectServiceExtensionAbility(connection: number): Promise&lt;void&gt;;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1312,7 +1272,7 @@ disconnectServiceExtensionAbility(connection: number): Promise&lt;void&gt;; ...@@ -1312,7 +1272,7 @@ disconnectServiceExtensionAbility(connection: number): Promise&lt;void&gt;;
**示例:** **示例:**
```js ```ts
// connection为connectAbility中的返回值 // connection为connectAbility中的返回值
var connection = 1; var connection = 1;
...@@ -1324,8 +1284,8 @@ disconnectServiceExtensionAbility(connection: number): Promise&lt;void&gt;; ...@@ -1324,8 +1284,8 @@ disconnectServiceExtensionAbility(connection: number): Promise&lt;void&gt;;
}) })
.catch((error) => { .catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('disconnectServiceExtensionAbility failed, error.code: ' + JSON.stringify(err.code) + console.log('disconnectServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -1358,8 +1318,6 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;; ...@@ -1358,8 +1318,6 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
**错误码:** **错误码:**
以下错误码的详细介绍请参见[元能力错误码](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 201 | The application does not have permission to call the interface. |
...@@ -1374,9 +1332,9 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;; ...@@ -1374,9 +1332,9 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
**示例:** **示例:**
台启动: 台启动:
```js ```ts
var caller = undefined; var caller = undefined;
// 后台启动Ability,不配置parameters // 后台启动Ability,不配置parameters
...@@ -1395,8 +1353,8 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;; ...@@ -1395,8 +1353,8 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
console.log('startAbilityByCall succeed'); console.log('startAbilityByCall succeed');
}).catch((error) => { }).catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startAbilityByCall failed, error.code: ' + JSON.stringify(err.code) + console.log('startAbilityByCall failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
...@@ -1407,7 +1365,7 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;; ...@@ -1407,7 +1365,7 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
前台启动: 前台启动:
```js ```ts
var caller = undefined; var caller = undefined;
// 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true // 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true
...@@ -1422,15 +1380,15 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;; ...@@ -1422,15 +1380,15 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
}; };
try { try {
this.context.startAbilityByCall(wantBackground) this.context.startAbilityByCall(wantForeground)
.then((obj) => { .then((obj) => {
// 执行正常业务 // 执行正常业务
caller = obj; caller = obj;
console.log('startAbilityByCall succeed'); console.log('startAbilityByCall succeed');
}).catch((error) => { }).catch((error) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.log('startAbilityByCall failed, error.code: ' + JSON.stringify(err.code) + console.log('startAbilityByCall failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(err.message)); ' error.message: ' + JSON.stringify(error.message));
}); });
} catch (paramError) { } catch (paramError) {
// 处理入参错误异常 // 处理入参错误异常
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册