提交 47709560 编写于 作者: G Gloria

Update docs against 16780+17051+17211+16804+16815+16852+17293+17211+16927+16836+16490

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 c7900e92
......@@ -39,6 +39,7 @@ Enumerates the initial ability launch reasons. You can use it together with [onC
| CALL | 2 | The ability is started by calling [startAbilityByCall](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartabilitybycall).|
| CONTINUATION | 3 | The ability is started by means of cross-device migration.|
| APP_RECOVERY | 4 | The ability is automatically started when the application is restored from a fault.|
| SHARE<sup>10+</sup> | 5 | The ability is started by calling [acquireShareData](js-apis-app-ability-abilityManager.md#acquiresharedata).|
**Example**
......
......@@ -45,7 +45,7 @@ Updates the configuration. This API uses an asynchronous callback to return the
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| config | [Configuration](js-apis-app-ability-configuration.md) | Yes | New configuration. You only need to configure the items to be updated.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the API call result. You can perform error handling or custom processing in this callback. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the API call result. You can perform error handling or custom processing in it. |
**Error codes**
......@@ -72,7 +72,7 @@ const config = {
try {
abilityManager.updateConfiguration(config, (err) => {
if (err && err.code !== 0) {
if (err) {
console.error('updateConfiguration fail, err: ${JSON.stringify(err)}');
} else {
console.log('updateConfiguration success.');
......@@ -103,7 +103,7 @@ Updates the configuration. This API uses a promise to return the result.
| Type | Description |
| ---------------------------------------- | ------- |
| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.|
| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in it.|
**Error codes**
......@@ -153,7 +153,7 @@ Obtains the ability running information. This API uses an asynchronous callback
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | Yes | Callback used to return the API call result and the ability running information. You can perform error handling or custom processing in this callback. |
| callback | AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | Yes | Callback used to return the API call result and the ability running information. You can perform error handling or custom processing in it. |
**Error codes**
......@@ -170,7 +170,7 @@ import abilityManager from '@ohos.app.ability.abilityManager';
try {
abilityManager.getAbilityRunningInfos((err, data) => {
if (err && err.code !== 0) {
if (err) {
console.error('getAbilityRunningInfos fail, error: ${JSON.stringify(err)}');
} else {
console.log('getAbilityRunningInfos success, data: ${JSON.stringify(data)}');
......@@ -195,7 +195,7 @@ Obtains the UIAbility running information. This API uses a promise to return the
| Type | Description |
| ---------------------------------------- | ------- |
| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | Promise used to return the API call result and the UIAbility running information. You can perform error handling or custom processing in this callback.|
| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | Promise used to return the API call result and the UIAbility running information. You can perform error handling or custom processing in it.|
**Error codes**
......@@ -236,7 +236,7 @@ Obtains the ExtensionAbility running information. This API uses an asynchronous
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| upperLimit | number | Yes| Maximum number of messages that can be obtained. The maximum value is 2<sup>31</sup>-1.|
| callback | AsyncCallback\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | Yes | Callback used to return the API call result and the ExtensionAbility running information. You can perform error handling or custom processing in this callback. |
| callback | AsyncCallback\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | Yes | Callback used to return the API call result and the ExtensionAbility running information. You can perform error handling or custom processing in it. |
**Error codes**
......@@ -254,8 +254,8 @@ import abilityManager from '@ohos.app.ability.abilityManager';
let upperLimit = 10;
try {
abilityManager.getExtensionRunningInfos(upperLimit, (err, data) => {
if (err && err.code !== 0) {
abilityManager.getExtensionRunningInfos(upperLimit, (err, data) => {
if (err) {
console.error('getExtensionRunningInfos fail, err: ${JSON.stringify(err)}');
} else {
console.log('getExtensionRunningInfos success, data: ${JSON.stringify(data)}');
......@@ -286,7 +286,7 @@ Obtains the ExtensionAbility running information. This API uses a promise to ret
| Type | Description |
| ---------------------------------------- | ------- |
| Promise\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | Promise used to return the API call result and the ExtensionAbility running information. You can perform error handling or custom processing in this callback.|
| Promise\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | Promise used to return the API call result and the ExtensionAbility running information. You can perform error handling or custom processing in it.|
**Error codes**
......@@ -326,7 +326,7 @@ Obtains the top ability, which is the ability that has the window focus. This AP
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<[ElementName](js-apis-bundleManager-elementName.md)> | Yes | Callback used to return the API call result and the element name of the top ability. You can perform error handling or custom processing in this callback. |
| callback | AsyncCallback\<[ElementName](js-apis-bundleManager-elementName.md)> | Yes | Callback used to return the API call result and the element name of the top ability. You can perform error handling or custom processing in it. |
**Error codes**
......@@ -342,7 +342,7 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
import abilityManager from '@ohos.app.ability.abilityManager';
abilityManager.getTopAbility((err, data) => {
if (err && err.code !== 0) {
if (err) {
console.error('getTopAbility fail, err: ${JSON.stringify(err)}');
} else {
console.log('getTopAbility success, data: ${JSON.stringify(data)}');
......@@ -362,7 +362,7 @@ Obtains the top ability, which is the ability that has the window focus. This AP
| Type | Description |
| ---------------------------------------- | ------- |
| Promise\<[ElementName](js-apis-bundleManager-elementName.md)>| Promise used to return the API call result and the element name of the top ability. You can perform error handling or custom processing in this callback.|
| Promise\<[ElementName](js-apis-bundleManager-elementName.md)>| Promise used to return the API call result and the element name of the top ability. You can perform error handling or custom processing in it.|
**Error codes**
......@@ -383,3 +383,78 @@ abilityManager.getTopAbility().then((data) => {
console.error('getTopAbility fail, err: ${JSON.stringify(err)}');
});
```
## acquireShareData<sup>10+</sup>
acquireShareData(missionId: number, callback: AsyncCallback<{[key: string]: Object}>): void;
Acquires the shared data of the target device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| missionId | number | Yes| Mission ID on the target device. The maximum value is 2<sup>31</sup>-1.|
| callback | AsyncCallback<{[key: string]: Object}> | Yes | Callback used to return the API call result and the shared data. You can perform error handling or custom processing in it. |
**Error codes**
| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
import abilityManager from '@ohos.app.ability.abilityManager';
abilityManager.acquireShareData(1, (err, wantParam) => {
if (err) {
console.error(`acquireShareData fail, err: ${JSON.stringify(err)}`);
} else {
console.log(`acquireShareData success, data: ${JSON.stringify(data)}`);
}
});
```
## acquireShareData<sup>10+</sup>
acquireShareData(missionId: number): Promise<{[key: string]: Object}>;
Acquires the shared data of the target device. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| ---------------------------------------- | ------- |
| Promise<{[key: string]: Object}>| Promise used to return the API call result and the shared data. You can perform error handling or custom processing in it.|
**Error codes**
| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
import abilityManager from '@ohos.app.ability.abilityManager';
try {
abilityManager.acquireShareData(1).then((wantParam) => {
console.log(`acquireShareData success, data: ${JSON.stringify(data)}`);
}).catch((err) => {
console.error(`acquireShareData fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
console.error(`error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}`);
}
```
......@@ -63,8 +63,8 @@ Enables application recovery. After this API is called, the first ability that i
| saveOccasion | [SaveOccasionFlag](#apprecoverysaveoccasionflag) | No| Scenario for saving the application state. By default, the state is saved when a fault occurs.|
| saveMode | [SaveModeFlag](#apprecoverysavemodeflag) | No| Application state saving mode. By default, the application state is written to the local file cache.|
**Example**
**Example**
```ts
import appRecovery from '@ohos.app.ability.appRecovery';
import AbilityStage from '@ohos.app.ability.AbilityStage';
......@@ -87,19 +87,17 @@ restartApp(): void;
Restarts the current process and starts the first ability that is displayed when the application is started. If the state of this ability is saved, the saved state data is passed into the **wantParam** attribute in the **want** parameter of the **OnCreate** lifecycle callback of the ability.
In API version 10, the ability specified by [setRestartWant](#apprecoverysetrestartwant) is started. If no ability is specified, the following rules are used:
- If the ability of the current application running in the foreground supports recovery, that ability is started.
- If multiple abilities that support recovery is running in the foreground, only the last ability is started.
- If no ability is running in the foreground, none of them is started.
This API can be used together with the APIs of [errorManager](js-apis-app-ability-errorManager.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Example**
**Example**
```ts
import appRecovery from '@ohos.app.ability.appRecovery';
import errorManager from '@ohos.app.ability.errorManager';
......@@ -132,8 +130,8 @@ Saves the application state. This API can be used together with the APIs of [err
| -------- | -------- |
| boolean | Whether the application state is saved. The value **true** is returned if the application state is saved, and **false** is returned otherwise.|
**Example**
**Example**
```ts
import appRecovery from '@ohos.app.ability.appRecovery';
import errorManager from '@ohos.app.ability.errorManager';
......@@ -160,6 +158,12 @@ Saves the ability state, which will be used for recovery. This API can be used t
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md)| No| UIAbility context.|
**Return value**
| Type| Description|
......@@ -184,6 +188,12 @@ Sets an ability that will be recovered. The ability must be a UIAbility in the c
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md)| Yes| Want of the target ability. You can set the **bundleName** and **abilityName** fields in **Want** to specify the ability.|
**Example**
```ts
......
......@@ -32,12 +32,27 @@ Registers an error observer.
| -------- | -------- |
| number | Index of the observer.|
**Error codes**
| ID| Error Message|
| ------- | -------- |
| 16000003 | Id does not exist. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg);
},
onException(errorObj) {
console.log('onException, name: ', errorObj.name);
console.log('onException, message: ', errorObj.message);
if (typeof(errorObj.stack) === 'string') {
console.log('onException, stack: ', errorObj.stack);
}
}
};
let observerId = -1;
......@@ -64,6 +79,14 @@ Deregisters an error observer. This API uses an asynchronous callback to return
| observerId | number | Yes| Index of the observer returned by **on()**.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------- |
| 16000003 | Id does not exist. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
......@@ -102,6 +125,14 @@ Deregisters an error observer. This API uses a promise to return the result.
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------- |
| 16000003 | Id does not exist. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
......
......@@ -148,7 +148,7 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal
## ServiceExtensionAbility.onDisconnect
onDisconnect(want: Want): void | Promise<void>;
onDisconnect(want: Want): void | Promise\<void>;
Called when a client is disconnected from this ServiceExtensionAbility.
......
......@@ -300,6 +300,33 @@ class MyUIAbility extends UIAbility {
}
```
## UIAbility.onShare<sup>10+</sup>
onShare(wantParam:{ [key: string]: Object }): void;
Called when an ability shares data.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wantParam | {[key:&nbsp;string]:&nbsp;Object} | Yes| **want** parameter.|
**Example**
```ts
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
onShare(wantParams) {
console.log('onShare');
wantParams['ohos.extra.param.key.contentTitle'] = {title: "W3"};
wantParams['ohos.extra.param.key.shareAbstract'] = {abstract: "communication for huawei employee"};
wantParams['ohos.extra.param.key.shareUrl'] = {url: "w3.huawei.com"};
}
}
```
## Caller
......@@ -331,7 +358,9 @@ Sends sequenceable data to the target ability.
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -410,7 +439,9 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -478,10 +509,10 @@ Releases the caller interface of the target ability.
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
......@@ -515,6 +546,14 @@ Registers a callback that is invoked when the stub on the target ability is disc
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 16200001 | Caller released. The caller has been released. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -538,7 +577,7 @@ Registers a callback that is invoked when the stub on the target ability is disc
console.log(' Caller OnRelease CallBack is called ${str}');
});
} catch (error) {
console.log('Caller.onRelease catch error, error.code: ${error.code}, error.message: ${error.message}');
console.log('Caller.onRelease catch error, error.code: $error.code}, error.message: ${error.message}');
}
}).catch((err) => {
console.log('Caller GetCaller error, error.code: ${err.code}, error.message: ${err.message}');
......@@ -547,6 +586,57 @@ Registers a callback that is invoked when the stub on the target ability is disc
}
```
## Caller.onRemoteStateChange
onRemoteStateChange(callback: OnRemoteStateChangeCallback): void;
Registers a callback that is invoked when the remote ability state changes in the collaboration scenario.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | [OnRemoteStateChangeCallback](#onremotestatechangecallback) | Yes| Callback used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 16200001 | Caller released. The caller has been released. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let caller;
let dstDeviceId: string;
export default class MainAbility extends UIAbility {
onWindowStageCreate(windowStage: Window.WindowStage) {
this.context.startAbilityByCall({
bundleName: 'com.example.myservice',
abilityName: 'MainUIAbility',
deviceId: dstDeviceId
}).then((obj) => {
caller = obj;
try {
caller.onRemoteStateChange((str) => {
console.log('Remote state changed ' + str);
});
} catch (error) {
console.log('Caller.onRemoteStateChange catch error, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
}
}).catch((err) => {
console.log('Caller GetCaller error, error.code: ${JSON.stringify(err.code)}, error.message: ${JSON.stringify(err.message)}');
});
}
}
```
## Caller.on
on(type: 'release', callback: OnReleaseCallback): void;
......@@ -566,7 +656,7 @@ Registers a callback that is invoked when the stub on the target ability is disc
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
| 16200001 | Caller released. The caller has been released. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -611,13 +701,6 @@ Deregisters a callback that is invoked when the stub on the target ability is di
| type | string | Yes| Event type. The value is fixed at **release**.|
| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
......@@ -660,13 +743,6 @@ Deregisters a callback that is invoked when the stub on the target ability is di
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is fixed at **release**.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
......@@ -718,7 +794,8 @@ Registers a caller notification callback, which is invoked when the target abili
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
| 16200004 | Method registered. The method has registered. |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -783,7 +860,8 @@ Deregisters a caller notification callback, which is invoked when the target abi
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
| 16200005 | Method not registered. The method has not registered. |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -814,6 +892,16 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
| -------- | -------- | -------- | -------- | -------- |
| (msg: string) | Yes| No| function | Prototype of the listener function registered by the caller.|
## OnRemoteStateChangeCallback
(msg: string): void;
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Readable| Writable| Type| Description|
| -------- | -------- | -------- | -------- | -------- |
| (msg: string) | Yes| No| function | Prototype of the ability state change listener function registered by the caller in the collaboration scenario.|
## CalleeCallback
(indata: rpc.MessageSequence): rpc.Parcelable;
......
......@@ -16,13 +16,17 @@ import wantConstant from '@ohos.app.ability.wantConstant';
Defines **Params** (specifying the action that can be performed) in the Want.
| Name | Value | Description |
| ----------------------- | --------------------------- | ------------------------------------------------------------ |
| DLP_PARAMS_SANDBOX | ohos.dlp.params.sandbox | Action of obtaining the sandbox flag.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| DLP_PARAMS_BUNDLE_NAME | ohos.dlp.params.bundleName | Action of obtaining the DLP bundle name.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| DLP_PARAMS_MODULE_NAME | ohos.dlp.params.moduleName | Action of obtaining the DLP module name.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| DLP_PARAMS_ABILITY_NAME | ohos.dlp.params.abilityName | Action of obtaining the DLP ability name.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| DLP_PARAMS_INDEX | ohos.dlp.params.index | Action of obtaining the DLP index.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| Name | Value | Description |
| ----------------------- | ---------------------------------- | ------------------------------------------------------------------------------ |
| DLP_PARAMS_SANDBOX | ohos.dlp.params.sandbox | Action of obtaining the sandbox flag.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| DLP_PARAMS_BUNDLE_NAME | ohos.dlp.params.bundleName | Action of obtaining the DLP bundle name.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| DLP_PARAMS_MODULE_NAME | ohos.dlp.params.moduleName | Action of obtaining the DLP module name.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| DLP_PARAMS_ABILITY_NAME | ohos.dlp.params.abilityName | Action of obtaining the DLP ability name.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| DLP_PARAMS_INDEX | ohos.dlp.params.index | Action of obtaining the DLP index.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| ABILITY_RECOVERY_RESTART | ohos.ability.params.abilityRecoveryRestart | Action of recovering an ability from a fault and restarting it.|
| CONTENT_TITLE_KEY | ohos.extra.param.key.contentTitle | Action of sharing the content title.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| SHARE_ABSTRACT_KEY | ohos.extra.param.key.shareAbstract | Action of sharing the abstract.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| SHARE_URL_KEY | ohos.extra.param.key.shareUrl | Action of sharing the URL.<br>**System API**: This is a system API and cannot be called by third-party applications.|
## wantConstant.Flags
......
......@@ -449,8 +449,9 @@ For details about the error codes, see [AVSession Management Error Codes](../err
import audio from '@ohos.multimedia.audio';
let audioManager = audio.getAudioManager();
let audioRoutingManager = audioManager.getRoutingManager();
let audioDevices;
await audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
audioDevices = data;
console.info('Promise returned to indicate that the device list is obtained.');
}).catch((err) => {
......@@ -502,8 +503,9 @@ For details about the error codes, see [AVSession Management Error Codes](../err
import audio from '@ohos.multimedia.audio';
let audioManager = audio.getAudioManager();
let audioRoutingManager = audioManager.getRoutingManager();
let audioDevices;
await audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
audioDevices = data;
console.info('Promise returned to indicate that the device list is obtained.');
}).catch((err) => {
......
......@@ -88,7 +88,7 @@ export default class EntryAbility extends UIAbility {
}
```
## ApplicationContext.off(type: 'abilityLifecycle', callbackId: number, callback: AsyncCallback<void>)
## ApplicationContext.off(type: 'abilityLifecycle', callbackId: number, callback: AsyncCallback\<void>)
off(type: 'abilityLifecycle', callbackId: **number**, callback: AsyncCallback<**void**>): **void**;
......@@ -116,7 +116,7 @@ export default class EntryAbility extends UIAbility {
let applicationContext = this.context.getApplicationContext();
console.log('stage applicationContext: ${applicationContext}');
applicationContext.off('abilityLifecycle', lifecycleId, (error, data) => {
if (error && error.code !== 0) {
if (error) {
console.error('unregisterAbilityLifecycleCallback fail, err: ${JSON.stringify(error)}');
} else {
console.log('unregisterAbilityLifecycleCallback success, data: ${JSON.stringify(data)}');
......@@ -206,7 +206,7 @@ export default class EntryAbility extends UIAbility {
}
```
## ApplicationContext.off(type: 'environment', callbackId: number, callback: AsyncCallback<void>)
## ApplicationContext.off(type: 'environment', callbackId: number, callback: AsyncCallback\<void>)
off(type: 'environment', callbackId: **number**, callback: AsyncCallback<**void**>): **void**;
......@@ -233,7 +233,7 @@ export default class EntryAbility extends UIAbility {
onDestroy() {
let applicationContext = this.context.getApplicationContext();
applicationContext.off('environment', callbackId, (error, data) => {
if (error && error.code !== 0) {
if (error) {
console.error('unregisterEnvironmentCallback fail, err: ${JSON.stringify(error)}');
} else {
console.log('unregisterEnvironmentCallback success, data: ${JSON.stringify(data)}');
......@@ -291,6 +291,15 @@ Obtains information about the running processes. This API uses a promise to retu
| -------- | -------- |
| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
**Error codes**
| ID| Error Message|
| ------- | -------- |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
......@@ -320,12 +329,21 @@ Obtains information about the running processes. This API uses an asynchronous c
| -------- | -------- |
|AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
**Error codes**
| ID| Error Message|
| ------- | -------- |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
let applicationContext = this.context.getApplicationContext();
applicationContext.getRunningProcessInformation((err, data) => {
if (err.code !== 0) {
if (err) {
console.error('getRunningProcessInformation faile, err: ${JSON.stringify(err)}');
} else {
console.log('The process running information is: ${JSON.stringify(data)}');
......@@ -347,6 +365,14 @@ Kills all the processes where the application is located. This API uses a promis
| -------- | -------- |
| Promise\<void\> | Promise used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------- |
| 16000011 | The context does not exist. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
......@@ -368,12 +394,20 @@ Kills all the processes where the application is located. This API uses an async
| -------- | -------- |
|AsyncCallback\<void\> | Callback used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------- |
| 16000011 | The context does not exist. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
let applicationContext = this.context.getApplicationContext();
applicationContext.killAllProcesses(error => {
if (error && error.code !== 0) {
if (error) {
console.error('killAllProcesses fail, error: ${JSON.stringify(error)}');
}
});
......
......@@ -2,6 +2,12 @@
The **ErrorObserver** module defines an observer to listen for application errors. It can be used as an input parameter in [ErrorManager.on](js-apis-app-ability-errorManager.md#errormanageron) to listen for errors that occur in the current application.
## Modules to Import
```ts
import errorManager from '@ohos.app.ability.errorManager';
```
## ErrorObserver.onUnhandledException
onUnhandledException(errMsg: string): void;
......@@ -33,3 +39,42 @@ try {
console.error('registerErrorObserver failed, error.code: ${error.code}, error.message: ${error.message}');
}
```
## ErrorObserver.onException
onException?(errObject: Error): void;
Called when an exception occurs during the application running.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| errObject | Error | Yes| Event name, message, and error stack of the exception.|
**Example**
```ts
import errorManager from '@ohos.app.ability.errorManager';
let observer = {
onUnhandledException(errorMsg) {
console.error('onUnhandledException, errorMsg: ', errorMsg);
},
onException(errorObj) {
console.log('onException, name: ', errorObj.name);
console.log('onException, message: ', errorObj.message);
if (typeof(errorObj.stack) === 'string') {
console.log('onException, stack: ', errorObj.stack);
}
}
};
try {
errorManager.on('error', observer);
} catch (error) {
console.error('registerErrorObserver failed, error.code: ${error.code}, error.message: ${error.message}');
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册