未验证 提交 365b7ada 编写于 作者: O openharmony_ci 提交者: Gitee

!15011 翻译完成:13858 connectServiceExtensionAbility 为非系统接口

Merge pull request !15011 from wusongqing/TR13858
# @ohos.app.ability.dialogRequest (dialogRequest)
The **dialogRequest** module provides APIs related to modal dialog box processing, including obtaining the request information (used to bind a modal dialog box) and request callback (used to set the request result).
A modal dialog box is a system pop-up box that intercepts events (such as mouse, keyboard, and touchscreen events) triggered for the page displayed under it. The page can be operated only after the modal dialog box is destroyed.
> **NOTE**
>
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are used in ServiceExtensionAbilities. For a ServiceExtensionAbility that implements modal dialog boxes, you can use the APIs to obtain the request information and request callback and return the request result.
## Modules to Import
```js
import dialogRequest from '@ohos.app.ability.dialogRequest';
```
## dialogRequest.getRequestInfo
getRequestInfo(want: Want): RequestInfo
Obtains the request information from Want.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| want | [Want](js-apis-application-want.md) | Yes | Want passed in the request for a modal dialog box.|
**Return value**
| Type | Description |
| ------ | ------------------------ |
| [RequestInfo](#requestinfo) | **RequestInfo** object obtained, which is used to bind a modal dialog box.|
**Example**
```ts
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest';
export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) {
console.info(TAG, `onCreate, want: ${want.abilityName}`);
}
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestInfo = dialogRequest.getRequestInfo(want);
} catch(err) {
console.error('getRequestInfo err= ${JSON.stringify(err)}');
}
}
onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`);
}
onDisconnect(want) {
console.info(TAG, `onDisconnect, want: ${want.abilityName}`);
}
onDestroy() {
console.info(TAG, `onDestroy`);
}
}
```
## dialogRequest.getRequestCallback
getRequestCallback(want: Want): RequestCallback
Obtains the request callback from Want.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| want | [Want](js-apis-application-want.md) | Yes | Want passed in the request for a modal dialog box.|
**Return value**
| Type | Description |
| ------ | ------------------------ |
| [RequestCallback](#requestcallback) | **RequestCallback** object obtained, which is used to set the return result.|
**Example**
```ts
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest';
export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) {
console.info(TAG, `onCreate, want: ${want.abilityName}`);
}
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestCallback = dialogRequest.getRequestCallback(want);
} catch(err) {
console.error('getRequestInfo err= ${JSON.stringify(err)}');
}
}
onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`);
}
onDisconnect(want) {
console.info(TAG, `onDisconnect, want: ${want.abilityName}`);
}
onDestroy() {
console.info(TAG, `onDestroy`);
}
}
```
## RequestInfo
Defines the request information, which is used as an input parameter for binding the modal dialog box.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
```ts
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest';
import window from '@ohos.window';
export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) {
console.info(TAG, `onCreate, want: ${want.abilityName}`);
}
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestInfo = dialogRequest.getRequestInfo(want);
window.bindDialogTarget(requestInfo, () => {
console.info('Dialog Window Need Destroy.');
}, (err) => {
if (err.code) {
console.error('Failed to bind dialog target. Cause: ${JSON.stringify(err)}');
return;
}
console.info('Succeeded in binding dialog target.');
});
} catch(err) {
console.error('getRequestInfo err= ${JSON.stringify(err)}');
}
}
onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`);
}
onDisconnect(want) {
console.info(TAG, `onDisconnect, want: ${want.abilityName}`);
}
onDestroy() {
console.info(TAG, `onDestroy`);
}
}
```
## ResultCode
Enumerates the result codes of the request for the modal dialog box.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name | Value | Description |
| ------------ | ------------------ | ---------------------- |
| RESULT_OK | 0 | The request succeeds. |
| RESULT_CANCEL | 1 | The request fails. |
## RequestResult
Defines the result of the request for the modal dialog box. Only the result code is included.
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| result | [ResultCode](#resultcode) | Yes| Yes| Result code of the request.|
## RequestCallback
Provides a callback for setting the modal dialog box request result.
### RequestCallback.setRequestResult
setRequestResult(result: RequestResult): void;
Sets the result of the request for the modal dialog box.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| result | [RequestResult](#requestresult) | Yes| Request result to set.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest';
export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) {
console.info(TAG, `onCreate, want: ${want.abilityName}`);
}
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestCallback = dialogRequest.getRequestCallback(want);
let myResult = {
result : dialogRequest.ResultCode.RESULT_CANCEL,
};
requestCallback.setRequestResult(myResult);
} catch(err) {
console.error('getRequestInfo err= ${JSON.stringify(err)}');
}
}
onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`);
}
onDisconnect(want) {
console.info(TAG, `onDisconnect, want: ${want.abilityName}`);
}
onDestroy() {
console.info(TAG, `onDestroy`);
}
}
```
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
| config | [Configuration](js-apis-app-ability-configuration.md) | Yes| No| UIAbility configuration, such as the language and color mode.| | config | [Configuration](js-apis-app-ability-configuration.md) | Yes| No| UIAbility configuration, such as the language and color mode.|
> **NOTE** > **NOTE**
> - In the sample code provided in this topic, **this.context** is used to obtain **UIAbilityContext**, where **this** indicates a UIAbility instance inherited from **UIAbility**. To use **UIAbilityContext** capabilities on pages, see [Obtaining the Context of UIAbility](../../application-models/uiability-usage.md#obtaining-the-context-of-uiability). >
> In the sample code provided in this topic, **this.context** is used to obtain **UIAbilityContext**, where **this** indicates a UIAbility instance inherited from **UIAbility**. To use **UIAbilityContext** APIs on pages, see [Obtaining the Context of UIAbility](../../application-models/uiability-usage.md#obtaining-the-context-of-uiability).
## UIAbilityContext.startAbility ## UIAbilityContext.startAbility
...@@ -44,50 +45,42 @@ Observe the following when using this API: ...@@ -44,50 +45,42 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000008 | The crowdtesting application expires. |
| 16000008 | Crowdtest App Expiration. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000009 | Can not start ability in wukong mode. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000010 | Can not operation with continue flag. | | 16000011 | The context does not exist. |
| 16000011 | Context does not exist. | | 16000050 | Internal error. |
| 16000051 | Network error. The network is abnormal. | | 16000053 | The ability is not on the top of the UI. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16000055 | Installation-free timed out. |
| 16000053 | Not top ability. The application is not top ability. | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
bundleName: "com.example.myapp", bundleName: 'com.example.myapplication',
abilityName: "MyAbility" abilityName: 'EntryAbility'
}; };
try { try {
this.context.startAbility(want, (error) => { this.context.startAbility(want, (err) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbility failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('startAbility succeed');
console.log('startAbility succeed'); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startAbility failed failed, code is ${err.code}, message is ${err.message}`);
console.log('startAbility failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.startAbility ## UIAbilityContext.startAbility
...@@ -115,54 +108,46 @@ Observe the following when using this API: ...@@ -115,54 +108,46 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000008 | The crowdtesting application expires. |
| 16000008 | Crowdtest App Expiration. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000009 | Can not start ability in wukong mode. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000010 | Can not operation with continue flag. | | 16000011 | The context does not exist. |
| 16000011 | Context does not exist. | | 16000050 | Internal error. |
| 16000051 | Network error. The network is abnormal. | | 16000053 | The ability is not on the top of the UI. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16000055 | Installation-free timed out. |
| 16000053 | Not top ability. The application is not top ability. | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
}; };
var options = { let options = {
windowMode: 0 windowMode: 0
}; };
try { try {
this.context.startAbility(want, options, (error) => { this.context.startAbility(want, options, (err) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbility failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('startAbility succeed');
console.log('startAbility succeed'); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startAbility failed failed, code is ${err.code}, message is ${err.message}`);
console.log('startAbility failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.startAbility ## UIAbilityContext.startAbility
...@@ -195,60 +180,55 @@ Observe the following when using this API: ...@@ -195,60 +180,55 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000008 | The crowdtesting application expires. |
| 16000008 | Crowdtest App Expiration. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000009 | Can not start ability in wukong mode. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000010 | Can not operation with continue flag. | | 16000011 | The context does not exist. |
| 16000011 | Context does not exist. | | 16000050 | Internal error. |
| 16000051 | Network error. The network is abnormal. | | 16000053 | The ability is not on the top of the UI. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16000055 | Installation-free timed out. |
| 16000053 | Not top ability. The application is not top ability. | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
bundleName: "com.example.myapp", bundleName: 'com.example.myapplication',
abilityName: "MyAbility" abilityName: 'EntryAbility'
}; };
var options = { let options = {
windowMode: 0, windowMode: 0,
}; };
try { try {
this.context.startAbility(want, options) this.context.startAbility(want, options)
.then(() => { .then(() => {
// Carry out normal service processing. // Carry out normal service processing.
console.log('startAbility succeed'); console.info('startAbility succeed');
}) })
.catch((error) => { .catch((err) => {
// Process service logic errors. // Process service logic errors.
console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbility failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startAbility failed, code is ${err.code}, message is ${err.message}`);
console.log('startAbility failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.startAbilityForResult ## UIAbilityContext.startAbilityForResult
startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void; startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void;
Starts an ability. After the ability is started, you can call [terminateSelfWithResult](#uiabilitycontextterminateselfwithresult) to terminate the ability and return the result to the caller. If an exception occurs, for example, the ability is killed, exception information is returned to the caller. This API uses an asynchronous callback to return the result. Starts an ability. This API uses an asynchronous callback to return the result when the ability is terminated. The following situations may be possible for a started ability:
- Normally, you can call [terminateSelfWithResult](#uiabilitycontextterminateselfwithresult) to terminate the ability. The result is returned to the caller.
- If an exception occurs, for example, the ability is killed, an error message, in which **resultCode** is **-1**, is returned to the caller.
- If different applications call this API to start an ability that uses the singleton mode and then call [terminateSelfWithResult](#uiabilitycontextterminateselfwithresult) to terminate the ability, the normal result is returned to the last caller, and an error message, in which **resultCode** is **-1**, is returned to others.
Observe the following when using this API: Observe the following when using this API:
- If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
...@@ -268,58 +248,53 @@ Observe the following when using this API: ...@@ -268,58 +248,53 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000008 | The crowdtesting application expires. |
| 16000008 | Crowdtest App Expiration. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000009 | Can not start ability in wukong mode. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000010 | Can not operation with continue flag. | | 16000011 | The context does not exist. |
| 16000011 | Context does not exist. | | 16000050 | Internal error. |
| 16000051 | Network error. The network is abnormal. | | 16000053 | The ability is not on the top of the UI. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16000055 | Installation-free timed out. |
| 16000053 | Not top ability. The application is not top ability. | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
}; };
try { try {
this.context.startAbilityForResult(want, (error, result) => { this.context.startAbilityForResult(want, (err, result) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('startAbilityForResult succeed');
console.log("startAbilityForResult succeed, result.resultCode = " + result.resultCode) });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.startAbilityForResult ## UIAbilityContext.startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): void; startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): void;
Starts an ability with the start options specified. After the ability is started, you can call [terminateSelfWithResult](#uiabilitycontextterminateselfwithresult) to terminate the ability and return the result to the caller. If an exception occurs, for example, the ability is killed, exception information is returned to the caller. This API uses an asynchronous callback to return the result. Starts an ability with the start options specified. This API uses an asynchronous callback to return the result when the ability is terminated. The following situations may be possible for a started ability:
- Normally, you can call [terminateSelfWithResult](#uiabilitycontextterminateselfwithresult) to terminate the ability. The result is returned to the caller.
- If an exception occurs, for example, the ability is killed, an error message, in which **resultCode** is **-1**, is returned to the caller.
- If different applications call this API to start an ability that uses the singleton mode and then call [terminateSelfWithResult](#uiabilitycontextterminateselfwithresult) to terminate the ability, the normal result is returned to the last caller, and an error message, in which **resultCode** is **-1**, is returned to others.
Observe the following when using this API: Observe the following when using this API:
- If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
...@@ -340,54 +315,46 @@ Observe the following when using this API: ...@@ -340,54 +315,46 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000008 | The crowdtesting application expires. |
| 16000008 | Crowdtest App Expiration. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000009 | Can not start ability in wukong mode. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000010 | Can not operation with continue flag. | | 16000011 | The context does not exist. |
| 16000011 | Context does not exist. | | 16000050 | Internal error. |
| 16000051 | Network error. The network is abnormal. | | 16000053 | The ability is not on the top of the UI. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16000055 | Installation-free timed out. |
| 16000053 | Not top ability. The application is not top ability. | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
}; };
var options = { let options = {
windowMode: 0, windowMode: 0,
}; };
try { try {
this.context.startAbilityForResult(want, options, (error, result) => { this.context.startAbilityForResult(want, options, (err, result) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('startAbilityForResult succeed');
console.log("startAbilityForResult succeed, result.resultCode = " + result.resultCode) });
}); } catch (paramError) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
...@@ -395,7 +362,10 @@ Observe the following when using this API: ...@@ -395,7 +362,10 @@ Observe the following when using this API:
startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult>; startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult>;
Starts an ability. After the ability is started, you can call [terminateSelfWithResult](#uiabilitycontextterminateselfwithresult) to terminate the ability and return the result to the caller. If an exception occurs, for example, the ability is killed, exception information is returned to the caller. This API uses a promise to return the result. Starts an ability. This API uses a promise to return the result when the ability is terminated. The following situations may be possible to an ability after it is started:
- Normally, you can call [terminateSelfWithResult](#uiabilitycontextterminateselfwithresult) to terminate the ability. The result is returned to the caller.
- If an exception occurs, for example, the ability is killed, an error message, in which **resultCode** is **-1**, is returned to the caller.
- If different applications call this API to start an ability that uses the singleton mode and then call [terminateSelfWithResult](#uiabilitycontextterminateselfwithresult) to terminate the ability, the normal result is returned to the last caller, and an error message, in which **resultCode** is **-1**, is returned to others.
Observe the following when using this API: Observe the following when using this API:
- If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
...@@ -422,53 +392,45 @@ Observe the following when using this API: ...@@ -422,53 +392,45 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000008 | The crowdtesting application expires. |
| 16000008 | Crowdtest App Expiration. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000009 | Can not start ability in wukong mode. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000010 | Can not operation with continue flag. | | 16000011 | The context does not exist. |
| 16000011 | Context does not exist. | | 16000050 | Internal error. |
| 16000051 | Network error. The network is abnormal. | | 16000053 | The ability is not on the top of the UI. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16000055 | Installation-free timed out. |
| 16000053 | Not top ability. The application is not top ability. | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
}; };
var options = { let options = {
windowMode: 0, windowMode: 0,
}; };
try { try {
this.context.startAbilityForResult(want, options) this.context.startAbilityForResult(want, options)
.then((result) => { .then((result) => {
// Carry out normal service processing. // Carry out normal service processing.
console.log("startAbilityForResult succeed, result.resultCode = " + result.resultCode); console.info('startAbilityForResult succeed');
}) })
.catch((error) => { .catch((err) => {
// Process service logic errors. // Process service logic errors.
console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.startAbilityForResultWithAccount ## UIAbilityContext.startAbilityForResultWithAccount
...@@ -500,54 +462,44 @@ Observe the following when using this API: ...@@ -500,54 +462,44 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000006 | Can not cross user operations. | | 16000008 | The crowdtesting application expires. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000008 | Crowdtest App Expiration. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000009 | Can not start ability in wukong mode. | | 16000011 | The context does not exist. |
| 16000010 | Can not operation with continue flag. | | 16000050 | Internal error. |
| 16000011 | Context does not exist. | | 16000053 | The ability is not on the top of the UI. |
| 16000051 | Network error. The network is abnormal. | | 16000055 | Installation-free timed out. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
}; };
var accountId = 100; let accountId = 100;
try { try {
this.context.startAbilityForResultWithAccount(want, accountId, (error, result) => { this.context.startAbilityForResultWithAccount(want, accountId, (err, result) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('startAbilityForResultWithAccount failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbilityForResultWithAccount failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('startAbilityForResultWithAccount succeed');
console.log("startAbilityForResultWithAccount succeed, result.resultCode = " + });
result.resultCode + ' result.want = ' + JSON.stringify(result.want)) } catch (err) {
}); // Process input parameter errors.
} catch (paramError) { console.error(`startAbilityForResultWithAccount failed, code is ${err.code}, message is ${err.message}`);
// Process input parameter errors. }
console.log('startAbilityForResultWithAccount failed, error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
...@@ -581,56 +533,47 @@ Observe the following when using this API: ...@@ -581,56 +533,47 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000006 | Can not cross user operations. | | 16000008 | The crowdtesting application expires. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000008 | Crowdtest App Expiration. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000009 | Can not start ability in wukong mode. | | 16000011 | The context does not exist. |
| 16000010 | Can not operation with continue flag. | | 16000050 | Internal error. |
| 16000011 | Context does not exist. | | 16000053 | The ability is not on the top of the UI. |
| 16000051 | Network error. The network is abnormal. | | 16000055 | Installation-free timed out. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
}; };
var accountId = 100; let accountId = 100;
var options = { let options = {
windowMode: 0 windowMode: 0
}; };
try { try {
this.context.startAbilityForResultWithAccount(want, accountId, options, (error) => { this.context.startAbilityForResultWithAccount(want, accountId, options, (err) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('startAbilityForResultWithAccount failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbilityForResultWithAccount failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('startAbilityForResultWithAccount succeed');
console.log("startAbilityForResultWithAccount succeed") });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startAbilityForResultWithAccount failed, code is ${err.code}, message is ${err.message}`);
console.log('startAbilityForResultWithAccount failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
...@@ -669,57 +612,47 @@ Observe the following when using this API: ...@@ -669,57 +612,47 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000006 | Can not cross user operations. | | 16000008 | The crowdtesting application expires. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000008 | Crowdtest App Expiration. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000009 | Can not start ability in wukong mode. | | 16000011 | The context does not exist. |
| 16000010 | Can not operation with continue flag. | | 16000050 | Internal error. |
| 16000011 | Context does not exist. | | 16000053 | The ability is not on the top of the UI. |
| 16000051 | Network error. The network is abnormal. | | 16000055 | Installation-free timed out. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
}; };
var accountId = 100; let accountId = 100;
var options = { let options = {
windowMode: 0 windowMode: 0
}; };
try { try {
this.context.startAbilityForResultWithAccount(want, accountId, options) this.context.startAbilityForResultWithAccount(want, accountId, options)
.then((result) => { .then((result) => {
// Carry out normal service processing. // Carry out normal service processing.
console.log("startAbilityForResultWithAccount succeed, result.resultCode = " + console.info('startAbilityForResultWithAccount succeed');
result.resultCode) })
}) .catch((err) => {
.catch((error) => { // Process service logic errors.
// Process service logic errors. console.error(`startAbilityForResultWithAccount failed, code is ${err.code}, message is ${err.message}`);
console.log('startAbilityForResultWithAccount failed, error.code: ' + JSON.stringify(error.code) + });
' error.message: ' + JSON.stringify(error.message)); } catch (err) {
}); // Process input parameter errors.
} catch (paramError) { console.error(`startAbilityForResultWithAccount failed, code is ${err.code}, message is ${err.message}`);
// Process input parameter errors. }
console.log('startAbilityForResultWithAccount failed, error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.startServiceExtensionAbility ## UIAbilityContext.startServiceExtensionAbility
...@@ -742,44 +675,38 @@ Starts a ServiceExtensionAbility. This API uses an asynchronous callback to retu ...@@ -742,44 +675,38 @@ Starts a ServiceExtensionAbility. This API uses an asynchronous callback to retu
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000002 | Ability type error. The specified ability type is wrong. | | 16000006 | Cross-user operations are not allowed. |
| 16000004 | Visibility verification failed. | | 16000008 | The crowdtesting application expires. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000011 | The context does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000050 | Internal error. |
| 16000008 | Crowdtest App Expiration. | | 16200001 | The caller has been released. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "ServiceExtensionAbility" abilityName: 'ServiceExtensionAbility'
}; };
try { try {
this.context.startServiceExtensionAbility(want, (error) => { this.context.startServiceExtensionAbility(want)
if (error.code) { .then(() => {
// Process service logic errors.
console.log('startServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
return;
}
// Carry out normal service processing. // Carry out normal service processing.
console.log('startServiceExtensionAbility succeed'); console.info('startServiceExtensionAbility succeed');
})
.catch((err) => {
// Process service logic errors.
console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
}); });
} catch (paramError) { } catch (err) {
// Process input parameter errors. // Process input parameter errors.
console.log('startServiceExtensionAbility failed, error.code: ' + JSON.stringify(paramError.code) + console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(paramError.message)); }
}
``` ```
## UIAbilityContext.startServiceExtensionAbility ## UIAbilityContext.startServiceExtensionAbility
...@@ -802,44 +729,38 @@ Starts a ServiceExtensionAbility. This API uses a promise to return the result. ...@@ -802,44 +729,38 @@ Starts a ServiceExtensionAbility. This API uses a promise to return the result.
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000002 | Ability type error. The specified ability type is wrong. | | 16000006 | Cross-user operations are not allowed. |
| 16000004 | Visibility verification failed. | | 16000008 | The crowdtesting application expires. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000011 | The context does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000050 | Internal error. |
| 16000008 | Crowdtest App Expiration. | | 16200001 | The caller has been released. |
| 16000009 | Can not start ability in wukong mode. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "ServiceExtensionAbility" abilityName: 'ServiceExtensionAbility'
}; };
try { try {
this.context.startServiceExtensionAbility(want) this.context.startServiceExtensionAbility(want)
.then(() => { .then(() => {
// Carry out normal service processing. // Carry out normal service processing.
console.log('startServiceExtensionAbility succeed'); console.info('startServiceExtensionAbility succeed');
}) })
.catch((error) => { .catch((err) => {
// Process service logic errors. // Process service logic errors.
console.log('startServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) + console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); });
}); } catch (paramError) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
console.log('startServiceExtensionAbility failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.startServiceExtensionAbilityWithAccount ## UIAbilityContext.startServiceExtensionAbilityWithAccount
...@@ -866,42 +787,39 @@ Starts a ServiceExtensionAbility with the account ID specified. This API uses an ...@@ -866,42 +787,39 @@ Starts a ServiceExtensionAbility with the account ID specified. This API uses an
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000002 | Ability type error. The specified ability type is wrong. | | 16000006 | Cross-user operations are not allowed. |
| 16000004 | Visibility verification failed. | | 16000008 | The crowdtesting application expires. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000011 | The context does not exist. |
| 16000011 | Context does not exist. | | 16000050 | Internal error. |
| 16200001 | Caller released. The caller has been released. | | 16200001 | The caller has been released. |
| 16000050 | Internal Error. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "ServiceExtensionAbility" abilityName: 'ServiceExtensionAbility'
}; };
var accountId = 100; let accountId = 100;
try { try {
this.context.startServiceExtensionAbilityWithAccount(want, accountId, (error) => { this.context.startServiceExtensionAbilityWithAccount(want, accountId, (err) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('startServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) + console.error(`startServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('startServiceExtensionAbilityWithAccount succeed');
console.log('startServiceExtensionAbilityWithAccount succeed'); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
console.log('startServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.startServiceExtensionAbilityWithAccount ## UIAbilityContext.startServiceExtensionAbilityWithAccount
...@@ -927,46 +845,39 @@ Starts a ServiceExtensionAbility with the account ID specified. This API uses a ...@@ -927,46 +845,39 @@ Starts a ServiceExtensionAbility with the account ID specified. This API uses a
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000002 | Ability type error. The specified ability type is wrong. | | 16000006 | Cross-user operations are not allowed. |
| 16000004 | Visibility verification failed. | | 16000008 | The crowdtesting application expires. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000011 | The context does not exist. |
| 16000006 | Can not cross user operations. | | 16000050 | Internal error. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "ServiceExtensionAbility" abilityName: 'ServiceExtensionAbility'
}; };
var accountId = 100; let accountId = 100;
try { try {
this.context.startServiceExtensionAbilityWithAccount(want, accountId) this.context.startServiceExtensionAbilityWithAccount(want, accountId)
.then((data) => { .then(() => {
// Carry out normal service processing. // Carry out normal service processing.
console.log('startServiceExtensionAbilityWithAccount succeed'); console.info('startServiceExtensionAbilityWithAccount succeed');
}) })
.catch((error) => { .catch((err) => {
// Process service logic errors. // Process service logic errors.
console.log('startServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) + console.error(`startServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
console.log('startServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.stopServiceExtensionAbility ## UIAbilityContext.stopServiceExtensionAbility
...@@ -989,41 +900,37 @@ Stops a ServiceExtensionAbility in the same application. This API uses an asynch ...@@ -989,41 +900,37 @@ Stops a ServiceExtensionAbility in the same application. This API uses an asynch
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000002 | Ability type error. The specified ability type is wrong. | | 16000006 | Cross-user operations are not allowed. |
| 16000004 | Visibility verification failed. | | 16000011 | The context does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000050 | Internal error. |
| 16000011 | Context does not exist. | | 16200001 | The caller has been released. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "ServiceExtensionAbility" abilityName: 'ServiceExtensionAbility'
}; };
try { try {
this.context.stopServiceExtensionAbility(want, (error) => { this.context.stopServiceExtensionAbility(want, (err) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) + console.error(`stopServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('stopServiceExtensionAbility succeed');
console.log('stopServiceExtensionAbility succeed'); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`stopServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.stopServiceExtensionAbility ## UIAbilityContext.stopServiceExtensionAbility
...@@ -1046,41 +953,37 @@ Stops a ServiceExtensionAbility in the same application. This API uses a promise ...@@ -1046,41 +953,37 @@ Stops a ServiceExtensionAbility in the same application. This API uses a promise
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000002 | Ability type error. The specified ability type is wrong. | | 16000006 | Cross-user operations are not allowed. |
| 16000004 | Visibility verification failed. | | 16000011 | The context does not exist. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000050 | Internal error. |
| 16000011 | Context does not exist. | | 16200001 | The caller has been released. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "ServiceExtensionAbility" abilityName: 'ServiceExtensionAbility'
}; };
try { try {
this.context.stopServiceExtensionAbility(want) this.context.stopServiceExtensionAbility(want)
.then((data) => { .then(() => {
// Carry out normal service processing. // Carry out normal service processing.
console.log('stopServiceExtensionAbility succeed'); console.info('stopServiceExtensionAbility succeed');
}) })
.catch((error) => { .catch((err) => {
// Process service logic errors. // Process service logic errors.
console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) + console.error(`stopServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`stopServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.stopServiceExtensionAbilityWithAccount ## UIAbilityContext.stopServiceExtensionAbilityWithAccount
...@@ -1107,43 +1010,38 @@ Stops a ServiceExtensionAbility with the account ID specified in the same applic ...@@ -1107,43 +1010,38 @@ Stops a ServiceExtensionAbility with the account ID specified in the same applic
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000002 | Ability type error. The specified ability type is wrong. | | 16000006 | Cross-user operations are not allowed. |
| 16000004 | Visibility verification failed. | | 16000011 | The context does not exist. |
| 16000006 | Can not cross user operations. | | 16000050 | Internal error. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16200001 | The caller has been released. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "ServiceExtensionAbility" abilityName: 'ServiceExtensionAbility'
}; };
var accountId = 100; let accountId = 100;
try { try {
this.context.stopServiceExtensionAbilityWithAccount(want, accountId, (error) => { this.context.stopServiceExtensionAbilityWithAccount(want, accountId, (err) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('stopServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) + console.error(`stopServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('stopServiceExtensionAbilityWithAccount succeed');
console.log('stopServiceExtensionAbilityWithAccount succeed'); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`stopServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
console.log('stopServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.stopServiceExtensionAbilityWithAccount ## UIAbilityContext.stopServiceExtensionAbilityWithAccount
...@@ -1169,43 +1067,38 @@ Stops a ServiceExtensionAbility with the account ID specified in the same applic ...@@ -1169,43 +1067,38 @@ Stops a ServiceExtensionAbility with the account ID specified in the same applic
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000002 | Ability type error. The specified ability type is wrong. | | 16000006 | Cross-user operations are not allowed. |
| 16000004 | Visibility verification failed. | | 16000011 | The context does not exist. |
| 16000006 | Can not cross user operations. | | 16000050 | Internal error. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16200001 | The caller has been released. |
| 16000011 | Context does not exist. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "ServiceExtensionAbility" abilityName: 'ServiceExtensionAbility'
}; };
var accountId = 100; let accountId = 100;
try { try {
this.context.stopServiceExtensionAbilityWithAccount(want, accountId) this.context.stopServiceExtensionAbilityWithAccount(want, accountId)
.then((data) => { .then(() => {
// Carry out normal service processing. // Carry out normal service processing.
console.log('stopServiceExtensionAbilityWithAccount succeed'); console.info('stopServiceExtensionAbilityWithAccount succeed');
}) })
.catch((error) => { .catch((err) => {
// Process service logic errors. // Process service logic errors.
console.log('stopServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) + console.error(`stopServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`stopServiceExtensionAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
console.log('stopServiceExtensionAbilityWithAccount failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.terminateSelf ## UIAbilityContext.terminateSelf
...@@ -1226,31 +1119,29 @@ Terminates this ability. This API uses an asynchronous callback to return the re ...@@ -1226,31 +1119,29 @@ Terminates this ability. This API uses an asynchronous callback to return the re
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000004 | Can not start invisible component. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000011 | Context does not exist. | | 16000011 | The context does not exist. |
| 16000050 | Internal Error. | | 16000050 | Internal error. |
**Example** **Example**
```ts ```ts
try { try {
this.context.terminateSelf((error) => { this.context.terminateSelf((err) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('terminateSelf failed, error.code: ' + JSON.stringify(error.code) + console.error(`terminateSelf failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message));
return; return;
} }
// Carry out normal service processing. // Carry out normal service processing.
console.log('terminateSelf succeed'); console.info('terminateSelf succeed');
}); });
} catch (error) { } catch (err) {
// Capture the synchronization parameter error. // Capture the synchronization parameter error.
console.log('terminateSelf failed, error.code: ' + JSON.stringify(error.code) + console.error(`terminateSelf failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message));
} }
``` ```
...@@ -1273,12 +1164,12 @@ Terminates this ability. This API uses a promise to return the result. ...@@ -1273,12 +1164,12 @@ Terminates this ability. This API uses a promise to return the result.
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000004 | Can not start invisible component. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000011 | Context does not exist. | | 16000011 | The context does not exist. |
| 16000050 | Internal Error. | | 16000050 | Internal error. |
**Example** **Example**
...@@ -1287,17 +1178,15 @@ Terminates this ability. This API uses a promise to return the result. ...@@ -1287,17 +1178,15 @@ Terminates this ability. This API uses a promise to return the result.
this.context.terminateSelf() this.context.terminateSelf()
.then(() => { .then(() => {
// Carry out normal service processing. // Carry out normal service processing.
console.log('terminateSelf succeed'); console.info('terminateSelf succeed');
}) })
.catch((error) => { .catch((err) => {
// Process service logic errors. // Process service logic errors.
console.log('terminateSelf failed, error.code: ' + JSON.stringify(error.code) + console.error(`terminateSelf failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message));
}); });
} catch (error) { } catch (error) {
// Capture the synchronization parameter error. // Capture the synchronization parameter error.
console.log('terminateSelf failed, error.code: ' + JSON.stringify(error.code) + console.error(`terminateSelf failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message));
} }
``` ```
...@@ -1306,7 +1195,7 @@ Terminates this ability. This API uses a promise to return the result. ...@@ -1306,7 +1195,7 @@ Terminates this ability. This API uses a promise to return the result.
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void; terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void;
Terminates this ability. If the ability is started by calling [startAbilityForResult](#uiabilitycontextstartabilityforresult), the result is returned to the caller in the form of a callback when **terminateSelfWithResult** is called. Otherwise, no result is returned to the caller when **terminateSelfWithResult** is called. Terminates this ability. If the ability is started by calling [startAbilityForResult](#uiabilitycontextstartabilityforresult), the result is returned to the caller in the form of an asynchronous callback when **terminateSelfWithResult** is called. Otherwise, no result is returned to the caller when **terminateSelfWithResult** is called.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -1321,43 +1210,41 @@ Terminates this ability. If the ability is started by calling [startAbilityForRe ...@@ -1321,43 +1210,41 @@ Terminates this ability. If the ability is started by calling [startAbilityForRe
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000004 | Can not start invisible component. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000011 | Context does not exist. | | 16000011 | The context does not exist. |
| 16000050 | Internal Error. | | 16000050 | Internal error. |
**Example** **Example**
```ts ```ts
var want = { let want = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
} };
var resultCode = 100; let resultCode = 100;
// AbilityResult information returned to the caller. // AbilityResult information returned to the caller.
var abilityResult = { let abilityResult = {
want, want,
resultCode resultCode
} };
try { try {
this.context.terminateSelfWithResult(abilityResult, (error) => { this.context.terminateSelfWithResult(abilityResult, (err) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('terminateSelfWithResult failed, error.code: ' + JSON.stringify(error.code) + console.error(`terminateSelfWithResult failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('terminateSelfWithResult succeed');
console.log('terminateSelfWithResult succeed'); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`terminateSelfWithResult failed, code is ${err.code}, message is ${err.message}`);
console.log('terminateSelfWithResult failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
...@@ -1385,44 +1272,41 @@ Terminates this ability. If the ability is started by calling [startAbilityForRe ...@@ -1385,44 +1272,41 @@ Terminates this ability. If the ability is started by calling [startAbilityForRe
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000004 | Can not start invisible component. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000005 | The specified process does not have the permission. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000011 | Context does not exist. | | 16000011 | The context does not exist. |
| 16000050 | Internal Error. | | 16000050 | Internal error. |
**Example** **Example**
```ts ```ts
var want = { let want = {
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
} };
var resultCode = 100; let resultCode = 100;
// AbilityResult information returned to the caller. // AbilityResult information returned to the caller.
var abilityResult = { let abilityResult = {
want, want,
resultCode resultCode
} };
try { try {
this.context.terminateSelfWithResult(abilityResult) this.context.terminateSelfWithResult(abilityResult)
.then((data) => { .then(() => {
// Carry out normal service processing. // Carry out normal service processing.
console.log('terminateSelfWithResult succeed'); console.info('terminateSelfWithResult succeed');
}) })
.catch((error) => { .catch((err) => {
// Process service logic errors. // Process service logic errors.
console.log('terminateSelfWithResult failed, error.code: ' + JSON.stringify(error.code) + console.error(`terminateSelfWithResult failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`terminateSelfWithResult failed, code is ${err.code}, message is ${err.message}`);
console.log('terminateSelfWithResult failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.connectServiceExtensionAbility ## UIAbilityContext.connectServiceExtensionAbility
...@@ -1433,8 +1317,6 @@ Connects this ability to an ability that uses the **AbilityInfo.AbilityType.SERV ...@@ -1433,8 +1317,6 @@ Connects this ability to an ability that uses the **AbilityInfo.AbilityType.SERV
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -1452,42 +1334,38 @@ Connects this ability to an ability that uses the **AbilityInfo.AbilityType.SERV ...@@ -1452,42 +1334,38 @@ Connects this ability to an ability that uses the **AbilityInfo.AbilityType.SERV
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000005 | The specified process does not have the permission. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000011 | The context does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. | | 16000050 | Internal error. |
| 16000004 | Visibility verification failed. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "ServiceExtensionAbility" abilityName: 'ServiceExtensionAbility'
}; };
var options = { let options = {
onConnect(elementName, remote) { onConnect(elementName, remote) {
console.log('----------- onConnect -----------') console.info('onConnect...')
}, },
onDisconnect(elementName) { onDisconnect(elementName) {
console.log('----------- onDisconnect -----------') console.info('onDisconnect...')
}, },
onFailed(code) { onFailed(code) {
console.log('----------- onFailed -----------') console.info('onFailed...')
}
}
var connection = null;
try {
connection = this.context.connectServiceExtensionAbility(want, options);
} catch (paramError) {
// Process input parameter errors.
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
} }
};
let connection = null;
try {
connection = this.context.connectServiceExtensionAbility(want, options);
} catch (err) {
// Process input parameter errors.
console.error(`connectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
}
``` ```
...@@ -1521,44 +1399,39 @@ Connects this ability to an ability that uses the **AbilityInfo.AbilityType.SERV ...@@ -1521,44 +1399,39 @@ Connects this ability to an ability that uses the **AbilityInfo.AbilityType.SERV
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000005 | The specified process does not have the permission. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000011 | The context does not exist. |
| 16000002 | Ability type error. The specified ability type is wrong. | | 16000050 | Internal error. |
| 16000004 | Visibility verification failed. |
| 16000006 | Can not cross user operations. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "ServiceExtensionAbility" abilityName: 'ServiceExtensionAbility'
}; };
var accountId = 100; let accountId = 100;
var options = { let options = {
onConnect(elementName, remote) { onConnect(elementName, remote) {
console.log('----------- onConnect -----------') console.info('onConnect...')
}, },
onDisconnect(elementName) { onDisconnect(elementName) {
console.log('----------- onDisconnect -----------') console.info('onDisconnect...')
}, },
onFailed(code) { onFailed(code) {
console.log('----------- onFailed -----------') console.info('onFailed...')
}
}
var connection = null;
try {
connection = this.context.connectServiceExtensionAbilityWithAccount(want, accountId, options);
} catch (paramError) {
// Process input parameter errors.
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
} }
};
let connection = null;
try {
connection = this.context.connectServiceExtensionAbilityWithAccount(want, accountId, options);
} catch (err) {
// Process input parameter errors.
console.error(`connectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
}
``` ```
## UIAbilityContext.disconnectServiceExtensionAbility ## UIAbilityContext.disconnectServiceExtensionAbility
...@@ -1569,8 +1442,6 @@ Disconnects from a ServiceExtensionAbility. This API uses a promise to return th ...@@ -1569,8 +1442,6 @@ Disconnects from a ServiceExtensionAbility. This API uses a promise to return th
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -1587,35 +1458,31 @@ Disconnects from a ServiceExtensionAbility. This API uses a promise to return th ...@@ -1587,35 +1458,31 @@ Disconnects from a ServiceExtensionAbility. This API uses a promise to return th
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000005 | The specified process does not have the permission. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000011 | The context does not exist. |
| 16000003 | Input error. The specified id does not exist. | | 16000050 | Internal error. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**Example** **Example**
```ts ```ts
// connection is the return value of connectServiceExtensionAbility. // connection is the return value of connectServiceExtensionAbility.
var connection = 1; let connection = 1;
try { try {
this.context.disconnectServiceExtensionAbility(connection) this.context.disconnectServiceExtensionAbility(connection, (err) => {
.then((data) => { if (err.code) {
// Carry out normal service processing. // Process service logic errors.
console.log('disconnectServiceExtensionAbility succeed'); console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
}) return;
.catch((error) => { }
// Process service logic errors. // Carry out normal service processing.
console.log('disconnectServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) + console.info('disconnectServiceExtensionAbility succeed');
' error.message: ' + JSON.stringify(error.message)); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
console.log('error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.disconnectServiceExtensionAbility ## UIAbilityContext.disconnectServiceExtensionAbility
...@@ -1626,8 +1493,6 @@ Disconnects from a ServiceExtensionAbility. This API uses an asynchronous callba ...@@ -1626,8 +1493,6 @@ Disconnects from a ServiceExtensionAbility. This API uses an asynchronous callba
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -1639,35 +1504,31 @@ Disconnects from a ServiceExtensionAbility. This API uses an asynchronous callba ...@@ -1639,35 +1504,31 @@ Disconnects from a ServiceExtensionAbility. This API uses an asynchronous callba
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000005 | The specified process does not have the permission. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000011 | The context does not exist. |
| 16000003 | Input error. The specified id does not exist. | | 16000050 | Internal error. |
| 16000011 | Context does not exist. |
| 16000050 | Internal Error. |
**Example** **Example**
```ts ```ts
// connection is the return value of connectServiceExtensionAbility. // connection is the return value of connectServiceExtensionAbility.
var connection = 1; let connection = 1;
try { try {
this.context.disconnectServiceExtensionAbility(connection, (error) => { this.context.disconnectServiceExtensionAbility(connection, (err) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('disconnectServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) + console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('disconnectServiceExtensionAbility succeed');
console.log('disconnectServiceExtensionAbility succeed'); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
console.log('error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.startAbilityByCall ## UIAbilityContext.startAbilityByCall
...@@ -1695,71 +1556,85 @@ Observe the following when using this API: ...@@ -1695,71 +1556,85 @@ Observe the following when using this API:
| -------- | -------- | | -------- | -------- |
| Promise<Caller> | Promise used to return the caller object to communicate with.| | Promise<Caller> | Promise used to return the caller object to communicate with.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 16000001 | The specified ability does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Can not start invisible component. |
| 16000005 | The specified process does not have the permission. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | The crowdtesting application expires. |
| 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000010 | The call with the continuation flag is forbidden. |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
| 16200001 | The caller has been released. |
**Example** **Example**
Start an ability in the background. Start an ability in the background.
```ts ```ts
var caller = undefined; let caller;
// Start an ability in the background by not passing parameters. // Start an ability in the background by not passing parameters.
var wantBackground = { let wantBackground = {
bundleName: "com.example.myservice", bundleName: 'com.example.myapplication',
moduleName: "entry", moduleName: 'entry',
abilityName: "MainAbility", abilityName: 'EntryAbility',
deviceId: "" deviceId: ''
}; };
try { try {
this.context.startAbilityByCall(wantBackground) this.context.startAbilityByCall(wantBackground)
.then((obj) => { .then((obj) => {
// Carry out normal service processing. // Carry out normal service processing.
caller = obj; caller = obj;
console.log('startAbilityByCall succeed'); console.info('startAbilityByCall succeed');
}).catch((error) => { }).catch((err) => {
// Process service logic errors. // Process service logic errors.
console.log('startAbilityByCall failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbilityByCall failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startAbilityByCall failed, code is ${err.code}, message is ${err.message}`);
console.log('error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
Start an ability in the foreground. Start an ability in the foreground.
```ts ```ts
var caller = undefined; let caller;
// Start an ability in the foreground with ohos.aafwk.param.callAbilityToForeground in parameters set to true. // Start an ability in the foreground with ohos.aafwk.param.callAbilityToForeground in parameters set to true.
var wantForeground = { let wantForeground = {
bundleName: "com.example.myservice", bundleName: 'com.example.myapplication',
moduleName: "entry", moduleName: 'entry',
abilityName: "MainAbility", abilityName: 'EntryAbility',
deviceId: "", deviceId: '',
parameters: { parameters: {
"ohos.aafwk.param.callAbilityToForeground": true 'ohos.aafwk.param.callAbilityToForeground': true
}
};
try {
this.context.startAbilityByCall(wantForeground)
.then((obj) => {
// Carry out normal service processing.
caller = obj;
console.log('startAbilityByCall succeed');
}).catch((error) => {
// Process service logic errors.
console.log('startAbilityByCall failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
});
} catch (paramError) {
// Process input parameter errors.
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
} }
};
try {
this.context.startAbilityByCall(wantForeground)
.then((obj) => {
// Carry out normal service processing.
caller = obj;
console.info('startAbilityByCall succeed');
}).catch((error) => {
// Process service logic errors.
console.error(`startAbilityByCall failed, code is ${err.code}, message is ${err.message}`);
});
} catch (paramError) {
// Process input parameter errors.
console.error(`startAbilityByCall failed, code is ${err.code}, message is ${err.message}`);
}
``` ```
## UIAbilityContext.startAbilityWithAccount ## UIAbilityContext.startAbilityWithAccount
...@@ -1791,53 +1666,44 @@ Observe the following when using this API: ...@@ -1791,53 +1666,44 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000006 | Can not cross user operations. | | 16000008 | The crowdtesting application expires. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000008 | Crowdtest App Expiration. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000009 | Can not start ability in wukong mode. | | 16000011 | The context does not exist. |
| 16000010 | Can not operation with continue flag. | | 16000050 | Internal error. |
| 16000011 | Context does not exist. | | 16000053 | The ability is not on the top of the UI. |
| 16000051 | Network error. The network is abnormal. | | 16000055 | Installation-free timed out. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
}; };
var accountId = 100; let accountId = 100;
try { try {
this.context.startAbilityWithAccount(want, accountId, (error) => { this.context.startAbilityWithAccount(want, accountId, (err) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('startAbilityWithAccount succeed');
console.log('startAbilityWithAccount succeed'); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
console.log('error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
...@@ -1871,56 +1737,47 @@ Observe the following when using this API: ...@@ -1871,56 +1737,47 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000006 | Can not cross user operations. | | 16000008 | The crowdtesting application expires. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000008 | Crowdtest App Expiration. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000009 | Can not start ability in wukong mode. | | 16000011 | The context does not exist. |
| 16000010 | Can not operation with continue flag. | | 16000050 | Internal error. |
| 16000011 | Context does not exist. | | 16000053 | The ability is not on the top of the UI. |
| 16000051 | Network error. The network is abnormal. | | 16000055 | Installation-free timed out. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
}; };
var accountId = 100; let accountId = 100;
var options = { let options = {
windowMode: 0 windowMode: 0
}; };
try { try {
this.context.startAbilityWithAccount(want, accountId, options, (error) => { this.context.startAbilityWithAccount(want, accountId, options, (err) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('startAbilityWithAccount succeed');
console.log('startAbilityWithAccount succeed'); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
...@@ -1953,63 +1810,54 @@ Observe the following when using this API: ...@@ -1953,63 +1810,54 @@ Observe the following when using this API:
| ID| Error Message| | ID| Error Message|
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. | | 16000001 | The specified ability does not exist. |
| 401 | Invalid input parameter. | | 16000002 | Incorrect ability type. |
| 16000001 | Input error. The specified ability name does not exist. | | 16000004 | Can not start invisible component. |
| 16000004 | Visibility verification failed. | | 16000005 | The specified process does not have the permission. |
| 16000005 | Static permission denied. The specified process does not have the permission. | | 16000006 | Cross-user operations are not allowed. |
| 16000006 | Can not cross user operations. | | 16000008 | The crowdtesting application expires. |
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry. | | 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000008 | Crowdtest App Expiration. | | 16000010 | The call with the continuation flag is forbidden. |
| 16000009 | Can not start ability in wukong mode. | | 16000011 | The context does not exist. |
| 16000010 | Can not operation with continue flag. | | 16000050 | Internal error. |
| 16000011 | Context does not exist. | | 16000053 | The ability is not on the top of the UI. |
| 16000051 | Network error. The network is abnormal. | | 16000055 | Installation-free timed out. |
| 16000052 | Free install not support. The application does not support freeinstall | | 16200001 | The caller has been released. |
| 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. |
**Example** **Example**
```ts ```ts
var want = { let want = {
deviceId: "", deviceId: '',
bundleName: "com.example.myapplication", bundleName: 'com.example.myapplication',
abilityName: "MainAbility" abilityName: 'EntryAbility'
}; };
var accountId = 100; let accountId = 100;
var options = { let options = {
windowMode: 0 windowMode: 0
}; };
try { try {
this.context.startAbilityWithAccount(want, accountId, options) this.context.startAbilityWithAccount(want, accountId, options)
.then((data) => { .then(() => {
// Carry out normal service processing. // Carry out normal service processing.
console.log('startAbilityWithAccount succeed'); console.info('startAbilityWithAccount succeed');
}) })
.catch((error) => { .catch((err) => {
// Process service logic errors. // Process service logic errors.
console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startAbilityWithAccount failed, code is ${err.code}, message is ${err.message}`);
console.log('startAbilityWithAccount failed, error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.setMissionLabel ## UIAbilityContext.setMissionLabel
setMissionLabel(label: string, callback:AsyncCallback<void>): void; setMissionLabel(label: string, callback:AsyncCallback<void>): void;
Sets a label for this ability in the mission. This API uses an asynchronous callback to return the result. Sets a label for this UIAbility in the mission. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -2023,8 +1871,8 @@ Sets a label for this ability in the mission. This API uses an asynchronous call ...@@ -2023,8 +1871,8 @@ Sets a label for this ability in the mission. This API uses an asynchronous call
**Example** **Example**
```ts ```ts
this.context.setMissionLabel("test", (result) => { this.context.setMissionLabel('test', (result) => {
console.log('setMissionLabel:' + JSON.stringify(result)); console.info(`setMissionLabel: ${JSON.stringify(result)}`);
}); });
``` ```
...@@ -2032,7 +1880,7 @@ Sets a label for this ability in the mission. This API uses an asynchronous call ...@@ -2032,7 +1880,7 @@ Sets a label for this ability in the mission. This API uses an asynchronous call
setMissionLabel(label: string): Promise<void>; setMissionLabel(label: string): Promise<void>;
Sets a label for this ability in the mission. This API uses a promise to return the result. Sets a label for this UIAbility in the mission. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -2048,13 +1896,20 @@ Sets a label for this ability in the mission. This API uses a promise to return ...@@ -2048,13 +1896,20 @@ Sets a label for this ability in the mission. This API uses a promise to return
| -------- | -------- | | -------- | -------- |
| Promise<void> | Promise used to return the result.| | Promise<void> | Promise used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
**Example** **Example**
```ts ```ts
this.context.setMissionLabel("test").then(() => { this.context.setMissionLabel('test').then(() => {
console.log('success'); console.info('success');
}).catch((error) => { }).catch((err) => {
console.log('failed:' + JSON.stringify(error)); console.error(`setMissionLabel failed, code is ${err.code}, message is ${err.message}`);
}); });
``` ```
## UIAbilityContext.setMissionIcon ## UIAbilityContext.setMissionIcon
...@@ -2074,13 +1929,21 @@ Sets an icon for this ability in the mission. This API uses an asynchronous call ...@@ -2074,13 +1929,21 @@ Sets an icon for this ability in the mission. This API uses an asynchronous call
| icon | image.PixelMap | Yes| Icon of the ability to set.| | icon | image.PixelMap | Yes| Icon of the ability to set.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| | callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
**Example** **Example**
```ts ```ts
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
var imagePixelMap;
var color = new ArrayBuffer(0); let imagePixelMap;
var initializationOptions = { let color = new ArrayBuffer(0);
let initializationOptions = {
size: { size: {
height: 100, height: 100,
width: 100 width: 100
...@@ -2091,10 +1954,10 @@ Sets an icon for this ability in the mission. This API uses an asynchronous call ...@@ -2091,10 +1954,10 @@ Sets an icon for this ability in the mission. This API uses an asynchronous call
imagePixelMap = data; imagePixelMap = data;
}) })
.catch((err) => { .catch((err) => {
console.log('--------- createPixelMap fail, err: ---------', err) console.error(`createPixelMap failed, code is ${err.code}, message is ${err.message}`);
}); });
this.context.setMissionIcon(imagePixelMap, (err) => { this.context.setMissionIcon(imagePixelMap, (err) => {
console.log('---------- setMissionIcon fail, err: -----------', err); console.error(`setMissionLabel failed, code is ${err.code}, message is ${err.message}`);
}) })
``` ```
...@@ -2121,12 +1984,19 @@ Sets an icon for this ability in the mission. This API uses a promise to return ...@@ -2121,12 +1984,19 @@ Sets an icon for this ability in the mission. This API uses a promise to return
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
**Example** **Example**
```ts ```ts
var imagePixelMap; let imagePixelMap;
var color = new ArrayBuffer(0); let color = new ArrayBuffer(0);
var initializationOptions = { let initializationOptions = {
size: { size: {
height: 100, height: 100,
width: 100 width: 100
...@@ -2137,21 +2007,21 @@ Sets an icon for this ability in the mission. This API uses a promise to return ...@@ -2137,21 +2007,21 @@ Sets an icon for this ability in the mission. This API uses a promise to return
imagePixelMap = data; imagePixelMap = data;
}) })
.catch((err) => { .catch((err) => {
console.log('--------- createPixelMap fail, err: ---------', err) console.error(`createPixelMap failed, code is ${err.code}, message is ${err.message}`);
}); });
this.context.setMissionIcon(imagePixelMap) this.context.setMissionIcon(imagePixelMap)
.then(() => { .then(() => {
console.log('-------------- setMissionIcon success -------------'); console.info('setMissionIcon succeed');
}) })
.catch((err) => { .catch((err) => {
console.log('-------------- setMissionIcon fail, err: -------------', err); console.error(`setMissionLabel failed, code is ${err.code}, message is ${err.message}`);
}); });
``` ```
## UIAbilityContext.restoreWindowStage ## UIAbilityContext.restoreWindowStage
restoreWindowStage(localStorage: LocalStorage) : void; restoreWindowStage(localStorage: LocalStorage) : void;
Restores the window stage data for this ability. Restores the WindowStage data in the UIAbility.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -2161,10 +2031,17 @@ Restores the window stage data for this ability. ...@@ -2161,10 +2031,17 @@ Restores the window stage data for this ability.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| localStorage | image.LocalStorage | Yes| Storage used to store the restored window stage.| | localStorage | image.LocalStorage | Yes| Storage used to store the restored window stage.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
**Example** **Example**
```ts ```ts
var storage = new LocalStorage(); let storage = new LocalStorage();
this.context.restoreWindowStage(storage); this.context.restoreWindowStage(storage);
``` ```
...@@ -2172,7 +2049,7 @@ Restores the window stage data for this ability. ...@@ -2172,7 +2049,7 @@ Restores the window stage data for this ability.
isTerminating(): boolean; isTerminating(): boolean;
Checks whether this ability is in the terminating state. Checks whether this UIAbility is in the terminating state.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -2180,11 +2057,117 @@ Checks whether this ability is in the terminating state. ...@@ -2180,11 +2057,117 @@ Checks whether this ability is in the terminating state.
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean| The value **true** means that the ability is in the terminating state, and **false** means the opposite.| | boolean| The value **true** means that the UIAbility is in the terminating state, and **false** means the opposite.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
**Example** **Example**
```ts ```ts
var isTerminating = this.context.isTerminating(); let isTerminating = this.context.isTerminating();
console.log('ability state :' + isTerminating); console.info(`ability state is ${isTerminating}`);
```
## UIAbilityContext.requestDialogService
requestDialogService(want: Want, result: AsyncCallback&lt;dialogRequest.RequestResult&gt;): void;
Starts a ServiceExtensionAbility that supports modal dialog boxes. After the ServiceExtensionAbility is started, the application displays a modal dialog box. You can call [setRequestResult](js-apis-app-ability-dialogRequest.md#requestcallbacksetrequestresult) to obtain the result.
Observe the following when using this API:
- If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
- If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
- For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-want.md) | Yes| Want information about the target ServiceExtensionAbility.|
| result | AsyncCallback&lt;[dialogRequest.RequestResult](js-apis-app-ability-dialogRequest.md)&gt; | Yes| Callback used to return the result.|
**Example**
```ts
import dialogRequest from '@ohos.app.ability.dialogRequest';
let want = {
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'AuthAccountServiceExtension'
};
try {
this.context.requestDialogService(want, (err, result) => {
if (err.code) {
// Process service logic errors.
console.error(`requestDialogService failed, code is ${err.code}, message is ${err.message}`);
return;
}
// Carry out normal service processing.
console.info('requestDialogService succeed, result = ' + JSON.stringify(result));
});
} catch (err) {
// Process input parameter errors.
console.error(`requestDialogService failed, code is ${err.code}, message is ${err.message}`);
}
```
## UIAbilityContext.requestDialogService
requestDialogService(want: Want): Promise&lt;dialogRequest.RequestResult&gt;;
Starts a ServiceExtensionAbility that supports modal dialog boxes. After the ServiceExtensionAbility is started, the application displays a modal dialog box. You can call [setRequestResult](js-apis-app-ability-dialogRequest.md#requestcallbacksetrequestresult) to obtain the result, which is returned to the caller in promise mode.
Observe the following when using this API:
- If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
- If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
- For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | Yes| Want information about the target ServiceExtensionAbility.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[dialogRequest.RequestResult](js-apis-app-ability-dialogRequest.md)&gt; | Promise used to return the result.
**Example**
```ts
import dialogRequest from '@ohos.app.ability.dialogRequest';
let want = {
bundleName: 'com.example.myapplication',
abilityName: 'AuthAccountServiceExtension'
};
try {
this.context.requestDialogService(want)
.then((result) => {
// Carry out normal service processing.
console.info('requestDialogService succeed, result = ' + JSON.stringify(result));
})
.catch((err) => {
// Process service logic errors.
console.error(`requestDialogService failed, code is ${err.code}, message is ${err.message}`);
});
} catch (err) {
// Process input parameter errors.
console.error(`requestDialogService failed, code is ${err.code}, message is ${err.message}`);
}
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册