提交 0c107a55 编写于 作者: G Gloria

Update docs against 14256+14349+14622+14786+14943

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 f473f432
...@@ -10,7 +10,7 @@ The **Ability** module provides all level-2 module APIs for developers to export ...@@ -10,7 +10,7 @@ The **Ability** module provides all level-2 module APIs for developers to export
## Modules to Import ## Modules to Import
```ts ```ts
import ability from '@ohos.ability.ability' import ability from '@ohos.ability.ability';
``` ```
**System capability**: SystemCapability.Ability.AbilityBase **System capability**: SystemCapability.Ability.AbilityBase
......
...@@ -35,7 +35,7 @@ Obtains the ID attached to the end of a given URI. ...@@ -35,7 +35,7 @@ Obtains the ID attached to the end of a given URI.
**Example** **Example**
```ts ```ts
let id = dataUriUtils.getId("com.example.dataUriUtils/1221"); let id = dataUriUtils.getId('com.example.dataUriUtils/1221');
``` ```
...@@ -66,9 +66,9 @@ Attaches an ID to the end of a given URI. ...@@ -66,9 +66,9 @@ Attaches an ID to the end of a given URI.
```ts ```ts
let id = 1122; let id = 1122;
let uri = dataUriUtils.attachId( let uri = dataUriUtils.attachId(
"com.example.dataUriUtils", 'com.example.dataUriUtils',
id, id,
) );
``` ```
...@@ -96,7 +96,7 @@ Deletes the ID from the end of a given URI. ...@@ -96,7 +96,7 @@ Deletes the ID from the end of a given URI.
**Example** **Example**
```ts ```ts
let uri = dataUriUtils.deleteId("com.example.dataUriUtils/1221") let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221');
``` ```
...@@ -127,7 +127,7 @@ Updates the ID in a given URI. ...@@ -127,7 +127,7 @@ Updates the ID in a given URI.
```ts ```ts
let id = 1122; let id = 1122;
let uri = dataUriUtils.updateId( let uri = dataUriUtils.updateId(
"com.example.dataUriUtils/1221", 'com.example.dataUriUtils/1221',
id id
) );
``` ```
...@@ -9,7 +9,7 @@ The **ErrorCode** module defines the error codes that may be returned when an ab ...@@ -9,7 +9,7 @@ The **ErrorCode** module defines the error codes that may be returned when an ab
## Modules to Import ## Modules to Import
```ts ```ts
import errorCode from '@ohos.ability.errorCode' import errorCode from '@ohos.ability.errorCode';
``` ```
## ErrorCode ## ErrorCode
......
...@@ -27,7 +27,7 @@ Enumerates the ability states. This enum can be used together with [AbilityRunni ...@@ -27,7 +27,7 @@ Enumerates the ability states. This enum can be used together with [AbilityRunni
| FOREGROUND | 9 | The ability is in the foreground state. | | FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state. | | BACKGROUND | 10 | The ability is in the background state. |
| FOREGROUNDING | 11 | The ability is in the state of being switched to the foreground. | | FOREGROUNDING | 11 | The ability is in the state of being switched to the foreground. |
| BACKGROUNDING | 12 | The ability is in the state of being switched to the background. | | BACKGROUNDING | 12 | The ability is in the state of being switched to the background. |
## updateConfiguration ## updateConfiguration
...@@ -63,7 +63,7 @@ const config = { ...@@ -63,7 +63,7 @@ const config = {
language: 'Zh-Hans', // Simplified Chinese. language: 'Zh-Hans', // Simplified Chinese.
colorMode: COLOR_MODE_LIGHT, // Light theme. colorMode: COLOR_MODE_LIGHT, // Light theme.
direction: DIRECTION_VERTICAL, // Vertical direction. direction: DIRECTION_VERTICAL, // Vertical direction.
screenDensity: SCREEN_DENSITY_SDPI, // The screen resolution is SDPI. screenDensity: SCREEN_DENSITY_SDPI, // The screen pixel density is 'sdpi'.
displayId: 1, // The application is displayed on the display with ID 1. displayId: 1, // The application is displayed on the display with ID 1.
hasPointerDevice: true, // A pointer device is connected. hasPointerDevice: true, // A pointer device is connected.
}; };
...@@ -121,7 +121,7 @@ const config = { ...@@ -121,7 +121,7 @@ const config = {
language: 'Zh-Hans', // Simplified Chinese. language: 'Zh-Hans', // Simplified Chinese.
colorMode: COLOR_MODE_LIGHT, // Light theme. colorMode: COLOR_MODE_LIGHT, // Light theme.
direction: DIRECTION_VERTICAL, // Vertical direction. direction: DIRECTION_VERTICAL, // Vertical direction.
screenDensity: SCREEN_DENSITY_SDPI, // The screen resolution is SDPI. screenDensity: SCREEN_DENSITY_SDPI, // The screen pixel density is 'sdpi'.
displayId: 1, // The application is displayed on the display with ID 1. displayId: 1, // The application is displayed on the display with ID 1.
hasPointerDevice: true, // A pointer device is connected. hasPointerDevice: true, // A pointer device is connected.
}; };
...@@ -131,7 +131,7 @@ try { ...@@ -131,7 +131,7 @@ try {
console.log('updateConfiguration success.'); console.log('updateConfiguration success.');
}).catch((err) => { }).catch((err) => {
console.log('updateConfiguration fail, err: ' + JSON.stringify(err)); console.log('updateConfiguration fail, err: ' + JSON.stringify(err));
}) });
} catch (paramError) { } catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) console.log('error.code: ' + JSON.stringify(paramError.code)
+ ' error.message: ' + JSON.stringify(paramError.message)); + ' error.message: ' + JSON.stringify(paramError.message));
...@@ -310,7 +310,7 @@ try { ...@@ -310,7 +310,7 @@ try {
console.log('getExtensionRunningInfos success, data: ' + JSON.stringify(data)); console.log('getExtensionRunningInfos success, data: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err) => {
console.log('getExtensionRunningInfos fail, err: ' + JSON.stringify(err)); console.log('getExtensionRunningInfos fail, err: ' + JSON.stringify(err));
}) });
} catch (paramError) { } catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) console.log('error.code: ' + JSON.stringify(paramError.code)
+ ' error.message: ' + JSON.stringify(paramError.message)); + ' error.message: ' + JSON.stringify(paramError.message));
...@@ -384,5 +384,5 @@ abilityManager.getTopAbility().then((data) => { ...@@ -384,5 +384,5 @@ abilityManager.getTopAbility().then((data) => {
console.log('getTopAbility success, data: ' + JSON.stringify(data)); console.log('getTopAbility success, data: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err) => {
console.log('getTopAbility fail, err: ' + JSON.stringify(err)); console.log('getTopAbility fail, err: ' + JSON.stringify(err));
}) });
``` ```
...@@ -45,7 +45,7 @@ appManager.isRunningInStabilityTest((err, flag) => { ...@@ -45,7 +45,7 @@ appManager.isRunningInStabilityTest((err, flag) => {
} else { } else {
console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag)); console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag));
} }
}) });
``` ```
...@@ -151,7 +151,7 @@ appManager.isRamConstrainedDevice((err, data) => { ...@@ -151,7 +151,7 @@ appManager.isRamConstrainedDevice((err, data) => {
} else { } else {
console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data)); console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data));
} }
}) });
``` ```
## appManager.getAppMemorySize ## appManager.getAppMemorySize
...@@ -221,7 +221,7 @@ appManager.getAppMemorySize((err, data) => { ...@@ -221,7 +221,7 @@ appManager.getAppMemorySize((err, data) => {
} else { } else {
console.log('The size of app memory is:' + JSON.stringify(data)); console.log('The size of app memory is:' + JSON.stringify(data));
} }
}) });
``` ```
## appManager.getProcessRunningInformation ## appManager.getProcessRunningInformation
...@@ -299,7 +299,7 @@ appManager.getProcessRunningInformation((err, data) => { ...@@ -299,7 +299,7 @@ appManager.getProcessRunningInformation((err, data) => {
} else { } else {
console.log('The process running information is:' + JSON.stringify(data)); console.log('The process running information is:' + JSON.stringify(data));
} }
}) });
``` ```
## appManager.on ## appManager.on
...@@ -356,7 +356,7 @@ let applicationStateObserver = { ...@@ -356,7 +356,7 @@ let applicationStateObserver = {
onProcessStateChanged(processData) { onProcessStateChanged(processData) {
console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
} }
} };
try { try {
const observerId = appManager.on('applicationState', applicationStateObserver); const observerId = appManager.on('applicationState', applicationStateObserver);
console.log(`[appManager] observerCode: ${observerId}`); console.log(`[appManager] observerCode: ${observerId}`);
...@@ -420,7 +420,7 @@ let applicationStateObserver = { ...@@ -420,7 +420,7 @@ let applicationStateObserver = {
onProcessStateChanged(processData) { onProcessStateChanged(processData) {
console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
} }
} };
let bundleNameList = ['bundleName1', 'bundleName2']; let bundleNameList = ['bundleName1', 'bundleName2'];
try { try {
const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
...@@ -482,7 +482,7 @@ let applicationStateObserver = { ...@@ -482,7 +482,7 @@ let applicationStateObserver = {
onProcessStateChanged(processData) { onProcessStateChanged(processData) {
console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
} }
} };
let bundleNameList = ['bundleName1', 'bundleName2']; let bundleNameList = ['bundleName1', 'bundleName2'];
try { try {
observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
...@@ -563,7 +563,7 @@ let applicationStateObserver = { ...@@ -563,7 +563,7 @@ let applicationStateObserver = {
onProcessStateChanged(processData) { onProcessStateChanged(processData) {
console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
} }
} };
let bundleNameList = ['bundleName1', 'bundleName2']; let bundleNameList = ['bundleName1', 'bundleName2'];
try { try {
observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
...@@ -578,7 +578,7 @@ try { ...@@ -578,7 +578,7 @@ try {
console.log('unregisterApplicationStateObserver success, data: ' + JSON.stringify(data)); console.log('unregisterApplicationStateObserver success, data: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err) => {
console.log('unregisterApplicationStateObserver faile, err: ' + JSON.stringify(err)); console.log('unregisterApplicationStateObserver faile, err: ' + JSON.stringify(err));
}) });
} catch (paramError) { } catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message); console.log('error: ' + paramError.code + ', ' + paramError.message);
} }
...@@ -664,7 +664,7 @@ appManager.getForegroundApplications().then((data) => { ...@@ -664,7 +664,7 @@ appManager.getForegroundApplications().then((data) => {
console.log('getForegroundApplications success, data: ' + JSON.stringify(data)); console.log('getForegroundApplications success, data: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err) => {
console.log('getForegroundApplications fail, err: ' + JSON.stringify(err)); console.log('getForegroundApplications fail, err: ' + JSON.stringify(err));
}) });
``` ```
## appManager.killProcessWithAccount ## appManager.killProcessWithAccount
...@@ -706,7 +706,7 @@ try { ...@@ -706,7 +706,7 @@ try {
console.log('killProcessWithAccount success'); console.log('killProcessWithAccount success');
}).catch((err) => { }).catch((err) => {
console.error('killProcessWithAccount fail, err: ' + JSON.stringify(err)); console.error('killProcessWithAccount fail, err: ' + JSON.stringify(err));
}) });
} catch (paramError) { } catch (paramError) {
console.error('error: ' + paramError.code + ', ' + paramError.message); console.error('error: ' + paramError.code + ', ' + paramError.message);
} }
...@@ -848,7 +848,7 @@ try { ...@@ -848,7 +848,7 @@ try {
console.log('killProcessesByBundleName success.'); console.log('killProcessesByBundleName success.');
}).catch((err) => { }).catch((err) => {
console.log('killProcessesByBundleName fail, err: ' + JSON.stringify(err)); console.log('killProcessesByBundleName fail, err: ' + JSON.stringify(err));
}) });
} catch (paramError) { } catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message); console.log('error: ' + paramError.code + ', ' + paramError.message);
} }
...@@ -944,7 +944,7 @@ try { ...@@ -944,7 +944,7 @@ try {
console.log('clearUpApplicationData success.'); console.log('clearUpApplicationData success.');
}).catch((err) => { }).catch((err) => {
console.log('clearUpApplicationData fail, err: ' + JSON.stringify(err)); console.log('clearUpApplicationData fail, err: ' + JSON.stringify(err));
}) });
} catch (paramError) { } catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message); console.log('error: ' + paramError.code + ', ' + paramError.message);
} }
......
...@@ -10,7 +10,7 @@ The **Common** module provides all level-2 module APIs for developers to export. ...@@ -10,7 +10,7 @@ The **Common** module provides all level-2 module APIs for developers to export.
## Modules to Import ## Modules to Import
```ts ```ts
import common from '@ohos.app.ability.common' import common from '@ohos.app.ability.common';
``` ```
**System capability**: SystemCapability.Ability.AbilityBase **System capability**: SystemCapability.Ability.AbilityBase
...@@ -33,7 +33,7 @@ import common from '@ohos.app.ability.common' ...@@ -33,7 +33,7 @@ import common from '@ohos.app.ability.common'
**Example** **Example**
```ts ```ts
import common from '@ohos.app.ability.common' import common from '@ohos.app.ability.common';
let uiAbilityContext: common.UIAbilityContext; let uiAbilityContext: common.UIAbilityContext;
let abilityStageContext: common.AbilityStageContext; let abilityStageContext: common.AbilityStageContext;
......
# @ohos.app.ability.Configuration (Configuration) # @ohos.app.ability.Configuration (Configuration)
The **Configuration** module defines environment change information. The **Configuration** module defines environment change information. **Configuration** is an interface definition and is used only for field declaration.
> **NOTE** > **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 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.
## Modules to Import
```ts
import Configuration from '@ohos.app.ability.Configuration'
```
**System capability**: SystemCapability.Ability.AbilityBase **System capability**: SystemCapability.Ability.AbilityBase
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| language | string | Yes| Yes| Language of the application, for example, **zh**.| | language | string | Yes| Yes| Language of the application, for example, **zh**.|
| colorMode | [ColorMode](js-apis-app-ability-configurationConstant.md#configurationconstantcolormode) | Yes| Yes| Color mode, which can be **COLOR_MODE_LIGHT** or **COLOR_MODE_DARK**. The default value is **COLOR_MODE_LIGHT**.| | colorMode | [ColorMode](js-apis-app-ability-configurationConstant.md#configurationconstantcolormode) | Yes| Yes| Color mode. The default value is **COLOR_MODE_LIGHT**. The options are as follows:<br>- **COLOR_MODE_NOT_SET**: The color mode is not set.<br>- **COLOR_MODE_LIGHT**: light mode.<br>- **COLOR_MODE_DARK**: dark mode.|
| direction | [Direction](js-apis-app-ability-configurationConstant.md#configurationconstantdirection) | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.| | direction | [Direction](js-apis-app-ability-configurationConstant.md#configurationconstantdirection) | Yes| No| Screen orientation. The options are as follows:<br>- **DIRECTION_NOT_SET**: The screen orientation is not set.<br>- **DIRECTION_HORIZONTAL**: horizontal direction.<br>- **DIRECTION_VERTICAL**: vertical direction.|
| screenDensity | [ScreenDensity](js-apis-app-ability-configurationConstant.md#configurationconstantscreendensity) | Yes| No| Screen resolution, which can be **SCREEN_DENSITY_SDPI** (120), **SCREEN_DENSITY_MDPI** (160), **SCREEN_DENSITY_LDPI** (240), **SCREEN_DENSITY_XLDPI** (320), **SCREEN_DENSITY_XXLDPI** (480), or **SCREEN_DENSITY_XXXLDPI** (640).| | screenDensity | [ScreenDensity](js-apis-app-ability-configurationConstant.md#configurationconstantscreendensity) | Yes| No| Pixel density of the screen. The options are as follows:<br>- **SCREEN_DENSITY_NOT_SET**: The pixel density is not set.<br>- **SCREEN_DENSITY_SDPI**: 120.<br>- **SCREEN_DENSITY_MDPI**: 160.<br>- **SCREEN_DENSITY_LDPI**: 240.<br>- **SCREEN_DENSITY_XLDPI**: 320.<br>- **SCREEN_DENSITY_XXLDPI**: 480.<br>- **SCREEN_DENSITY_XXXLDPI**: 640.|
| displayId | number | Yes| No| ID of the display where the application is located.| | displayId | number | Yes| No| ID of the display where the application is located.|
| hasPointerDevice | boolean | Yes| No| Whether a pointer device, such as a keyboard, mouse, or touchpad, is connected.| | hasPointerDevice | boolean | Yes| No| Whether a pointer device, such as a keyboard, mouse, or touchpad, is connected.|
...@@ -34,7 +28,7 @@ For details about the fields, see the **ohos.app.ability.Configuration.d.ts** fi ...@@ -34,7 +28,7 @@ For details about the fields, see the **ohos.app.ability.Configuration.d.ts** fi
onCreate(want, launchParam) { onCreate(want, launchParam) {
let envCallback = { let envCallback = {
onConfigurationUpdated(config) { onConfigurationUpdated(config) {
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`) console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`);
let language = config.language; let language = config.language;
let colorMode = config.colorMode; let colorMode = config.colorMode;
let direction = config.direction; let direction = config.direction;
...@@ -45,10 +39,10 @@ For details about the fields, see the **ohos.app.ability.Configuration.d.ts** fi ...@@ -45,10 +39,10 @@ For details about the fields, see the **ohos.app.ability.Configuration.d.ts** fi
}; };
try { try {
let applicationContext = this.context.getApplicationContext(); let applicationContext = this.context.getApplicationContext();
let callbackId = applicationContext.on("environment", envCallback); let callbackId = applicationContext.on('environment', envCallback);
console.log("callbackId: " + callbackId); console.log('callbackId: ' + callbackId);
} catch (paramError) { } catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message); console.log('error: ' + paramError.code + ', ' + paramError.message);
} }
} }
} }
......
...@@ -25,7 +25,7 @@ You can obtain the value of this constant by calling the **ConfigurationConstant ...@@ -25,7 +25,7 @@ You can obtain the value of this constant by calling the **ConfigurationConstant
| COLOR_MODE_LIGHT | 1 | Light mode.| | COLOR_MODE_LIGHT | 1 | Light mode.|
## ConfigurationConstant.Direction ## ConfigurationConstant.Direction<sup>9+</sup>
You can obtain the value of this constant by calling the **ConfigurationConstant.Direction** API. You can obtain the value of this constant by calling the **ConfigurationConstant.Direction** API.
...@@ -38,7 +38,7 @@ You can obtain the value of this constant by calling the **ConfigurationConstant ...@@ -38,7 +38,7 @@ You can obtain the value of this constant by calling the **ConfigurationConstant
| DIRECTION_HORIZONTAL | 1 | Horizontal direction.| | DIRECTION_HORIZONTAL | 1 | Horizontal direction.|
## ConfigurationConstant.ScreenDensity ## ConfigurationConstant.ScreenDensity<sup>9+</sup>
You can obtain the value of this constant by calling the **ConfigurationConstant.ScreenDensity** API. You can obtain the value of this constant by calling the **ConfigurationConstant.ScreenDensity** API.
...@@ -46,10 +46,10 @@ You can obtain the value of this constant by calling the **ConfigurationConstant ...@@ -46,10 +46,10 @@ You can obtain the value of this constant by calling the **ConfigurationConstant
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| SCREEN_DENSITY_NOT_SET | 0 | Unspecified screen resolution.| | SCREEN_DENSITY_NOT_SET | 0 | The screen pixel density is not set.|
| SCREEN_DENSITY_SDPI | 120 | The screen resolution is sdpi.| | SCREEN_DENSITY_SDPI | 120 | The pixel density of the screen is 'sdpi'.|
| SCREEN_DENSITY_MDPI | 160 | The screen resolution is mdpi.| | SCREEN_DENSITY_MDPI | 160 | The pixel density of the screen is 'mdpi'.|
| SCREEN_DENSITY_LDPI | 240 | The screen resolution is ldpi.| | SCREEN_DENSITY_LDPI | 240 | The pixel density of the screen is 'ldpi'.|
| SCREEN_DENSITY_XLDPI | 320 | The screen resolution is xldpi.| | SCREEN_DENSITY_XLDPI | 320 | The pixel density of the screen is 'xldpi'.|
| SCREEN_DENSITY_XXLDPI | 480 | The screen resolution is xxldpi.| | SCREEN_DENSITY_XXLDPI | 480 | The pixel density of the screen is 'xxldpi'.|
| SCREEN_DENSITY_XXXLDPI | 640 | The screen resolution is xxxldpi.| | SCREEN_DENSITY_XXXLDPI | 640 | The pixel density of the screen is 'xxxldpi'.|
...@@ -11,7 +11,7 @@ The **EnvironmentCallback** module provides the **onConfigurationUpdated** API f ...@@ -11,7 +11,7 @@ The **EnvironmentCallback** module provides the **onConfigurationUpdated** API f
## Modules to Import ## Modules to Import
```ts ```ts
import EnvironmentCallback from "@ohos.app.ability.EnvironmentCallback"; import EnvironmentCallback from '@ohos.app.ability.EnvironmentCallback';
``` ```
...@@ -29,33 +29,50 @@ Called when the system environment changes. ...@@ -29,33 +29,50 @@ Called when the system environment changes.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-app-ability-configuration.md) | Yes| **Configuration** object after the change.| | config | [Configuration](js-apis-app-ability-configuration.md) | Yes| **Configuration** object after the change.|
## EnvironmentCallback.onMemoryLevel
onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
Called when the system memory level changes.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| level | [AbilityConstant.MemoryLevel](js-apis-app-ability-abilityConstant.md#abilityconstantmemorylevel) | Yes| Memory level that indicates the memory usage status. When the specified memory level is reached, a callback will be invoked and the system will start adjustment.|
**Example** **Example**
```ts ```ts
import UIAbility from "@ohos.app.ability.Ability"; import Ability from '@ohos.application.Ability';
var callbackId; let callbackId;
export default class MyAbility extends UIAbility { export default class MyAbility extends Ability {
onCreate() { onCreate() {
console.log("MyAbility onCreate") console.log('MyAbility onCreate');
globalThis.applicationContext = this.context.getApplicationContext(); globalThis.applicationContext = this.context.getApplicationContext();
let EnvironmentCallback = { let environmentCallback = {
onConfigurationUpdated(config){ onConfigurationUpdated(config){
console.log("onConfigurationUpdated config:" + JSON.stringify(config)); console.log('onConfigurationUpdated config:' + JSON.stringify(config));
},
onMemoryLevel(level){
console.log('onMemoryLevel level: ${JSON.stringify(level)}');
} }
} };
// 1. Obtain an applicationContext object. // 1. Obtain an applicationContext object.
let applicationContext = globalThis.applicationContext; let applicationContext = globalThis.applicationContext;
// 2. Register a listener for the environment changes through the applicationContext object. // 2. Register a listener for the environment changes through the applicationContext object.
callbackId = applicationContext.registerEnvironmentCallback(EnvironmentCallback); callbackId = applicationContext.registerEnvironmentCallback(environmentCallback);
console.log("registerEnvironmentCallback number: " + JSON.stringify(callbackId)); console.log('registerEnvironmentCallback number: ' + JSON.stringify(callbackId));
} }
onDestroy() { onDestroy() {
let applicationContext = globalThis.applicationContext; let applicationContext = globalThis.applicationContext;
applicationContext.unregisterEnvironmentCallback(callbackId, (error, data) => { applicationContext.unregisterEnvironmentCallback(callbackId, (error, data) => {
console.log("unregisterEnvironmentCallback success, err: " + JSON.stringify(error)); console.log('unregisterEnvironmentCallback success, err: ' + JSON.stringify(error));
}); });
} }
} }
......
# @ohos.app.ability.errorManager (ErrorManager) # @ohos.app.ability.errorManager (ErrorManager)
The **ErrorManager** module provides APIs for registering and deregistering error observers. For example, you can use the APIs to register an observer when your application wants to capture JS crashes. The **ErrorManager** module provides APIs for registering and deregistering error observers.
> **NOTE** > **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 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.
## Modules to Import ## Modules to Import
```ts ```
import errorManager from '@ohos.app.ability.errorManager' import errorManager from '@ohos.app.ability.errorManager'
``` ```
## ErrorManager.on ## ErrorManager.on
on(type: "error", observer: ErrorObserver): number; on(type: 'error', observer: ErrorObserver): number;
Registers an error observer. Registers an error observer.
...@@ -23,34 +23,27 @@ Registers an error observer. ...@@ -23,34 +23,27 @@ Registers an error observer.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the API to call. It is fixed at **"error"**.| | type | string | Yes| Type of the API to call.|
| observer | [ErrorObserver](./js-apis-inner-application-errorObserver.md) | Yes| Digital code of the observer.| | observer | [ErrorObserver](./js-apis-inner-application-errorObserver.md) | Yes| Digital code of the observer.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Index of the observer.|
**Example** **Example**
```ts ```js
var observer = { let observer = {
onUnhandledException(errorMsg) { onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg) console.log('onUnhandledException, errorMsg: ', errorMsg);
} }
} };
var observerId = -1;
try { try {
observerId = errorManager.on("error", observer); errorManager.on('error', observer);
} catch (paramError) { } catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message); console.log('error: ' + paramError.code + ', ' + paramError.message);
} }
``` ```
## ErrorManager.off ## ErrorManager.off
off(type: "error", observerId: number, callback: AsyncCallback\<void>): void; off(type: 'error', observerId: number, callback: AsyncCallback\<void>): void;
Deregisters an error observer. This API uses an asynchronous callback to return the result. Deregisters an error observer. This API uses an asynchronous callback to return the result.
...@@ -60,14 +53,14 @@ Deregisters an error observer. This API uses an asynchronous callback to return ...@@ -60,14 +53,14 @@ Deregisters an error observer. This API uses an asynchronous callback to return
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the API to call. It is fixed at **"error"**.| | type | string | Yes| Type of the API to call.|
| observerId | number | Yes| Index of the observer returned by **on()**.| | observerId | number | Yes| Digital code of the observer.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| | callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
**Example** **Example**
```ts ```js
var observerId = 100; let observerId = 100;
function unregisterErrorObserverCallback(err) { function unregisterErrorObserverCallback(err) {
if (err) { if (err) {
...@@ -75,15 +68,15 @@ function unregisterErrorObserverCallback(err) { ...@@ -75,15 +68,15 @@ function unregisterErrorObserverCallback(err) {
} }
} }
try { try {
errorManager.off("error", observerId, unregisterErrorObserverCallback); errorManager.off('error', observerId, unregisterErrorObserverCallback);
} catch (paramError) { } catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message); console.log('error: ' + paramError.code + ', ' + paramError.message);
} }
``` ```
## ErrorManager.off ## ErrorManager.off
off(type: "error", observerId: number): Promise\<void>; off(type: 'error', observerId: number): Promise\<void>;
Deregisters an error observer. This API uses a promise to return the result. Deregisters an error observer. This API uses a promise to return the result.
...@@ -93,8 +86,8 @@ Deregisters an error observer. This API uses a promise to return the result. ...@@ -93,8 +86,8 @@ Deregisters an error observer. This API uses a promise to return the result.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the API to call. It is fixed at **"error"**.| | type | string | Yes| Type of the API to call.|
| observerId | number | Yes| Index of the observer returned by **on()**.| | observerId | number | Yes| Digital code of the observer.|
**Return value** **Return value**
...@@ -104,18 +97,18 @@ Deregisters an error observer. This API uses a promise to return the result. ...@@ -104,18 +97,18 @@ Deregisters an error observer. This API uses a promise to return the result.
**Example** **Example**
```ts ```js
var observerId = 100; let observerId = 100;
try { try {
errorManager.off("error", observerId) errorManager.off('error', observerId)
.then((data) => { .then((data) => {
console.log('----------- unregisterErrorObserver success ----------', data); console.log('----------- unregisterErrorObserver success ----------', data);
}) })
.catch((err) => { .catch((err) => {
console.log('----------- unregisterErrorObserver fail ----------', err); console.log('----------- unregisterErrorObserver fail ----------', err);
}) });
} catch (paramError) { } catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message); console.log('error: ' + paramError.code + ', ' + paramError.message);
} }
``` ```
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
The **quickFixManager** module provides APIs for quick fix. With quick fix, you can fix bugs in your application by applying patches, which is more efficient than by updating the entire application. The **quickFixManager** module provides APIs for quick fix. With quick fix, you can fix bugs in your application by applying patches, which is more efficient than by updating the entire application.
> **NOTE** > **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 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.
## Modules to Import ## Modules to Import
...@@ -24,7 +24,7 @@ Defines the quick fix information at the HAP file level. ...@@ -24,7 +24,7 @@ Defines the quick fix information at the HAP file level.
| ----------- | -------------------- | ---- | ------------------------------------------------------------ | | ----------- | -------------------- | ---- | ------------------------------------------------------------ |
| moduleName | string | Yes | Name of the HAP file. | | moduleName | string | Yes | Name of the HAP file. |
| originHapHash | string | Yes | Hash value of the HAP file. | | originHapHash | string | Yes | Hash value of the HAP file. |
| quickFixFilePath | string | Yes | Installation path of the quick fix file. | | quickFixFilePath | string | Yes | Installation path of the quick fix patch file. |
## ApplicationQuickFixInfo ## ApplicationQuickFixInfo
...@@ -57,25 +57,31 @@ Applies a quick fix patch. This API uses an asynchronous callback to return the ...@@ -57,25 +57,31 @@ Applies a quick fix patch. This API uses an asynchronous callback to return the
**Parameters** **Parameters**
| Parameter| Type| Mandatory| Description| | Parameter| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| hapModuleQuickFixFiles | Array\<string> | Yes| Quick fix files, each of which must contain a valid file path.| | hapModuleQuickFixFiles | Array\<string> | Yes| Quick fix patch files, each of which must contain a valid file path.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| | callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
> **NOTE**
>
> The file path passed in the API must be an application sandbox path. For details about how to obtain the sandbox path, see [Obtaining the Sandbox Path](js-apis-bundle-BundleInstaller.md#obtaining-the-sandbox-path). The path mapped to the device is **/proc/<*applicationProcessId*>/root/*sandboxPath***.
**Example** **Example**
```ts ```ts
import quickFixManager from '@ohos.app.ability.quickFixManager';
try { try {
let hapModuleQuickFixFiles = ["/data/storage/el2/base/entry.hqf"] let hapModuleQuickFixFiles = ['/data/storage/el2/base/entry.hqf'];
quickFixManager.applyQuickFix(hapModuleQuickFixFiles, (error) => { quickFixManager.applyQuickFix(hapModuleQuickFixFiles, (error) => {
if (error) { if (error) {
console.info( `applyQuickFix failed with error + ${error}`) console.info( `applyQuickFix failed with error + ${error}`);
} else { } else {
console.info( 'applyQuickFix success') console.info( 'applyQuickFix success');
} }
}) });
} catch (paramError) { } catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message); console.log('error: ' + paramError.code + ', ' + paramError.message);
} }
``` ```
...@@ -93,28 +99,30 @@ Applies a quick fix patch. This API uses a promise to return the result. ...@@ -93,28 +99,30 @@ Applies a quick fix patch. This API uses a promise to return the result.
**Parameters** **Parameters**
| Parameter| Type| Mandatory| Description| | Parameter| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| hapModuleQuickFixFiles | Array\<string> | Yes| Quick fix files, each of which must contain a valid file path.| | hapModuleQuickFixFiles | Array\<string> | Yes| Quick fix patch files, each of which must contain a valid file path.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result.|
**Example** **Example**
```ts ```ts
let hapModuleQuickFixFiles = ["/data/storage/el2/base/entry.hqf"] import quickFixManager from '@ohos.app.ability.quickFixManager';
let hapModuleQuickFixFiles = ['/data/storage/el2/base/entry.hqf'];
try { try {
quickFixManager.applyQuickFix(hapModuleQuickFixFiles).then(() => { quickFixManager.applyQuickFix(hapModuleQuickFixFiles).then(() => {
console.info('applyQuickFix success') console.info('applyQuickFix success');
}).catch((error) => { }).catch((error) => {
console.info(`applyQuickFix err: + ${error}`) console.info(`applyQuickFix err: + ${error}`);
}) });
} catch (paramError) { } catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message); console.log('error: ' + paramError.code + ', ' + paramError.message);
} }
``` ```
...@@ -138,20 +146,22 @@ Obtains the quick fix information of the application. This API uses an asynchron ...@@ -138,20 +146,22 @@ Obtains the quick fix information of the application. This API uses an asynchron
| callback | AsyncCallback\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | Yes| Callback used to return the quick fix information.| | callback | AsyncCallback\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | Yes| Callback used to return the quick fix information.|
**Example** **Example**
```ts ```ts
import quickFixManager from '@ohos.app.ability.quickFixManager';
try { try {
let bundleName = "bundleName" let bundleName = 'bundleName';
quickFixManager.getApplicationQuickFixInfo(bundleName, (error, data) => { quickFixManager.getApplicationQuickFixInfo(bundleName, (error, data) => {
if (error) { if (error) {
console.info(`getApplicationQuickFixInfo error: + ${error}`) console.info(`getApplicationQuickFixInfo error: + ${error}`);
} else { } else {
console.info(`getApplicationQuickFixInfo success: + ${data}`) console.info(`getApplicationQuickFixInfo success: + ${data}`);
} }
}) });
} catch (paramError) { } catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message); console.log('error: ' + paramError.code + ', ' + paramError.message);
} }
``` ```
## quickFixManager.getApplicationQuickFixInfo ## quickFixManager.getApplicationQuickFixInfo
...@@ -174,21 +184,23 @@ Obtains the quick fix information of the application. This API uses a promise to ...@@ -174,21 +184,23 @@ Obtains the quick fix information of the application. This API uses a promise to
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | Promise used to return the quick fix information.| | Promise\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | Promise used to return the quick fix information.|
**Example** **Example**
```ts ```ts
import quickFixManager from '@ohos.app.ability.quickFixManager';
try { try {
let bundleName = "bundleName" let bundleName = 'bundleName';
quickFixManager.getApplicationQuickFixInfo(bundleName).then((data) => { quickFixManager.getApplicationQuickFixInfo(bundleName).then((data) => {
console.info(`getApplicationQuickFixInfo success: + ${data}`) console.info(`getApplicationQuickFixInfo success: + ${data}`);
}).catch((error) => { }).catch((error) => {
console.info(`getApplicationQuickFixInfo err: + ${error}`) console.info(`getApplicationQuickFixInfo err: + ${error}`);
}) });
} catch (paramError) { } catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message); console.log('error: ' + paramError.code + ', ' + paramError.message);
} }
``` ```
# @ohos.app.ability.ServiceExtensionAbility (ServiceExtensionAbility) # @ohos.app.ability.ServiceExtensionAbility (ServiceExtensionAbility)
The **ServiceExtensionAbility** module provides lifecycle callbacks when a ServiceExtensionAbility (background service) is created, destroyed, connected, or disconnected. The **ServiceExtensionAbility** module provides APIs for ServiceExtensionAbilities.
> **NOTE** > **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 of this module are supported since API version 9 and are deprecated in versions later than API version 9. You are advised to use [@ohos.app.ability.ServiceExtensionAbility](js-apis-app-ability-serviceExtensionAbility.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model. > The APIs of this module can be used only in the stage model.
## Modules to Import ## Modules to Import
...@@ -80,7 +80,7 @@ Called when this ServiceExtensionAbility is destroyed to clear resources. ...@@ -80,7 +80,7 @@ Called when this ServiceExtensionAbility is destroyed to clear resources.
onRequest(want: Want, startId: number): void; onRequest(want: Want, startId: number): void;
Called following **onCreate()** when a ServiceExtensionAbility is started by calling **startAbility()**. The value of **startId** is incremented for each ability that is started. Called following **onCreate()** when a ServiceExtensionAbility is started by calling **startAbility()** or **startServiceExtensionAbility()**. The value of **startId** is incremented for each ability that is started.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -129,7 +129,7 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal ...@@ -129,7 +129,7 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal
**Example** **Example**
```ts ```ts
import rpc from '@ohos.rpc' import rpc from '@ohos.rpc';
class StubTest extends rpc.RemoteObject{ class StubTest extends rpc.RemoteObject{
constructor(des) { constructor(des) {
super(des); super(des);
...@@ -140,7 +140,7 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal ...@@ -140,7 +140,7 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal
class ServiceExt extends ServiceExtension { class ServiceExt extends ServiceExtension {
onConnect(want) { onConnect(want) {
console.log('onConnect , want:' + want.abilityName); console.log('onConnect , want:' + want.abilityName);
return new StubTest("test"); return new StubTest('test');
} }
} }
``` ```
...@@ -150,7 +150,7 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal ...@@ -150,7 +150,7 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal
onDisconnect(want: Want): void; onDisconnect(want: Want): void;
Called when a client is disconnected from this ServiceExtensionAbility. Called when this ServiceExtensionAbility is disconnected.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -176,7 +176,7 @@ Called when a client is disconnected from this ServiceExtensionAbility. ...@@ -176,7 +176,7 @@ Called when a client is disconnected from this ServiceExtensionAbility.
onReconnect(want: Want): void; onReconnect(want: Want): void;
Called when a new client attempts to connect to this ServiceExtensionAbility after all previous clients are disconnected. This capability is reserved. Called when this ServiceExtensionAbility is reconnected.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -246,7 +246,8 @@ Dumps the client information. ...@@ -246,7 +246,8 @@ Dumps the client information.
class ServiceExt extends ServiceExtension { class ServiceExt extends ServiceExtension {
onDump(params) { onDump(params) {
console.log('dump, params:' + JSON.stringify(params)); console.log('dump, params:' + JSON.stringify(params));
return ["params"] return ['params'];
} }
} }
``` ```
...@@ -16,7 +16,7 @@ import StartOptions from '@ohos.app.ability.StartOptions'; ...@@ -16,7 +16,7 @@ import StartOptions from '@ohos.app.ability.StartOptions';
## Attributes ## Attributes
**System API**: This is a system API and cannot be called by third-party applications. **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
......
...@@ -18,119 +18,118 @@ import Want from '@ohos.app.ability.Want'; ...@@ -18,119 +18,118 @@ import Want from '@ohos.app.ability.Want';
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | -------------------- | ---- | ------------------------------------------------------------ | | ----------- | -------------------- | ---- | ------------------------------------------------------------ |
| deviceId | string | No | ID of the device running the ability. If this field is unspecified, the local device is used. | | deviceId | string | No | ID of the device running the ability. |
| bundleName | string | No | Bundle name of the ability.| | bundleName | string | No | Bundle name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can match a specific ability. |
| moduleName | string | No| Name of the module to which the ability belongs.|
| abilityName | string | No | Name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can match a specific ability. The value of **abilityName** must be unique in an application.| | abilityName | string | No | Name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can match a specific ability. The value of **abilityName** must be unique in an application.|
| [action](js-apis-app-ability-wantConstant.md#wantconstantaction) | string | No | Action to take, such as viewing and sharing application details. In implicit Want, you can define this field and use it together with **uri** or **parameters** to specify the operation to be performed on the data. For details about the definition and matching rules of implicit Want, see [Matching Rules of Explicit Want and Implicit Want](../../application-models/explicit-implicit-want-mappings.md). | | uri | string | No| If **uri** is specified in a **Want**, the **Want** will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path** components.|
| [entities](js-apis-app-ability-wantConstant.md#wantconstantentity) | Array\<string> | No| Additional category information (such as browser and video player) of the ability. It is a supplement to the **action** field for implicit Want. and is used to filter ability types.| | type | string | No| MIME type, that is, the type of the file to open, for example, **'text/xml'** and **'image/*'**. For details about the MIME type definition, see https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com.|
| uri | string | No| Data carried. This field is used together with **type** to specify the data type. If **uri** is specified in a Want, the Want will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path**.| | flags | number | No| How the **Want** object will be handled. By default, a number is passed in. For details, see [flags](js-apis-ability-wantConstant.md#wantConstant.Flags). |
| type | string | No| MIME type, that is, the type of the file to open, for example, **text/xml** and **image/***. For details about the MIME type definition, see https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com.| | action | string | No | Action to take, such as viewing and sharing application details. In implicit Want, you can define this field and use it together with **uri** or **parameters** to specify the operation to be performed on the data. |
| parameters | {[key: string]: any} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:<br>- **ohos.aafwk.callerPid**: PID of the caller.<br>- **ohos.aafwk.param.callerToken**: token of the caller.<br>- **ohos.aafwk.param.callerUid**: UID in [BundleInfo](js-apis-bundleManager-bundleInfo.md#bundleinfo-1), that is, the application UID in the bundle information. | | parameters | {[key: string]: any} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:<br>- **ohos.aafwk.callerPid**: PID of the caller.<br>- **ohos.aafwk.param.callerToken**: token of the caller.<br>- **ohos.aafwk.param.callerUid**: UID in [BundleInfo](js-apis-bundleManager-bundleInfo.md#bundleinfo-1), that is, the application UID in the bundle information.<br>- **component.startup.newRules**: whether to enable the new control rule.<br/>- **moduleName**: module name of the caller. No matter what this field is set to, the correct module name will be sent to the peer.<br/>- **ohos.dlp.params.sandbox**: available only for DLP files. |
| [flags](js-apis-ability-wantConstant.md#wantconstantflags) | number | No| How the **Want** object will be handled. By default, a number is passed in.<br>For example, **wantConstant.Flags.FLAG_ABILITY_CONTINUATION** specifies whether to start the ability in cross-device migration scenarios.| | entities | Array\<string> | No| Additional category information (such as browser and video player) of the ability. It is a supplement to the **action** field for implicit Want. and is used to filter ability types.|
| moduleName | string | ·ñ | Module to which the ability belongs. |
**Example** **Example**
- Basic usage (called in a UIAbility object, where context in the example is the context object of the UIAbility). - Basic usage
```ts ```ts
let want = { let want = {
"deviceId": "", // An empty deviceId indicates the local device. 'deviceId': '', // An empty deviceId indicates the local device.
"bundleName": "com.example.myapplication", 'bundleName': 'com.extreme.test',
"abilityName": "FuncAbility", 'abilityName': 'MainAbility',
"moduleName": "entry" // moduleName is optional. 'moduleName': 'entry' // moduleName is optional
}; };
this.context.startAbility(want, (error) => { this.context.startAbility(want, (error) => {
// Start an ability explicitly. The bundleName, abilityName, and moduleName parameters work together to uniquely identify an ability. // Start an ability explicitly. The bundleName, abilityName, and moduleName parameters work together to uniquely identify an ability.
console.log("error.code = " + error.code) console.log('error.code = ' + error.code);
}) });
``` ```
- Data is transferred through user-defined fields. The following data types are supported (called in a UIAbility object, where context in the example is the context object of the UIAbility): - Data is transferred through user-defined fields. The following data types are supported:
* String * String
```ts ```ts
let want = { let want = {
bundleName: "com.example.myapplication", bundleName: 'com.example.demo',
abilityName: "FuncAbility", abilityName: 'com.example.demo.MainAbility',
parameters: { parameters: {
keyForString: "str", keyForString: 'str',
}, },
} };
``` ```
* Number * Number
```ts ```ts
let want = { let want = {
bundleName: "com.example.myapplication", bundleName: 'com.example.demo',
abilityName: "FuncAbility", abilityName: 'com.example.demo.MainAbility',
parameters: { parameters: {
keyForInt: 100, keyForInt: 100,
keyForDouble: 99.99, keyForDouble: 99.99,
}, },
} };
``` ```
* Boolean * Boolean
```ts ```ts
let want = { let want = {
bundleName: "com.example.myapplication", bundleName: 'com.example.demo',
abilityName: "FuncAbility", abilityName: 'com.example.demo.MainAbility',
parameters: { parameters: {
keyForBool: true, keyForBool: true,
}, },
} };
``` ```
* Object * Object
```ts ```ts
let want = { let want = {
bundleName: "com.example.myapplication", bundleName: 'com.example.demo',
abilityName: "FuncAbility", abilityName: 'com.example.demo.MainAbility',
parameters: { parameters: {
keyForObject: { keyForObject: {
keyForObjectString: "str", keyForObjectString: 'str',
keyForObjectInt: -200, keyForObjectInt: -200,
keyForObjectDouble: 35.5, keyForObjectDouble: 35.5,
keyForObjectBool: false, keyForObjectBool: false,
}, },
}, },
} };
``` ```
* Array * Array
```ts ```ts
let want = { let want = {
bundleName: "com.example.myapplication", bundleName: 'com.example.demo',
abilityName: "FuncAbility", abilityName: 'com.example.demo.MainAbility',
parameters: { parameters: {
keyForArrayString: ["str1", "str2", "str3"], keyForArrayString: ['str1', 'str2', 'str3'],
keyForArrayInt: [100, 200, 300, 400], keyForArrayInt: [100, 200, 300, 400],
keyForArrayDouble: [0.1, 0.2], keyForArrayDouble: [0.1, 0.2],
keyForArrayObject: [{obj1: "aaa"}, {obj2: 100}], keyForArrayObject: [{obj1: 'aaa'}, {obj2: 100}],
}, },
} };
``` ```
* File descriptor (FD) * File descriptor (FD)
```ts ```ts
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
let fd; let fd;
try { try {
fd = fileio.openSync("/data/storage/el2/base/haps/pic.png"); fd = fileio.openSync('/data/storage/el2/base/haps/pic.png');
} catch(e) { } catch(e) {
console.log("openSync fail:" + JSON.stringify(e)); console.log('openSync fail:' + JSON.stringify(e));
}
let want = {
"deviceId": "", // An empty deviceId indicates the local device.
"bundleName": "com.example.myapplication",
"abilityName": "FuncAbility",
"moduleName": "entry", // moduleName is optional.
"parameters": {
"keyFd":{"type":"FD", "value":fd}
} }
}; let want = {
this.context.startAbility(want, (error) => { 'deviceId': '', // An empty deviceId indicates the local device.
'bundleName': 'com.extreme.test',
'abilityName': 'MainAbility',
'moduleName': 'entry', // moduleName is optional.
'parameters': {
'keyFd':{'type':'FD', 'value':fd} // {'type':'FD', 'value':fd} is a fixed usage, indicating that the data is a file descriptor.
}
};
this.context.startAbility(want, (error) => {
// Start an ability explicitly. The bundleName, abilityName, and moduleName parameters work together to uniquely identify an ability. // Start an ability explicitly. The bundleName, abilityName, and moduleName parameters work together to uniquely identify an ability.
console.log("error.code = " + error.code) console.log('error.code = ' + error.code);
}) });
``` ```
- For more details and examples, see [Want](../../application-models/want-overview.md).
...@@ -8,7 +8,7 @@ The **wantConstant** module provides the actions, entities, and flags used in ** ...@@ -8,7 +8,7 @@ The **wantConstant** module provides the actions, entities, and flags used in **
## Modules to Import ## Modules to Import
```js ```ts
import wantConstant from '@ohos.app.ability.wantConstant'; import wantConstant from '@ohos.app.ability.wantConstant';
``` ```
...@@ -79,4 +79,17 @@ Enumerates the entity constants of the **Want** object. **entity** specifies add ...@@ -79,4 +79,17 @@ Enumerates the entity constants of the **Want** object. **entity** specifies add
| ------------------------------------ | ---------- | ------------------------------------------------------------ | | ------------------------------------ | ---------- | ------------------------------------------------------------ |
| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI. | | FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI. |
| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write data to the URI. | | FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write data to the URI. |
| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed. | | FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Returns the result to the ability. |
| FLAG_ABILITY_CONTINUATION | 0x00000008 | Indicates whether the ability on the local device can be continued on a remote device. |
| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS. |
| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates that an ability is enabled. |
| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Supports cross-device startup in a distributed scheduler. |
| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started. |
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that ability continuation is reversible.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed. |
| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | Indicates that the specific ability will be installed in the background if it has not been installed. |
| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | Clears other operation missions. This flag can be set for the **Want** object in the **startAbility** API passed to **[ohos.app.Context](js-apis-ability-context.md)**. |
| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Indicates the operation of creating a mission on the history mission stack. |
| FLAG_ABILITY_MISSION_TOP | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists. |
\ No newline at end of file
...@@ -35,7 +35,7 @@ Creates a **FormBindingData** object. ...@@ -35,7 +35,7 @@ Creates a **FormBindingData** object.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | ------------------------------------------------------------ | | ------ | -------------- | ---- | ------------------------------------------------------------ |
| obj | Object\|string | No | Data to be displayed on the JS widget. The value can be an object containing multiple key-value pairs or a string in JSON format. The image data is identified by "formImages", and the content is multiple key-value pairs, each of which consists of an image identifier and image file descriptor. The final format is {"formImages": {"key1": fd1, "key2": fd2}}.| | obj | Object\|string | No | Data to be displayed on the JS widget. The value can be an object containing multiple key-value pairs or a string in JSON format. The image data is identified by **'formImages'**, and the content is multiple key-value pairs, each of which consists of an image identifier and image file descriptor. The final format is {'formImages': {'key1': fd1, 'key2': fd2}}.|
**Return value** **Return value**
...@@ -48,17 +48,20 @@ Creates a **FormBindingData** object. ...@@ -48,17 +48,20 @@ Creates a **FormBindingData** object.
**Example** **Example**
```ts ```ts
import fs from '@ohos.file.fs'; import featureAbility from '@ohos.ability.featureAbility';
import formBindingData from '@ohos.app.form.formBindingData'; import fileio from '@ohos.fileio';
let context=featureAbility.getContext();
try { context.getOrCreateLocalDir((err,data)=>{
let fd = fs.openSync('/path/to/form.png') let path=data+'/xxx.jpg';
let fd = fileio.openSync(path);
let obj = { let obj = {
"temperature": "21°", 'temperature': '21°',
"formImages": { "image": fd } 'formImages': {'image': fd}
}; };
formBindingData.createFormBindingData(obj); try {
} catch (error) { formBindingData.createFormBindingData(obj);
console.log(`catch error, code: ${error.code}, message: ${error.message}`); } catch (error) {
} console.log(`catch err->${JSON.stringify(err)}`);
}
})
``` ```
# @ohos.application.abilityDelegatorRegistry (AbilityDelegatorRegistry) # @ohos.application.abilityDelegatorRegistry (AbilityDelegatorRegistry)
The **AbilityDelegatorRegistry** module provides APIs for storing the global registers of the registered **AbilityDelegator** and **AbilityDelegatorArgs** objects. You can use the APIs to obtain the **AbilityDelegator** and **AbilityDelegatorArgs** objects of an application. The **AbilityDelegatorRegistry** module provides APIs for storing the global registers of the registered **AbilityDelegator** and **AbilityDelegatorArgs** objects. You can use the APIs to obtain the **AbilityDelegator** and **AbilityDelegatorArgs** objects of an application. The APIs can be used only in the test framework.
> **NOTE** > **NOTE**
> >
> The APIs of this module are supported since API version 8 and deprecated since API version 9. You are advised to use [@ohos.app.ability.abilityDelegatorRegistry](js-apis-app-ability-abilityDelegatorRegistry.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -43,7 +43,7 @@ Obtains the **AbilityDelegator** object of the application. ...@@ -43,7 +43,7 @@ Obtains the **AbilityDelegator** object of the application.
**Example** **Example**
```ts ```ts
var abilityDelegator; let abilityDelegator;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
``` ```
...@@ -65,8 +65,8 @@ Obtains the **AbilityDelegatorArgs** object of the application. ...@@ -65,8 +65,8 @@ Obtains the **AbilityDelegatorArgs** object of the application.
**Example** **Example**
```ts ```ts
var args = AbilityDelegatorRegistry.getArguments(); let args = AbilityDelegatorRegistry.getArguments();
console.info("getArguments bundleName:" + args.bundleName); console.info('getArguments bundleName:' + args.bundleName);
console.info("getArguments testCaseNames:" + args.testCaseNames); console.info('getArguments testCaseNames:' + args.testCaseNames);
console.info("getArguments testRunnerClassName:" + args.testRunnerClassName); console.info('getArguments testRunnerClassName:' + args.testRunnerClassName);
``` ```
...@@ -4,13 +4,13 @@ The **AbilityManager** module provides APIs for obtaining, adding, and modifying ...@@ -4,13 +4,13 @@ The **AbilityManager** module provides APIs for obtaining, adding, and modifying
> **NOTE** > **NOTE**
> >
> The APIs of this module are supported since API version 8 and deprecated since API version 9. You are advised to use [@ohos.app.ability.abilityManager](js-apis-app-ability-abilityManager.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module are system APIs and cannot be called by third-party applications. > The APIs of this module are system APIs and cannot be called by third-party applications.
## Modules to Import ## Modules to Import
```ts ```ts
import abilityManager from '@ohos.application.abilityManager' import AbilityManager from '@ohos.application.abilityManager';
``` ```
## AbilityState ## AbilityState
...@@ -38,7 +38,7 @@ Updates the configuration. This API uses an asynchronous callback to return the ...@@ -38,7 +38,7 @@ Updates the configuration. This API uses an asynchronous callback to return the
**Permission required**: ohos.permission.UPDATE_CONFIGURATION **Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -49,11 +49,13 @@ Updates the configuration. This API uses an asynchronous callback to return the ...@@ -49,11 +49,13 @@ Updates the configuration. This API uses an asynchronous callback to return the
**Example** **Example**
```ts ```ts
var config = { import abilitymanager from '@ohos.application.abilityManager';
let config = {
language: 'chinese' language: 'chinese'
} };
abilityManager.updateConfiguration(config, () => { abilitymanager.updateConfiguration(config, () => {
console.log('------------ updateConfiguration -----------'); console.log('------------ updateConfiguration -----------');
}) })
``` ```
...@@ -83,11 +85,13 @@ Updates the configuration. This API uses a promise to return the result. ...@@ -83,11 +85,13 @@ Updates the configuration. This API uses a promise to return the result.
**Example** **Example**
```ts ```ts
var config = { import abilitymanager from '@ohos.application.abilityManager';
let config = {
language: 'chinese' language: 'chinese'
} };
abilityManager.updateConfiguration(config).then(() => { abilitymanager.updateConfiguration(config).then(() => {
console.log('updateConfiguration success'); console.log('updateConfiguration success');
}).catch((err) => { }).catch((err) => {
console.log('updateConfiguration fail'); console.log('updateConfiguration fail');
...@@ -113,7 +117,9 @@ Obtains the ability running information. This API uses an asynchronous callback ...@@ -113,7 +117,9 @@ Obtains the ability running information. This API uses an asynchronous callback
**Example** **Example**
```ts ```ts
abilityManager.getAbilityRunningInfos((err,data) => { import abilitymanager from '@ohos.application.abilityManager';
abilitymanager.getAbilityRunningInfos((err,data) => {
console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data)); console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data));
}); });
``` ```
...@@ -137,116 +143,11 @@ Obtains the ability running information. This API uses a promise to return the r ...@@ -137,116 +143,11 @@ Obtains the ability running information. This API uses a promise to return the r
**Example** **Example**
```ts ```ts
abilityManager.getAbilityRunningInfos().then((data) => { import abilitymanager from '@ohos.application.abilityManager';
console.log("getAbilityRunningInfos data: " + JSON.stringify(data))
}).catch((err) => {
console.log("getAbilityRunningInfos err: " + err)
});
```
## getExtensionRunningInfos<sup>9+</sup>
getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<ExtensionRunningInfo>>): void
Obtains the extension running information. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| upperLimit | number | Yes| Maximum number of messages that can be obtained.|
| callback | AsyncCallback\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | Yes | Callback used to return the result. |
**Example**
```ts
var upperLimit = 0;
abilityManager.getExtensionRunningInfos(upperLimit, (err,data) => {
console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
```
## getExtensionRunningInfos<sup>9+</sup>
getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningInfo>>
Obtains the extension running information. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO abilitymanager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data));
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| upperLimit | number | Yes| Maximum number of messages that can be obtained.|
**Return value**
| Type | Description |
| ---------------------------------------- | ------- |
| Promise\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | Promise used to return the result.|
**Example**
```ts
var upperLimit = 0;
abilityManager.getExtensionRunningInfos(upperLimit).then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data));
}).catch((err) => { }).catch((err) => {
console.log("getAbilityRunningInfos err: " + err); console.log("getAbilityRunningInfos err: " + err);
})
```
## getTopAbility<sup>9+</sup>
getTopAbility(callback: AsyncCallback\<ElementName>): void;
Obtains the top ability, which is the ability that has the window focus. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<[ElementName](js-apis-bundleManager-elementName.md)> | Yes | Callback used to return the result. |
**Example**
```ts
abilityManager.getTopAbility((err,data) => {
console.log("getTopAbility err: " + err + " data: " + JSON.stringify(data));
}); });
``` ```
## getTopAbility<sup>9+</sup>
getTopAbility(): Promise\<ElementName>;
Obtains the top ability, which is the ability that has the window focus. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| ---------------------------------------- | ------- |
| Promise\<[ElementName](js-apis-bundleManager-elementName.md)>| Promise used to return the result.|
**Example**
```ts
abilityManager.getTopAbility().then((data) => {
console.log("getTopAbility data: " + JSON.stringify(data));
}).catch((err) => {
console.log("getTopAbility err: " + err);
})
```
...@@ -9,7 +9,7 @@ The **appManager** module implements application management. You can use the API ...@@ -9,7 +9,7 @@ The **appManager** module implements application management. You can use the API
## Modules to Import ## Modules to Import
```ts ```ts
import app from '@ohos.application.appManager'; import appManager from '@ohos.application.appManager';
``` ```
## appManager.isRunningInStabilityTest<sup>8+</sup> ## appManager.isRunningInStabilityTest<sup>8+</sup>
...@@ -161,7 +161,7 @@ getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>; ...@@ -161,7 +161,7 @@ getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>;
Obtains information about the running processes. This API uses a promise to return the result. Obtains information about the running processes. This API uses a promise to return the result.
> This API is deprecated since API Version 9. You are advised to use [appManager.getProcessRunningInformation<sup>9+</sup>](js-apis-app-ability-appManager.md#appmanagergetprocessrunninginformation9) instead. > This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation<sup>9+</sup>](js-apis-app-ability-appManager.md#appmanagergetprocessrunninginformation9) instead.
**Required permissions**: ohos.permission.GET_RUNNING_INFO **Required permissions**: ohos.permission.GET_RUNNING_INFO
...@@ -189,7 +189,7 @@ getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): vo ...@@ -189,7 +189,7 @@ getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): vo
Obtains information about the running processes. This API uses an asynchronous callback to return the result. Obtains information about the running processes. This API uses an asynchronous callback to return the result.
> This API is deprecated since API Version 9. You are advised to use [appManager.getProcessRunningInformation<sup>9+</sup>](js-apis-app-ability-appManager.md#appmanagergetprocessrunninginformation9-1) instead. > This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation<sup>9+</sup>](js-apis-app-ability-appManager.md#appmanagergetprocessrunninginformation9-1) instead.
**Required permissions**: ohos.permission.GET_RUNNING_INFO **Required permissions**: ohos.permission.GET_RUNNING_INFO
...@@ -199,7 +199,7 @@ Obtains information about the running processes. This API uses an asynchronous c ...@@ -199,7 +199,7 @@ Obtains information about the running processes. This API uses an asynchronous c
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<[ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md)>> | Yes| Obtains information about the running processes. This API uses a promise to return the result.| | callback | AsyncCallback\<Array\<[ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md)>> | Yes| Callback used to return the running processes. |
**Example** **Example**
...@@ -359,7 +359,7 @@ Deregisters the application state observer. This API uses an asynchronous callba ...@@ -359,7 +359,7 @@ Deregisters the application state observer. This API uses an asynchronous callba
**System API**: This is a system API and cannot be called by third-party applications. **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|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| observerId | number | Yes| Numeric code of the observer.| | observerId | number | Yes| Numeric code of the observer.|
...@@ -421,7 +421,7 @@ Deregisters the application state observer. This API uses a promise to return th ...@@ -421,7 +421,7 @@ Deregisters the application state observer. This API uses a promise to return th
getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void; getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
Obtains information about the applications that are running in the foreground. This API uses an asynchronous callback to return the result. The application information is defined by [AppStateData](js-apis-inner-application-appStateData.md). Obtains information about the applications that are running in the foreground. This API uses an asynchronous callback to return the result. The application information is defined by [AppStateData](js-apis-inner-application-appStateData.md).
**Required permissions**: ohos.permission.GET_RUNNING_INFO **Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
......
# @ohos.application.Configuration (Configuration) # @ohos.application.Configuration (Configuration)
The **Configuration** module defines environment change information. The **Configuration** module defines environment change information. **Configuration** is an interface definition and is used only for field declaration.
> **NOTE** > **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> This module is deprecated since API version 9. You are advised to use [@ohos.app.ability.Configuration](js-apis-app-ability-configuration.md) instead. > This module is deprecated since API version 9. You are advised to use [@ohos.app.ability.Configuration](js-apis-app-ability-configuration.md) instead.
## Modules to Import
```ts
import Configuration from '@ohos.application.Configuration'
```
**System capability**: SystemCapability.Ability.AbilityBase **System capability**: SystemCapability.Ability.AbilityBase
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| language<sup>8+</sup> | string | Yes| Yes| Language of the application, for example, **zh**.| | language<sup>8+</sup> | string | Yes| Yes| Language of the application.|
| colorMode<sup>8+</sup> | [ColorMode](js-apis-application-configurationConstant.md#configurationconstantcolormode) | Yes| Yes| Color mode, which can be **COLOR_MODE_LIGHT** or **COLOR_MODE_DARK**. The default value is **COLOR_MODE_LIGHT**.| | colorMode<sup>8+</sup> | [ColorMode](js-apis-application-configurationConstant.md#configurationconstantcolormode) | Yes| Yes| Color mode, which can be **COLOR_MODE_LIGHT** or **COLOR_MODE_DARK**. The default value is **COLOR_MODE_LIGHT**.|
| direction<sup>9+</sup> | [Direction](js-apis-application-configurationConstant.md#configurationconstantdirection9) | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.|
| screenDensity<sup>9+</sup> | [ScreenDensity](js-apis-application-configurationConstant.md#configurationconstantscreendensity9) | Yes| No| Screen resolution, which can be **SCREEN_DENSITY_SDPI** (120), **SCREEN_DENSITY_MDPI** (160), **SCREEN_DENSITY_LDPI** (240), **SCREEN_DENSITY_XLDPI** (320), **SCREEN_DENSITY_XXLDPI** (480), or **SCREEN_DENSITY_XXXLDPI** (640).|
| displayId<sup>9+</sup> | number | Yes| No| ID of the display where the application is located.|
| hasPointerDevice<sup>9+</sup> | boolean | Yes| No| Whether a pointer device, such as a keyboard, mouse, or touchpad, is connected.|
For details about the fields, see the **ohos.application.Configuration.d.ts** file. For details about the fields, see the **ohos.application.Configuration.d.ts** file.
**Example** **Example**
```ts ```ts
import hilog from '@ohos.hilog'; import Ability from '@ohos.application.Ability';
import UIAbility from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window'; import Window from '@ohos.window';
export default class EntryAbility extends UIAbility { export default class MainAbility extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
} }
...@@ -42,13 +31,9 @@ export default class EntryAbility extends UIAbility { ...@@ -42,13 +31,9 @@ export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: Window.WindowStage) { onWindowStageCreate(windowStage: Window.WindowStage) {
let envCallback = { let envCallback = {
onConfigurationUpdated(config) { onConfigurationUpdated(config) {
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`) console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`);
let language = config.language; let language = config.language;
let colorMode = config.colorMode; let colorMode = config.colorMode;
let direction = config.direction;
let screenDensity = config.screenDensity;
let displayId = config.displayId;
let hasPointerDevice = config.hasPointerDevice;
} }
}; };
...@@ -57,12 +42,10 @@ export default class EntryAbility extends UIAbility { ...@@ -57,12 +42,10 @@ export default class EntryAbility extends UIAbility {
windowStage.loadContent('pages/index', (err, data) => { windowStage.loadContent('pages/index', (err, data) => {
if (err.code) { if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); console.error('failed to load the content, error: + ${JSON.stringify(err)}');
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return; return;
} }
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); console.info('Succeeded in loading the content, data: + ${JSON.stringify(data)}');
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
}); });
} }
} }
......
...@@ -23,33 +23,3 @@ You can obtain the value of this constant by calling the **ConfigurationConstant ...@@ -23,33 +23,3 @@ You can obtain the value of this constant by calling the **ConfigurationConstant
| COLOR_MODE_NOT_SET | -1 | Unspecified color mode.| | COLOR_MODE_NOT_SET | -1 | Unspecified color mode.|
| COLOR_MODE_DARK | 0 | Dark mode.| | COLOR_MODE_DARK | 0 | Dark mode.|
| COLOR_MODE_LIGHT | 1 | Light mode.| | COLOR_MODE_LIGHT | 1 | Light mode.|
## ConfigurationConstant.Direction<sup>9+</sup>
You can obtain the value of this constant by calling the **ConfigurationConstant.Direction** API.
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Value| Description|
| -------- | -------- | -------- |
| DIRECTION_NOT_SET | -1 | Unspecified direction.|
| DIRECTION_VERTICAL | 0 | Vertical direction.|
| DIRECTION_HORIZONTAL | 1 | Horizontal direction.|
## ConfigurationConstant.ScreenDensity<sup>9+</sup>
You can obtain the value of this constant by calling the **ConfigurationConstant.ScreenDensity** API.
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Value| Description|
| -------- | -------- | -------- |
| SCREEN_DENSITY_NOT_SET | 0 | Unspecified screen resolution.|
| SCREEN_DENSITY_SDPI | 120 | The screen resolution is sdpi.|
| SCREEN_DENSITY_MDPI | 160 | The screen resolution is mdpi.|
| SCREEN_DENSITY_LDPI | 240 | The screen resolution is ldpi.|
| SCREEN_DENSITY_XLDPI | 320 | The screen resolution is xldpi.|
| SCREEN_DENSITY_XXLDPI | 480 | The screen resolution is xxldpi.|
| SCREEN_DENSITY_XXXLDPI | 640 | The screen resolution is xxxldpi.|
# @ohos.application.EnvironmentCallback (EnvironmentCallback) # @ohos.application.EnvironmentCallback (EnvironmentCallback)
The **EnvironmentCallback** module provides APIs, such as **onConfigurationUpdated** and **onMemoryLevel**, for the application context to listen for system environment changes. The **EnvironmentCallback** module provides APIs, such as **onConfigurationUpdated**, for the application context to listen for system environment changes.
> **NOTE** > **NOTE**
> >
> The APIs of this module are supported since API version 9 and are deprecated in versions later than API version 9. You are advised to use [@ohos.app.ability.EnvironmentCallback](js-apis-app-ability-environmentCallback.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module are supported and deprecated in API version 9. You are advised to use [@ohos.app.ability.EnvironmentCallback](js-apis-app-ability-environmentCallback.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model. > The APIs of this module can be used only in the stage model.
## Modules to Import ## Modules to Import
```ts ```ts
import EnvironmentCallback from "@ohos.application.EnvironmentCallback"; import EnvironmentCallback from '@ohos.application.EnvironmentCallback';
``` ```
...@@ -30,48 +30,32 @@ Called when the system environment changes. ...@@ -30,48 +30,32 @@ Called when the system environment changes.
| config | [Configuration](js-apis-application-configuration.md) | Yes| **Configuration** object after the change.| | config | [Configuration](js-apis-application-configuration.md) | Yes| **Configuration** object after the change.|
## EnvironmentCallback.onMemoryLevel ## EnvironmentCallback.onMemoryLevel
onMemoryLevel(level: number): void;
Called when the system memory level changes.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| level | [MemoryLevel](js-apis-application-abilityConstant.md#abilityconstantmemorylevel) | Yes| New memory level.|
**Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import Ability from '@ohos.application.Ability';
var callbackId; let callbackId;
export default class EntryAbility extends UIAbility { export default class MyAbility extends Ability {
onCreate() { onCreate() {
console.log("MyAbility onCreate") console.log('MyAbility onCreate');
globalThis.applicationContext = this.context.getApplicationContext(); globalThis.applicationContext = this.context.getApplicationContext();
let EnvironmentCallback = { let EnvironmentCallback = {
onConfigurationUpdated(config){ onConfigurationUpdated(config){
console.log("onConfigurationUpdated config:" + JSON.stringify(config)); console.log('onConfigurationUpdated config:' + JSON.stringify(config));
}, },
onMemoryLevel(level){ };
console.log("onMemoryLevel level:" + level);
}
}
// 1. Obtain an applicationContext object. // 1. Obtain an applicationContext object.
let applicationContext = globalThis.applicationContext; let applicationContext = globalThis.applicationContext;
// 2. Register a listener for the environment changes through the applicationContext object. // 2. Register a listener for the environment changes through the applicationContext object.
callbackId = applicationContext.registerEnvironmentCallback(EnvironmentCallback); callbackId = applicationContext.registerEnvironmentCallback(EnvironmentCallback);
console.log("registerEnvironmentCallback number: " + JSON.stringify(callbackId)); console.log('registerEnvironmentCallback number: ' + JSON.stringify(callbackId));
} }
onDestroy() { onDestroy() {
let applicationContext = globalThis.applicationContext; let applicationContext = globalThis.applicationContext;
applicationContext.unregisterEnvironmentCallback(callbackId, (error, data) => { applicationContext.unregisterEnvironmentCallback(callbackId, (error, data) => {
console.log("unregisterEnvironmentCallback success, err: " + JSON.stringify(error)); console.log('unregisterEnvironmentCallback success, err: ' + JSON.stringify(error));
}); });
} }
} }
......
# AbilityDelegatorArgs # AbilityDelegatorArgs
The **AbilityDelegatorArgs** module provides APIs to obtain an **AbilityDelegatorArgs** object during the execution of test cases. The **AbilityDelegatorArgs** module provides a global register to store the registered **AbilityDelegator** and **AbilityDelegatorArgs** instances during application startup.
> **NOTE** > **NOTE**
> >
...@@ -28,5 +28,5 @@ Describes the ability delegator arguments. ...@@ -28,5 +28,5 @@ Describes the ability delegator arguments.
```ts ```ts
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
var args = AbilityDelegatorRegistry.getArguments(); let args = AbilityDelegatorRegistry.getArguments();
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册