提交 d120e141 编写于 作者: G Gloria

Update docs against 14188+14620+14253+14202+14649+13561+14558+14342+14442+14939

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 a22b5149
......@@ -10,7 +10,7 @@ The **Ability** module provides all level-2 module APIs for developers to export
## Modules to Import
```ts
import ability from '@ohos.ability.ability'
import ability from '@ohos.ability.ability';
```
**System capability**: SystemCapability.Ability.AbilityBase
......
......@@ -35,7 +35,7 @@ Obtains the ID attached to the end of a given URI.
**Example**
```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.
```ts
let id = 1122;
let uri = dataUriUtils.attachId(
"com.example.dataUriUtils",
'com.example.dataUriUtils',
id,
)
);
```
......@@ -96,7 +96,7 @@ Deletes the ID from the end of a given URI.
**Example**
```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.
```ts
let id = 1122;
let uri = dataUriUtils.updateId(
"com.example.dataUriUtils/1221",
'com.example.dataUriUtils/1221',
id
)
);
```
......@@ -9,7 +9,7 @@ The **ErrorCode** module defines the error codes that may be returned when an ab
## Modules to Import
```ts
import errorCode from '@ohos.ability.errorCode'
import errorCode from '@ohos.ability.errorCode';
```
## ErrorCode
......
......@@ -44,7 +44,7 @@ Enumerates the action constants of the **Want** object. **action** specifies the
| INTENT_PARAMS_INTENT | ability.want.params.INTENT | Action of displaying selection options with an action selector. |
| INTENT_PARAMS_TITLE | ability.want.params.TITLE | Title of the character sequence dialog box used with the action selector. |
| ACTION_FILE_SELECT<sup>7+</sup> | ohos.action.fileSelect | Action of selecting a file. |
| PARAMS_STREAM<sup>7+</sup> | ability.params.stream | URI of the data stream associated with the target when the data is sent. |
| PARAMS_STREAM<sup>7+</sup> | ability.params.stream | URI of the data stream associated with the target when the data is sent. The value must be an array of the string type. |
| ACTION_APP_ACCOUNT_OAUTH <sup>8+</sup> | ohos.account.appAccount.action.oauth | Action of providing the OAuth service. |
| ACTION_APP_ACCOUNT_AUTH <sup>9+</sup> | account.appAccount.action.auth | Action of providing the authentication service. |
| ACTION_MARKET_DOWNLOAD <sup>9+</sup> | ohos.want.action.marketDownload | Action of downloading an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. |
......
......@@ -21,14 +21,14 @@ Enumerates the ability states. This enum can be used together with [AbilityRunni
**System API**: This enum is an internal definition of a system API and cannot be called by third-party applications.
| Name| Value| Description|
| Name| Value| Description|
| -------- | -------- | -------- |
| INITIAL | 0 | The ability is in the initial state.|
| FOCUS | 2 | The ability has the focus.|
| FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state. |
| 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. |
| INITIAL | 0 | The ability is in the initial state.|
| FOCUS | 2 | The ability has the focus. |
| FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state. |
| 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. |
## updateConfiguration
......@@ -39,7 +39,7 @@ Updates the configuration. This API uses an asynchronous callback to return the
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
......@@ -64,7 +64,7 @@ const config = {
language: 'Zh-Hans', // Simplified Chinese.
colorMode: COLOR_MODE_LIGHT, // Light theme.
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.
hasPointerDevice: true, // A pointer device is connected.
};
......@@ -76,7 +76,7 @@ try {
} else {
console.log('updateConfiguration success.');
}
})
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code)
+ ' error.message: ' + JSON.stringify(paramError.message));
......@@ -122,7 +122,7 @@ const config = {
language: 'Zh-Hans', // Simplified Chinese.
colorMode: COLOR_MODE_LIGHT, // Light theme.
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.
hasPointerDevice: true, // A pointer device is connected.
};
......@@ -132,7 +132,7 @@ try {
console.log('updateConfiguration success.');
}).catch((err) => {
console.log('updateConfiguration fail, err: ' + JSON.stringify(err));
})
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code)
+ ' error.message: ' + JSON.stringify(paramError.message));
......@@ -153,7 +153,7 @@ Obtains the UIAbility running information. This API uses an asynchronous callbac
| 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 UIAbility 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 UIAbility running information. You can perform error handling or custom processing in this callback. |
**Error codes**
......@@ -274,7 +274,7 @@ try {
getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningInfo>>
Obtains the ExtensionAbility running information. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -311,7 +311,7 @@ try {
console.log('getExtensionRunningInfos success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log('getExtensionRunningInfos fail, err: ' + JSON.stringify(err));
})
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code)
+ ' error.message: ' + JSON.stringify(paramError.message));
......@@ -359,7 +359,7 @@ abilityManager.getTopAbility((err, data) => {
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**
......@@ -385,5 +385,5 @@ abilityManager.getTopAbility().then((data) => {
console.log('getTopAbility success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log('getTopAbility fail, err: ' + JSON.stringify(err));
})
});
```
......@@ -45,7 +45,7 @@ appManager.isRunningInStabilityTest((err, flag) => {
} else {
console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag));
}
})
});
```
......@@ -151,7 +151,7 @@ appManager.isRamConstrainedDevice((err, data) => {
} else {
console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data));
}
})
});
```
## appManager.getAppMemorySize
......@@ -221,7 +221,7 @@ appManager.getAppMemorySize((err, data) => {
} else {
console.log('The size of app memory is:' + JSON.stringify(data));
}
})
});
```
## appManager.getRunningProcessInformation
......@@ -295,7 +295,7 @@ appManager.getRunningProcessInformation((err, data) => {
} else {
console.log('The process running information is:' + JSON.stringify(data));
}
})
});
```
## appManager.on
......@@ -352,7 +352,7 @@ let applicationStateObserver = {
onProcessStateChanged(processData) {
console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
}
}
};
try {
const observerId = appManager.on('applicationState', applicationStateObserver);
console.log(`[appManager] observerCode: ${observerId}`);
......@@ -416,7 +416,7 @@ let applicationStateObserver = {
onProcessStateChanged(processData) {
console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
}
}
};
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
......@@ -478,7 +478,7 @@ let applicationStateObserver = {
onProcessStateChanged(processData) {
console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
}
}
};
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
......@@ -559,7 +559,7 @@ let applicationStateObserver = {
onProcessStateChanged(processData) {
console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
}
}
};
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
......@@ -574,7 +574,7 @@ try {
console.log('unregisterApplicationStateObserver success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log('unregisterApplicationStateObserver faile, err: ' + JSON.stringify(err));
})
});
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
......@@ -660,7 +660,7 @@ appManager.getForegroundApplications().then((data) => {
console.log('getForegroundApplications success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log('getForegroundApplications fail, err: ' + JSON.stringify(err));
})
});
```
## appManager.killProcessWithAccount
......@@ -702,7 +702,7 @@ try {
console.log('killProcessWithAccount success');
}).catch((err) => {
console.error('killProcessWithAccount fail, err: ' + JSON.stringify(err));
})
});
} catch (paramError) {
console.error('error: ' + paramError.code + ', ' + paramError.message);
}
......@@ -844,7 +844,7 @@ try {
console.log('killProcessesByBundleName success.');
}).catch((err) => {
console.log('killProcessesByBundleName fail, err: ' + JSON.stringify(err));
})
});
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
......@@ -940,7 +940,7 @@ try {
console.log('clearUpApplicationData success.');
}).catch((err) => {
console.log('clearUpApplicationData fail, err: ' + JSON.stringify(err));
})
});
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
......
......@@ -21,8 +21,8 @@ Enumerates the application restart flags. This enum is used as an input paramete
| Name | Value | Description |
| ---------- | ---- | ---------- |
| ALWAYS_RESTART | 0 | The application is restarted in all cases.|
| RESTART_WHEN_JS_CRASH | 0x0001 | The application is restarted in the case of JS_CRASH.|
| RESTART_WHEN_APP_FREEZE | 0x0002 | The application is restarted in the case of APP_FREEZE.|
| RESTART_WHEN_JS_CRASH | 0x0001 | The application is restarted in the case of JS_CRASH. |
| RESTART_WHEN_APP_FREEZE | 0x0002 | The application is restarted in the case of APP_FREEZE. |
| NO_RESTART | 0xFFFF | The application is not restarted in any case.|
## appRecovery.SaveOccasionFlag
......
......@@ -10,7 +10,7 @@ The **Common** module provides all level-2 module APIs for developers to export.
## Modules to Import
```ts
import common from '@ohos.app.ability.common'
import common from '@ohos.app.ability.common';
```
**System capability**: SystemCapability.Ability.AbilityBase
......@@ -33,7 +33,7 @@ import common from '@ohos.app.ability.common'
**Example**
```ts
import common from '@ohos.app.ability.common'
import common from '@ohos.app.ability.common';
let uiAbilityContext: common.UIAbilityContext;
let abilityStageContext: common.AbilityStageContext;
......
# @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**
>
> 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
| Name| Type| Readable| Writable| Description|
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| 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**.|
| direction | [Direction](js-apis-app-ability-configurationConstant.md#configurationconstantdirection) | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.|
| 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).|
| 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. 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| 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.|
| 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
onCreate(want, launchParam) {
let envCallback = {
onConfigurationUpdated(config) {
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`)
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`);
let language = config.language;
let colorMode = config.colorMode;
let direction = config.direction;
......@@ -45,10 +39,10 @@ For details about the fields, see the **ohos.app.ability.Configuration.d.ts** fi
};
try {
let applicationContext = this.context.getApplicationContext();
let callbackId = applicationContext.on("environment", envCallback);
console.log("callbackId: " + callbackId);
let callbackId = applicationContext.on('environment', envCallback);
console.log('callbackId: ' + callbackId);
} 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
| 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.
......@@ -38,7 +38,7 @@ You can obtain the value of this constant by calling the **ConfigurationConstant
| 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.
......@@ -46,10 +46,10 @@ You can obtain the value of this constant by calling the **ConfigurationConstant
| 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.|
| SCREEN_DENSITY_NOT_SET | 0 | The screen pixel density is not set.|
| SCREEN_DENSITY_SDPI | 120 | The pixel density of the screen is 'sdpi'.|
| SCREEN_DENSITY_MDPI | 160 | The pixel density of the screen is 'mdpi'.|
| SCREEN_DENSITY_LDPI | 240 | The pixel density of the screen is 'ldpi'.|
| SCREEN_DENSITY_XLDPI | 320 | The pixel density of the screen is 'xldpi'.|
| SCREEN_DENSITY_XXLDPI | 480 | The pixel density of the screen is 'xxldpi'.|
| SCREEN_DENSITY_XXXLDPI | 640 | The pixel density of the screen is 'xxxldpi'.|
......@@ -11,7 +11,7 @@ The **EnvironmentCallback** module provides the **onConfigurationUpdated** API f
## Modules to Import
```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.
| -------- | -------- | -------- | -------- |
| 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**
```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() {
console.log("MyAbility onCreate")
console.log('MyAbility onCreate');
globalThis.applicationContext = this.context.getApplicationContext();
let EnvironmentCallback = {
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.
let applicationContext = globalThis.applicationContext;
// 2. Register a listener for the environment changes through the applicationContext object.
callbackId = applicationContext.registerEnvironmentCallback(EnvironmentCallback);
console.log("registerEnvironmentCallback number: " + JSON.stringify(callbackId));
console.log('registerEnvironmentCallback number: ' + JSON.stringify(callbackId));
}
onDestroy() {
let applicationContext = globalThis.applicationContext;
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)
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**
>
> 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 errorManager from '@ohos.app.ability.errorManager'
```
## ErrorManager.on
on(type: "error", observer: ErrorObserver): number;
on(type: 'error', observer: ErrorObserver): number;
Registers an error observer.
......@@ -23,34 +23,27 @@ Registers an error observer.
| 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.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Index of the observer.|
**Example**
```ts
var observer = {
```js
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
}
}
var observerId = -1;
};
try {
observerId = errorManager.on("error", observer);
errorManager.on('error', observer);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
## 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.
......@@ -60,14 +53,14 @@ Deregisters an error observer. This API uses an asynchronous callback to return
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the API to call. It is fixed at **"error"**.|
| observerId | number | Yes| Index of the observer returned by **on()**.|
| type | string | Yes| Type of the API to call.|
| observerId | number | Yes| Digital code of the observer.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
**Example**
```ts
var observerId = 100;
```js
let observerId = 100;
function unregisterErrorObserverCallback(err) {
if (err) {
......@@ -75,15 +68,15 @@ function unregisterErrorObserverCallback(err) {
}
}
try {
errorManager.off("error", observerId, unregisterErrorObserverCallback);
errorManager.off('error', observerId, unregisterErrorObserverCallback);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
## 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.
......@@ -93,8 +86,8 @@ Deregisters an error observer. This API uses a promise to return the result.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the API to call. It is fixed at **"error"**.|
| observerId | number | Yes| Index of the observer returned by **on()**.|
| type | string | Yes| Type of the API to call.|
| observerId | number | Yes| Digital code of the observer.|
**Return value**
......@@ -104,18 +97,18 @@ Deregisters an error observer. This API uses a promise to return the result.
**Example**
```ts
var observerId = 100;
```js
let observerId = 100;
try {
errorManager.off("error", observerId)
errorManager.off('error', observerId)
.then((data) => {
console.log('----------- unregisterErrorObserver success ----------', data);
})
.catch((err) => {
console.log('----------- unregisterErrorObserver fail ----------', err);
})
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -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.
> **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.
## Modules to Import
......@@ -24,7 +24,7 @@ Defines the quick fix information at the HAP file level.
| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
| moduleName | string | Yes | Name 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
......@@ -57,25 +57,31 @@ Applies a quick fix patch. This API uses an asynchronous callback to return the
**Parameters**
| Parameter| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| hapModuleQuickFixFiles | Array\<string> | Yes| Quick fix files, each of which must contain a valid file path.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
| Parameter| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
> **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**
```ts
import quickFixManager from '@ohos.app.ability.quickFixManager';
try {
let hapModuleQuickFixFiles = ["/data/storage/el2/base/entry.hqf"]
let hapModuleQuickFixFiles = ['/data/storage/el2/base/entry.hqf'];
quickFixManager.applyQuickFix(hapModuleQuickFixFiles, (error) => {
if (error) {
console.info( `applyQuickFix failed with error + ${error}`)
console.info( `applyQuickFix failed with error + ${error}`);
} else {
console.info( 'applyQuickFix success')
console.info( 'applyQuickFix success');
}
})
});
} 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.
**Parameters**
| Parameter| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| hapModuleQuickFixFiles | Array\<string> | Yes| Quick fix files, each of which must contain a valid file path.|
| Parameter| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| hapModuleQuickFixFiles | Array\<string> | Yes| Quick fix patch files, each of which must contain a valid file path.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```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 {
quickFixManager.applyQuickFix(hapModuleQuickFixFiles).then(() => {
console.info('applyQuickFix success')
console.info('applyQuickFix success');
}).catch((error) => {
console.info(`applyQuickFix err: + ${error}`)
})
console.info(`applyQuickFix err: + ${error}`);
});
} 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
| callback | AsyncCallback\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | Yes| Callback used to return the quick fix information.|
**Example**
```ts
import quickFixManager from '@ohos.app.ability.quickFixManager';
try {
let bundleName = "bundleName"
let bundleName = 'bundleName'
quickFixManager.getApplicationQuickFixInfo(bundleName, (error, data) => {
if (error) {
console.info(`getApplicationQuickFixInfo error: + ${error}`)
console.info(`getApplicationQuickFixInfo error: + ${error}`);
} else {
console.info(`getApplicationQuickFixInfo success: + ${data}`)
console.info(`getApplicationQuickFixInfo success: + ${data}`);
}
})
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
## quickFixManager.getApplicationQuickFixInfo
......@@ -174,21 +184,23 @@ Obtains the quick fix information of the application. This API uses a promise to
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | Promise used to return the quick fix information.|
| Type| Description|
| -------- | -------- |
| Promise\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | Promise used to return the quick fix information.|
**Example**
```ts
import quickFixManager from '@ohos.app.ability.quickFixManager';
try {
let bundleName = "bundleName"
let bundleName = 'bundleName';
quickFixManager.getApplicationQuickFixInfo(bundleName).then((data) => {
console.info(`getApplicationQuickFixInfo success: + ${data}`)
console.info(`getApplicationQuickFixInfo success: + ${data}`);
}).catch((error) => {
console.info(`getApplicationQuickFixInfo err: + ${error}`)
})
console.info(`getApplicationQuickFixInfo err: + ${error}`);
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
```
# @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**
>
> 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.
## Modules to Import
......@@ -80,7 +80,7 @@ Called when this ServiceExtensionAbility is destroyed to clear resources.
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
......@@ -129,7 +129,7 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal
**Example**
```ts
import rpc from '@ohos.rpc'
import rpc from '@ohos.rpc';
class StubTest extends rpc.RemoteObject{
constructor(des) {
super(des);
......@@ -140,7 +140,7 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal
class ServiceExt extends ServiceExtension {
onConnect(want) {
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
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
......@@ -176,7 +176,7 @@ Called when a client is disconnected from this ServiceExtensionAbility.
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
......@@ -246,7 +246,8 @@ Dumps the client information.
class ServiceExt extends ServiceExtension {
onDump(params) {
console.log('dump, params:' + JSON.stringify(params));
return ["params"]
return ['params'];
}
}
```
......@@ -18,119 +18,118 @@ import Want from '@ohos.app.ability.Want';
| Name | Type | Mandatory| Description |
| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
| deviceId | string | No | ID of the device running the ability. If this field is unspecified, the local device is used. |
| bundleName | string | No | Bundle name of the ability.|
| moduleName | string | No| Name of the module to which the ability belongs.|
| deviceId | string | No | ID of the device running 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. |
| 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). |
| [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.|
| 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**.|
| 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.|
| 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. |
| [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.|
| 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.|
| 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.|
| 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). |
| 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.<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. |
| 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**
- Basic usage (called in a UIAbility object, where context in the example is the context object of the UIAbility).
- Basic usage
```ts
let want = {
"deviceId": "", // An empty deviceId indicates the local device.
"bundleName": "com.example.myapplication",
"abilityName": "FuncAbility",
"moduleName": "entry" // moduleName is optional.
'deviceId': '', // An empty deviceId indicates the local device.
'bundleName': 'com.extreme.test',
'abilityName': 'MainAbility',
'moduleName': 'entry' // moduleName is optional
};
this.context.startAbility(want, (error) => {
// 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
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "FuncAbility",
bundleName: 'com.example.demo',
abilityName: 'com.example.demo.MainAbility',
parameters: {
keyForString: "str",
keyForString: 'str',
},
}
};
```
* Number
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "FuncAbility",
bundleName: 'com.example.demo',
abilityName: 'com.example.demo.MainAbility',
parameters: {
keyForInt: 100,
keyForDouble: 99.99,
},
}
};
```
* Boolean
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "FuncAbility",
bundleName: 'com.example.demo',
abilityName: 'com.example.demo.MainAbility',
parameters: {
keyForBool: true,
},
}
};
```
* Object
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "FuncAbility",
bundleName: 'com.example.demo',
abilityName: 'com.example.demo.MainAbility',
parameters: {
keyForObject: {
keyForObjectString: "str",
keyForObjectString: 'str',
keyForObjectInt: -200,
keyForObjectDouble: 35.5,
keyForObjectBool: false,
},
},
}
};
```
* Array
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "FuncAbility",
bundleName: 'com.example.demo',
abilityName: 'com.example.demo.MainAbility',
parameters: {
keyForArrayString: ["str1", "str2", "str3"],
keyForArrayString: ['str1', 'str2', 'str3'],
keyForArrayInt: [100, 200, 300, 400],
keyForArrayDouble: [0.1, 0.2],
keyForArrayObject: [{obj1: "aaa"}, {obj2: 100}],
keyForArrayObject: [{obj1: 'aaa'}, {obj2: 100}],
},
}
};
```
* File descriptor (FD)
```ts
import fileio from '@ohos.fileio';
let fd;
try {
fd = fileio.openSync("/data/storage/el2/base/haps/pic.png");
} catch(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}
import fileio from '@ohos.fileio';
let fd;
try {
fd = fileio.openSync('/data/storage/el2/base/haps/pic.png');
} catch(e) {
console.log('openSync fail:' + JSON.stringify(e));
}
};
this.context.startAbility(want, (error) => {
let want = {
'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.
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 **
## Modules to Import
```js
```ts
import wantConstant from '@ohos.app.ability.wantConstant';
```
......@@ -79,4 +79,4 @@ 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_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_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed. |
......@@ -35,7 +35,7 @@ Creates a **FormBindingData** object.
| 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**
......@@ -48,17 +48,20 @@ Creates a **FormBindingData** object.
**Example**
```ts
import fs from '@ohos.file.fs';
import formBindingData from '@ohos.app.form.formBindingData';
try {
let fd = fs.openSync('/path/to/form.png')
import featureAbility from '@ohos.ability.featureAbility';
import fileio from '@ohos.fileio';
let context=featureAbility.getContext();
context.getOrCreateLocalDir((err,data)=>{
let path=data+'/xxx.jpg';
let fd = fileio.openSync(path);
let obj = {
"temperature": "21°",
"formImages": { "image": fd }
'temperature': '21°',
'formImages': {'image': fd}
};
formBindingData.createFormBindingData(obj);
} catch (error) {
console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
try {
formBindingData.createFormBindingData(obj);
} catch (error) {
console.log(`catch err->${JSON.stringify(err)}`);
}
})
```
# @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**
>
> 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
......@@ -43,7 +43,7 @@ Obtains the **AbilityDelegator** object of the application.
**Example**
```ts
var abilityDelegator;
let abilityDelegator;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
```
......@@ -65,8 +65,8 @@ Obtains the **AbilityDelegatorArgs** object of the application.
**Example**
```ts
var args = AbilityDelegatorRegistry.getArguments();
console.info("getArguments bundleName:" + args.bundleName);
console.info("getArguments testCaseNames:" + args.testCaseNames);
console.info("getArguments testRunnerClassName:" + args.testRunnerClassName);
let args = AbilityDelegatorRegistry.getArguments();
console.info('getArguments bundleName:' + args.bundleName);
console.info('getArguments testCaseNames:' + args.testCaseNames);
console.info('getArguments testRunnerClassName:' + args.testRunnerClassName);
```
......@@ -4,13 +4,13 @@ The **AbilityManager** module provides APIs for obtaining, adding, and modifying
> **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.
## Modules to Import
```ts
import abilityManager from '@ohos.application.abilityManager'
import AbilityManager from '@ohos.application.abilityManager';
```
## AbilityState
......@@ -38,7 +38,7 @@ Updates the configuration. This API uses an asynchronous callback to return the
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
......@@ -49,11 +49,13 @@ Updates the configuration. This API uses an asynchronous callback to return the
**Example**
```ts
var config = {
import abilitymanager from '@ohos.application.abilityManager';
let config = {
language: 'chinese'
}
};
abilityManager.updateConfiguration(config, () => {
abilitymanager.updateConfiguration(config, () => {
console.log('------------ updateConfiguration -----------');
})
```
......@@ -83,11 +85,13 @@ Updates the configuration. This API uses a promise to return the result.
**Example**
```ts
var config = {
import abilitymanager from '@ohos.application.abilityManager';
let config = {
language: 'chinese'
}
};
abilityManager.updateConfiguration(config).then(() => {
abilitymanager.updateConfiguration(config).then(() => {
console.log('updateConfiguration success');
}).catch((err) => {
console.log('updateConfiguration fail');
......@@ -113,7 +117,9 @@ Obtains the ability running information. This API uses an asynchronous callback
**Example**
```ts
abilityManager.getAbilityRunningInfos((err,data) => {
import abilitymanager from '@ohos.application.abilityManager';
abilitymanager.getAbilityRunningInfos((err,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
**Example**
```ts
abilityManager.getAbilityRunningInfos().then((data) => {
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.
import abilitymanager from '@ohos.application.abilityManager';
**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.|
**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));
abilitymanager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data));
}).catch((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
## Modules to Import
```ts
import app from '@ohos.application.appManager';
import appManager from '@ohos.application.appManager';
```
## appManager.isRunningInStabilityTest<sup>8+</sup>
......@@ -22,9 +22,9 @@ Checks whether this application is undergoing a stability test. This API uses an
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
**Example**
......@@ -46,9 +46,9 @@ Checks whether this application is undergoing a stability test. This API uses a
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
**Example**
......@@ -72,9 +72,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example**
......@@ -96,9 +96,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example**
......@@ -119,9 +119,9 @@ Obtains the memory size of this application. This API uses a promise to return t
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the memory size, in MB.|
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the memory size, in MB.|
**Example**
......@@ -143,9 +143,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the memory size, in MB.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the memory size, in MB.|
**Example**
......@@ -199,7 +199,7 @@ Obtains information about the running processes. This API uses an asynchronous c
| 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**
......
# @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**
> 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.
## Modules to Import
```ts
import Configuration from '@ohos.application.Configuration'
```
**System capability**: SystemCapability.Ability.AbilityBase
| 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**.|
| 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.
**Example**
```ts
import hilog from '@ohos.hilog';
import UIAbility from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window';
import Ability from '@ohos.application.Ability'
import Window from '@ohos.window'
export default class EntryAbility extends UIAbility {
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
}
......@@ -42,13 +31,9 @@ export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: Window.WindowStage) {
let envCallback = {
onConfigurationUpdated(config) {
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`)
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`);
let language = config.language;
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 {
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
console.error('failed to load the content, error: + ${JSON.stringify(err)}');
return;
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
console.info('Succeeded in loading the content, data: + ${JSON.stringify(data)}');
});
}
}
......
......@@ -11,7 +11,7 @@ To implement your own unit test framework, extend this class and override its AP
## Modules to Import
```ts
import TestRunner from '@ohos.application.testRunner'
import TestRunner from '@ohos.application.testRunner';
```
## TestRunner.onPrepare
......@@ -27,7 +27,7 @@ Prepares the unit test environment to run test cases.
```ts
export default class UserTestRunner implements TestRunner {
onPrepare() {
console.log("Trigger onPrepare")
console.log('Trigger onPrepare');
}
onRun() {}
};
......@@ -49,7 +49,7 @@ Runs test cases.
export default class UserTestRunner implements TestRunner {
onPrepare() {}
onRun() {
console.log("Trigger onRun")
console.log('Trigger onRun');
}
};
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册