diff --git a/en/application-dev/application-models/data-share-via-want.md b/en/application-dev/application-models/data-share-via-want.md
index 63d7d26d47b64407e30fc03c2edb7ead210dc392..4ecdf35ead5482d4b4b2e0d0a2a4544e75686612 100644
--- a/en/application-dev/application-models/data-share-via-want.md
+++ b/en/application-dev/application-models/data-share-via-want.md
@@ -56,20 +56,20 @@ Users often need to share data (such as a text or an image) from one application
}
}
}
- ```
-
- In the preceding code, the custom field **parameters** is used. The **ability.picker.\*** fields in the first-layer **parameters** are used to pass the information to be displayed on the application selector. The following fields are involved:
-
+ ```
+
+ In the preceding code, the custom field **parameters** is used. The **ability.picker.\*** fields in the first-layer **parameters** are used to pass the information to be displayed on the application selector. The following fields are involved:
+
- **"ability.picker.type"**: The application selector renders the file type icon based on this field.
- **"ability.picker.fileNames"**: The application selector displays the file name based on this field.
- **"ability.picker.fileSizes"**: The application selector displays the file size based on this field. The unit is byte.
- - **"ability.picker.fileNames"** and **"ability.picker.fileSizes"** are arrays and have a one-to-one mapping.
-
+ - **"ability.picker.fileNames"** and **"ability.picker.fileSizes"** are arrays and have a one-to-one mapping.
+
For example, when **"ability.picker.type"** is **"application/pdf"**, **"ability.picker.fileNames"** is **"["APIs.pdf"]"**, and **"ability.picker.fileSizes"** is **"[350 \* 1024]"**, the application selector is displayed as follows:
-
+
- In the preceding code, the **ability.want.params.INTENT** field is nested Want. In this field, **action** and **type** are used for implicit matching by the application selector. For details about implicit matching, see [Implicit Want Matching Rules](explicit-implicit-want-mappings.md#interpretation-of-implicit-want-matching-rules). After the user selects an application, the nested Want of the **ability.want.params.INTENT** field is passed to that application.
+ In the preceding code, the **ability.want.params.INTENT** field is nested Want. In this field, **action** and **type** are used for implicit matching by the application selector. For details about implicit matching, see [Matching Rules of Implicit Want](explicit-implicit-want-mappings.md#matching-rules-of-implicit-want). After the user selects an application, the nested Want of the **ability.want.params.INTENT** field is passed to that application.
- Shared party
1. As mentioned above, the application selector performs implicit matching based on the **ability.want.params.INTENT** field. Therefore, you must set **skills** in the ability configuration file (**module.json5** file in the stage model) of the shared party as follows:
diff --git a/en/application-dev/application-models/redirection-rules.md b/en/application-dev/application-models/redirection-rules.md
index c5c9987c261364f87dadc0333b310744fe12f971..d7456653640942bca333a28f7f6d5262ec4d63f3 100644
--- a/en/application-dev/application-models/redirection-rules.md
+++ b/en/application-dev/application-models/redirection-rules.md
@@ -33,4 +33,4 @@ To enable an ability to be called by any application, configure the **config.jso
```
-If the ability contains **skills**, you are advised to set **visible** to **true** so that the ability can be [implicitly started](explicit-implicit-want-mappings.md#interpretation-of-implicit-want-matching-rules) by other applications. If this attribute is set to **false**, the system returns **PERMISSION_DENIED** when other applications attempt to start the ability. In this case, a system application can request the [START_INVISIBLE_ABILITY](../security/permission-list.md) permission to start the ability. Example abilities with **visible** set to **false** are home screen, voice assistant, or search assistant.
+If the ability contains **skills**, you are advised to set **visible** to **true** so that the ability can be [implicitly started](explicit-implicit-want-mappings.md#matching-rules-of-implicit-want) by other applications. If this attribute is set to **false**, the system returns **PERMISSION_DENIED** when other applications attempt to start the ability. In this case, a system application can request the [START_INVISIBLE_ABILITY](../security/permission-list.md) permission to start the ability. Example abilities with **visible** set to **false** are home screen, voice assistant, or search assistant.
diff --git a/en/application-dev/database/database-datashare-guidelines.md b/en/application-dev/database/database-datashare-guidelines.md
index 064c3e393fe27cedceb1f3f7d2d1e03b8ec22db6..95001df839e0d5ef56bc12126f0fdcd59c72db30 100644
--- a/en/application-dev/database/database-datashare-guidelines.md
+++ b/en/application-dev/database/database-datashare-guidelines.md
@@ -13,7 +13,7 @@ The **DataShare** module allows an application to manage its own data and share
|query?(uri: string, predicates: DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>): void|Queries data from the database.|
|delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback<number>): void|Deletes data from the database.|
-For more information, see [DataShareExtensionAbility](../reference/apis/js-apis-application-DataShareExtensionAbility.md).
+For more information, see [DataShareExtensionAbility](../reference/apis/js-apis-application-dataShareExtensionAbility.md).
**Table 2** APIs of the data consumer
@@ -29,7 +29,7 @@ For more information, see [DataShareHelper](../reference/apis/js-apis-data-dataS
## When to Use
-There are two roles in **DataShare**:
+There are two roles in **DataShare**:
- Data provider: adds, deletes, modifies, and queries data, opens files, and shares data.
- Data consumer: accesses the data provided by the provider using **DataShareHelper**.
@@ -108,8 +108,8 @@ Examples are given below.
| ------------ | ------------------------------------------------------------ |
| "name" | Ability name, corresponding to the **ExtensionAbility** class name derived from **Ability**. |
| "type" | Ability type. The value is **dataShare**, indicating the development is based on the **datashare** template.|
- | "uri" | URI used for communication. It is the unique identifier for the data consumer to connect to the provider. |
- | "visible" | Whether it is visible to other applications. Data sharing is allowed only when the value is **true**.|
+ | "uri" | URI used for communication. It is the unique identifier for the data consumer to connect to the provider. |
+ | "visible" | Whether it is visible to other applications. Data sharing is allowed only when the value is **true**. |
**module.json5 example**
@@ -129,10 +129,10 @@ Examples are given below.
### Data Consumer Application Development
-1. Import the dependencies.
+1. Import dependencies.
```ts
- import Ability from '@ohos.application.Ability';
+ import UIAbility from '@ohos.app.ability.UIAbility';
import dataShare from '@ohos.data.dataShare';
import dataSharePredicates from '@ohos.data.dataSharePredicates';
```
@@ -150,7 +150,7 @@ Examples are given below.
let dsHelper;
let abilityContext;
- export default class MainAbility extends Ability {
+ export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
abilityContext = this.context;
dataShare.createDataShareHelper(abilityContext, dseUri, (err, data)=>{
@@ -180,7 +180,7 @@ Examples are given below.
dsHelper.query(dseUri, predicates, valArray, (err, data) => {
console.log("dsHelper query result: " + data);
});
- // Delete data.
+ // Delete specified data.
dsHelper.delete(dseUri, predicates, (err, data) => {
console.log("dsHelper delete result: " + data);
});
diff --git a/en/application-dev/device/device-location-geocoding.md b/en/application-dev/device/device-location-geocoding.md
deleted file mode 100644
index e18c3fbcce93e40b87c3af9e473b3e1b2828fd4c..0000000000000000000000000000000000000000
--- a/en/application-dev/device/device-location-geocoding.md
+++ /dev/null
@@ -1,87 +0,0 @@
-# Geocoding and Reverse Geocoding Capabilities
-
-
-## When to Use
-
-Describing a location using coordinates is accurate, but neither intuitive nor user-friendly. With the geocoding and reverse geocoding capabilities, you will be able to convert geographic description into specific coordinates and vice versa.
-
-The geographic description helps users understand a location easily by providing several key attributes, for example, country, administrative region, street, house number, and address.
-
-
-## Available APIs
-
-The following table describes APIs available for mutual conversion between coordinates and geographic description. For details, see [Geolocation Manager](../reference/apis/js-apis-geoLocationManager.md).
-
- **Table1** APIs for geocoding and reverse geocoding
-
-| API | Description |
-| -------- | -------- |
-| isGeocoderAvailable(): boolean; | Checks whether the (reverse) geocoding service is available.|
-| getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void | Converts coordinates into geographic description through reverse geocoding. This API uses an asynchronous callback to return the result. |
-| getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise<Array<GeoAddress>> | Converts coordinates into geographic description through reverse geocoding. This API uses a promise to return the result. |
-| getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void | Converts geographic description into coordinates through geocoding. This API uses an asynchronous callback to return the result. |
-| getAddressesFromLocationName(request: GeoCodeRequest): Promise<Array<GeoAddress>> | Converts geographic description into coordinates through geocoding. This API uses a promise to return the result. |
-
-
-## How to Develop
-
-> **NOTE**
->
-> The **GeoConvert** instance needs to access backend services to obtain information. Therefore, before performing the following steps, ensure that your device is connected to the network.
-
-1. Import the **geoLocationManager** module by which you can implement all APIs related to the geocoding and reverse geocoding conversion capabilities.
-
- ```ts
- import geoLocationManager from '@ohos.geolocation';
- ```
-
-2. Query whether geocoder service is available.
- - Call **isGeoServiceAvailable** to query whether the geocoder service is available. If the service is available, continue with step 3.
- ```ts
- import geoLocationManager from '@ohos.geoLocationManager';
- try {
- var isAvailable = geoLocationManager.isGeocoderAvailable();
- } catch (err) {
- console.error("errCode:" + err.code + ",errMessage:" + err.message);
- }
- ```
-
-3. Obtain the conversion result.
- - Call **getAddressesFromLocation** to convert coordinates into geographical location information.
-
- ```ts
- var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
- try {
- geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
- if (err) {
- console.log('getAddressesFromLocation err: ' + JSON.stringify(err));
- } else {
- console.log('getAddressesFromLocation data: ' + JSON.stringify(data));
- }
- });
- } catch (err) {
- console.error("errCode:" + err.code + ",errMessage:" + err.message);
- }
- ```
-
- Your application can obtain the **GeoAddress** list that matches the specified coordinates and then read location information from it. For details, see [Geolocation](../reference/apis/js-apis-geolocation.md).
- - Call **getAddressesFromLocationName** to convert geographic description into coordinates.
-
- ```ts
- var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
- try {
- geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => {
- if (err) {
- console.log('getAddressesFromLocationName err: ' + JSON.stringify(err));
- } else {
- console.log('getAddressesFromLocationName data: ' + JSON.stringify(data));
- }
- });
- } catch (err) {
- console.error("errCode:" + err.code + ",errMessage:" + err.message);
- }
- ```
-
- Your application can obtain the **GeoAddress** list that matches the specified location information and read coordinates from it. For details, see [Geolocation](../reference/apis/js-apis-geolocation.md).
-
- To improve the accuracy of location results, you can set the longitude and latitude ranges in **GeoCodeRequest**.
diff --git a/en/application-dev/device/device-location-info.md b/en/application-dev/device/device-location-info.md
deleted file mode 100644
index 1a386fe6bbfd44009b3aa8ab5ea48e36ad87f3c3..0000000000000000000000000000000000000000
--- a/en/application-dev/device/device-location-info.md
+++ /dev/null
@@ -1,145 +0,0 @@
-# Obtaining Device Location Information
-
-
-## When to Use
-
-You can call location-related APIs in OpenHarmony to obtain the real-time location or last known location of a mobile device.
-
-Real-time location of the device is recommended for location-sensitive services. If you want to lower power consumption when the real-time location of the device is not needed, you may consider obtaining the last known location of the device.
-
-
-## Available APIs
-
-For details about the APIs used to obtain the device location information, see [Geolocation Manager](../reference/apis/js-apis-geoLocationManager.md).
-
-## How to Develop
-
-To learn more about the APIs for obtaining device location information, see [Geolocation](../reference/apis/js-apis-geoLocationManager.md).
-
-1. Before using basic location capabilities, check whether your application has been granted the permission to access the device location information. If not, your application needs to obtain the permission from the user as described below.
- The system provides the following location permissions:
- - ohos.permission.LOCATION
-
- - ohos.permission.APPROXIMATELY_LOCATION
-
- - ohos.permission.LOCATION_IN_BACKGROUND
-
- If your application needs to access the device location information, it must first apply for required permissions. Specifically speaking:
-
- API versions earlier than 9: Apply for **ohos.permission.LOCATION**.
-
- API version 9 and later: Apply for **ohos.permission.APPROXIMATELY\_LOCATION**, or apply for **ohos.permission.APPROXIMATELY\_LOCATION** and **ohos.permission.LOCATION**. Note that **ohos.permission.LOCATION** cannot be applied for separately.
-
- | Target API Level| Location Permission| Permission Application Result| Location Accuracy|
- | -------- | -------- | -------- | -------- |
- | Earlier than 9| ohos.permission.LOCATION | Success| Location accurate to meters|
- | 9 and later| ohos.permission.LOCATION | Failure| No location obtained|
- | 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers|
- | 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters|
-
- If your application needs to access the device location information when running on the background, it must be configured to be able to run on the background and be granted the **ohos.permission.LOCATION_IN_BACKGROUND** permission. In this way, the system continues to report device location information after your application moves to the background.
-
- You can declare the required permission in your application's configuration file. For details, see [Access Control (Permission) Development](../security/accesstoken-guidelines.md).
-
-2. Import the **geoLocationManager** module by which you can implement all APIs related to the basic location capabilities.
-
- ```ts
- import geoLocationManager from '@ohos.geolocation';
- ```
-
-3. Instantiate the **LocationRequest** object. This object provides APIs to notify the system of the location service type and the interval of reporting location information.
- **Method 1:**
-
- To better serve your needs for using APIs, the system has categorized APIs into different packages to match your common use cases of the location function. In this way, you can directly use the APIs specific to a certain use case, making application development much easier. The following table lists the use cases currently supported.
-
-
- ```
- export enum LocationRequestScenario {
- UNSET = 0x300,
- NAVIGATION,
- TRAJECTORY_TRACKING,
- CAR_HAILING,
- DAILY_LIFE_SERVICE,
- NO_POWER,
- }
- ```
-
-
- **Table 2** Common use cases of the location function
-
- | Use Case | Constant | Description |
- | ------------ | ------------------- | ------------------------------------------------------------ |
- | Navigation | NAVIGATION | Applicable when your application needs to obtain the real-time location of a mobile device outdoors, such as navigation for driving or walking. In this scenario, the GNSS positioning technology is mainly used to ensure the location accuracy. However, due to its limitations, the technology may be unable to provide the location service when navigation is just started or when the user moves into a shielded environment such as indoors or a garage. To resolve this issue, the system uses the network positioning technology as an alternative to provide the location service for your application until the GNSS can provide stable location results. This helps achieve a smooth navigation experience for users.
By default, the system reports location results at a minimal interval of 1s. To adopt this use case, you must declare the **ohos.permission.LOCATION** permission and obtain users' authorization.|
- | Trajectory tracking| TRAJECTORY_TRACKING | Applicable when your application needs to record user trajectories, for example, the track recording function of sports applications. In this scenario, the GNSS positioning technology is mainly used to ensure the location accuracy.
By default, the system reports location results at a minimal interval of 1s. To adopt this use case, you must declare the **ohos.permission.LOCATION** permission and obtain users' authorization.|
- | Ride hailing| CAR_HAILING | Applicable when your application needs to obtain the current location of a user who is hailing a taxi.
By default, the system reports location results at a minimal interval of 1s. To adopt this use case, you must declare the **ohos.permission.LOCATION** permission and obtain users' authorization.|
- | Life service| DAILY_LIFE_SERVICE | Applicable when your application only needs the approximate user location for recommendations and push notifications in scenarios such as when the user is browsing news, shopping online, and ordering food.
By default, the system reports location results at a minimal interval of 1s. To adopt this use case, you must declare the **ohos.permission.LOCATION** permission and obtain users' authorization.|
- | Power efficiency | NO_POWER | Applicable when your application does not proactively start the location service for a higher battery efficiency. When responding to another application requesting the same location service, the system marks a copy of the location result to your application. In this way, your application will not consume extra power for obtaining the user location.
By default, the system reports location results at a minimal interval of 1s. To adopt this use case, you must declare the **ohos.permission.LOCATION** permission and obtain users' authorization.|
-
- Sample code for initializing **requestInfo** for navigation:
-
- ```ts
- var requestInfo = {'scenario': geoLocationManager.LocationRequestScenario.NAVIGATION, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
- ```
-
- **Method 2:**
-
- If the predefined use cases do not meet your needs, you can also use the basic location priority policies provided by the system.
-
-
- ```ts
- export enum LocationRequestPriority {
- UNSET = 0x200,
- ACCURACY,
- LOW_POWER,
- FIRST_FIX,
- }
- ```
-
-
- **Table 3** Location priority policies
-
- | Policy | Constant | Description |
- | ------------------ | -------------- | ------------------------------------------------------------ |
- | Location accuracy priority | ACCURACY | This policy mainly uses the GNSS positioning technology. In an open area, the technology can achieve the meter-level location accuracy, depending on the hardware performance of the device. However, in a shielded environment, the location accuracy may significantly decrease.
To use this policy, you must declare the **ohos.permission.LOCATION** permission and obtain users' authorization.|
- | Fast location priority | FAST_FIRST_FIX | This policy uses the GNSS positioning, base station positioning, WLAN positioning, and Bluetooth positioning technologies simultaneously to obtain the device location in both the indoor and outdoor scenarios. When all positioning technologies provide a location result, the system provides the most accurate location result for your application. This policy can lead to significant hardware resource consumption and power consumption.
To use this policy, you must declare the **ohos.permission.LOCATION** permission and obtain users' authorization.|
- | Power efficiency priority| LOW_POWER | This policy mainly uses the base station positioning, WLAN positioning, and Bluetooth positioning technologies to obtain device location in both indoor and outdoor scenarios. The location accuracy depends on the distribution of surrounding base stations, visible WLANs, and Bluetooth devices and therefore may fluctuate greatly. This policy is recommended and can reduce power consumption when your application does not require high location accuracy or when base stations, visible WLANs, and Bluetooth devices are densely distributed.
To use this policy, you must declare at least the **ohos.permission.LOCATION** permission and obtain users' authorization.|
-
- Sample code for initializing **requestInfo** for the location accuracy priority policy:
-
- ```ts
- var requestInfo = {'priority': geoLocationManager.LocationRequestPriority.ACCURACY, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
- ```
-
-4. Instantiate the **Callback** object for the system to report location results.
- Your application needs to implement the callback defined by the system. When the system successfully obtains the real-time location of a device, it will report the location result to your application through the callback interface. Your application can implement the callback interface in such a way to complete your own service logic.
-
- ```ts
- var locationChange = (location) => {
- console.log('locationChanger: data: ' + JSON.stringify(location));
- };
- ```
-
-5. Start device location.
-
- ```ts
- geoLocationManager.on('locationChange', requestInfo, locationChange);
- ```
-
-6. (Optional) Stop device location.
-
- ```ts
- geoLocationManager.off('locationChange', locationChange);
- ```
-
-If your application does not need the real-time device location, it can use the last known device location cached in the system instead.
-
- ```ts
- import geoLocationManager from '@ohos.geoLocationManager';
- try {
- var location = geoLocationManager.getLastLocation();
- } catch (err) {
- console.error("errCode:" + err.code + ",errMessage:" + err.message);
- }
- ```
-
- To call this method, your application needs to request the **ohos.permission.LOCATION** permission from the user.
diff --git a/en/application-dev/device/device-location-overview.md b/en/application-dev/device/device-location-overview.md
deleted file mode 100644
index a26f0c5a7003a14c13cf4fc697e3a55a202f1eec..0000000000000000000000000000000000000000
--- a/en/application-dev/device/device-location-overview.md
+++ /dev/null
@@ -1,48 +0,0 @@
-# Location Overview
-
-
-People take their mobile devices wherever they go. Mobile devices have become a necessity in people's daily routines, whether it be for looking at the weather forecast, browsing news, hailing a taxi, navigating, or recording data from a workout. All these activities are so much associated with the location services on mobile devices.
-
-
-With the location awareness capability offered by , mobile devices will be able to obtain real-time, accurate location data. Building location awareness into your application can also lead to a better contextual experience for application users.
-
-
-Your application can call location-specific APIs to obtain the location information of a mobile device for offering location-based services such as drive navigation and motion track recording.
-
-
-## Basic Concepts
-
-Location awareness helps determine where a mobile device locates. The system identifies the location of a mobile device with its coordinates, and uses location technologies such as Global Navigation Satellite System (GNSS) and network positioning (for example, base station positioning or WLAN/Bluetooth positioning) to provide diverse location-based services. These advanced location technologies make it possible to obtain the accurate location of the mobile device, regardless of whether it is indoors or outdoors.
-
-- **Coordinate**
-
- A coordinate describes a location on the earth using the longitude and latitude in reference to the World Geodetic Coordinate System 1984.
-
-- **GNSS positioning**
- GNSS positioning locates a mobile device by using the location algorithm offered by the device chip to compute the location information provided by the Global Navigation Satellite System, for example, GPS, GLONASS, BeiDou, and Galileo. Whichever positioning system will be used during the location process depends on a hardware capability of the device.
-
-- **Base station positioning**
-
- Base station positioning estimates the current location of a mobile device based on the location of the resident base station in reference to the neighboring base stations. This technology provides only a low accuracy and requires access to the cellular network.
-
-- **WLAN or Bluetooth positioning**
-
- WLAN or Bluetooth positioning estimates the current location of a mobile device based on the locations of WLANs and Bluetooth devices that can be discovered by the device. The location accuracy of this technology depends on the distribution of fixed WLAN access points (APs) and Bluetooth devices around the device. A high density of WLAN APs and Bluetooth devices can produce a more accurate location result than base station positioning. This technology also requires access to the network.
-
-
-## Working Principles
-
-Location awareness is offered by the system as a basic service for applications. Depending on the service scenario, an application needs to initiate a location request to the system and stop the location request when the service scenario ends. In this process, the system reports the location information to the application on a real-time basis.
-
-
-## Limitations and Constraints
-
-Your application can use the location function only after the user has granted the permission and turned on the function. If the location function is off, the system will not provide the location service for any application.
-
-Since the location information is considered sensitive, your application still needs to obtain the location access permission from the user even if the user has turned on the location function. The system will provide the location service for your application only after it has been granted the permission to access the device location information.
-
-## Samples
-
-The following sample is provided to help you better understand how to develop location services:
-
--[`Location`: Location (eTS) (API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/device/Location)
diff --git a/en/application-dev/device/inputdevice-guidelines.md b/en/application-dev/device/inputdevice-guidelines.md
index d29d1ae340f5f2c569559791fe2b001e07adce4a..da6eef71d750b74e01d1ea8a9eaaf49b1bf598cb 100644
--- a/en/application-dev/device/inputdevice-guidelines.md
+++ b/en/application-dev/device/inputdevice-guidelines.md
@@ -16,8 +16,8 @@ The following table lists the common APIs for input device management. For detai
| Instance| API | Description|
| ----------- | ------------------------------------------------------------ | -------------------------- |
-| inputDevice | function getDeviceList(callback: AsyncCallback\>): void; | Obtains the list of input devices.|
-| inputDevice | function getKeyboardType(deviceId: number, callback: AsyncCallback\): void; | Obtains the keyboard type of the input device.|
+| inputDevice | function getDeviceList(): Promise\>; | Obtains the list of input devices.|
+| inputDevice | function getKeyboardType(deviceId: number): Promise\; | Obtains the keyboard type of the input device.|
| inputDevice | function on(type: "change", listener: Callback\): void; | Enables listening for device hot swap events.|
| inputDevice | function off(type: "change", listener?: Callback\): void; | Disables listening for device hot swap events.|
@@ -51,7 +51,7 @@ try {
// 2. Listen for device hot swap events.
inputDevice.on("change", (data) => {
console.log(`Device event info: ${JSON.stringify(data)}`);
- inputDevice.getKeyboardType(data.deviceId, (error, type) => {
+ inputDevice.getKeyboardType(data.deviceId).then((type) => {
console.log("The keyboard type is: " + type);
if (type === inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// The physical keyboard is inserted.
diff --git a/en/application-dev/faqs/faqs-event-notification.md b/en/application-dev/faqs/faqs-event-notification.md
index 06a811e0ca13d1bf8f634a65593a2424ad3999bd..496abb06928728e6275feff3dc423964060701f5 100644
--- a/en/application-dev/faqs/faqs-event-notification.md
+++ b/en/application-dev/faqs/faqs-event-notification.md
@@ -16,15 +16,15 @@ Reference: [Notification](../reference/apis/js-apis-notification.md#notification
Example:
-```
+```ts
import WantAgent from '@ohos.wantAgent';
async function publishNotification() {
let wantAgentInfo = {
wants: [
{
- bundleName: "com.example.notification",
- abilityName: "MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility",
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
diff --git a/en/application-dev/faqs/faqs-language.md b/en/application-dev/faqs/faqs-language.md
index db7e95d5ede5c3bead52e16bceb16e90c6188b79..22a450b4c8e37dc85a28c2ea3b972b03d6ea16ae 100644
--- a/en/application-dev/faqs/faqs-language.md
+++ b/en/application-dev/faqs/faqs-language.md
@@ -155,7 +155,9 @@ The global function **encodeURI** is used for URI encoding, and **decodeURI** is
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
-Yes. The **convert** API of the **convertxml** module can be used to convert XML text into JavaScript objects. Reference: [@ohos.convertxml](../reference/apis/js-apis-convertxml.md)
+Yes. The **convert** API of the **convertxml** module can be used to convert XML text into JavaScript objects.
+
+Reference: [@ohos.convertxml](../reference/apis/js-apis-convertxml.md)
## How do I configure application icons to be used across devices?
@@ -287,4 +289,4 @@ Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
No. Relational database operations cannot be performed in the worker thread.
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/en/application-dev/faqs/faqs-ui-ets.md b/en/application-dev/faqs/faqs-ui-ets.md
index 074a404683bda39d3e5499c66bb193d97784c4dd..8564d2f0969a2cf6eac9bb2d9ac521e62045d162 100644
--- a/en/application-dev/faqs/faqs-ui-ets.md
+++ b/en/application-dev/faqs/faqs-ui-ets.md
@@ -165,9 +165,9 @@ Before the window content is loaded, enable listening for the **systemAvoidAreaC
Example:
-```
-// MainAbility.ts
-import window from '@ohos.window';
+```ts
+import Window from '@ohos.window';
+import UIAbility from '@ohos.app.ability.UIAbility';
/**
* Set the immersive window and obtain the height of the status bar and navigation bar.
@@ -187,7 +187,7 @@ async function enterImmersion(mainWindow: window.Window) {
statusBarContentColor: "#FF0000"
})
}
-export default class MainAbility extends Ability {
+export default class EntryAbility extends UIAbility {
// do something
async onWindowStageCreate(windowStage: window.WindowStage) {
let mainWindow = await windowStage.getMainWindow()
@@ -213,7 +213,7 @@ You can obtain the changes in the width and height of a component through **onAr
Example:
-```
+```ts
Column() {
Text(this.value)
.backgroundColor(Color.Green).margin(30).fontSize(20)
@@ -235,7 +235,7 @@ Bind the **\** component to a **Scoller** object and obtain the offset thr
Example:
-```
+```ts
Column() {
List({ space: 20, initialIndex: 0,scroller: this.scroller}) {
ForEach(this.arr, (item) => {
@@ -259,7 +259,7 @@ Column() {
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
-```
+```ts
// In versions earlier than 3.1.5.5, obtain the value through router.getParams().key.
private value: string = router.getParams().value;
// In 3.1.6.5 and later versions, obtain the value through router.getParams()['key'].
@@ -299,7 +299,7 @@ Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
The color can be represented in two formats, for example, 0x7F000000 or '\#7F000000'. The first two digits indicate opacity, and the last six digits indicate RGB.
-```
+```ts
fontColor(0x7F000000)
fontColor( '#7F000000' )
```
diff --git a/en/application-dev/file-management/Readme-EN.md b/en/application-dev/file-management/Readme-EN.md
index fff002316e8ad2364dedd6c870d3a64ca234a94b..4aa7c9af2c977aac2a987de80bad2b6f164b1215 100644
--- a/en/application-dev/file-management/Readme-EN.md
+++ b/en/application-dev/file-management/Readme-EN.md
@@ -7,3 +7,4 @@
- File Access Framework
- [File Access Framework Overview](file-access-framework-overview.md)
+- [FilePicker Guide](filepicker-guidelines.md)
\ No newline at end of file
diff --git a/en/application-dev/file-management/filepicker-guidelines.md b/en/application-dev/file-management/filepicker-guidelines.md
new file mode 100644
index 0000000000000000000000000000000000000000..8fcf96b2219151a9c197cd1f6bc2e738775646b7
--- /dev/null
+++ b/en/application-dev/file-management/filepicker-guidelines.md
@@ -0,0 +1,68 @@
+# FilePicker Guide
+
+FilePicker is a system application preset in OpenHarmony. You can use it to select and save files. For details about the implementation of FilePicker, see [applications_filepicker](https://gitee.com/openharmony/applications_filepicker).
+
+FilePicker provides the following modes:
+- **choose**: Use this mode when an application needs to select and upload or send files (including media resources such as images, and audio and video clips) in the device. When this mode is selected, the FilePicker **choose** mode window will be triggered to display a dialog box for you to select a file. You can select the target file and tap **Upload**. The application will receive the URI of the target file returned by FilePicker.
+- **save**: Use this mode when an application needs to download and save files (including media resources such as images and audio and video clips). When this mode is selected, the FilePicker **save** mode window will be triggered to display a dialog box for you to select the destination path of the file to save. You can select the destination path and tap **Save**. The application will receive the URI of the saved file returned by FilePicker.
+
+## Development Guidelines
+
+> **NOTE**
+>
+> FilePicker supports only the applications developed based on the stage model.
+> For details about the stage model, see [Interpretation of the Application Model](../application-models/application-model-description.md).
+
+You can use [AbilityContext.startAbilityForResult(want, options)](../reference/apis/js-apis-ability-context.md##abilitycontextstartabilityforresult-1) with different parameters to start different FilePicker modes.
+
+You need to use [Want](../reference/apis/js-apis-application-want.md) to specify **bundleName** and **abilityName** to start FilePicker. For details, see the following sample code.
+
+You also need to set **Want.parameters** to specify the FilePicker mode to start and the name of the file to save.
+- To select a file, set **'startMode': 'choose'**.
+- To save a file, set **'startMode': 'save'** and **'saveFile'**.
+
+You can set **options** of the [StartOptions](../reference/apis/js-apis-app-ability-startOptions.md) type to specify the dialog box style. The recommended value is **windowMode: 102**, which indicates a floating window.
+
+> **CAUTION**
+> - In the **save** mode, a strong verification is performed on the file path based on the name of the file to save. For details about the file path format, see [File Path Management](medialibrary-filepath-guidelines.md).
+> - If a file with the same name exists, a dialog box will be displayed asking you whether to overwrite the existing file.
+
+ArkTS sample code:
+```ts
+// Start FilePicker to select a file.
+globalThis.context.startAbilityForResult(
+ {
+ bundleName: "com.ohos.filepicker",
+ abilityName: "EntryAbility",
+ parameters: {
+ 'startMode': 'choose', //choose or save
+ }
+ },
+ { windowMode: 102 }
+)
+
+// Start FilePicker to save a file.
+globalThis.context.startAbilityForResult(
+ {
+ bundleName: "com.ohos.filepicker",
+ abilityName: "EntryAbility",
+ parameters: {
+ 'startMode': 'save', //choose or save
+ 'saveFile': 'test.jpg',
+ }
+ },
+ { windowMode: 102 }
+)
+
+// Data returned by FilePicker to startAbilityForResult.
+let abilityResult = {
+ resultCode: resultCode,
+ want: {
+ parameters: {
+ 'startMode': startMode,
+ 'result': result
+ }
+ }
+}
+globalThis.context.terminateSelfWithResult(abilityResult)
+```
diff --git a/en/application-dev/internationalization/Readme-EN.md b/en/application-dev/internationalization/Readme-EN.md
index d7042968cf5c6824e49f77911e207e4cbb4be443..6c89740e15daf19fcb712aba339484caad2ed7c3 100644
--- a/en/application-dev/internationalization/Readme-EN.md
+++ b/en/application-dev/internationalization/Readme-EN.md
@@ -1,6 +1,6 @@
# Internationalization
- [Internationalization Overview](international-overview.md)
-- [Internationalization Development (intl)](intl-guidelines.md)
-- [Internationalization Development (i18n)](i18n-guidelines.md)
+- [intl Development](intl-guidelines.md)
+- [i18n Development](i18n-guidelines.md)
diff --git a/en/application-dev/internationalization/i18n-guidelines.md b/en/application-dev/internationalization/i18n-guidelines.md
index 62bf66fd7cabb7e30c765126ddacba639bd951f5..8218f2561376c4119f66be0175c5c9ea16c7d024 100644
--- a/en/application-dev/internationalization/i18n-guidelines.md
+++ b/en/application-dev/internationalization/i18n-guidelines.md
@@ -1,391 +1,732 @@
-# Internationalization Development (I18N)
+# i18n Development
-This module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402. For more details about APIs and their usage, see [I18N](../reference/apis/js-apis-i18n.md).
+The **i18n** module provides system-related or enhanced i18n capabilities, such as locale management, phone number formatting, and calendar, through supplementary i18n APIs that are not defined in ECMA 402. For more details about APIs and their usage, see [i18n](../reference/apis/js-apis-i18n.md).
-## Obtaining System Language and Region Information
+The [intl](intl-guidelines.md) module provides basic i18n capabilities through the standard i18n interfaces defined in ECMA 402. It works with the **i18n** module to provide a complete suite of i18n capabilities.
-You can use APIs provided in the following table to obtain the system language and region information.
+## Obtaining and Setting i18n Information
+The system provides APIs to configure information such as the system language, preferred language, country or region, 24-hour clock, and local digit switch.
### Available APIs
-| Module | API | Description |
-| -------- | -------- | -------- |
-| ohos.i18n | getSystemLanguage(): string | Obtains the system language. |
-| ohos.i18n | getSystemRegion(): string | Obtains the system region. |
-| ohos.i18n | getSystemLocale(): string | Obtains the system locale. |
-| ohos.i18n | isRTL(locale: string): boolean7+ | Checks whether the locale uses a right-to-left (RTL) language. |
-| ohos.i18n | is24HourClock(): boolean7+ | Checks whether the system uses a 24-hour clock. |
-| ohos.i18n | getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string | Obtains the localized display of a language. |
-| ohos.i18n | getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string | Obtains the localized display of a country name. |
-
+| Class | API | Description |
+| --------- | ---------------------------------------- | --------------------- |
+| System | getDisplayCountry(country:string,locale:string,sentenceCase?:boolean):string9+ | Obtains the localized representation of a country. |
+| System | getDisplayLanguage(language:string,locale:string,sentenceCase?:boolean):string9+ | Obtains the localized representation of a language. |
+| System | getSystemLanguages():Array9+ | Obtains the system language list. |
+| System | getSystemCountries(language: string):Array9+ | Obtains the list of countries and regions supported for the specified language. |
+| System | isSuggested(language: string, region?: string): boolean9+ | Checks whether the system language matches the specified region. |
+| System | getSystemLanguage():string9+ | Obtains the system language. |
+| System | setSystemLanguage(language: string)9+ | Sets the system language. |
+| System | getSystemRegion():string9+ | Obtains the system region. |
+| System | setSystemRegion(region: string)9+ | Sets the system region. |
+| System | getSystemLocale():string9+ | Obtains the system locale. |
+| System | setSystemLocale(locale: string)9+ | Sets the system locale. |
+| System | is24HourClock():boolean9+ | Checks whether the 24-hour clock is used. |
+| System | set24HourClock():boolean9+ | Sets the 24-hour clock. |
+| System | addPreferredLanguage(language: string, index?: number)9+ | Adds a preferred language to the specified position on the preferred language list. |
+| System | removePreferredLanguage(index: number)9+ | Deletes a preferred language from the specified position on the preferred language list. |
+| System | getPreferredLanguageList()9+ | Obtains the preferred language list. |
+| System | getFirstPreferredLanguage()9+ | Obtains the first language in the preferred language list. |
+| System | getAppPreferredLanguage()9+ | Obtains the preferred language of an application. |
+| System | setUsingLocalDigit(flag: boolean)9+ | Sets whether to enable the local digit switch. |
+| System | getUsingLocalDigit()9+ | Checks whether the local digit switch is turned on. |
+| | isRTL(locale:string):boolean9+ | Checks whether the locale uses a right-to-left (RTL) language.|
### How to Develop
+1. Import the **i18n** module.
+
+ ```js
+ import I18n from '@ohos.i18n'
+ ```
+
+2. Obtain and set the system language.
+
+ Call **setSystemLanguage** to set the system language. (This is a system API and can be called only by system applications with the **UPDATE_CONFIGURATION** permission.)
+ Call the **getSystemLanguage** API to obtain the system language.
+
+ ```js
+ try {
+ I18n.System.setSystemLanguage("en"); // Set the system language to en.
+ let language = I18n.System.getSystemLanguage(); // language = "en"
+ } catch(error) {
+ console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`)
+ }
+ ```
-1. Obtain the system language.
+3. Obtain and set the system locale.
+
+ Call **setSystemRegion** to set the system country or region. (This is a system API and can be called only by system applications with the **UPDATE_CONFIGURATION** permission.)
+ Call **getSystemRegion** to obtain the system country or region.
+
+ ```js
+ try {
+ I18n.System.setSystemRegion("CN"); // Set the system country to CN.
+ let region = I18n.System.getSystemRegion(); // region = "CN"
+ } catch(error) {
+ console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`)
+ }
+ ```
- Call the **getSystemLanguage** method to obtain the system language (**i18n** is the name of the imported module).
+4. Obtain and set the system locale.
+ Call **setSystemLocale** to set the system locale. (This is a system API and can be called only by system applications with the **UPDATE_CONFIGURATION** permission.) For details about how to set a locale, see [Setting Locale Information](../internationalization/intl-guidelines.md#setting-locale-information).
+ Call **getSystemLocale** to obtain the system locale.
- ```js
- var language = i18n.getSystemLanguage();
+ ```js
+ try {
+ I18n.System.setSystemLocale("zh-Hans-CN"); // Set the system locale to zh-Hans-CN.
+ let locale = I18n.System.getSystemLocale(); // locale = "zh-Hans-CN"
+ } catch(error) {
+ console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`)
+ }
```
-2. Obtain the system region.
+5. Check whether the locale uses a right-to-left (RTL) language.
+
+ Call **isRTL** to check whether the locale uses an RTL language.
- Call the **getSystemRegion** method to obtain the system region.
-
- ```js
- var region = i18n.getSystemRegion();
+ ```js
+ try {
+ let rtl = I18n.isRTL("zh-CN"); // rtl = false
+ rtl = I18n.isRTL("ar"); // rtl = true
+ } catch(error) {
+ console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`)
+ }
```
-3. Obtain the system locale.
+6. Obtain and set the 24-hour clock.
- Call the **getSystemLocale** method to obtain the system locale.
-
- ```js
- var locale = i18n.getSystemLocale();
+ Call **set24HourClock** to enable the 24-hour clock.
+ Call **is24HourClock** to check whether the 24-hour clock is enabled.
+
+ ```js
+ try {
+ I18n.System.set24HourClock(true);
+ let hourClock = I18n.System.is24HourClock(); // hourClock = true
+ } catch(error) {
+ console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`)
+ }
```
-4. Check whether the locale's language is RTL.
+7. Obtain the localized representation of a language.
+
+ Call **getDisplayLanguage** to obtain the localized representation of a language. **language** indicates the language to be localized, **locale** indicates the locale, and **sentenceCase** indicates whether the first letter of the result must be capitalized.
- Call the **isRTL** method to check whether the locale's language is RTL.
+ ```js
+ try {
+ let language = "en";
+ let locale = "zh-CN";
+ let sentenceCase = false;
+ let localizedLanguage = I18n.System.getDisplayLanguage(language, locale, sentenceCase); // localizedLanguage = "English"
+ } catch(error) {
+ console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`)
+ }
+ ```
+8. Obtain the localized representation of a country.
- ```js
- var rtl = i18n.isRTL("zh-CN");
+ Call **getDisplayCountry** to obtain the localized representation of a country. **country** indicates the country to be localized, **locale** indicates the locale, and **sentenceCase** indicates whether the first letter of the result must be capitalized.
+
+ ```js
+ try {
+ let country = "US";
+ let locale = "zh-CN";
+ let sentenceCase = false;
+ let localizedCountry = I18n.System.getDisplayCountry(country, locale, sentenceCase); // localizedCountry = "U.S."
+ } catch(error) {
+ console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`)
+ }
```
-5. Check whether the system uses a 24-hour clock.
+9. Obtain the list of system languages and the list of countries supported by a system language.
- Call the **is24HourClock** method to check whether the system uses a 24-hour clock.
-
- ```js
- var hourClock = i18n.is24HourClock();
+ Call **getSystemLanguages** to obtain the list of system languages.
+ Call **getSystemCountries** to obtain the list of countries and regions supported by a system language.
+ ```js
+
+ try {
+ let languageList = I18n.System.getSystemLanguages(); // languageList = ["en-Latn-US", "zh-Hans"]
+ let countryList = I18n.System.getSystemCountries("zh"); // countryList = ["ZW", "YT", ..., "CN", "DE"], 240 countries and regions in total
+ } catch(error) {
+ console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`)
+ }
```
-6. Obtain the localized display of a language.
+10. Check whether the language matches a country or region.
- Call the **getDisplayLanguage** method to obtain the localized display of a language. **language** indicates the language to be localized, **locale** indicates the locale, and **sentenceCase** indicates whether the first letter of the result must be capitalized.
-
- ```js
- var language = "en";
- var locale = "zh-CN";
- var sentenceCase = false;
- var localizedLanguage = i18n.getDisplayLanguage(language, locale, sentenceCase);
+ Call **isSuggested** to check whether the language matches a country or region.
+
+ ```js
+ try {
+ let isSuggest = I18n.System.isSuggested("zh", "CN"); // isSuggest = true
+ } catch(error) {
+ console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`)
+ }
```
-7. Obtain the localized display of a country.
+11. Obtain and set the preferred language.
- Call the **getDisplayCountry** method to obtain the localized display of a country name. **country** indicates the country code (a two-letter code in compliance with ISO-3166, for example, CN), **locale** indicates the locale, and **sentenceCase** indicates whether the first letter of the result must be capitalized.
-
- ```js
- var country = "US";
- var locale = "zh-CN";
- var sentenceCase = false;
- var localizedCountry = i18n.getDisplayCountry(country, locale, sentenceCase);
+ Call **addPreferredLanguage** to add a preferred language to the preferred language list.
+ Call **removePreferredLanguage** to remove a preferred language from the preferred language list. (**addPreferredLanguage** and **removePreferredLanguage** are system APIs and can be called only by system applications with the **UPDATE_CONFIGURATION** permission.)
+ Call **getPreferredLanguageList** to obtain the preferred language list.
+ Call **getFirstPreferredLanguage** to obtain the first preferred language in the preferred language list.
+ Call **getAppPreferredLanguageList** to obtain the preferred language of the application. It is the first language that matches the application resource in the preferred language list.
+
+ ```js
+ try {
+ I18n.System.addPreferredLanguage("en-GB", 0); // Set the first language in the preferred language list to en-GB.
+ let list = I18n.System.getPreferredLanguageList(); // Obtain the preferred language list. Example: list = ["en-GB", ...]
+ I18n.System.removePreferredLanguage(list.length - 1); // Remove the last preferred language from the preferred language list.
+ let firstPreferredLanguage = I18n.System.getFirstPreferredLanguage(); // firstPreferredLanguage = "en-GB"
+ let appPreferredLanguage = I18n.System.getAppPreferredLanguage(); // Set the preferred language of the application to en-GB if the application contains en-GB resources.
+ } catch(error) {
+ console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`)
+ }
```
+12. Obtain and set the local digit switch.
-## Obtaining Calendar Information
+ Call **setUsingLocalDigit** to enable the local digit switch. (This is a system API and can be called only by system applications with the UPDATE_CONFIGURATION permission.)
+ Call **getUsingLocalDigit** to check whether the local digit switch is enabled.
+ Currently, the local digit switch applies only to the following languages: "ar", "as", "bn", "fa", "mr", "my", "ne", and "ur".
-[Calendar](../reference/apis/js-apis-i18n.md#calendar8) APIs are used to obtain calendar information, for example, the localized display of the calendar, the first day of a week, and the minimum count of days in the first week of a year.
+```js
+try {
+ I18n.System.setUsingLocalDigit(true); // Enable the local digit switch.
+ let status = I18n.System.getUsingLocalDigit(); // status = true
+} catch(error) {
+ console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`)
+}
+```
+## Obtain the calendar information.
-### Available APIs
+[Calendar](../reference/apis/js-apis-i18n.md#calendar8) provides APIs to obtain calendar information, for example, localized representation of the calendar, the start day of a week, and the minimum number of days in the first week of a year.
-| Module | API | Description |
-| -------- | -------- | -------- |
-| ohos.i18n | getCalendar(locale: string, type?: string): Calendar8+ | Obtains the **Calendar** object for a specific locale and type. |
-| ohos.i18n | setTime(date: Date): void8+ | Sets the date for the **Calendar** object. |
-| ohos.i18n | setTime(time: number): void8+ | Sets the time for the **Calendar** object. |
-| ohos.i18n | set(year: number, month: number, date: number, hour?: number, minute?: number, second?: number): void8+ | Sets the year, month, day, hour, minute, and second for the **Calendar** object. |
-| ohos.i18n | setTimeZone(timezone: string): void8+ | Sets the time zone for the **Calendar** object. |
-| ohos.i18n | getTimeZone(): string8+ | Obtains the time zone for the **Calendar** object. |
-| ohos.i18n | getFirstDayOfWeek(): number8+ | Obtains the first day of a week for the **Calendar** object. |
-| ohos.i18n | setFirstDayOfWeek(value: number): void8+ | Sets the first day of a week for the **Calendar** object. |
-| ohos.i18n | getMinimalDaysInFirstWeek(): number8+ | Obtains the minimum count of days in the first week of a year. |
-| ohos.i18n | setMinimalDaysInFirstWeek(value: number): void8+ | Sets the minimum count of days in the first week of a year. |
-| ohos.i18n | getDisplayName(locale: string): string8+ | Obtains the localized display of the **Calendar** object. |
-| ohos.i18n | isWeekend(date?: Date): boolean8+ | Checks whether a given date is a weekend. |
+### Available APIs
+| Class | API | Description |
+| --------- | ---------------------------------------- | --------------------- |
+| | getCalendar(locale:string,type?:string):Calendar8+ | Obtains the **Calendar** object for a specific locale and type.|
+| Calendar | setTime(date:Date): void8+ | Sets the date for this **Calendar** object. |
+| Calendar | setTime(time:number): void8+ | Sets the date for this **Calendar** object. |
+| Calendar | set(year:number,month:number,date:number,hour?:number,minute?:number,second?:number): void8+ | Sets the year, month, day, hour, minute, and second for this **Calendar** object. |
+| Calendar | setTimeZone(timezone:string): void8+ | Sets the time zone of this **Calendar** object. |
+| Calendar | getTimeZone():string8+ | Obtains the time zone of this **Calendar** object. |
+| Calendar | getFirstDayOfWeek():number8+ | Obtains the start day of a week for this **Calendar** object. |
+| Calendar | setFirstDayOfWeek(value:number): void8+ | Sets the first day of a week for the **Calendar** object. |
+| Calendar | getMinimalDaysInFirstWeek():number8+ | Obtains the minimum number of days in the first week of a year. |
+| Calendar | setMinimalDaysInFirstWeek(value:number): void8+ | Sets the minimum number of days in the first week of a year. |
+| Calendar | getDisplayName(locale:string):string8+ | Obtains the localized display of the **Calendar** object. |
+| Calendar | isWeekend(date?:Date):boolean8+ | Checks whether the specified date in this **Calendar** object is a weekend. |
### How to Develop
-1. Instantiate a **Calendar** object.
+1. Import the **i18n** module.
- Call the **getCalendar** method to obtain the time zone object of a specific locale and type (**i18n** is the name of the imported module). **type** indicates the valid calendar type, for example, **buddhist**, **chinese**, **coptic**, **ethiopic**, **hebrew**, **gregory**, **indian**, **islamic_civil**, **islamic_tbla**, **islamic_umalqura**, **japanese**, and **persian**. If **type** is left unspecified, the default calendar type of the locale is used.
+ ```js
+ import I18n from '@ohos.i18n'
+ ```
+
+2. Instantiate a **Calendar** object.
+ Call **getCalendar** to obtain the time zone object of a specific locale and type (**i18n** is the name of the imported module). **type** indicates the valid calendar type, for example, **buddhist**, **chinese**, **coptic**, **ethiopic**, **hebrew**, **gregory**, **indian**, **islamic_civil**, **islamic_tbla**, **islamic_umalqura**, **japanese**, and **persian**. If **type** is left unspecified, the default calendar type of the locale is used.
- ```js
- var calendar = i18n.getCalendar("zh-CN", "gregory");
+ ```js
+ let calendar = I18n.getCalendar("zh-CN", "chinese"); // Create the Calendar object for the Chinese lunar calendar.
```
-2. Set the time for the **Calendar** object.
+3. Set the time for the **Calendar** object.
+
+ Call **setTime** to set the time of the **Calendar** object. Two types of parameters are supported. One is a **Date** object, and the other is a value indicating the number of milliseconds elapsed since January 1, 1970, 00:00:00 GMT.
- Call the **setTime** method to set the time of the **Calendar** object. This method receives two types of parameters. One is a **Date** object, and the other is a value indicating the number of milliseconds elapsed since January 1, 1970, 00:00:00 GMT.
-
- ```js
- var date1 = new Date();
+ ```js
+ let date1 = new Date();
calendar.setTime(date1);
- var date2 = 1000;
+ let date2 = 1000;
calendar.setTime(date2);
```
-3. Set the year, month, day, hour, minute, and second for the **Calendar** object.
+4. Set the year, month, day, hour, minute, and second for this **Calendar** object.
- Call the **set** method to set the year, month, day, hour, minute, and second for the **Calendar** object.
-
- ```js
+ Call **set** to set the year, month, day, hour, minute, and second for the **Calendar** object.
+
+ ```js
calendar.set(2021, 12, 21, 6, 0, 0)
```
-4. Set and obtain the time zone for the **Calendar** object.
-
- Call the **setTimeZone** and **getTimeZone** methods to set and obtain the time zone for the **Calendar** object. The **setTimeZone** method requires an input string to indicate the time zone to be set.
+5. Set and obtain the time zone for the **Calendar** object.
+ Call **setTimeZone** and **getTimeZone** to set and obtain the time zone of the **Calendar** object. Note that **setTimeZone** requires an input string to indicate the time zone to be set.
- ```js
+ ```js
calendar.setTimeZone("Asia/Shanghai");
- var timezone = calendar.getTimeZone();
+ let timezone = calendar.getTimeZone(); // timezone = "China Standard Time"
```
-5. Set and obtain the first day of a week for the **Calendar** object.
+6. Set and obtain the first day of a week for the **Calendar** object.
- Call the **setFirstDayOfWeek** and **getFirstDayOfWeek** methods to set and obtain the first day of a week for the **Calendar** object. **setFirstDayOfWeek** must be set to a value indicating the first day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.
+ Call **setFirstDayOfWeek** and **getFirstDayOfWeek** to set and obtain the start day of a week for the **Calendar** object. **setFirstDayOfWeek** must be set to a value indicating the first day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.
-
- ```js
+ ```js
calendar.setFirstDayOfWeek(1);
- var firstDayOfWeek = calendar.getFirstDayOfWeek();
+ let firstDayOfWeek = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 1
```
-6. Set and obtain the minimum count of days in the first week for the **Calendar** object.
+7. Set and obtain the minimum count of days in the first week for the **Calendar** object.
+ Call **setMinimalDaysInFirstWeek** and **getMinimalDaysInFirstWeek** to set and obtain the minimum number of days in the first week for the **Calendar** object.
- Call the **setMinimalDaysInFirstWeek** and **getMinimalDaysInFirstWeek** methods to set and obtain the minimum count of days in the first week for the **Calendar** object.
-
- ```js
+ ```js
calendar.setMinimalDaysInFirstWeek(3);
- var minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek();
+ let minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 3
```
-7. Obtain the localized display of the **Calendar** object.
+8. Obtain the localized representation of the **Calendar** object.
+ Call **getDisplayName** to obtain the localized representation of the **Calendar** object.
+
+ ```js
+ let localizedName = calendar.getDisplayName("zh-CN"); // localizedName = " Lunar Calendar"
+ ```
- Call the **getDisplayName** method to obtain the localized display of the **Calendar** object.
+9. Check whether a date is a weekend.
+ Call **isWeekend** to determine whether the input date is a weekend.
- ```js
- var localizedName = calendar.getDisplayName("zh-CN");
+ ```js
+ let date = new Date(2022, 12, 12, 12, 12, 12);
+ let weekend = calendar.isWeekend(date); // weekend = false
```
-8. Check whether a date is a weekend.
+## Formatting a Phone Number
+
+[PhoneNumberFormat](../reference/apis/js-apis-i18n.md#phonenumberformat8) provides APIs to format phone numbers of different countries or regions and check whether the phone number format is correct.
- Call the **isWeekend** method to determine whether the input date is a weekend.
+### Available APIs
-
- ```js
- var date = new Date();
- var weekend = calendar.isWeekend(date);
+| Class | API | Description |
+| --------- | ---------------------------------------- | ----------------------- |
+| PhoneNumberFormat | constructor(country:string,options?:PhoneNumberFormatOptions)8+ | Instantiates a **PhoneNumberFormat** object.|
+| PhoneNumberFormat | isValidNumber(number:string):boolean8+ | Checks whether the value of **number** is a phone number in the correct format.|
+| PhoneNumberFormat | format(number:string):string8+ | Formats the value of **number** based on the specified country and style. |
+| PhoneNumberFormat | getLocationName(number: string, locale: string): string9+ | Obtains the home location of a phone number. |
+
+### How to Develop
+
+1. Import the **i18n** module.
+
+ ```js
+ import I18n from '@ohos.i18n'
```
+2. Instantiate a **PhoneNumberFormat** object.
-## Formatting a Phone Number
+ Call the **PhoneNumberFormat** constructor to instantiate a **PhoneNumberFormat** object. The country code and formatting options of the phone number need to be passed into this constructor. The formatting options are optional, including a style option. Values of this option include: **E164**, **INTERNATIONAL**, **NATIONAL**, and **RFC3966**.
-[PhoneNumberFormat](../reference/apis/js-apis-i18n.md#phonenumberformat8) APIs are used to format phone numbers in different countries and check whether the phone number formats are correct.
+ ```js
+ let phoneNumberFormat = new I18n.PhoneNumberFormat("CN", {type: "E164"});
+ ```
+3. Check whether the phone number format is correct.
+
+ Call **isValidNumber** to check whether the format of the input phone number is correct.
+
+ ```js
+ let validNumber = phoneNumberFormat.isValidNumber("15812341234"); // validNumber = true
+ ```
+
+4. Format a phone number.
+
+ Call **format** to format the input phone number.
+
+ ```js
+ let formattedNumber = phoneNumberFormat.format("15812341234"); // formattedNumber = "+8615812341234"
+ ```
+
+## Measurement Conversion
+
+The **I18NUtil** class provides an API to implement measurement conversion.
### Available APIs
-| Module | API | Description |
-| -------- | -------- | -------- |
-| ohos.i18n | constructor(country: string, options?: PhoneNumberFormatOptions)8+ | Instantiates a **PhoneNumberFormat** object. |
-| ohos.i18n | isValidNumber(number: string): boolean8+ | Checks whether the value of **number** is a phone number in the correct format. |
-| ohos.i18n | format(number: string): string8+ | Formats the value of **number** based on the specified country and style. |
+| Class | API | Description |
+| --------- | ---------------------------------------- | --------------------------------------- |
+| I18NUtil | unitConvert(fromUnit:UnitInfo,toUnit:UnitInfo,value:number,locale:string,style?:string):string9+ | Converts one measurement unit into another and formats the unit based on the specified locale and style.|
+
+### How to Develop
+
+1. Import the **i18n** module.
+
+ ```js
+ import I18n from '@ohos.i18n'
+ ```
+
+2. Convert a measurement unit.
+
+ Call [unitConvert](../reference/apis/js-apis-i18n.md#unitconvert9) to convert a measurement unit and format the display result.
+
+ ```js
+ let fromUnit = {unit: "cup", measureSystem: "US"};
+ let toUnit = {unit: "liter", measureSystem: "SI"};
+ let number = 1000;
+ let locale = "en-US";
+ let style = "long";
+ let converttedUnit = I18n.I18NUtil.unitConvert(fromUnit, toUnit, number, locale, style); // converttedUnit = "236.588 liters"
+ ```
+
+## Alphabet Indexing
+
+[IndexUtil](../reference/apis/js-apis-i18n.md#indexutil8) provides APIs to obtain the alphabet indexes of different locales and calculate the index to which a string belongs.
+
+### Available APIs
+| Class | API | Description |
+| --------- | ---------------------------------------- | ----------------------- |
+| | getInstance(locale?:string):IndexUtil8+ | Instantiates an **IndexUtil** object. |
+| IndexUtil | getIndexList():Array<string>8+ | Obtains the index list of the current locale. |
+| IndexUtil | addLocale(locale:string): void8+ | Adds the index of a new locale to the index list.|
+| IndexUtil | getIndex(text:string):string8+ | Obtains the index of a text object. |
### How to Develop
-1. Instantiate a **PhoneNumberFormat** object.
+1. Import the **i18n** module.
- Call the **PhoneNumberFormat** constructor to instantiate a **PhoneNumberFormat** object. The country code and formatting options of the phone number need to be passed into this constructor. The formatting options are optional, including a style option. Values of this option include: **E164**, **INTERNATIONAL**, **NATIONAL**, and **RFC3966**.
+ ```js
+ import I18n from '@ohos.i18n'
+ ```
+
+2. Instantiates an **IndexUtil** object.
+ Call **getInstance** to instantiate an **IndexUtil** object for a specific locale. When the **locale** parameter is empty, instantiate an **IndexUtil** object of the default locale.
- ```js
- var phoneNumberFormat = new i18n.PhoneNumberFormat("CN", {type: "E164"});
+
+ ```js
+ let indexUtil = I18n.getInstance("zh-CN");
```
-2. Check whether the phone number format is correct.
- Call the **isValidNumber** method to check whether the format of the input phone number is correct.
-
- ```js
- var validNumber = phoneNumberFormat.isValidNumber("15812341234");
+3. Obtain the index list.
+
+ Call **getIndexList** to obtain the alphabet index list of the current locale.
+
+ ```js
+ let indexList = indexUtil.getIndexList(); // indexList = ["...", "A", "B", "C", ..., "X", "Y", "Z", "..."]
```
-3. Format a phone number.
- Call the **format** method of **PhoneNumberFormat** to format the input phone number.
-
- ```js
- var formattedNumber = phoneNumberFormat.format("15812341234");
+4. Add an index.
+
+ Call **addLocale** to add the alphabet index of a new locale to the current index list.
+
+ ```js
+ indexUtil.addLocale("ar")
```
+5. Obtain the index of a string.
-## Measurement Conversion
+ Call **getIndex** to obtain the alphabet index of a string.
-The **unitConvert** API is provided to help you implement measurement conversion.
+ ```js
+ let text = "access index";
+ let index = indexUtil.getIndex(text); // index = "A"
+ ```
+
+## Obtaining Line Breaks of Text
+When a text is displayed in more than one line, use [BreakIterator8](../reference/apis/js-apis-i18n.md#breakiterator8) APIs to obtain the line break positions of the text.
### Available APIs
-| Module | API | Description |
-| -------- | -------- | -------- |
-| ohos.i18n | unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string8+ | Converts one measurement unit (**fromUnit**) into another (**toUnit**) and formats the unit based on the specified locale and style. |
-
+| Class | API | Description |
+| --------- | ---------------------------------------- | ------------------------------ |
+| | getLineInstance(locale:string):BreakIterator8+ | Instantiates a **BreakIterator** object. |
+| BreakIterator | setLineBreakText(text:string): void8+ | Sets the text to be processed. |
+| BreakIterator | getLineBreakText():string8+ | Obtains the text to be processed. |
+| BreakIterator | current():number8+ | Obtains the current position of a **BreakIterator** object in the text being processed. |
+| BreakIterator | first():number8+ | Sets a **BreakIterator** object to the first breakable point. |
+| BreakIterator | last():number8+ | Sets a **BreakIterator** object to the last breakable point. |
+| BreakIterator | next(index?:number):number8+ | Moves a **BreakIterator** object to the break point according to **index**. |
+| BreakIterator | previous():number8+ | Moves a **BreakIterator** object to the previous break point. |
+| BreakIterator | following(offset:number):number8+ | Moves a **BreakIterator** object to the break point following the position specified by **offset**.|
+| BreakIterator | isBoundary(offset:number):boolean8+ | Determines whether a position is a break point. |
### How to Develop
-1. Convert a measurement unit.
- Call the [unitConvert](../reference/apis/js-apis-i18n.md#unitconvert9) method to convert a measurement unit and format the display result.
+1. Import the **i18n** module.
-
- ```js
- var fromUnit = {unit: "cup", measureSystem: "US"};
- var toUnit = {unit: "liter", measureSystem: "SI"};
- var number = 1000;
- var locale = "en-US";
- var style = "long";
- i18n.Util.unitConvert(fromUtil, toUtil, number, locale, style);
- ```
+ ```js
+ import I18n from '@ohos.i18n'
+ ```
+2. Instantiate a **BreakIterator** object.
-## Alphabet Index
+ Call **getLineInstance** to instantiate a **BreakIterator** object.
-[IndexUtil](../reference/apis/js-apis-i18n.md#indexutil8) APIs are used to obtain the alphabet indexes of different locales and calculate the index to which a string belongs.
+ ```js
+ let locale = "en-US"
+ let breakIterator = I18n.getLineInstance(locale);
+ ```
+3. Set and access the text that requires line breaking.
-### Available APIs
+ Call **setLineBreakText** and **getLineBreakText** to set and access the text that requires line breaking.
-| Module | API | Description |
-| -------- | -------- | -------- |
-| ohos.i18n | getInstance(locale?: string): IndexUtil8+ | Instantiates an **IndexUtil** object. |
-| ohos.i18n | getIndexList(): Array<string>8+ | Obtains the index list of the current locale. |
-| ohos.i18n | addLocale(locale: string): void8+ | Adds the index of a new locale to the index list. |
-| ohos.i18n | getIndex(text: string): string8+ | Obtains the index of **text**. |
+ ```js
+ let text = "Apple is my favorite fruit";
+ breakIterator.setLineBreakText(text);
+ let breakText = breakIterator.getLineBreakText(); // breakText = "Apple is my favorite fruit"
+ ```
+4. Obtain the current position of the **BreakIterator** object.
-### How to Develop
+ Call **current** to obtain the current position of the **BreakIterator** object in the text being processed.
-1. Instantiate an **IndexUtil** object.
+ ```js
+ let pos = breakIterator.current(); // pos = 0
+ ```
- Call the **getInstance** method to instantiate an **IndexUtil** object for a specific locale. When the **locale** parameter is empty, instantiate an **IndexUtil** object of the default locale.
+5. Set the position of a **BreakIterator** object.
+ The following APIs are provided to adjust the **first**, **last**, **next**, **previous**, or **following** position of the **BreakIterator** object in the text to be processed.
- ```js
- var indexUtil = i18n.getInstance("zh-CN");
+ ```js
+ let firstPos = breakIterator.first(); // Set a BreakIterator object to the first break point, that is, the start position of the text (firstPos = 0).
+ let lastPos = breakIterator.last(); // Sets a BreakIterator object to the last break point, that is, the position after the text end (lastPos = 26).
+ // Move a BreakIterator object forward or backward by a certain number of break points.
+ // If a positive number is input, move backward. If a negative number is input, move forward. If no value is input, move one position backward.
+ // If the object is moved out of the text length range, **-1** is returned.
+ let nextPos = breakIterator.next(-2); // nextPos = 12
+ let previousPos = breakIterator.previous(); // Move a BreakIterator object to the previous break point. When the text length is out of the range, **-1** is returned. Example: previousPos = 9
+ // Move a BreakIterator object to the break point following the position specified by **offset**. If the object is moved out of the text length range, **-1** is returned.
+ let followingPos = breakIterator.following(10); // Example: followingPos = 12
```
-2. Obtain the index list.
+6. Determine whether a position is a break point.
- Call the **getIndexList** method to obtain the alphabet index list of the current locale.
-
- ```js
- var indexList = indexUtil.getIndexList();
+ Call **isBoundary** to determine whether a position is a break point. If yes, **true** is returned and the **BreakIterator** object is moved to this position. If no, **false** is returned and the **BreakIterator** object is moved to a break point after this position.
+
+ ```js
+ let isboundary = breakIterator.isBoundary(5); // isboundary = false
```
-3. Add an index.
+## Obtaining the Time Zone
- Call the **addLocale** method to add the alphabet index of a new locale to the current index list.
-
- ```js
- indexUtil.addLocale("ar")
+[TimeZone](../reference/apis/js-apis-i18n.md#timezone) provides APIs to obtain time zone information, such as the time zone ID, localized representation, and time zone offset.
+
+### Available APIs
+
+| Class | API | Description |
+| --------- | ---------------------------------------- | ------------------------------ |
+| | getTimeZone(zoneID?: string): TimeZone7+ | Obtains a **TimeZone** object. |
+| TimeZone | getID(): string7+ | Obtains the time zone ID. |
+| TimeZone | getDisplayName(locale?: string, isDST?: boolean): string7+ | Obtains the localized representation of the time zone. |
+| TimeZone | getRawOffset(): number7+ | Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone. |
+| TimeZone | getOffset(date?: number): number7+ | Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone at a certain time point. |
+| TimeZone | getAvailableIDs(): Array9+ | Obtains the list of time zone IDs supported by the system. |
+| TimeZone | getAvailableZoneCityIDs(): Array9+ | Obtains the list of time zone city IDs supported by the system. |
+| TimeZone | getCityDisplayName(cityID: string, locale: string): string9+ | Obtains the localized representation of a time zone city in the specified locale. |
+| TimeZone | getTimezoneFromCity(cityID: string): TimeZone9+ | Obtains the **TimeZone** object corresponding to the specified time zone ID.|
+
+### How to Develop
+
+1. Import the **i18n** module.
+
+ ```js
+ import I18n from '@ohos.i18n'
```
-4. Obtain the index of a string.
+2. Instantiate the **TimeZone** object, and obtain the time zone information.
- Call the **getIndex** method to obtain the alphabet index of a string.
-
- ```js
- var text = "access index";
- indexUtil.getIndex(text);
+ Call **getTimeZone** to obtain the **TimeZone** object.
+
+ ```js
+ let timezone = I18n.getTimeZone(); // If you use the default settings, you'll obtain the TimeZone object corresponding to the system time zone.
```
+ Obtain the time zone ID, localized representation, time zone offset, and time zone offset at a certain time point.
+
+ ```js
+ let timezoneID = timezone.getID(); // timezoneID = "Asia/Shanghai"
+ let timezoneDisplayName = timezone.getDisplayName(); // timezoneDisplayName = "China Standard Time"
+ let rawOffset = timezone.getRawOffset(); // rawOffset = 28800000
+ let offset = timezone.getOffset(new Date().getTime()); // offset = 28800000
+ ```
-## Obtaining Line Breaks of Text
+3. Obtain the list of time zone IDs supported by the system.
+
+ Call **getAvailableIDs** to obtain the list of time zone IDs supported by the system.
+ You can use the time zone ID in the time zone ID list as an input parameter of the **getTimeZone** API to create a **TimeZone** object.
+
+ ```js
+ let timezoneIDs = I18n.TimeZone.getAvailableIDs(); // timezoneIDs = ["America/Adak", ...], which contains 24 time zone IDs in total
+ let timezone = I18n.getTimeZone(timezoneIDs[0]);
+ let timezoneDisplayName = timezone.getDisplayName(); // timezoneDisplayName = "Hawaii-Aleutian Standard Time"
+ ```
+
+4. Obtain the list of time zone city IDs supported by the system.
+
+ Call **getAvailableZoneCityIDs** to obtain the list of time zone city IDs supported by the system.
+ Call **getCityDisplayName** to obtain the localized representation of the time zone city ID.
+ Call **getTimezoneFromCity** to create a **TimeZone** object based on the time zone city ID.
-When a text is displayed in more than one line, [BreakIterator8](../reference/apis/js-apis-i18n.md#breakiterator8) APIs are used to obtain the line break positions of the text.
+ ```js
+ let zoneCityIDs = I18n.TimeZone.getAvailableZoneCityIDs(); // ["Auckland", "Magadan", ...]
+ let cityDisplayName = I18n.TimeZone.getCityDisplayName(zoneCityIDs[0], "zh-Hans"); // cityDisplayName = "Auckland (New Zealand)"
+ let timezone = I18n.TimeZone.getTimezoneFromCity(zoneCityIDs[0]);
+ let timezoneDisplayName = timezone.getDisplayName(); // timezoneDisplayName = "New Zealand Standard Time"
+ ```
+
+## Obtain the **Transliterator** object.
+Call [Transliterator](../reference/apis/js-apis-i18n.md#transliterator9) APIs to create a **Transliterator** object and obtain the transliterated string.
### Available APIs
-| Module | API | Description |
-| -------- | -------- | -------- |
-| ohos.i18n | getLineInstance(locale: string): BreakIterator8+ | Instantiates a **BreakIterator** object. |
-| ohos.i18n | setLineBreakText(text: string): void8+ | Sets the text to be processed. |
-| ohos.i18n | getLineBreakText(): string8+ | Obtains the text to be processed. |
-| ohos.i18n | current(): number8+ | Obtains the current position of a **BreakIterator** object in the text being processed. |
-| ohos.i18n | first(): number8+ | Sets a **BreakIterator** object to the first breakable point. |
-| ohos.i18n | last(): number8+ | Sets a **BreakIterator** object to the last breakable point. |
-| ohos.i18n | next(index?: number): number8+ | Moves a **BreakIterator** object to the break point according to **index**. |
-| ohos.i18n | previous(): number8+ | Moves a **BreakIterator** object to the previous break point. |
-| ohos.i18n | following(offset: number): number8+ | Moves a **BreakIterator** object to the break point following the position specified by **offset**. |
-| ohos.i18n | isBoundary(offset: number): boolean8+ | Determines whether a position is a break point. |
+| Class | API | Description |
+| --------- | ---------------------------------------- | ------------------------------ |
+| Transliterator | getAvailableIDs():Array9+ | Obtains the transliterator ID list. |
+| Transliterator | getInstance(): Transliterator9+ | Creates a **Transliterator** object. |
+| Transliterator | transform(text: string): string9+ | Obtains a transliterated string. |
+### How to Develop
+
+1. Import the **i18n** module.
+
+ ```js
+ import I18n from '@ohos.i18n'
+ ```
+
+2. Obtains the transliterator ID list.
+
+ Call **getAvailableIDs** to obtain the transliterator ID list.
+ An ID is in the **source-destination** format. For example, **ASCII-Latin** means to convert the transliterator ID from ASCII to Latin.
+
+ ```js
+ let ids = I18n.Transliterator.getAvailableIDs(); // ids = ["ASCII-Latin", "Accents-Any", ... ], 671 languages in total
+ ```
+
+3. Create a **Transliterator** object, and obtain the transliterated string.
+
+ You can use the ID in the transliterator ID list as an input parameter of the **getInstance** API to create a **Transliterator** object.
+ Call **transform** to obtain the transliterated string.
+
+ ```js
+ let transliterator = I18n.Transliterator.getInstance("Any-Latn"); // Any-Latn means to convert any text to Latn text.
+ let transformText = transliterator.transform ("Hello"); // transformText = "nǐ hǎo"
+ ```
+
+## Obtaining the Character Type
+
+[Unicode](../reference/apis/js-apis-i18n.md#unicode9) provides APIs to obtain character information, for example, whether a character is a digit or a space.
+
+### Available APIs
+
+| Class | API | Description |
+| --------- | ---------------------------------------- | ------------------------------ |
+| Unicode | isDigit(char: string): boolean9+ | Checks whether the input character is a digit. |
+| Unicode | isSpaceChar(char: string): boolean9+ | Checks whether the input character is a space. |
+| Unicode | isWhitespace(char: string): boolean9+ | Checks whether the input character is a white space. |
+| Unicode | isRTL(char: string): boolean9+ | Checks whether the input character is of the RTL language. |
+| Unicode | isIdeograph(char: string): boolean9+ | Checks whether the input character is an ideographic character. |
+| Unicode | isLetter(char: string): boolean9+ | Checks whether the input character is a letter. |
+| Unicode | isLowerCase(char: string): boolean9+ | Checks whether the input character is a lowercase letter. |
+| Unicode | isUpperCase(char: string): boolean9+ | Checks whether the input character is an uppercase letter. |
+| Unicode | getType(char: string): string9+ | Obtains the type of a character.|
### How to Develop
-1. Instantiate a **BreakIterator** object.
+1. Import the **i18n** module.
+
+ ```js
+ import I18n from '@ohos.i18n'
+ ```
- Call the **getLineInstance** method to instantiate a **BreakIterator** object.
+2. Check the input character has a certain attribute.
+ Check whether the input character is a digit.
- ```js
- var locale = "en-US"
- var breakIterator = i18n.getLineInstance(locale);
+ ```js
+ let isDigit = I18n.Unicode.isDigit("1"); // isDigit = true
+ isDigit = I18n.Unicode.isDigit("a"); // isDigit = false
```
-2. Set and access the text that requires line breaking.
+ Check whether the input character is a space.
- Call the **setLineBreakText** and **getLineBreakText** methods to set and access the text that requires line breaking.
+ ```js
+ let isSpaceChar = I18n.Unicode.isSpaceChar(" "); // isSpaceChar = true
+ isSpaceChar = I18n.Unicode.isSpaceChar("\n"); // isSpaceChar = false
+ ```
-
- ```js
- var text = "Apple is my favorite fruit";
- breakIterator.setLineBreakText(text);
- var breakText = breakIterator.getLineBreakText();
+ Check whether the input character is a white space.
+
+ ```js
+ let isWhitespace = I18n.Unicode.isWhitespace(" "); // isWhitespace = true
+ isWhitespace = I18n.Unicode.isWhitespace("\n"); // isWhitespace = true
+ ```
+
+ Check whether the input character is of the RTL language.
+
+ ```js
+ let isRTL = I18n.Unicode.isRTL(""); // isRTL = true (Arabic characters are written from left to right.)
+ isRTL = I18n.Unicode.isRTL("a"); // isRTL = false
```
-3. Obtain the current position of the **BreakIterator** object.
+ Check whether the input character is an ideographic character.
- Call the **current** method to obtain the current position of the **BreakIterator** object in the text being processed.
+ ```js
+ let isIdeograph = I18n.Unicode.isIdeograph("Hello"); // isIdeograph = true
+ isIdeograph = I18n.Unicode.isIdeograph("a"); // isIdeograph = false
+ ```
+ Check whether the input character is a letter.
- ```js
- var pos = breakIterator.current();
+ ```js
+ let isLetter = I18n.Unicode.isLetter("a"); // isLetter = true
+ isLetter = I18n.Unicode.isLetter("."); // isLetter = false
```
-4. Set the position of a **BreakIterator** object.
+ Check whether the input character is a lowercase letter.
- The following APIs are provided to adjust the **first**, **last**, **next**, **previous**, or **following** position of the **BreakIterator** object in the text to be processed.
+ ```js
+ let isLowerCase = I18n.Unicode.isLowerCase("a"); // isLetter = true
+ isLowerCase = I18n.Unicode.isLowerCase("A"); // isLetter = false
+ ```
-
- ```js
- var firstPos = breakIterator.first(); // Set a BreakIterator object to the first break point, that is, the start position of the text.
- var lastPos = breakIterator.last(); // Set a BreakIterator object to the last break point, that is, the position after the text end.
- // Move a BreakIterator object forward or backward by a certain number of break points.
- // If a positive number is input, move backward. If a negative number is input, move forward. If no value is input, move one position backward.
- // When the object is moved out of the text length range, -1 is returned.
- var nextPos = breakIterator.next(-2);
- var previousPos = breakIterator.previous(); // Move a BreakIterator object to the previous break point. When the text length is out of the range, -1 is returned.
- // Move a BreakIterator object to the break point following the position specified by offset. If the object is moved out of the text length range, -1 is returned.
- var followingPos = breakIterator.following(10);
+ Check whether the input character is an uppercase letter.
+
+ ```js
+ let isUpperCase = I18n.Unicode.isUpperCase("a"); // isUpperCase = false
+ isUpperCase = I18n.Unicode.isUpperCase("A"); // isUpperCase = true
+ ```
+
+3. Obtain the character type.
+
+ Call **getType** to obtain the character type.
+
+ ```js
+ let type = I18n.Unicode.getType("a"); // type = U_LOWER_CASE_LETTER
```
-5. Determine whether a position is a break point.
+## Obtaining the Sequence of Year, Month, and Day in a Date
- Call the **isBoundary** method to determine whether a position is a break point. If yes, **true** is returned and the **BreakIterator** object is moved to this position. If no, **false** is returned and the **BreakIterator** object is moved to a break point after this position.
+### Available APIs
+| Class | API | Description |
+| --------- | ---------------------------------------- | ------------------------------ |
+| I18NUtil | getDateOrder(locale: string): string9+ | Checks the sequence of year, month, and day in a date. |
+
+### How to Develop
- ```js
- var isboundary = breakIterator.isBoundary(5);
+1. Import the **i18n** module.
+
+ ```js
+ import I18n from '@ohos.i18n'
```
- ```
\ No newline at end of file
+2. Check the sequence of year, month, and day in a date.
+
+ Call **getDateOrder** to obtain the sequence of year, month, and day in the date of the specified locale.
+ The API returns a string consisting of three parts, **y**, **L**, and **d**, which indicate the year, month, and day, respectively. The three parts are separated by using a hyphen (-), for example, **y-L-d**.
+
+ ```js
+ let order = I18n.I18NUtil.getDateOrder("zh-CN"); // order = "y-L-d" indicates that the sequence of year, month, and day in Chinese is year-month-day.
+ ```
diff --git a/en/application-dev/internationalization/intl-guidelines.md b/en/application-dev/internationalization/intl-guidelines.md
index f123a0b29a64a10b683f9fb90d163790e4f0524e..609af84500cecb0ce5bda8409216b6957182885f 100644
--- a/en/application-dev/internationalization/intl-guidelines.md
+++ b/en/application-dev/internationalization/intl-guidelines.md
@@ -1,38 +1,42 @@
-# Internationalization Development (Intl)
+# intl Development
-This module provides basic I18N capabilities, such as time and date formatting, number formatting, and string sorting, through the standard I18N APIs defined in ECMA 402. For more details about APIs and their usage, see [Intl](../reference/apis/js-apis-intl.md).
+The **intl** module provides basic i18n capabilities, such as time and date formatting, number formatting, and string sorting, through the standard i18n APIs defined in ECMA 402. For more details about APIs and their usage, see [intl](../reference/apis/js-apis-intl.md).
-> **NOTE**
->
-> In the code snippets in this document, **intl** refers to the name of the imported module.
+The [I18N](i18n-guidelines.md) module provides enhanced I18N capabilities through supplementary interfaces that are not defined in ECMA 402. It works with the Intl module to provide a complete suite of I18N capabilities.
## Setting Locale Information
-Use [Locale](../reference/apis/js-apis-intl.md#locale) APIs to maximize or minimize locale information.
-
+[Locale](../reference/apis/js-apis-intl.md#locale) provides APIs to maximize or minimize the locale information.
### Available APIs
-| Module | API | Description |
+| Class| API| Description|
| -------- | -------- | -------- |
-| ohos.intl | constructor()8+ | Instantiates a **Locale** object. |
-| ohos.intl | constructor(locale?: string, options?: options) | Instantiates a **Locale** object based on the locale parameter and options. |
-| ohos.intl | toString(): string | Converts locale information into a string. |
-| ohos.intl | maximize(): Locale | Maximizes locale information. |
-| ohos.intl | minimize(): Locale | Minimizes locale information. |
-
+| Locale | constructor()8+ | Instantiates a **Locale** object.|
+| Locale | constructor(locale:string,options?:LocaleOptions) | Instantiates a **Locale** object based on the locale parameter and options.|
+| Locale | toString():string | Converts locale information into a string.|
+| Locale | maximize():Locale | Maximizes locale information.|
+| Locale | minimize():Locale | Minimizes locale information.|
### How to Develop
-1. Instantiate a **Locale** object.
+1. Import the **intl** module.
+
+ Importing an incorrect bundle can lead to unexpected API behavior.
+
+ ```js
+ import Intl from '@ohos.intl'
+ ```
+
+2. Instantiates a **Locale** object.
- Create a **Locale** object by using the **Locale** constructor. This method receives a string representing the locale and an optional [Attributes](../reference/apis/js-apis-intl.md#localeoptions) list.
+ Create a **Locale** object using the **Locale** constructor. This API receives a string representing the locale and an optional [attribute](../reference/apis/js-apis-intl.md#localeoptions) list. (Note that **intl** is the name of the imported module.)
A **Locale** object consists of four parts: language, script, region, and extension, which are separated by using a hyphen (-).
- Language: mandatory. It is represented by a two-letter or three-letter code as defined in ISO-639. For example, **en** indicates English and **zh** indicates Chinese.
- Script: optional. It is represented by a four-letter code as defined in ISO-15924. The first letter is in uppercase, and the remaining three letters are in lowercase. For example, **Hant** represents the traditional Chinese, and **Hans** represents the simplified Chinese.
- Country or region: optional. It is represented by two-letter code as defined in ISO-3166. Both letters are in uppercase. For example, **CN** represents China, and **US** represents the United States.
- - Extensions: optional. Each extension consists of two parts, key and value. Currently, the extensions listed in the following table are supported (see BCP 47 Extensions). Extensions can be in any sequence and are written in the format of **-key-value**. They are appended to the language, script, and region by using **-u**. For example, **zh-u-nu-latn-ca-chinese** indicates that the Latin numbering system and Chinese calendar system are used. Extensions can also be passed via the second parameter.
+ - Extensions: optional. Each extension consists of two parts, key and value. Currently, the extensions listed in the following table are supported (see BCP 47 Extensions). Extensions can be in any sequence and are written in the format of **-key-value**. They are appended to the language, script, and region by using **-u**. For example, **zh-u-nu-latn-ca-chinese** indicates that the latn digital system and chinese calendar system are used. Extensions can also be passed via the second parameter.
| Extended Parameter ID| Description|
| -------- | -------- |
| ca | Calendar algorithm.|
@@ -40,305 +44,346 @@ Use [Locale](../reference/apis/js-apis-intl.md#locale) APIs to maximize or minim
| hc | Hour cycle.|
| nu | Numbering system.|
| kn | Whether numeric collation is used when sorting or comparing strings.|
- | kf | Whether upper case or lower case is considered when sorting or comparing strings.|
+ | kf | Whether capitalization is considered when sorting or comparing strings.|
```js
- var locale = "zh-CN";
- var options = {caseFirst: "false", calendar: "chinese", collation: "pinyin"};
- var localeObj = new intl.Locale(locale, options);
+ let locale = "zh-CN";
+ let options = {caseFirst: "false", calendar: "chinese", collation: "pinyin"};
+ let localeObj = new Intl.Locale(locale, options);
```
-2. Obtain the string representing a **Locale** object.
+3. Obtain the string representing a **Locale** object.
- Call the **toString** method to obtain the string representing a **Locale** object, which includes the language, region, and other options.
-
+ Call **toString** to obtain the string representing a **Locale** object, including the language, region, and other options.
+
```js
- var localeStr = localeObj.toString();
+ let localeStr = localeObj.toString(); // localeStr = "zh-CN-u-ca-chinese-co-pinyin-kf-false
```
-3. Maximize locale information.
+4. Maximize locale information.
- Call the **maximize** method to maximize locale information; that is, supplement the missing script and region information.
-
+ Call **maximize** to maximize locale information; that is, supplement the missing script and region information.
+
```js
- var maximizedLocale = localeObj.maximize();
+ let maximizedLocale = localeObj.maximize();
+ let maximizedLocaleStr = maximizedLocale.toString(); // localeStr = "zh-Hans-CN-u-ca-chinese-co-pinyin-kf-false
```
-4. Minimize locale information.
+5. Minimize locale information.
- Call the **minimize** method to minimize locale information; that is, delete the unnecessary script and region information.
-
+ Call **minimize** to minimize locale information; that is, delete the unnecessary script and region information.
+
```js
- var minimizedLocale = localeObj.minimize();
+ let minimizedLocale = localeObj.minimize();
+ let minimizedLocaleStr = minimizedLocale.toString(); // zh-u-ca-chinese-co-pinyin-kf-false
```
-
## Formatting the Date and Time
-Use [DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat) APIs to format the date and time for a specific locale.
-
+[DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat) provides APIs to format the date and time for the specified locale.
### Available APIs
-| Module | API | Description |
+| Class| API| Description|
| -------- | -------- | -------- |
-| ohos.intl | constructor()8+ | Creates a **DateTimeFormat** object. |
-| ohos.intl | constructor(locale: string \| Array<string>, options?: DateTimeOptions) | Creates a **DateTimeFormat** object and sets the locale and other formatting-related attributes. |
-| ohos.intl | format(date: Date): string | Calculates the date and time based on the locale and other formatting-related attributes of the **DateTimeFormat** object. |
-| ohos.intl | formatRange(startDate: Date, endDate: Date): string | Calculates the period based on the locale and other formatting-related attributes of the **DateTimeFormat** object. |
-| ohos.intl | resolvedOptions(): DateTimeOptions | Obtains the related attributes of the **DateTimeFormat** object. |
-
+| DateTimeFormat | constructor()8+ | Creates a **DateTimeFormat** object.|
+| DateTimeFormat | constructor(locale:string\|Array<string>,options?:DateTimeOptions) | Creates a **DateTimeFormat** object and sets the locale and other formatting-related attributes.|
+| DateTimeFormat | format(date:Date):string | Calculates the date and time based on the locale and other formatting-related attributes of the **DateTimeFormat** object.|
+| DateTimeFormat | formatRange(startDate:Date,endDate:Date):string | Calculates the period based on the locale and other formatting-related attributes of the **DateTimeFormat** object.|
+| DateTimeFormat | resolvedOptions():DateTimeOptions | Obtains the related attributes of the **DateTimeFormat** object.|
### How to Develop
-1. Instantiate a **DateTimeFormat** object.
-
- Use the default constructor of **DateTimeFormat** to obtain the system default locale by accessing the system language and region settings, and set it as the locale in the **DateTimeFormat** object.
+1. Import the **intl** module.
+ Importing an incorrect bundle can lead to unexpected API behavior.
```js
- var dateTimeFormat = new intl.DateTimeFormat();
+ import Intl from '@ohos.intl'
```
- Alternatively, use your own locale and formatting parameters to create a **DateTimeFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [DateTimeOptions](../reference/apis/js-apis-intl.md#datetimeoptions).
-
+2. Instantiate a **DateTimeFormat** object.
+
+ Use the default constructor of **DateTimeFormat** to obtain the system default locale by accessing the system language and region settings, and set it as the locale in the **DateTimeFormat** object.
+
```js
- var options = {dateStyle: "full", timeStyle: "full"};
- var dateTimeFormat = new intl.DateTimeFormat("zh-CN", options);
+ let dateTimeFormat = new Intl.DateTimeFormat();
```
-2. Format the date and time.
-
- Call the **format** method to format the date and time in the **DateTimeFormat** object. This method returns a string representing the formatting result.
+ Alternatively, use your own locale and formatting parameters to create a **DateTimeFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [DateTimeOptions](../reference/apis/js-apis-intl.md#datetimeoptions).
```js
- var date = new Date();
- var formatResult = dateTimeFormat.format(date);
+ let options = {dateStyle: "full", timeStyle: "full"};
+ let dateTimeFormat = new Intl.DateTimeFormat("zh-CN", options);
```
-3. Format a period.
+3. Format the date and time.
- Call the **formatRange** method to format the period in the **DateTimeFormat** object. This method requires input of two **Date** objects, which respectively indicate the start date and end date of a period. This method returns a string representing the formatting result.
-
+ Call **format** to format a **Date** object. A string is returned as the formatting result.
+
```js
- var startDate = new Date(2021, 11, 17, 3, 24, 0);
- var endDate = new Date(2021, 11, 18, 3, 24, 0);
- var datefmt = new Intl.DateTimeFormat("en-GB");
- datefmt.formatRange(startDate, endDate);
+ let options = {dateStyle: "full", timeStyle: "full"};
+ let dateTimeFormat = new Intl.DateTimeFormat("zh-CN", options);
+ let date = new Date(2022, 12, 12, 12, 12, 12);
+ let formatResult = dateTimeFormat.format(date); // formatResult = "January 12, 2023, Thursday, 12:12:12 pm, China Standard Time"
```
-4. Obtain attributes of the **DateTimeFormat** object.
+4. Format a period.
- Call the **resolvedOptions** method to obtain attributes of the **DateTimeFormat** object. This method will return an array that contains all attributes and values of the object.
-
+ Call **formatRange** to format a period. This API requires the input of two **Date** objects, which respectively indicate the start date and end date of a period. A string is returned as the formatting result.
+
```js
- var options = dateTimeFormat.resolvedOptions();
+ let startDate = new Date(2021, 11, 17, 3, 24, 0);
+ let endDate = new Date(2021, 11, 18, 3, 24, 0);
+ let datefmt = new Intl.DateTimeFormat("en-GB");
+ let formatRangeResult = datefmt.formatRange(startDate, endDate); // formatRangeResult = "17/12/2021-18/12/2021"
```
+5. Access the attributes of the **DateTimeFormat** object.
-## Formatting Numbers
+ Call **resolvedOptions** to obtain an object that contains all related attributes and values of the **DateTimeFormat** object.
+
+ ```js
+ let options = {dateStyle: "full", timeStyle: "full"};
+ let dateTimeFormat = new Intl.DateTimeFormat("zh-CN", options);
+ let resolvedOptions = dateTimeFormat.resolvedOptions(); // resolvedOptions = {"locale": "zh-CN", "calendar": "gregorian", "dateStyle":"full", "timeStyle":"full", "timeZone": "CST"}
+ ```
-Use [NumberFormat](../reference/apis/js-apis-intl.md#numberformat) APIs to format numbers for a specific locale.
+## Number Formatting
+[NumberFormat](../reference/apis/js-apis-intl.md#numberformat) provides APIs to implement the number formatting specific to a locale.
### Available APIs
-| Module | API | Description |
+| Class| API| Description|
| -------- | -------- | -------- |
-| ohos.intl | constructor()8+ | Creates a **NumberFormat** object. |
-| ohos.intl | constructor(locale: string \| Array<string>, options?: NumberOptions) | Creates a **NumberFormat** object and sets the locale and other formatting-related attributes. |
-| ohos.intl | format(number: number): string | Calculates the number based on the locale and other formatting-related attributes of the **NumberFormat** object. |
-| ohos.intl | resolvedOptions(): NumberOptions | Obtains attributes of the **NumberFormat** object. |
-
+| NumberFormat | constructor()8+ | Creates a **NumberFormat** object for the specified locale.|
+| NumberFormat | constructor(locale:string\|Array<string>,options?:NumberOptions) | Creates a **NumberFormat** object and sets the locale and other formatting-related attributes.|
+| NumberFormat | format(number:number):string | Calculates the number based on the locale and other formatting-related attributes of the **NumberFormat** object.|
+| NumberFormat | resolvedOptions():NumberOptions | Obtains the attributes of the **NumberFormat** object.|
### How to Develop
-1. Instantiate a **NumberFormat** object.
-
- Use the default constructor of **NumberFormat** to obtain the system default locale by accessing the system language and region settings, and set it as the locale in the **NumberFormat** object.
+1. Import the **intl** module.
+ Importing an incorrect bundle can lead to unexpected API behavior.
```js
- var numberFormat = new intl.NumberFormat();
+ import Intl from '@ohos.intl'
```
- Alternatively, use your own locale and formatting parameters to create a **NumberFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [NumberOptions](../reference/apis/js-apis-intl.md#numberoptions).
-
+2. Instantiate a **NumberFormat** object.
+
+ Use the default constructor of **NumberFormat** to obtain the system default locale by accessing the system language and region settings and set it as the locale in the **NumberFormat** object (**intl** is the name of the imported module).
+
```js
- var options = {compactDisplay: "short", notation: "compact"};
- var numberFormat = new intl.NumberFormat("zh-CN", options);
+ let numberFormat = new Intl.NumberFormat();
```
-2. Format a number.
-
- Call the **format** method to format a number. A string is returned as the formatting result.
+ Alternatively, use your own locale and formatting parameters to create a **NumberFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [NumberOptions](../reference/apis/js-apis-intl.md#numberoptions).
```js
- var number = 1234.5678
- var formatResult = numberFormat.format(number);
+ let options = {compactDisplay: "short", notation: "compact"};
+ let numberFormat = new Intl.NumberFormat("zh-CN", options);
```
-3. Obtain attributes of the **NumberFormat** object.
+3. Format a number.
- Call the **resolvedOptions** method to obtain attributes of the **NumberFormat** object. This method will return an array that contains all attributes and values of the object.
-
+ Call **format** to format a number. A string is returned as the formatting result.
+
```js
- var options = numberFormat.resolvedOptions();
+ let options = {compactDisplay: "short", notation: "compact"};
+ let numberFormat = new Intl.NumberFormat("zh-CN", options);
+ let number = 1234.5678
+ let formatResult = numberFormat.format(number); // formatResult = "1235"
```
+4. Access the attributes of the **NumberFormat** object.
-## Sorting Strings
+ Call **resolvedOptions** to obtain an object that contains all related attributes and values of the **NumberFormat** object.
+
+ ```js
+ let options = {compactDisplay: "short", notation: "compact"};
+ let numberFormat = new Intl.NumberFormat("zh-CN", options);
+ let resolvedOptions = numberFormat.resolvedOptions(); // resolvedOptions = {"locale": "zh-CN", "compactDisplay": "short", "notation": "compact", "numberingSystem": "Latn"}
+ ```
-Use [Collator](../reference/apis/js-apis-intl.md#collator8) APIs to sort strings based on a specific locale. Users in different regions have different preferences for string sorting.
+## String Sorting
+Users in different regions have different requirements for string sorting. [Collator](../reference/apis/js-apis-intl.md#collator8) provides APIs to sort character strings specific to a locale.
### Available APIs
-| Module | API | Description |
+| Class| API| Description|
| -------- | -------- | -------- |
-| ohos.intl | constructor()8+ | Creates a **Collator** object. |
-| ohos.intl | constructor(locale: string \| Array<string>, options?: CollatorOptions)8+ | Creates a **Collator** object and sets the locale and other related attributes. |
-| ohos.intl | compare(first: string, second: string): number8+ | Calculates the comparison result of two strings based on the locale and other attributes of the **Collator** object. |
-| ohos.intl | resolvedOptions(): CollatorOptions8+ | Obtains attributes of the **Collator** object. |
-
+| Collator | constructor()8+ | Creates a **Collator** object.|
+| Collator | constructor(locale:string\|Array<string>,options?:CollatorOptions)8+ | Creates a **Collator** object and sets the locale and other related attributes.|
+| Collator | compare(first:string,second:string):number8+ | Calculates the comparison result of two strings based on the locale and other attributes of the **Collator** object.|
+| Collator | resolvedOptions():CollatorOptions8+ | Obtains the attributes of the **Collator** object.|
### How to Develop
-1. Instantiate a **Collator** object.
-
- Use the default constructor of **Collator** to obtain the system default locale by accessing the system language and region settings, and set it as the locale in the **Collator** object.
+1. Import the **intl** module.
+ Importing an incorrect bundle can lead to unexpected API behavior.
```js
- var collator = new intl.Collator();
+ import Intl from '@ohos.intl'
```
- Alternatively, use your own locale and formatting parameters to create a **Collator** object. For a full list of parameters, see [CollatorOptions](../reference/apis/js-apis-intl.md#collatoroptions9).
-
+2. Instantiate a **Collator** object.
+
+ Use the default constructor of **Collator** to obtain the system default locale by accessing the system language and region settings and set it as the locale in the **Collator** object (**intl** is the name of the imported module).
+
```js
- var collator= new intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"});
+ let collator = new Intl.Collator();
```
-2. Compare two strings.
-
- Call the **compare** method to compare two input strings. This method returns a value as the comparison result. The return value **-1** indicates that the first string is shorter than the second string, the return value **1** indicates that the first string is longer than the second string, and the return value **0** indicates that the two strings are of equal lengths. This allows you to sort character strings based on the comparison result.
+ Alternatively, use your own locale and formatting parameters to create a **Collator** object. For a full list of parameters, see [CollatorOptions](../reference/apis/js-apis-intl.md#collatoroptions8).
+ The **sensitivity** parameter is used to specify the levels of differences that will be used for string comparison. The value **base** indicates that only characters are compared, but not the accent and capitalization. For example, 'a' != 'b', 'a' == '', 'a'=='A'. The value **accent** indicates that the accent is considered, but not the capitalization. For example, 'a' != 'b', 'a' == '', 'a'=='A'. The value **case** indicates that the capitalization is considered, but the accent. For example, 'a' != 'b', 'a' == '', 'a'=='A'. The value **variant** indicates that the accent and capitalization are considered. For example, 'a' != 'b', 'a' == '', 'a'=='A'.
```js
- var str1 = "first string";
- var str2 = "second string";
- var compareResult = collator.compare(str1, str2);
+ let collator= new Intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort", sensitivity: "case"});
```
-3. Obtain attributes of the **Collator** object.
+3. Compare two strings.
- Call the **resolvedOptions** method to obtain attributes of the **Collator** object. This method will return an array that contains all attributes and values of the object.
-
+ Call **compare** to compare two input strings. This API returns a value as the comparison result. The return value **-1** indicates that the first string is shorter than the second string, the return value **1** indicates that the first string is longer than the second string, and the return value **0** indicates that the two strings are of equal lengths. This allows you to sort character strings based on the comparison result.
+
```js
- var options = collator.resolvedOptions();
+ let collator= new Intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort", sensitivity: "case"});
+ let str1 = "first string";
+ let str2 = "second string";
+ let compareResult = collator.compare(str1, str2); // compareResult = -1
+ str1 = "first";
+ str2 = "First";
+ compareResult = collator.compare(str1, str2); // compareResult = -1
```
+4. Access the attributes of the **Collator** object.
-## Determining the Singular-Plural Type
+ Call **resolvedOptions** to obtain an object that contains all related attributes and values of the **Collator** object.
+
+ ```js
+ let collator= new Intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"});
+ let options = collator.resolvedOptions(); // options = {"localeMatcher": "best fit", "locale": "zh-CN", "usage": "sort", "sensitivity": "variant", "ignorePunctuation": "false", "numeric": false, "caseFirst": "false", "collation": "default"}
+ ```
-Use [PluralRules](../reference/apis/js-apis-intl.md#pluralrules8) APIs to determine the singular-plural type for a specific locale. According to the grammar of certain languages, the singular or plural form of a noun depends on its preceding number.
+## Determining the Singular-Plural Type
+According to grammars in certain languages, the singular or plural form of a noun depends on the number prior to the noun. [PluralRules](../reference/apis/js-apis-intl.md#pluralrules8) provides APIs to determine the singular-plural type for a specific locale.
### Available APIs
-| Module | API | Description |
+| Class| API| Description|
| -------- | -------- | -------- |
-| ohos.intl | constructor()8+ | Creates a **PluralRules** object. |
-| ohos.intl | constructor(locale: string \| Array<string>, options?: PluralRulesOptions)8+ | Creates a **PluralRules** object and sets the locale and other related attributes. |
-| ohos.intl | select(n: number): string8+ | Determines the singular-plural type based on the locale and other formatting-related attributes of the **PluralRules** object. |
+| PluralRules | constructor()8+ | Creates a **PluralRules** object.|
+| PluralRules | constructor(locale:string\|Array<string>,options?:PluralRulesOptions)8+ | Creates a **PluralRules** object and sets the locale and other related attributes.|
+| PluralRules | select(n:number):string8+ | Determines the singular-plural type based on the locale and other formatting-related attributes of the **PluralRules** object.|
### How to Develop
-1. Instantiate a **PluralRules** object.
-
- Use the default constructor of **PluralRules** to obtain the system default locale by accessing the system language and region settings, and set it as the locale in the **PluralRules** object.
+1. Import the **intl** module.
+ Importing an incorrect bundle can lead to unexpected API behavior.
```js
- var pluralRules = new intl.PluralRules();
+ import Intl from '@ohos.intl'
```
- Alternatively, use your own locale and formatting parameters to create a **PluralRules** object. For a full list of parameters, see [PluralRulesOptions](../reference/apis/js-apis-intl.md#pluralrulesoptions9).
-
+2. Instantiate a **PluralRules** object.
+
+ Use the default constructor of **PluralRules** to obtain the system default locale by accessing the system language and region settings and set it as the locale in the **PluralRules** object (**intl** is the name of the imported module).
+
```js
- var pluralRules = new intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
+ let pluralRules = new Intl.PluralRules();
```
-2. Determine the singular-plural type.
-
- Call the **select** method to determine the singular-plural type of an input number. This method will return a string representing the singular-plural type, which can be any of the following: **zero**, **one**, **two**, **few**, **many**, and **other**.
+ Alternatively, use your own locale and formatting parameters to create a **PluralRules** object. For a full list of parameters, see [PluralRulesOptions](../reference/apis/js-apis-intl.md#pluralrulesoptions8).
```js
- var number = 1234.5678
- var categoryResult = plurals.select(number);
+ let pluralRules = new Intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
```
+3. Determine the singular-plural type.
-## Formatting the Relative Time
+ Call **select** to determine the singular-plural type for an input number. This API returns a string as the category of the input number, which can be any of the following: **zero**, **one**, **two**, **few**, **many**, and **other**.
+
+ ```js
+ let pluralRules = new Intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
+ let number = 1234.5678
+ let categoryResult = pluralRules.select(number); // categoryResult = "other"
+ ```
-Use [RelativeTimeFormat](../reference/apis/js-apis-intl.md#relativetimeformat8) APIs to format the relative time for a specific locale.
+## Formatting Relative Time
+[RelativeTimeFormat](../reference/apis/js-apis-intl.md#relativetimeformat8) provides APIs to format the relative time for a specific locale.
### Available APIs
-| Module | API | Description |
+| Class| API| Description|
| -------- | -------- | -------- |
-| ohos.intl | constructor()8+ | Creates a **RelativeTimeFormat** object. |
-| ohos.intl | constructor(locale: string \| Array<string>, options?: RelativeTimeFormatInputOptions)8+ | Creates a **RelativeTimeFormat** object and sets the locale and other formatting-related attributes. |
-| ohos.intl | format(value: number, unit: string): string8+ | Calculates the relative time format based on the locale and other formatting-related attributes of the **RelativeTimeFormat** object. |
-| ohos.intl | formatToParts(value: number, unit: string): Array<object>8+ | Returns each part of the relative time format based on the locale and other formatting-related attributes of the **RelativeTimeFormat** object. |
-| ohos.intl | resolvedOptions(): RelativeTimeFormatResolvedOptions8+ | Obtains attributes of the **RelativeTimeFormat** object. |
-
+| RelativeTimeFormat | constructor()8+ | Creates a **RelativeTimeFormat** object.|
+| RelativeTimeFormat | constructor(locale:string\|Array<string>,options?:RelativeTimeFormatInputOptions)8+ | Creates a **RelativeTimeFormat** object and sets the locale and other formatting-related attributes.|
+| RelativeTimeFormat | format(value:number,unit:string):string8+ | Calculates the relative time format based on the locale and other formatting-related attributes of the **RelativeTimeFormat** object.|
+| RelativeTimeFormat | formatToParts(value:number,unit:string):Array<object>8+ | Obtains each part of the relative time format based on the locale and other formatting-related attributes of the **RelativeTimeFormat** object.|
+| RelativeTimeFormat | resolvedOptions():RelativeTimeFormatResolvedOptions8+ | Obtains the attributes of the **RelativeTimeFormat** object.|
### How to Develop
-1. Instantiate a **RelativeTimeFormat** object.
+1. Import the **intl** module.
- Use the default constructor of **RelativeTimeFormat** to obtain the system default locale by accessing the system language and region settings, and set it as the locale in the **RelativeTimeFormat** object.
+ Importing an incorrect bundle can lead to unexpected API behavior.
+
+ ```js
+ import Intl from '@ohos.intl'
+ ```
+
+2. Instantiate a **RelativeTimeFormat** object.
+ Use the default constructor of **RelativeTimeFormat** to obtain the system default locale by accessing the system language and region settings and set it as the locale in the **RelativeTimeFormat** object (**intl** is the name of the imported module).
```js
- var relativeTimeFormat = new intl.RelativeTimeFormat();
+ let relativeTimeFormat = new Intl.RelativeTimeFormat();
```
- Alternatively, use your own locale and formatting parameters to create a **RelativeTimeFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md#relativetimeformatinputoptions9).
+ Alternatively, use your own locale and formatting parameters to create a **RelativeTimeFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md#relativetimeformatinputoptions8).
```js
- var relativeTimeFormat = new intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
+ let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
```
-2. Format the relative time.
+3. Format the relative time.
- Call the **format** method to format the relative time. This method receives a numeric value representing the time length and a string-form unit, like **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, and **second**. This method returns a string representing the formatting result.
-
+ Call **format** to format the relative time. This API receives a numeric value representing the time length and a string-form unit, like **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, and **second**. A string is returned as the formatting result.
+
```js
- var number = 2;
- var unit = "year"
- var formatResult = relativeTimeFormat.format(number, unit);
+ let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
+ let number = 2;
+ let unit = "year"
+ let formatResult = relativeTimeFormat.format(number, unit); // 2 years later
```
-3. Obtain each part of the relative time format.
+4. Obtain each part of the relative time format.
- Upon obtaining each part of the relative time format, customize the relative time formatting result.
-
+ On obtaining each part of the relative time format, customize the relative time formatting result.
+
```js
- var number = 2;
- var unit = "year"
- var formatResult = relativeTimeFormat.formatToParts(number, unit);
+ let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
+ let number = 2;
+ let unit = "year"
+ let formatPartsResult = relativeTimeFormat.formatToParts(number, unit); // formatPartsResult = [{"type": "integer", "value": "2", "unit": "year"}, {"type":"literal", "value": "years later"}]
```
-4. Obtain attributes of the **RelativeTimeFormat** object.
+5. Access the attributes of the **RelativeTimeFormat** object.
- Call the **resolvedOptions** method to obtain attributes of the **RelativeTimeFormat** object. This method will return an array that contains all attributes and values of the object. For a full list of attributes, see [RelativeTimeFormatResolvedOptions](../reference/apis/js-apis-intl.md#relativetimeformatresolvedoptions8).
-
+ Call **resolvedOptions** to obtain an object that contains all related attributes and values of the **RelativeTimeFormat** object. For a full list of attributes, see [RelativeTimeFormatResolvedOptions](../reference/apis/js-apis-intl.md#relativetimeformatresolvedoptions8).
+
```js
- var options = numberFormat.resolvedOptions();
+ let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
+ let options = relativeTimeFormat.resolvedOptions(); // options = {"locale": "zh-CN", "style": "long", "numeric": "always", "numberingSystem": "latn"}
```
## Samples
diff --git a/en/application-dev/napi/mindspore-lite-guidelines.md b/en/application-dev/napi/mindspore-lite-guidelines.md
index 3dde56c84f321a6200c45b1839eccdabcba942aa..f4f5ac69bc57146d6ee63dde171da7628e0a108d 100644
--- a/en/application-dev/napi/mindspore-lite-guidelines.md
+++ b/en/application-dev/napi/mindspore-lite-guidelines.md
@@ -15,7 +15,6 @@ Before getting started, you need to understand the following basic concepts:
**Float16 inference**: a mode in which Float16 is used for inference. Float16, also called half-precision, uses 16 bits to represent a number.
-
## Available APIs
APIs involved in MindSpore Lite model inference are categorized into context APIs, model APIs, and tensor APIs.
### Context APIs
@@ -54,6 +53,33 @@ The following figure shows the development process for MindSpore Lite model infe
**Figure 1** Development process for MindSpore Lite model inference

+Before moving to the main process, you need to reference related header files and compile functions to generate random input.
+
+Example code:
+
+```c
+#include
+#include
+#include "mindspore/model.h"
+
+// Generate random input.
+int GenerateInputDataWithRandom(OH_AI_TensorHandleArray inputs) {
+ for (size_t i = 0; i < inputs.handle_num; ++i) {
+ float *input_data = (float *)OH_AI_TensorGetMutableData(inputs.handle_list[i]);
+ if (input_data == NULL) {
+ printf("MSTensorGetMutableData failed.\n");
+ return OH_AI_STATUS_LITE_ERROR;
+ }
+ int64_t num = OH_AI_TensorGetElementNum(inputs.handle_list[i]);
+ const int divisor = 10;
+ for (size_t j = 0; j < num; j++) {
+ input_data[j] = (float)(rand() % divisor) / divisor; // 0--0.9f
+ }
+ }
+ return OH_AI_STATUS_SUCCESS;
+}
+```
+
The development process consists of the following main steps:
1. Prepare the required model.
@@ -101,8 +127,8 @@ The development process consists of the following main steps:
return OH_AI_STATUS_LITE_ERROR;
}
- // Load and build the model. The model type is OH_AI_ModelTypeMindIR.
- int ret = OH_AI_ModelBuildFromFile(model, argv[1], OH_AI_ModelTypeMindIR, context);
+ // Load and build the model. The model type is OH_AI_MODELTYPE_MINDIR.
+ int ret = OH_AI_ModelBuildFromFile(model, argv[1], OH_AI_MODELTYPE_MINDIR, context);
if (ret != OH_AI_STATUS_SUCCESS) {
printf("OH_AI_ModelBuildFromFile failed, ret: %d.\n", ret);
OH_AI_ModelDestroy(&model);
@@ -193,7 +219,7 @@ The development process consists of the following main steps:
dl
)
```
- - To use ohos-sdk for cross compilation, you need to set the native toolchain path for the CMake tool as follows: `-DCMAKE_TOOLCHAIN_FILE="/xxx/ohos-sdk/linux/native/build/cmake/ohos.toolchain.cmake"`.
+ - To use ohos-sdk for cross compilation, you need to set the native toolchain path for the CMake tool as follows: `-DCMAKE_TOOLCHAIN_FILE="/xxx/ohos-sdk/linux/native/build/cmake/ohos.toolchain.camke"`.
- The toolchain builds a 64-bit application by default. To build a 32-bit application, add the following configuration: `-DOHOS_ARCH="armeabi-v7a"`.
@@ -213,4 +239,4 @@ The development process consists of the following main steps:
Tensor name: Softmax-65, tensor size is 4004 ,elements num: 1001.
output data is:
0.000018 0.000012 0.000026 0.000194 0.000156 0.001501 0.000240 0.000825 0.000016 0.000006 0.000007 0.000004 0.000004 0.000004 0.000015 0.000099 0.000011 0.000013 0.000005 0.000023 0.000004 0.000008 0.000003 0.000003 0.000008 0.000014 0.000012 0.000006 0.000019 0.000006 0.000018 0.000024 0.000010 0.000002 0.000028 0.000372 0.000010 0.000017 0.000008 0.000004 0.000007 0.000010 0.000007 0.000012 0.000005 0.000015 0.000007 0.000040 0.000004 0.000085 0.000023
- ```
+ ```
\ No newline at end of file
diff --git a/en/application-dev/napi/napi-guidelines.md b/en/application-dev/napi/napi-guidelines.md
index 188b4f1336e2c56562f594e42dc26cabf8a8fc55..5113c413d523b9d58363b78ac94ba42cc1954e9d 100644
--- a/en/application-dev/napi/napi-guidelines.md
+++ b/en/application-dev/napi/napi-guidelines.md
@@ -1,12 +1,14 @@
# Using Native APIs in Application Projects
-OpenHarmony applications use JavaScript (JS) when calling native APIs. The native APIs (NAPIs) provided by the [ace_napi](https://gitee.com/openharmony/arkui_napi/tree/master) repository are used to implement interaction with JS. Currently, the **ace_napi** repository supports some third-party **Node.js** interfaces. The names of the NAPIs are the same as those in the third-party **Node.js**. For details about the interfaces supported, see `libnapi.ndk.json` in this repository.
+OpenHarmony applications use JavaScript (JS) when calling native APIs. The native APIs (NAPIs) provided by the [ace_napi](https://gitee.com/openharmony/arkui_napi/tree/master) repository are used to implement interaction with JS. The names of the NAPIs are the same as those in the third-party **Node.js**. For details about the interfaces supported, see **libnapi.ndk.json** in the ace_napi repository.
## How to Develop
-The IDE has a default project that uses NAPIs. You can choose `File` > `New` > `Create Project` to create a `Native C++` project. The **cpp** directory is generated in the **main** directory. You can use the NAPIs provided by the **ace_napi** repository for development.
+The DevEco Studio has a default project that uses NAPIs.
-You can `import` the native .so that contains the JS processing logic. For example, `import hello from 'libhello.so'` to use the **libhello.so** capability. Then, the JS object created using the NAPI can be passed to the `hello` object of the application to call the native capability.
+You can choose **File** > **New** > **Create Project** to create a **Native C++** project. The **cpp** directory is generated in the **main** directory. You can use the NAPIs provided by the **ace_napi** repository for development.
+
+You can import the native .so that contains the JS processing logic. For example, **import hello from 'libhello.so'** to use the **libhello.so** capability. Then, the JS object created using the NAPI can be passed to the **hello** object of the application to call the native capability.
## Development Guidelines
@@ -17,7 +19,7 @@ You can `import` the native .so that contains the JS processing logic. For examp
### .so Naming Rules
-Each module has a .so file. For example, if the module name is `hello`, name the .so file `libhello.so`. The `nm_modname` field in `napi_module` must be `hello`, which is the same as the module name. The sample code for importing the .so file is `import hello from 'libhello.so'`.
+Each module has a .so file. For example, if the module name is **hello**, name the .so file **libhello.so**. The **nm_modname** field in **napi_module** must be **hello**, which is the same as the module name. The sample code for importing the .so file is **import hello from 'libhello.so'**.
### JS Objects and Threads
@@ -28,7 +30,7 @@ The Ark engine prevents NAPIs from being called to operate JS objects in non-JS
### Importing Header Files
-Before using NAPI objects and methods, include **napi/native_api.h**. Otherwise, when only the third-party library header file is included, an error will be reporting, indicating that the interface cannot be found.
+Before using NAPI objects and methods, include **napi/native_api.h**. Otherwise, if only the third-party library header file is included, an error will be reporting, indicating that the interface cannot be found.
### napi_create_async_work
@@ -50,11 +52,11 @@ napi_status napi_create_async_work(napi_env env,
-## Example 1: Encapsulating Synchronous and Asynchronous APIs for the Storage Module
+## Encapsulating Synchronous and Asynchronous APIs for the Storage Module
### Overview
-This example shows how to encapsulate the synchronous and asynchronous APIs of the storage module. The storage module implements the functions of storing, obtaining, deleting, and clearing data.
+This example shows how to encapsulate the synchronous and asynchronous APIs of the **Storage** module. The **Storage** module implements the functions of storing, obtaining, deleting, and clearing data.
### API Declaration
@@ -79,11 +81,11 @@ export default storage;
### Implementation
-You can obtain the complete code from `sample/native_module_storage/` in the [OpenHarmony/arkui_napi](https://gitee.com/openharmony/arkui_napi/tree/master) repository.
+You can obtain the complete code from sample/native_module_storage/ in the [OpenHarmony/arkui_napi](https://gitee.com/openharmony/arkui_napi/tree/master) repository.
-#### Registering the Module
+**1. Register the module.**
-Register four synchronous APIs (`getSync`, `setSync`, `removeSync`, and`clearSync`) and four asynchronous APIs (`get`, `set`, `remove`, and `clear`).
+Register four synchronous APIs (**getSync**, **setSync**, **removeSync**, and **clearSync**) and four asynchronous APIs (**get**, **set**, **remove**, and **clear**).
```c++
/***********************************************
@@ -122,9 +124,9 @@ extern "C" __attribute__((constructor)) void StorageRegister()
}
```
-#### Implementing getSync
+**2. Implement getSync.**
-The **getSync** function registered for the storage module is **JSStorageGetSync**. Obtain data from `gKeyValueStorage`, create a string object, and return it.
+The **getSync** function registered for the **Storage** module is **JSStorageGetSync**. Obtain data from **gKeyValueStorage**, create a string object, and return the object created.
```c
static napi_value JSStorageGetSync(napi_env env, napi_callback_info info)
@@ -168,9 +170,9 @@ static napi_value JSStorageGetSync(napi_env env, napi_callback_info info)
}
```
-#### Implementing get
+**3. Implement get().**
-The `get` function registered for the storage module is `JSStorageGet`.
+The **get** function registered for the **Storage** module is **JSStorageGet**.
```c
static napi_value JSStorageGet(napi_env env, napi_callback_info info)
@@ -268,7 +270,7 @@ static napi_value JSStorageGet(napi_env env, napi_callback_info info)
}
```
-### JS Sample Code
+**JS Sample Code**
```js
import storage from 'libstorage.so';
@@ -292,11 +294,11 @@ export default {
-## Example 2: Binding Native and JS Objects for the NetServer Module
+## Binding Native and JS Objects for the NetServer Module
### Overview
-This example shows how to implement the `on/off/once` method and bind C++ and JS objects using the **wrap** API. The NetServer module implements the network service.
+This example shows how to implement the **on**, **off**, and **once** methods and bind C++ and JS objects using **wrap()**. The **NetServer** module implements the network service.
### API Declaration
@@ -312,9 +314,9 @@ export class NetServer {
### Implementation
-You can obtain the complete code from `sample/native_module_netserver/` in the [OpenHarmony/arkui_napi](https://gitee.com/openharmony/arkui_napi/tree/master) repository.
+You can obtain the complete code from **sample/native_module_netserver/** in the [OpenHarmony/arkui_napi](https://gitee.com/openharmony/arkui_napi/tree/master) repository.
-#### Registering the Module
+**1. Register the module.**
```c
static napi_value NetServer::Export(napi_env env, napi_value exports)
@@ -338,7 +340,7 @@ static napi_value NetServer::Export(napi_env env, napi_value exports)
}
```
-#### Binding C++ and JS Objects in a Constructor
+**2. Bind C++ and JS objects in a constructor.**
```c
napi_value NetServer::JS_Constructor(napi_env env, napi_callback_info cbinfo)
@@ -365,7 +367,7 @@ napi_value NetServer::JS_Constructor(napi_env env, napi_callback_info cbinfo)
}
```
-#### Obtaining the C++ Object from the JS Object
+**3. Obtain a C++ object from a JS object.**
```c
napi_value NetServer::JS_Start(napi_env env, napi_callback_info cbinfo)
@@ -398,7 +400,7 @@ napi_value NetServer::JS_Start(napi_env env, napi_callback_info cbinfo)
}
```
-After `netServer->Start` is executed, call back the `start` event registered by `on`.
+After **netServer->Start** is executed, call back the **start** event registered by **on()**.
```c
int NetServer::Start(int port)
@@ -435,7 +437,7 @@ int NetServer::Start(int port)
}
```
-#### Registering Events (on)
+**4. Call on() to register an event observer.**
```c
napi_value NetServer::JS_On(napi_env env, napi_callback_info cbinfo)
@@ -475,7 +477,7 @@ napi_value NetServer::JS_On(napi_env env, napi_callback_info cbinfo)
}
```
-### JS Sample Code
+**JS Sample Code**
```javascript
import { NetServer } from 'libnetserver.so';
@@ -491,7 +493,7 @@ export default {
-## Example 3: Calling Back a JS API in a Non-JS Thread
+## Calling Back a JS API in a Non-JS Thread
### Overview
@@ -499,11 +501,11 @@ This example describes how to invoke a JS callback in a non-JS thread. For examp
### Implementation
-You can obtain the complete code from `sample/native_module_callback/` in the [OpenHarmony/arkui_napi](https://gitee.com/openharmony/arkui_napi/tree/master) repository.
+You can obtain the complete code from **sample/native_module_callback/** in the [OpenHarmony/arkui_napi](https://gitee.com/openharmony/arkui_napi/tree/master) repository.
-#### Registering the Module
+**1. Register the module.**
-Register the `test` API to pass in a parameter.
+Register the **test** API to pass in a parameter.
```c++
/***********************************************
@@ -536,7 +538,7 @@ extern "C" __attribute__((constructor)) void CallbackTestRegister()
}
```
-#### Obtaining the Loop in env and Throwing the Task to the JS Thread
+**2. Obtain the loop in env and throw the task to a JS thread.**
```c++
#include
@@ -627,7 +629,7 @@ static napi_value JSTest(napi_env env, napi_callback_info info)
}
```
-### JS Sample Code
+**JS Sample Code**
```js
import callback from 'libcallback.so';
diff --git a/en/application-dev/notification/Readme-EN.md b/en/application-dev/notification/Readme-EN.md
index dccfc8dbc4c59611db4aa53ff8a5a295cbba4d46..bf85581053f30d6aa56e0218c51339ef6ee3f268 100644
--- a/en/application-dev/notification/Readme-EN.md
+++ b/en/application-dev/notification/Readme-EN.md
@@ -1,9 +1,10 @@
-# Common Event and Notification
+# Notification
+
+- [Notification Overview](notification-overview.md)
+- [Notification Subscription (Open Only to System Applications)](notification-subscription.md)
+- [Enabling Notification](notification-enable.md)
+- Publishing a Notification
+ - [Publishing a Basic Notification](text-notification.md)
+ - [Publishing a Progress Notification](progress-bar-notification.md)
+ - [Adding a WantAgent Object to a Notification](notification-with-wantagent.md)
-- [Common Event and Notification Overview](notification-brief.md)
-- [Common Event Development](common-event.md)
-- [Notification Development](notification-guidelines.md)
-- Agent-Powered Scheduled Reminder
- - [Agent-Powered Scheduled Reminder Overview](background-agent-scheduled-reminder-overview.md)
- - [Agent-Powered Scheduled Reminder Development](background-agent-scheduled-reminder-guide.md)
-- [Debugging Assistant Usage](assistant-guidelines.md)
diff --git a/en/application-dev/notification/assistant-guidelines.md b/en/application-dev/notification/assistant-guidelines.md
deleted file mode 100644
index 5d83cf443c0f629fcb471a6c12ccd3069ac2e593..0000000000000000000000000000000000000000
--- a/en/application-dev/notification/assistant-guidelines.md
+++ /dev/null
@@ -1,134 +0,0 @@
-# Debugging Assistant Usage
-
-The common event and notification module provides debugging tools to facilitate your application development. With these tools, you can view common event and notification information, publish common events, and more. These tools have been integrated with the system. You can run related commands directly in the shell.
-
-## cem Debugging Assistant
-
-### publish
-
-* Function
-
- Publishes a common event.
-
-* Usage
-
- `cem publish []`
-
- The table below describes the available options.
-
- | Option | Description |
- | ------------ | ------------------------------------------ |
- | -e/--event | Indicates the name of the common event to publish. Mandatory. |
- | -s/--sticky | Indicates that the common event to publish is sticky. Optional. By default, non-sticky events are published. |
- | -o/--ordered | Indicates that the common event to publish is ordered. Optional. By default, non-ordered events are published. |
- | -c/--code | Indicates the result code of the common event. Optional. |
- | -d/--data | Indicates the data carried in the common event. Optional. |
- | -h/--help | Indicates the help Information |
-
-* Example
-
- `cem publish --event "testevent"`
-
- Publish a common event named **testevent**.
-
- 
-
-
-
- `cem publish -e "testevent" -s -o -c 100 -d "this is data" `
-
- Publish a sticky, ordered common event named **testevent**. The result code of the event is **100** and the data carried is **this is data**.
-
- 
-
-### dump
-
-* Function
-
- Displays information about common events.
-
-* Usage
-
- `cem dump []`
-
- The table below describes the available options.
-
- | Option | Description |
- | ---------- | -------------------------------------------- |
- | -a/--all | Displays information about all common events that have been sent since system startup. |
- | -e/--event | Displays information about a specific event. |
- | -h/--help | Displays the help information. |
-
-* Example
-
- `cem dump -e "testevent"`
-
- Display information about the common event testevent.
-
- 
-
-### help
-
-* Function
-
- Displays the help information.
-
-* Usage
-
- `cem help`
-
-* Example
-
- 
-
-
-
-## anm Debugging Assistant
-
-### dump
-
-* Function
-
- Displays information about notifications.
-
-* Usage
-
- `anm dump []`
-
- The table below describes the available options.
-
- | Option | Description |
- | ---------------- | ---------------------------------------- |
- | -A/--active | Displays information about all active notifications. |
- | -R/--recent | Displays information about the recent notifications. |
- | -D/--distributed | Displays information about distributed notifications from other devices. |
- | --setRecentCount | Indicates the number of the cached recent notifications to be displayed. Optional. |
- | -h/--help | Displays the help information. |
-
-* Example
-
- `anm dump -A`
-
- Display information about all active notifications.
-
- 
-
-
-
- `anm dump --setRecentCount 10`
-
- Set the number of the cached recent notifications to be displayed to **10**.
-
-### help
-
-* Function
-
- Displays the help information.
-
-* Usage
-
- `anm help`
-
-* Example
-
- 
diff --git a/en/application-dev/notification/common-event.md b/en/application-dev/notification/common-event.md
deleted file mode 100644
index dfb611ea572b80486756faaa4b004513cd6858a7..0000000000000000000000000000000000000000
--- a/en/application-dev/notification/common-event.md
+++ /dev/null
@@ -1,172 +0,0 @@
-# Common Event Development
-## Introduction
-OpenHarmony provides a Common Event Service (CES) for applications to subscribe to, publish, and unsubscribe from common events.
-
-Common events are classified into system common events and custom common events.
-
-+ System common events: The system sends an event based on system policies to the apps that have subscribed to this event when it occurs. This type of event is typically system events published by key system services, such as HAP installation, update, and uninstallation.
-
-+ Custom common event: customized by applications to implement cross-application event communication.
-
-Each application can subscribe to common events as required. After your application subscribes to a common event, the system sends it to your application every time the event is published. Such an event may be published by the system, other applications, or your own application.
-
-## Common Event Subscription Development
-
-### When to Use
-You can create a subscriber object to subscribe to a common event to obtain the parameters passed in the event. Certain system common events require specific permissions to subscribe to. For details, see [Required Permissions](../reference/apis/js-apis-commonEvent.md#support).
-
-### Available APIs
-| API | Description|
-| ---------------------------------------------------------------------------------------------- | ----------- |
-| createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback) | Creates a subscriber. This API uses a callback to return the result.|
-| createSubscriber(subscribeInfo: CommonEventSubscribeInfo) | Creates a subscriber. This API uses a promise to return the result. |
-| subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback) | Subscribes to common events.|
-
-### How to Develop
-1. Import the **commonEvent** module.
-
-```js
-import commonEvent from '@ohos.commonEvent';
-```
-
-2. Create a **subscribeInfo** object. For details about the data types and parameters of the object, see [CommonEventSubscribeInfo](../reference/apis/js-apis-commonEvent.md#commoneventsubscribeinfo).
-
-```js
-// Used to save the created subscriber object for subsequent subscription and unsubscription.
-private subscriber = null
-
-// Subscriber information
-var subscribeInfo = {
- events: ["event"],
-}
-```
-
-3. Create a subscriber object and save the returned object for subsequent operations such as subscription and unsubscription.
-
-```js
-// Callback for subscriber creation.
-commonEvent.createSubscriber(subscribeInfo, (err, subscriber) => {
- if (err.code) {
- console.error("[CommonEvent]CreateSubscriberCallBack err=" + JSON.stringify(err))
- } else {
- console.log("[CommonEvent]CreateSubscriber")
- this.subscriber = subscriber
- this.result = "Create subscriber succeed"
- }
-})
-```
-
-4. Create a subscription callback, which is triggered when an event is received. The data returned by the subscription callback contains information such as the common event name and data carried by the publisher. For details about the data types and parameters of the common event data, see [CommonEventData](../reference/apis/js-apis-commonEvent.md#commoneventdata).
-
-```js
-// Callback for common event subscription.
-if (this.subscriber != null) {
- commonEvent.subscribe(this.subscriber, (err, data) => {
- if (err.code) {
- console.error("[CommonEvent]SubscribeCallBack err=" + JSON.stringify(err))
- } else {
- console.log("[CommonEvent]SubscribeCallBack data=" + JSON.stringify(data))
- this.result = "receive, event = " + data.event + ", data = " + data.data + ", code = " + data.code
- }
- })
- this.result = "Subscribe succeed"
-} else {
- prompt.showToast({ message: "Need create subscriber" })
-}
-```
-
-## Common Event Publishing Development
-
-### When to Use
-You can use the **publish** APIs to publish a custom common event, which can carry data for subscribers to parse and process.
-
-### Available APIs
-| API | Description|
-| ---------------------------------- | ------ |
-| publish(event: string, callback: AsyncCallback) | Publishes a common event.|
-| publish(event: string, options: CommonEventPublishData, callback: AsyncCallback) | Publishes a common event with given attributes.|
-
-### How to Develop
-#### Development for Publishing a Common Event
-1. Import the **commonEvent** module.
-
-```js
-import commonEvent from '@ohos.commonEvent';
-```
-
-2. Pass in the common event name and callback, and publish the event.
-
-```js
-// Publish a common event.
-commonEvent.publish("event", (err) => {
- if (err.code) {
- console.error("[CommonEvent]PublishCallBack err=" + JSON.stringify(err))
- } else {
- console.info("[CommonEvent]Publish1")
- }
-})
-```
-
-#### Development for Publishing a Common Event with Given Attributes
-1. Import the **commonEvent** module.
-
-```js
-import commonEvent from '@ohos.commonEvent'
-```
-
-2. Define attributes of the common event to publish. For details about the data types and parameters in the data to publish, see [CommonEventPublishData](../reference/apis/js-apis-commonEvent.md#commoneventpublishdata).
-
-```js
-// Attributes of a common event.
-var options = {
- code: 1, // Result code of the common event
- data: "initial data";// Result data of the common event
-}
-```
-
-3. Pass in the common event name, attributes of the common event, and callback, and publish the event.
-
-```js
-// Publish a common event.
-commonEvent.publish("event", options, (err) => {
- if (err.code) {
- console.error("[CommonEvent]PublishCallBack err=" + JSON.stringify(err))
- } else {
- console.info("[CommonEvent]Publish2")
- }
-})
-```
-
-## Common Event Unsubscription Development
-
-### When to Use
-You can use the **unsubscribe** API to unsubscribe from a common event.
-
-### Available APIs
-| API | Description|
-| ---------------------------------- | ------ |
-| unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback) | Unsubscribes from a common event.|
-
-### How to Develop
-1. Import the **commonEvent** module.
-
-```js
-import commonEvent from '@ohos.commonEvent';
-```
-
-2. Subscribe to a common event by following instructions in [Common Event Subscription Development](#common-event-subscription-development).
-3. Invoke the **unsubscribe** API in **CommonEvent** to unsubscribe from the common event.
-
-```js
-if (this.subscriber != null) {
- commonEvent.unsubscribe(this.subscriber, (err) => {
- if (err.code) {
- console.error("[CommonEvent]UnsubscribeCallBack err=" + JSON.stringify(err))
- } else {
- console.log("[CommonEvent]Unsubscribe")
- this.subscriber = null
- this.result = "Unsubscribe succeed"
- }
- })
-}
-```
diff --git a/en/application-dev/notification/figures/anm-dump-A.png b/en/application-dev/notification/figures/anm-dump-A.png
deleted file mode 100644
index 368e6f2d810976486e786a4c8f0603a87ad48540..0000000000000000000000000000000000000000
Binary files a/en/application-dev/notification/figures/anm-dump-A.png and /dev/null differ
diff --git a/en/application-dev/notification/figures/anm-help.png b/en/application-dev/notification/figures/anm-help.png
deleted file mode 100644
index d80ac8e76a70c2be383f0a05a12e3e707dcf242b..0000000000000000000000000000000000000000
Binary files a/en/application-dev/notification/figures/anm-help.png and /dev/null differ
diff --git a/en/application-dev/notification/figures/ans.png b/en/application-dev/notification/figures/ans.png
deleted file mode 100644
index 8be552d2acedbef962326365fb2d19ded3838c14..0000000000000000000000000000000000000000
Binary files a/en/application-dev/notification/figures/ans.png and /dev/null differ
diff --git a/en/application-dev/notification/figures/cem-dump-e.png b/en/application-dev/notification/figures/cem-dump-e.png
deleted file mode 100644
index c2422ba0e51011174c333985ad7647f170e0f126..0000000000000000000000000000000000000000
Binary files a/en/application-dev/notification/figures/cem-dump-e.png and /dev/null differ
diff --git a/en/application-dev/notification/figures/cem-help.png b/en/application-dev/notification/figures/cem-help.png
deleted file mode 100644
index 8ca4bc0605f9c1f75a8cb45f8ab77c9c5d6f04e4..0000000000000000000000000000000000000000
Binary files a/en/application-dev/notification/figures/cem-help.png and /dev/null differ
diff --git a/en/application-dev/notification/figures/cem-publish-all.png b/en/application-dev/notification/figures/cem-publish-all.png
deleted file mode 100644
index 99526e1f7245d101914354e2a89d5e97d710c27f..0000000000000000000000000000000000000000
Binary files a/en/application-dev/notification/figures/cem-publish-all.png and /dev/null differ
diff --git a/en/application-dev/notification/figures/cem-publish-event.png b/en/application-dev/notification/figures/cem-publish-event.png
deleted file mode 100644
index f0ca7e73093f1be72c743bd7c08467f11e2a0e05..0000000000000000000000000000000000000000
Binary files a/en/application-dev/notification/figures/cem-publish-event.png and /dev/null differ
diff --git a/en/application-dev/notification/figures/ces.png b/en/application-dev/notification/figures/ces.png
deleted file mode 100644
index b1aa5438a19ac79899e0f45791f3e1a79e4242dc..0000000000000000000000000000000000000000
Binary files a/en/application-dev/notification/figures/ces.png and /dev/null differ
diff --git a/en/application-dev/notification/figures/en-us_image_0000001416585590.png b/en/application-dev/notification/figures/en-us_image_0000001416585590.png
new file mode 100644
index 0000000000000000000000000000000000000000..9da6812580fd6c7d785391c652104ef0698ce2bc
Binary files /dev/null and b/en/application-dev/notification/figures/en-us_image_0000001416585590.png differ
diff --git a/en/application-dev/notification/figures/en-us_image_0000001416745530.png b/en/application-dev/notification/figures/en-us_image_0000001416745530.png
new file mode 100644
index 0000000000000000000000000000000000000000..7a6fd0d9304abef2eb240a3c78a93b73bb9237af
Binary files /dev/null and b/en/application-dev/notification/figures/en-us_image_0000001416745530.png differ
diff --git a/en/application-dev/notification/figures/en-us_image_0000001417062434.png b/en/application-dev/notification/figures/en-us_image_0000001417062434.png
new file mode 100644
index 0000000000000000000000000000000000000000..07db3298f0db1c3357624b44d271dc1e6f97ea9e
Binary files /dev/null and b/en/application-dev/notification/figures/en-us_image_0000001417062434.png differ
diff --git a/en/application-dev/notification/figures/en-us_image_0000001417062446.png b/en/application-dev/notification/figures/en-us_image_0000001417062446.png
new file mode 100644
index 0000000000000000000000000000000000000000..c197fd6293f41890b2bfcf17a28a1477e8aa6d96
Binary files /dev/null and b/en/application-dev/notification/figures/en-us_image_0000001417062446.png differ
diff --git a/en/application-dev/notification/figures/en-us_image_0000001466462297.png b/en/application-dev/notification/figures/en-us_image_0000001466462297.png
new file mode 100644
index 0000000000000000000000000000000000000000..a07d9e818677e9364ad3239e61ce198471b68603
Binary files /dev/null and b/en/application-dev/notification/figures/en-us_image_0000001466462297.png differ
diff --git a/en/application-dev/notification/figures/en-us_image_0000001466462305.png b/en/application-dev/notification/figures/en-us_image_0000001466462305.png
new file mode 100644
index 0000000000000000000000000000000000000000..740f4b79a9ee234008cad6cf3616a8f213569476
Binary files /dev/null and b/en/application-dev/notification/figures/en-us_image_0000001466462305.png differ
diff --git a/en/application-dev/notification/figures/en-us_image_0000001466582017.png b/en/application-dev/notification/figures/en-us_image_0000001466582017.png
new file mode 100644
index 0000000000000000000000000000000000000000..1652d9111be2a27863fe2322c4feb577bab22ae9
Binary files /dev/null and b/en/application-dev/notification/figures/en-us_image_0000001466582017.png differ
diff --git a/en/application-dev/notification/figures/en-us_image_0000001466582045.png b/en/application-dev/notification/figures/en-us_image_0000001466582045.png
new file mode 100644
index 0000000000000000000000000000000000000000..4040452a87bc69ae8fa0eb9b55ca77ac32bdb2d8
Binary files /dev/null and b/en/application-dev/notification/figures/en-us_image_0000001466582045.png differ
diff --git a/en/application-dev/notification/figures/en-us_image_0000001466782025.png b/en/application-dev/notification/figures/en-us_image_0000001466782025.png
new file mode 100644
index 0000000000000000000000000000000000000000..d8e45c1746ab419a8056f9493c8796cfb734d2d0
Binary files /dev/null and b/en/application-dev/notification/figures/en-us_image_0000001466782025.png differ
diff --git a/en/application-dev/notification/figures/en-us_image_0000001466782033.png b/en/application-dev/notification/figures/en-us_image_0000001466782033.png
new file mode 100644
index 0000000000000000000000000000000000000000..218e5fcef6d163113c9037028215297ef626fcfa
Binary files /dev/null and b/en/application-dev/notification/figures/en-us_image_0000001466782033.png differ
diff --git a/en/application-dev/notification/figures/notification-with-wantagent.png b/en/application-dev/notification/figures/notification-with-wantagent.png
new file mode 100644
index 0000000000000000000000000000000000000000..234ef895c918404598cf7640f9d072de2bb2d0d0
Binary files /dev/null and b/en/application-dev/notification/figures/notification-with-wantagent.png differ
diff --git a/en/application-dev/notification/figures/notification.png b/en/application-dev/notification/figures/notification.png
deleted file mode 100644
index 18dcb99b0c531a19698f749105d88db91043837a..0000000000000000000000000000000000000000
Binary files a/en/application-dev/notification/figures/notification.png and /dev/null differ
diff --git a/en/application-dev/notification/notification-brief.md b/en/application-dev/notification/notification-brief.md
deleted file mode 100644
index 75237412fdf29d88843a9f23fa653f64f2de7c86..0000000000000000000000000000000000000000
--- a/en/application-dev/notification/notification-brief.md
+++ /dev/null
@@ -1,20 +0,0 @@
-# Common Event and Notification Overview
-
-The common event and notification module enables applications to publish messages to other applications, and receive messages from the system or other applications. These messages can be news push messages, advertisement notifications, warning information, and more.
-
-Common Event Service (CES) enables applications to publish, subscribe to, and unsubscribe from common events. Based on the sender type, common events are classified into system common events and custom common events.
-
-
-
-- System common event: sent by the system based on system policies to the applications that have subscribed to the event. This type of event includes the screen-on/off events that the users are aware of and the system events published by key system services, such as USB device attachment or detachment, network connection, and system update events.
-- Custom common event: customized by applications to be received by specific subscribers. This type of event is usually related to the service logic of the sender applications.
-
-The Advanced Notification Service (ANS) enables applications to publish notifications. Below are some typical use cases for publishing notifications:
-
-- Display received SMS messages and instant messages.
-- Display push messages of applications, such as advertisements, version updates, and news notifications.
-- Display ongoing events, such as music playback, navigation information, and download progress.
-
-Notifications are displayed in the notification panel. Uses can delete a notification or click the notification to trigger predefined actions.
-
-
diff --git a/en/application-dev/notification/notification-enable.md b/en/application-dev/notification/notification-enable.md
new file mode 100644
index 0000000000000000000000000000000000000000..12aa4f41eb1570d707b4c65310cefe6aa45e1b17
--- /dev/null
+++ b/en/application-dev/notification/notification-enable.md
@@ -0,0 +1,49 @@
+# Enabling Notification
+
+
+To publish a notification, you must have notification enabled for your application. You can call the [requestEnableNotification()](../reference/apis/js-apis-notificationManager.md#notificationrequestenablenotification) API to display a dialog box prompting the user to enable notification for your application. Note that the dialog box is displayed only when the API is called for the first time.
+
+ **Figure 1** Dialog box prompting the user to enable notification
+
+
+
+
+- Touching **allow** enables notification for the application, and touching **ban** keeps notification disabled.
+
+- The dialog box will not be displayed again when [requestEnableNotification()](../reference/apis/js-apis-notificationManager.md#notificationrequestenablenotification) is called later. The user can manually enable notification as follows.
+
+ | 1. Swipe down from the upper left corner of the device screen to access the notification panel. | 2. Touch the **Settings** icon in the upper right corner. On the notification screen, locate the target application.| 3. Toggle on **Allow notifications**. |
+ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
+ |  |  |  |
+
+
+## Available APIs
+
+For details about the APIs, see [@ohos.notificationManager](../reference/apis/js-apis-notificationManager.md#notificationrequestenablenotification).
+
+**Table 1** Notification APIs
+
+| Name | Description |
+| -------- | -------- |
+| isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback<boolean>): void | Checks whether notification is enabled.
**NOTE**
This is a system API and cannot be called by third-party applications. |
+| setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback<void>): void | Sets whether to enable notification. Notification can be enabled or disabled in **Notifications** of the target application under **Settings** > **Apps & services** > **Apps**.
**NOTE**
This is a system API and cannot be called by third-party applications.|
+| requestEnableNotification(callback: AsyncCallback<void>): void | Requests notification to be enabled. When called for the first time, this API displays a dialog box prompting the user to enable notification. |
+
+
+## How to Develop
+
+1. Import the **NotificationManager** module.
+
+ ```ts
+ import notificationManager from '@ohos.notificationManager';
+ ```
+
+2. Call the API to request notification to be enabled.
+
+ ```ts
+ notificationManager.requestEnableNotification().then(() => {
+ console.info(`[ANS] requestEnableNotification success`);
+ }).catch((err) => {
+ console.error(`[ANS] requestEnableNotification failed, errCode[${err}]`);
+ });
+ ```
diff --git a/en/application-dev/notification/notification-guidelines.md b/en/application-dev/notification/notification-guidelines.md
deleted file mode 100644
index fb73f274202aafd9ff852201ca2fb8c5116aba50..0000000000000000000000000000000000000000
--- a/en/application-dev/notification/notification-guidelines.md
+++ /dev/null
@@ -1,258 +0,0 @@
-
-
-# Notification Development
-
-## When to Use
-
-OpenHarmony uses the Advanced Notification Service (ANS) to manage notifications, with support for various notification types, including text, long text, multi-text, image, social, and media. All system services and applications can send notifications through the notification API. Users can view all notifications on the system UI.
-
-Below are some typical use cases for notifications:
-
-- Display received SMS messages and instant messages.
-- Display push messages of applications, such as advertisements and version updates.
-- Display ongoing events, such as navigation information and download progress.
-
-
-
-## Notification Service Process
-
-The notification service process involves the ANS subsystem, notification sender, and notification subscriber.
-
-A notification is generated by the notification sender and sent to the ANS through inter-process communication (IPC). The ANS then distributes the notification to the notification subscriber.
-
-System applications also support notification-related configuration options, such as switches. The system configuration initiates a configuration request and sends the request to the ANS for storage in the memory and database.
-
-
-
-
-
-## Available APIs
-
-Certain APIs can be called only by system applications that have been granted the **SystemCapability.Notification.Notification** permission. The APIs use either a callback or promise to return the result. The tables below list the APIs that use a callback, which provide the same functions as their counterparts that use a promise. For details about the APIs, see the [API document](../reference/apis/js-apis-notification.md).
-
-**Table 1** APIs for notification enabling
-
-| API | Description |
-| ------------------------------------------------------------ | ---------------- |
-| isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\): void | Checks whether notification is enabled.|
-| enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void | Sets whether to enable notification. |
-
-If the notification function of an application is disabled, it cannot send notifications.
-
-
-
-**Table 2** APIs for notification subscription
-
-| API | Description |
-| ------------------------------------------------------------ | ---------------- |
-| subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\): void | Subscribes to a notification with the subscription information specified.|
-| subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\): void | Subscribes to all notifications. |
-| unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\): void | Unsubscribes from a notification. |
-
-The subscription APIs support subscription to all notifications and notifications from specific applications.
-
-
-
-**Table 3** Notification subscription callbacks
-
-| API | Description |
-| ------------------------------------------------ | ---------------- |
-| onConsume?:(data: SubscribeCallbackData) => void | Callback for receiving notifications. |
-| onCancel?:(data: SubscribeCallbackData) => void | Callback for canceling notifications. |
-| onUpdate?:(data: NotificationSortingMap) => void | Callback for notification sorting updates.|
-| onConnect?:() => void; | Callback for subscription. |
-| onDisconnect?:() => void; | Callback for unsubscription. |
-
-
-
-**Table 4** APIs for notification sending
-
-| API | Description |
-| ------------------------------------------------------------ | ------------------------ |
-| publish(request: NotificationRequest, callback: AsyncCallback\): void | Publishes a notification. |
-| publish(request: NotificationRequest, userId: number, callback: AsyncCallback\): void | Publishes a notification to the specified user. |
-| cancel(id: number, label: string, callback: AsyncCallback\): void | Cancels a specified notification. |
-| cancelAll(callback: AsyncCallback\): void; | Cancels all notifications published by the application.|
-
-The **publish** API that carries **userId** can be used to publish notifications to subscribers of a specified user.
-
-
-
-## Development Guidelines
-
-The notification development process generally involves three aspects: subscribing to notifications, enabling the notification feature, and publishing notifications.
-
-### Modules to Import
-
-```js
-import Notification from '@ohos.notification';
-```
-
-
-
-### Subscribing to Notifications
-
-The notification recipient preferentially initiates a notification subscription request to the notification subsystem.
-
-```js
-var subscriber = {
- onConsume: function (data) {
- let req = data.request;
- console.info('===>onConsume callback req.id: ' + req.id);
- },
- onCancel: function (data) {
- let req = data.request;
- console.info('===>onCancel callback req.id: : ' + req.id);
- },
- onUpdate: function (data) {
- console.info('===>onUpdate in test===>');
- },
- onConnect: function () {
- console.info('===>onConnect in test===>');
- },
- onDisconnect: function () {
- console.info('===>onDisConnect in test===>');
- },
- onDestroy: function () {
- console.info('===>onDestroy in test===>');
- },
- };
-
- Notification.subscribe(subscriber, (err, data) => { // This API uses an asynchronous callback to return the result.
- if (err.code) {
- console.error('===>failed to subscribe because ' + JSON.stringify(err));
- return;
- }
- console.info('===>subscribeTest success : ' + JSON.stringify(data));
- });
-```
-
-
-
-### Publishing Notifications
-
-##### Enabling Notification
-
-Before publishing a notification, check whether the notification feature is enabled for your application. By default, the feature is disabled. The application calls **Notification.requestEnableNotification** to prompt the user to enable the feature.
-
-```js
-Notification.requestEnableNotification().then((data) => {
- console.info('===>requestEnableNotification success');
-}).catch((err) => {
- console.error('===>requestEnableNotification failed because ' + JSON.stringify(err));
-});
-```
-
-
-
-##### Publishing Notifications
-
-To publish a notification, create a **NotificationRequest** object and set attributes such as the notification type, title, and content. In the following examples, a normal text notification and a notification containing a **WantAgent** are being published.
-
-Normal text notification:
-
-```js
-// Create a NotificationRequest object.
-var notificationRequest = {
- id: 1,
- content: {
- contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
- normal: {
- title: "test_title",
- text: "test_text",
- additionalText: "test_additionalText"
- }
- }
-}
-
-// Publish the notification.
-Notification.publish(notificationRequest).then((data) => {
- console.info('===>publish promise success req.id : ' + notificationRequest.id);
-}).catch((err) => {
- console.error('===>publish promise failed because ' + JSON.stringify(err));
-});
-```
-
-
-
-Notification containing **WantAgent**:
-
-For details about how to use **WantAgent**, see [WantAgent Development](https://gitee.com/openharmony/docs/blob/master/en/application-dev/ability/wantagent.md).
-
-- Create a **WantAgent** object.
-
-```js
-import wantAgent from '@ohos.wantAgent';
-
-// WantAgentInfo object
-var wantAgentInfo = {
- wants: [
- {
- bundleName: 'ohos.samples.eTSNotification',
- abilityName: 'ohos.samples.eTSNotification.MainAbility',
- }
- ],
- operationType: wantAgent.OperationType.START_ABILITY,
- requestCode: 0,
- wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
-}
-
-// WantAgent object
-var WantAgent;
-
-// getWantAgent callback
-function getWantAgentCallback(err, data) {
- console.info("===>getWantAgentCallback===>");
- if (err.code == 0) {
- WantAgent = data;
- } else {
- console.info('----getWantAgent failed!----');
- }
-}
-
-// Obtain the WantAgent object.
-wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
-```
-
-- Publish the notification.
-
-```js
-// Create a NotificationRequest object.
-var notificationRequest = {
- content: {
- contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
- normal: {
- title: "AceApplication_Title",
- text: "AceApplication_Text",
- additionalText: "AceApplication_AdditionalText"
- },
- },
- id: 1,
- label: 'TEST',
- wantAgent: WantAgent,
- slotType: Notification.SlotType.OTHER_TYPES,
- deliveryTime: new Date().getTime()
-}
-
-// Publish the notification.
-Notification.publish(notificationRequest).then((data) => {
- console.info('===>publish promise success req.id : ' + notificationRequest.id);
-}).catch((err) => {
- console.error('===>publish promise failed because ' + JSON.stringify(err));
-});
-```
-
-
-
-- Cancel the notification.
-
-An application can cancel a single notification or all notifications. An application can cancel only the notifications published by itself.
-
-```js
-// cancel callback
-function cancelCallback(err) {
- console.info("===>cancelCallback===>");
-}
-
-Notification.cancel(1, "label", cancelCallback)
-```
diff --git a/en/application-dev/notification/notification-overview.md b/en/application-dev/notification/notification-overview.md
new file mode 100644
index 0000000000000000000000000000000000000000..6bef8be8fd446e62b3e3da04582b467c9ddc5961
--- /dev/null
+++ b/en/application-dev/notification/notification-overview.md
@@ -0,0 +1,27 @@
+# Notification Overview
+
+
+## Introduction
+
+All system applications and services can publish notifications through the notification APIs. Users can view the notifications in the notification panel or click a notification to open the publishing application.
+
+Below are some typical use cases for notifications:
+
+- Display received SMS messages and instant messages.
+
+- Display push messages, such as advertisements and version updates.
+
+- Display ongoing events, such as the download progress.
+
+The Advanced Notification Service (ANS) in OpenHarmony is used to manage notifications of various types, such as basic notifications, progress notifications, and reminders published through the background agent.
+
+
+## Notification Service Process
+
+The notification service process involves the notification subsystem, notification sender, and notification subscriber.
+
+A notification is generated by the notification sender and sent to the notification subsystem through [inter-process communication (IPC)](../connectivity/ipc-rpc-overview.md). The notification subsystem then distributes the notification to the notification subscriber.
+
+System applications also support notification-related configuration options, such as switches. The system configuration initiates a configuration request and sends the request to the notification subsystem for storage in the memory and database.
+
+
diff --git a/en/application-dev/notification/notification-subscription.md b/en/application-dev/notification/notification-subscription.md
new file mode 100644
index 0000000000000000000000000000000000000000..a633a2bb955bcf877fbe4befb8b40ad103d7e7e6
--- /dev/null
+++ b/en/application-dev/notification/notification-subscription.md
@@ -0,0 +1,82 @@
+# Notification Subscription (Open Only to System Applications)
+
+
+To receive notifications, an application must subscribe to notifications first. The notification subsystem provides two types of subscription APIs, allowing applications to subscribe to notifications from all applications or notifications from a specific application.
+
+
+You can use the **NotificationSubscriber** object to provide callbacks for subscription events, such as subscription success, notification reception, notification cancellation, and subscription cancellation.
+
+
+## Available APIs
+
+The major APIs for notification subscription are described as follows. For details about the APIs, see [@ohos.notificationSubscribe](../reference/apis/js-apis-notificationSubscribe.md).
+
+**Table 1** Major APIs for notification subscription
+
+| Name | Description|
+| -------- | -------- |
+| subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback<void>): void | Subscribes to notifications from a specific application.|
+| subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback<void>): void | Subscribes to notifications from all applications. |
+
+**Table 2** Callbacks for notification subscription
+
+| Name | Description|
+| -------- | -------- |
+| onConsume?:(data: SubscribeCallbackData) => void | Callback for receiving notifications. |
+| onCancel?:(data: SubscribeCallbackData) => void | Callback for canceling notifications. |
+| onUpdate?:(data: NotificationSortingMap) => void | Callback for notification sorting updates. |
+| onConnect?:() => void; | Callback for subscription. |
+| onDisconnect?:() => void; | Callback for unsubscription. |
+| onDestroy?:() => void | Callback for disconnecting from the notification subsystem. |
+| onDoNotDisturbDateChange?:(mode: notification.DoNotDisturbDate) => void | Callback for the Do Not Disturb (DNT) time changes.|
+| onEnabledNotificationChanged?:(callbackData: EnabledNotificationCallbackData) => void | Callback for notification switch changes. |
+
+
+## How to Develop
+
+1. Request the **ohos.permission.NOTIFICATION_CONTROLLER** permission. For details, see [Permission Application Guide](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file).
+
+2. Import the **notificationSubscribe** module.
+
+ ```ts
+ import notificationSubscribe from '@ohos.notificationSubscribe';
+ ```
+
+3. Create a **subscriber** object.
+
+ ```ts
+ let subscriber = {
+ onConsume: function (data) {
+ let req = data.request;
+ console.info('[ANS] onConsume callback req.id: ' + req.id);
+ },
+ onCancel: function (data) {
+ let req = data.request;
+ console.info('[ANS] onCancel callback req.id: : ' + req.id);
+ },
+ onUpdate: function (data) {
+ console.info('[ANS] onUpdate in test');
+ },
+ onConnect: function () {
+ console.info('[ANS] onConnect in test');
+ },
+ onDisconnect: function () {
+ console.info('[ANS] onDisConnect in test');
+ },
+ onDestroy: function () {
+ console.info('[ANS] onDestroy in test');
+ },
+ };
+ ```
+
+4. Initiate notification subscription.
+
+ ```ts
+ notificationSubscribe.subscribe(subscriber, (err, data) => { // This API uses an asynchronous callback to return the result.
+ if (err) {
+ console.error(`[ANS] failed to subscribe, error[${err}]`);
+ return;
+ }
+ console.info(`[ANS] subscribeTest success : + ${data}`);
+ });
+ ```
diff --git a/en/application-dev/notification/notification-with-wantagent.md b/en/application-dev/notification/notification-with-wantagent.md
new file mode 100644
index 0000000000000000000000000000000000000000..d8f0321d28738749d6ed6073e49f26181c22e706
--- /dev/null
+++ b/en/application-dev/notification/notification-with-wantagent.md
@@ -0,0 +1,121 @@
+# Adding a WantAgent Object to a Notification
+
+A [WantAgent](../reference/apis/js-apis-app-ability-wantAgent.md) object encapsulates an intention to start a specified ability, release a common event, and more. In OpenHarmony, a **WantAgent** object can be passed in a notification from the publisher to the subscriber, so as to trigger the intention specified. For example, you may want the user to start a specific ability by touching the notification published by your application. In this case, you can add a **WantAgent** object that encapsulates such an action to the notification. After receiving the **WantAgent** object, the system triggers it once the user touches the notification from the notification panel, starting the specified ability.
+
+Below you can see the process of adding a **WantAgent** object to a notification. The notification publisher requests a **WantAgent** object from the Ability Manager Service (AMS), and then sends a notification carrying the **WantAgent** object to the home screen. When the user touches the notification from the notification panel on the home screen, the **WantAgent** object is triggered.
+
+ **Figure 1** Publishing a notification with a WantAgent object
+
+
+
+## Available APIs
+
+For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/js-apis-app-ability-wantAgent.md).
+
+| Name| Description|
+| -------- | -------- |
+| getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>): void | Creates a **WantAgent** object.|
+| trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback<CompleteData>): void | Triggers a **WantAgent** object.|
+| cancel(agent: WantAgent, callback: AsyncCallback<void>): void | Cancels a **WantAgent** object.|
+| getWant(agent: WantAgent, callback: AsyncCallback<Want>): void | Obtains a **WantAgent** object.|
+| equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback<boolean>): void | Checks whether two **WantAgent** objects are equal. |
+
+
+## How to Develop
+
+1. [Enable notification](notification-enable.md). An application can use the notification feature only after being authorized by the user.
+
+2. Import the modules.
+
+ ```typescript
+ import notificationManager from '@ohos.notificationManager';
+ import wantAgent from '@ohos.app.ability.wantAgent';
+ ```
+
+3. Create a **WantAgentInfo** object.
+
+ Scenario 1: Create a [WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md) object for starting a UIAbility component.
+
+ ```typescript
+ let wantAgentObj = null; // Save the WantAgent object created. It will be used to complete the trigger operations.
+
+ // Set the action type through operationType of WantAgentInfo.
+ let wantAgentInfo = {
+ wants: [
+ {
+ deviceId: '',
+ bundleName: 'com.example.myapplication',
+ abilityName: 'EntryAbility',
+ action: '',
+ entities: [],
+ uri: '',
+ parameters: {}
+ }
+ ],
+ operationType: wantAgent.OperationType.START_ABILITY,
+ requestCode: 0,
+ wantAgentFlags:[wantAgent.WantAgentFlags.CONSTANT_FLAG]
+ };
+ ```
+
+ Scenario 2: Create a [WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md) object for publishing a [common event](../application-models/common-event-overview.md).
+
+ ```typescript
+ let wantAgentObj = null; // Save the WantAgent object created. It will be used to complete the trigger operations.
+
+ // Set the action type through operationType of WantAgentInfo.
+ let wantAgentInfo = {
+ wants: [
+ {
+ action: 'event_name', // Set the action name.
+ parameters: {},
+ }
+ ],
+ operationType: wantAgent.OperationType.SEND_COMMON_EVENT,
+ requestCode: 0,
+ wantAgentFlags: [wantAgent.WantAgentFlags.CONSTANT_FLAG],
+ }
+ ```
+
+4. Invoke the [getWantAgent()](../reference/apis/js-apis-app-ability-wantAgent.md#wantagentgetwantagent) API to create a **WantAgent** object.
+
+ ```typescript
+ // Create a WantAgent object.
+ wantAgent.getWantAgent(wantAgentInfo, (err, data) => {
+ if (err) {
+ console.error('[WantAgent]getWantAgent err=' + JSON.stringify(err));
+ return;
+ }
+ console.info('[WantAgent]getWantAgent success');
+ wantAgentObj = data;
+ });
+ ```
+
+5. Create a **NotificationRequest** object and publish a notification that carries the **WantAgent** object.
+
+ ```typescript
+ // Create a NotificationRequest object.
+ let notificationRequest = {
+ content: {
+ contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
+ normal: {
+ title: 'Test_Title',
+ text: 'Test_Text',
+ additionalText: 'Test_AdditionalText',
+ },
+ },
+ id: 1,
+ label: 'TEST',
+ wantAgent: wantAgentObj,
+ }
+
+ notificationManager.publish(notificationRequest, (err) => {
+ if (err) {
+ console.error(`[ANS] failed to publish, error[${err}]`);
+ return;
+ }
+ console.info(`[ANS] publish success`);
+ });
+ ```
+
+6. When the user touches the notification from the notification panel, the system automatically triggers the action specified in the **WantAgent** object.
diff --git a/en/application-dev/notification/progress-bar-notification.md b/en/application-dev/notification/progress-bar-notification.md
new file mode 100644
index 0000000000000000000000000000000000000000..de430008e3048532e9afea94d83a62dd2f8342c1
--- /dev/null
+++ b/en/application-dev/notification/progress-bar-notification.md
@@ -0,0 +1,69 @@
+# Publishing a Progress Notification
+
+
+The progress notification is a commonly used notification type, mainly used to display the progress of an ongoing operation, such as file downloading. When publishing a progress notification through the notification subsystem, you can use the readily available template by specifying the related attributes, such as the template name and template data.
+
+In the [NotificationTemplate](../reference/apis/js-apis-notificationManager.md#notificationtemplate), which can only be of the progress type, **data** indicates custom template data.
+
+
+## Available APIs
+
+| Name| Description|
+| -------- | -------- |
+| isSupportTemplate(templateName: string, callback: AsyncCallback<boolean>): void | Checks whether a specific template is supported. This API uses an asynchronous callback to return the result.
Only the progress-type template is supported.|
+
+
+## How to Develop
+
+1. [Enable notification](notification-enable.md). An application can use the notification feature only after being authorized by the user.
+
+2. Import the module.
+
+ ```ts
+ import notificationManager from '@ohos.notificationManager';
+ ```
+
+3. Check whether a specific template is supported. In this example, the template of the **downloadTemplate** type is checked.
+
+ ```ts
+ notificationManager.isSupportTemplate('downloadTemplate').then((data) => {
+ console.info(`[ANS] isSupportTemplate success`);
+ let isSupportTpl: boolean = data; // The value **true** means that the template of the **downloadTemplate** type is supported; and false means the opposite.
+ // ...
+ }).catch((err) => {
+ console.error(`[ANS] isSupportTemplate failed, error[${err}]`);
+ });
+ ```
+
+ > **NOTE**
+ >
+ > Proceed with the step below only when the specified template is supported.
+4. Create a **NotificationRequest** object and publish a progress notification.
+
+ ```ts
+ let notificationRequest = {
+ id: 1,
+ content: {
+ contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
+ normal: {
+ title: 'test_title',
+ text: 'test_text',
+ additionalText: 'test_additionalText'
+ }
+ },
+ // Create a progress template. The name field has a fixed value of downloadTemplate.
+ template: {
+ name: 'downloadTemplate',
+ data: { title: 'File Title', fileName: 'music.mp4', progressValue: 45 }
+ }
+ }
+
+ // Publish the notification.
+ notificationManager.publish(notificationRequest, (err) => {
+ if (err) {
+ console.error(`[ANS] failed to publish, error[${err}]`);
+ return;
+ }
+ console.info(`[ANS] publish success `);
+ });
+ ```
diff --git a/en/application-dev/notification/text-notification.md b/en/application-dev/notification/text-notification.md
new file mode 100644
index 0000000000000000000000000000000000000000..ddbc5478cee37208da33d2acecb71417deaccdc2
--- /dev/null
+++ b/en/application-dev/notification/text-notification.md
@@ -0,0 +1,160 @@
+# Publishing a Basic Notification
+
+
+You can publish basic notifications to send SMS messages, prompt messages, and advertisements. Available content types of basic notifications include normal text, long text, multi-line text, and picture-attached.
+
+
+ **Table 1** Basic notification content types
+
+| Type| Description|
+| -------- | -------- |
+| NOTIFICATION_CONTENT_BASIC_TEXT | Normal text notification.|
+| NOTIFICATION_CONTENT_LONG_TEXT | Long text notification.|
+| NOTIFICATION_CONTENT_MULTILINE | Multi-line text notification.|
+| NOTIFICATION_CONTENT_PICTURE | Picture-attached notification.|
+
+
+Notifications are displayed in the notification panel, which is the only system subscriber to notifications. Below you can see two examples of the basic notification.
+
+**Figure 1** Examples of the basic notification
+
+
+
+## Available APIs
+
+The following table describes the APIs for notification publishing. You specify the notification type by setting the [NotificationRequest](../reference/apis/js-apis-notificationManager.md#notificationrequest) parameter in the APIs.
+
+| Name| Description|
+| -------- | -------- |
+| publish(request: NotificationRequest, callback: AsyncCallback<void>): void | Publishes a notification. |
+| cancel(id: number, label: string, callback: AsyncCallback<void>): void | Cancels a notification. |
+| cancelAll(callback: AsyncCallback<void>): void; | Cancels all notifications published by the application.|
+
+
+## How to Develop
+
+1. [Enable notification](notification-enable.md). An application can use the notification feature only after being authorized by the user.
+
+2. Import the module.
+
+ ```ts
+ import notificationManager from '@ohos.notificationManager';
+ ```
+
+3. Create a **NotificationRequest** object and publish a progress notification.
+ - A normal text notification consists of the **title**, **text**, and **additionalText** parameters, of which **title** and **text** are mandatory. The value of these parameters contains less than 200 bytes.
+
+ ```ts
+ let notificationRequest = {
+ id: 1,
+ content: {
+ contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, // Basic notification
+ normal: {
+ title: 'test_title',
+ text: 'test_text',
+ additionalText: 'test_additionalText',
+ }
+ }
+ }
+
+ notificationManager.publish(notificationRequest, (err) => {
+ if (err) {
+ console.error(`[ANS] failed to publish, error[${err}]`);
+ return;
+ }
+ console.info(`[ANS] publish success`);
+ });
+ ```
+
+ Below is an example of the normal text notification.
+ 
+ - In addition to the parameters in the normal text notification, the long text notification provides the **longText**, **briefText**, and **expandedTitle** parameters. The value of **longText** contains a maximum of 1024 bytes, while that of any other parameters contains less than 200 bytes. By default, a long-text notification looks in the same way as a normal text notification. When expanded, the notification displays the title and content specified in **expandedTitle** and **longText**, respectively.
+
+ ```ts
+ let notificationRequest = {
+ id: 1,
+ content: {
+ contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_LONG_TEXT, // Long-text notification
+ longText: {
+ title: 'test_title',
+ text: 'test_text',
+ additionalText: 'test_additionalText',
+ longText: 'test_longText',
+ briefText: 'test_briefText',
+ expandedTitle: 'test_expandedTitle',
+ }
+ }
+ }
+
+ // Publish the notification.
+ notificationManager.publish(notificationRequest, (err) => {
+ if (err) {
+ console.error(`[ANS] failed to publish, error[${err}]`);
+ return;
+ }
+ console.info(`[ANS] publish success`);
+ });
+ ```
+
+ Below is an example of the long-text notification.
+ 
+ - In addition to the parameters in the normal text notification, the multi-line text notification provides the **lines**, **briefText**, and **longTitle** parameters. The value of these parameters contains less than 200 bytes. By default, a multi-line notification looks in the same way as a normal text notification. When expanded, the notification displays the title and content specified in **longTitle** and **lines**, respectively.
+
+ ```ts
+ let notificationRequest = {
+ id: 1,
+ content: {
+ contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_MULTILINE, // Multi-line text notification
+ multiLine: {
+ title: 'test_title',
+ text: 'test_text',
+ briefText: 'test_briefText',
+ longTitle: 'test_longTitle',
+ lines: ['line_01', 'line_02', 'line_03', 'line_04'],
+ }
+ }
+ }
+
+ // Publish the notification.
+ notificationManager.publish(notificationRequest, (err) => {
+ if (err) {
+ console.error(`[ANS] failed to publish, error[${err}]`);
+ return;
+ }
+ console.info(`[ANS] publish success`);
+ });
+ ```
+
+ Below is an example of the multi-line notification.
+ 
+ - In addition to the parameters in the normal text notification, the picture-attached text notification provides the **picture**, **briefText**, and **expandedTitle** parameters. The value of **picture** is a pixel map that does not exceed 2 MB.
+
+ ```ts
+ let notificationPicture: PixelMap = undefined; // Obtain the pixel map information.
+ let notificationRequest = {
+ id: 1,
+ content: {
+ contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_PICTURE,
+ picture: {
+ title: 'test_title',
+ text: 'test_text',
+ additionalText: 'test_additionalText',
+ briefText: 'test_briefText',
+ expandedTitle: 'test_expandedTitle',
+ picture: notificationPicture
+ }
+ }
+ }
+
+ // Publish the notification.
+ notificationManager.publish(notificationRequest, (err) => {
+ if (err) {
+ console.error(`[ANS] failed to publish, error[${err}]`);
+ return;
+ }
+ console.info(`[ANS] publish success `);
+ });
+ ```
+
+ Below is an example of the picture-attached notification.
+ 
diff --git a/en/application-dev/quick-start/figures/02.png b/en/application-dev/quick-start/figures/02.png
index 19dd76ca232282b19883dde63075c5d155e7db70..eef374a1fd63f2b1e4d72e3323e7f4c23f5705fb 100644
Binary files a/en/application-dev/quick-start/figures/02.png and b/en/application-dev/quick-start/figures/02.png differ
diff --git a/en/application-dev/quick-start/figures/04.png b/en/application-dev/quick-start/figures/04.png
index cf23d17c7ee8552e30a5b234c97862b51981dcf8..1190d1e5aa631b12171632d258e4c4fae32e9bba 100644
Binary files a/en/application-dev/quick-start/figures/04.png and b/en/application-dev/quick-start/figures/04.png differ
diff --git a/en/application-dev/quick-start/figures/07.png b/en/application-dev/quick-start/figures/07.png
index 0f34d01d824ae1780c73cade9a39fff5f4b9b84e..17f2b060d300667ff250935b6a37485843e854ce 100644
Binary files a/en/application-dev/quick-start/figures/07.png and b/en/application-dev/quick-start/figures/07.png differ
diff --git a/en/application-dev/reference/apis/Readme-EN.md b/en/application-dev/reference/apis/Readme-EN.md
index 7ec2ef1b9e52f9d3e4e53a0caa9bcfd5a9498c9f..80d0336aa005712ce116d5eb131ab299c1bff006 100644
--- a/en/application-dev/reference/apis/Readme-EN.md
+++ b/en/application-dev/reference/apis/Readme-EN.md
@@ -196,21 +196,22 @@
- Security
- [@ohos.abilityAccessCtrl (Ability Access Control)](js-apis-abilityAccessCtrl.md)
- [@ohos.privacyManager (Privacy Management)](js-apis-privacyManager.md)
+ - [@ohos.security.cert (Certificate)](js-apis-cert.md)
- [@ohos.security.cryptoFramework (Crypto Framework)](js-apis-cryptoFramework.md)
- [@ohos.security.huks (HUKS)](js-apis-huks.md)
- [@ohos.userIAM.faceAuth (Facial Authentication)](js-apis-useriam-faceauth.md)
- [@ohos.userIAM.userAuth (User Authentication)](js-apis-useriam-userauth.md)
- [@system.cipher (Cipher Algorithm)](js-apis-system-cipher.md)
- Data Management
- - [@ohos.data.dataAbility ](js-apis-data-ability.md)
- - [@ohos.data.dataShare](js-apis-data-dataShare.md)
- - [@ohos.data.dataSharePredicates](js-apis-data-dataSharePredicates.md)
- - [@ohos.data.dataShareResultSet](js-apis-data-DataShareResultSet.md)
- - [@ohos.data.distributedDataObject](js-apis-data-distributedobject.md)
- - [@ohos.data.distributedKVStore](js-apis-distributedKVStore.md)
- - [@ohos.data.preferences](js-apis-data-preferences.md)
- - [@ohos.data.rdb](js-apis-data-rdb.md)
- - [@ohos.data.ValuesBucket](js-apis-data-valuesBucket.md)
+ - [@ohos.data.dataAbility (DataAbility Predicates)](js-apis-data-ability.md)
+ - [@ohos.data.dataShare (DataShare)](js-apis-data-dataShare.md)
+ - [@ohos.data.dataSharePredicates (DataShare Predicates)](js-apis-data-dataSharePredicates.md)
+ - [@ohos.data.dataShareResultSet (DataShare Result Set)](js-apis-data-DataShareResultSet.md)
+ - [@ohos.data.distributedDataObject (Distributed Data Object)](js-apis-data-distributedobject.md)
+ - [@ohos.data.distributedKVStore (Distributed KV Store)](js-apis-distributedKVStore.md)
+ - [@ohos.data.preferences (Preferences)](js-apis-data-preferences.md)
+ - [@ohos.data.rdb (RDB)](js-apis-data-rdb.md)
+ - [@ohos.data.ValuesBucket (Value Bucket)](js-apis-data-valuesBucket.md)
- data/rdb
- [resultSet](js-apis-data-resultset.md)
- File Management
@@ -325,7 +326,7 @@
- [@ohos.enterprise.dateTimeManager](js-apis-enterprise-dateTimeManager.md)
- Language Base Class Library
- - [@ohos.buffer](js-apis-buffer.md)
+ - [@ohos.buffer (Buffer)](js-apis-buffer.md)
- [@ohos.convertxml](js-apis-convertxml.md)
- [@ohos.process](js-apis-process.md)
- [@ohos.uri](js-apis-uri.md)
diff --git a/en/application-dev/reference/apis/js-apis-Bundle-BundleStatusCallback.md b/en/application-dev/reference/apis/js-apis-Bundle-BundleStatusCallback.md
index b3476c86cce52d57a0d54c6b01c1fbed71076ef9..13fa28f551fe677055c589c11a0b4a1b581757b5 100644
--- a/en/application-dev/reference/apis/js-apis-Bundle-BundleStatusCallback.md
+++ b/en/application-dev/reference/apis/js-apis-Bundle-BundleStatusCallback.md
@@ -1,10 +1,10 @@
# BundleStatusCallback
-The **BundleStatusCallback** module provides bundle callback information, which is obtained through [innerBundleManager.on](js-apis-Bundle-InnerBundleManager.md).
+The **BundleStatusCallback** module provides callbacks for bundle status changes. The changes can be obtained through [innerBundleManager.on](js-apis-Bundle-InnerBundleManager.md).
> **NOTE**
>
-> This module is deprecated since API version 9. You are advised to use [bundleMonitor](js-apis-bundleMonitor.md) instead.
+> 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.
## BundleStatusCallback(deprecated)
diff --git a/en/application-dev/reference/apis/js-apis-Bundle-InnerBundleManager.md b/en/application-dev/reference/apis/js-apis-Bundle-InnerBundleManager.md
index 40725aefbf65838c8da46d75a13368c68118df0d..f45268cb699527ed412518bdee3b5f8b41f6520f 100644
--- a/en/application-dev/reference/apis/js-apis-Bundle-InnerBundleManager.md
+++ b/en/application-dev/reference/apis/js-apis-Bundle-InnerBundleManager.md
@@ -1,4 +1,4 @@
-# @ohos.bundle.innerBundleManager
+# @ohos.bundle.innerBundleManager (innerBundleManager)
The **innerBundleManager** module provides APIs for the **Home Screen** application.
@@ -22,7 +22,7 @@ SystemCapability.BundleManager.BundleFramework
getLauncherAbilityInfos(bundleName: string, userId: number, callback: AsyncCallback<Array<LauncherAbilityInfo>>) : void;
Obtains the launcher ability information based on a given bundle name. This API uses an asynchronous callback to return the result.
-> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getLauncherAbilityInfo](js-apis-launcherBundleManager.md) instead.
+> This API is deprecated since API version 9. You are advised to use [launcherBundleManager.getLauncherAbilityInfo](js-apis-launcherBundleManager.md#launcherbundlemanagergetlauncherabilityinfo9) instead.
**Required permissions**
@@ -38,11 +38,11 @@ This is a system API and cannot be called by third-party applications.
**Parameters**
-| Name | Type | Mandatory| Description |
-| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
-| bundleName | string | Yes | Bundle name of an application. |
-| userId | number | Yes | User ID. The value must be greater than or equal to 0.|
-| callback | AsyncCallback\> | Yes | Callback used to return an array of the launcher ability information. |
+| Name | Type | Mandatory| Description |
+| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
+| bundleName | string | Yes | Bundle name. |
+| userId | number | Yes | User ID. The value must be greater than or equal to 0. |
+| callback | AsyncCallback\> | Yes | Callback used to return an array of the launcher ability information.|
## innerBundleManager.getLauncherAbilityInfos(deprecated)
@@ -50,7 +50,7 @@ This is a system API and cannot be called by third-party applications.
getLauncherAbilityInfos(bundleName: string, userId: number) : Promise<Array<LauncherAbilityInfo>>
Obtains the launcher ability information based on a given bundle name. This API uses a promise to return the result.
-> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getLauncherAbilityInfo](js-apis-launcherBundleManager.md) instead.
+> This API is deprecated since API version 9. You are advised to use [launcherBundleManager.getLauncherAbilityInfo](js-apis-launcherBundleManager.md#launcherbundlemanagergetlauncherabilityinfo9) instead.
**Required permissions**
@@ -66,9 +66,9 @@ This is a system API and cannot be called by third-party applications.
**Parameters**
-| Name | Type | Mandatory| Description |
-| ---------- | ------ | ---- | ----------------------------------------------------- |
-| bundleName | string | Yes | Bundle name of an application. |
+| Name | Type | Mandatory| Description |
+| ---------- | ------ | ---- | ----------------------------- |
+| bundleName | string | Yes | Bundle name. |
| userId | number | Yes | User ID. The value must be greater than or equal to 0.|
**Return value**
@@ -82,7 +82,7 @@ This is a system API and cannot be called by third-party applications.
on(type:"BundleStatusChange", bundleStatusCallback : BundleStatusCallback, callback: AsyncCallback<string>) : void;
Registers a callback to receive bundle status changes. This API uses an asynchronous callback to return the result.
-> This API is deprecated since API version 9. You are advised to use [bundleMonitor#on](js-apis-bundleMonitor.md) instead.
+> This API is deprecated since API version 9. You are advised to use [bundleMonitor.on](js-apis-bundleMonitor.md#bundlemonitoron) instead.
**Required permissions**
@@ -109,7 +109,7 @@ This is a system API and cannot be called by third-party applications.
on(type:"BundleStatusChange", bundleStatusCallback : BundleStatusCallback) : Promise<string>
Registers a callback to receive bundle status changes. This API uses a promise to return the result.
-> This API is deprecated since API version 9. You are advised to use [bundleMonitor#on](js-apis-bundleMonitor.md) instead.
+> This API is deprecated since API version 9. You are advised to use [bundleMonitor.on](js-apis-bundleMonitor.md#bundlemonitoron) instead.
**Required permissions**
@@ -141,7 +141,7 @@ This is a system API and cannot be called by third-party applications.
off(type:"BundleStatusChange", callback: AsyncCallback<string>) : void;
Deregisters the callback that receives bundle status changes. This API uses an asynchronous callback to return the result.
-> This API is deprecated since API version 9. You are advised to use [bundleMonitor#off](js-apis-bundleMonitor.md) instead.
+> This API is deprecated since API version 9. You are advised to use [bundleMonitor.off](js-apis-bundleMonitor.md#bundlemonitoroff) instead.
**Required permissions**
@@ -167,7 +167,7 @@ This is a system API and cannot be called by third-party applications.
off(type:"BundleStatusChange") : Promise<string>
Deregisters the callback that receives bundle status changes. This API uses a promise to return the result.
-> This API is deprecated since API version 9. You are advised to use [bundleMonitor#off](js-apis-bundleMonitor.md) instead.
+> This API is deprecated since API version 9. You are advised to use [bundleMonitor.off](js-apis-bundleMonitor.md#bundlemonitoroff) instead.
**Required permissions**
@@ -198,7 +198,7 @@ This is a system API and cannot be called by third-party applications.
getAllLauncherAbilityInfos(userId: number, callback: AsyncCallback<Array<LauncherAbilityInfo>>) : void;
Obtains the information about all launcher abilities. This API uses an asynchronous callback to return the result.
-> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getAllLauncherAbilityInfo](js-apis-launcherBundleManager.md) instead.
+> This API is deprecated since API version 9. You are advised to use [launcherBundleManager.getAllLauncherAbilityInfo](js-apis-launcherBundleManager.md#launcherbundlemanagergetalllauncherabilityinfo9) instead.
**Required permissions**
@@ -224,7 +224,7 @@ This is a system API and cannot be called by third-party applications.
getAllLauncherAbilityInfos(userId: number) : Promise<Array<LauncherAbilityInfo>>
Obtains the information about all launcher abilities. This API uses a promise to return the result.
-> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getAllLauncherAbilityInfo](js-apis-launcherBundleManager.md) instead.
+> This API is deprecated since API version 9. You are advised to use [launcherBundleManager.getAllLauncherAbilityInfo](js-apis-launcherBundleManager.md#launcherbundlemanagergetalllauncherabilityinfo9) instead.
**Required permissions**
@@ -255,7 +255,7 @@ This is a system API and cannot be called by third-party applications.
getShortcutInfos(bundleName :string, callback: AsyncCallback<Array<ShortcutInfo>>) : void;
Obtains the shortcut information based on a given bundle name. This API uses an asynchronous callback to return the result.
-> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getShortcutInfo](js-apis-launcherBundleManager.md) instead.
+> This API is deprecated since API version 9. You are advised to use [launcherBundleManager.getShortcutInfo](js-apis-launcherBundleManager.md#launcherbundlemanagergetshortcutinfo9) instead.
**Required permissions**
@@ -273,7 +273,7 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | ---------------------------------------------- |
-| bundleName | string | Yes | Bundle name of an application. |
+| bundleName | string | Yes | Bundle name. |
| callback | AsyncCallback\> | Yes | Callback used to return an array of the shortcut information.|
## innerBundleManager.getShortcutInfos(deprecated)
@@ -281,7 +281,7 @@ This is a system API and cannot be called by third-party applications.
getShortcutInfos(bundleName : string) : Promise<Array<ShortcutInfo>>
Obtains the shortcut information based on a given bundle name. This API uses a promise to return the result.
-> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getShortcutInfo](js-apis-launcherBundleManager.md) instead.
+> This API is deprecated since API version 9. You are advised to use [launcherBundleManager.getShortcutInfo](js-apis-launcherBundleManager.md#launcherbundlemanagergetshortcutinfo9) instead.
**Required permissions**
@@ -299,7 +299,7 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------ |
-| bundleName | string | Yes | Bundle name of an application.|
+| bundleName | string | Yes | Bundle name.|
**Return value**
diff --git a/en/application-dev/reference/apis/js-apis-Bundle-distributedBundle.md b/en/application-dev/reference/apis/js-apis-Bundle-distributedBundle.md
index 493b263bd25d74fa7cfa5d9c59a45659fb4b5740..eda69bbe8857d6d787753bc91247dcde124f9633 100644
--- a/en/application-dev/reference/apis/js-apis-Bundle-distributedBundle.md
+++ b/en/application-dev/reference/apis/js-apis-Bundle-distributedBundle.md
@@ -1,4 +1,4 @@
-# distributedBundle
+# @ohos.distributedBundle (Distributed Bundle Management)
The **distributedBundle** module manages distributed bundles.
@@ -26,7 +26,7 @@ For details, see [Permission Levels](../../security/accesstoken-overview.md#perm
## distributedBundle.getRemoteAbilityInfodeprecated
-> This API is deprecated since API version 9. You are advised to use [getRemoteAbilityInfo](js-apis-distributedBundle.md) instead.
+> This API is deprecated since API version 9. You are advised to use [getRemoteAbilityInfo(@ohos.bundle.distributedBundleManager)](js-apis-distributedBundleManager.md) instead.
getRemoteAbilityInfo(elementName: ElementName, callback: AsyncCallback<RemoteAbilityInfo>): void;
@@ -55,7 +55,7 @@ This is a system API and cannot be called by third-party applications.
## distributedBundle.getRemoteAbilityInfodeprecated
-> This API is deprecated since API version 9. You are advised to use [getRemoteAbilityInfo](js-apis-distributedBundle.md) instead.
+> This API is deprecated since API version 9. You are advised to use [getRemoteAbilityInfo(@ohos.bundle.distributedBundleManager)](js-apis-distributedBundleManager.md) instead.
getRemoteAbilityInfo(elementName: ElementName): Promise<RemoteAbilityInfo>
@@ -87,7 +87,7 @@ This is a system API and cannot be called by third-party applications.
## distributedBundle.getRemoteAbilityInfosdeprecated
-> This API is deprecated since API version 9. You are advised to use [getRemoteAbilityInfo](js-apis-distributedBundle.md) instead.
+> This API is deprecated since API version 9. You are advised to use [getRemoteAbilityInfo(@ohos.bundle.distributedBundleManager)](js-apis-distributedBundleManager.md) instead.
getRemoteAbilityInfos(elementNames: Array<ElementName>, callback: AsyncCallback<Array<RemoteAbilityInfo>>): void;
@@ -116,7 +116,7 @@ This is a system API and cannot be called by third-party applications.
## distributedBundle.getRemoteAbilityInfosdeprecated
-> This API is deprecated since API version 9. You are advised to use [getRemoteAbilityInfo](js-apis-distributedBundle.md) instead.
+> This API is deprecated since API version 9. You are advised to use [getRemoteAbilityInfo(@ohos.bundle.distributedBundleManager)](js-apis-distributedBundleManager.md) instead.
getRemoteAbilityInfos(elementNames: Array<ElementName>): Promise<Array<RemoteAbilityInfo>>
diff --git a/en/application-dev/reference/apis/js-apis-Bundle.md b/en/application-dev/reference/apis/js-apis-Bundle.md
index 83cf9c77d2899e1c0c0969be8199c602e4374816..5908fc527c4d6f1c1a3391671a0ac9dcc4b41d6f 100644
--- a/en/application-dev/reference/apis/js-apis-Bundle.md
+++ b/en/application-dev/reference/apis/js-apis-Bundle.md
@@ -1,4 +1,4 @@
-# @ohos.bundle
+# @ohos.bundle (Bundle)
The **bundle** module provides APIs for obtaining information about an application, including [bundle information](js-apis-bundle-BundleInfo.md), [application information](js-apis-bundle-ApplicationInfo.md), and [ability information](js-apis-bundle-AbilityInfo.md). It also provides APIs to obtain and set the application disabling state.
@@ -15,10 +15,11 @@ import bundle from '@ohos.bundle';
| Required Permissions | Permission Level | Description |
|--------------------------------------------|--------------|---------------|
-| ohos.permission.GET_BUNDLE_INFO | normal | Permission to query information about a specified bundle. |
+| ohos.permission.CHANGE_ABILITY_ENABLED_STATE | system_basic | Permission to enable or disable an application or ability.|
+| ohos.permission.GET_BUNDLE_INFO | normal | Permission to query information about a specified bundle.|
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED| system_basic | Permission to query information about all bundles. |
| ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall bundles. |
-| ohos.permission.MANAGE_DISPOSED_APP_STATUS | system_core | Permission to set and query the application disposal status.|
+| ohos.permission.REMOVE_CACHE_FILES | system_basic | Permission to clear cache files of a bundle.|
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
@@ -44,7 +45,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ------------------------------------------------------------ |
-| bundleName | string | Yes | Bundle name of the application. |
+| bundleName | string | Yes | Bundle name. |
| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the application information flags in [BundleFlag](#bundleflagdeprecated).|
| userId | number | No | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
@@ -90,9 +91,9 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
-| bundleName | string | Yes | Bundle name of the application. |
-| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
-| userId | number | Yes | User ID. The value must be greater than or equal to 0. |
+| bundleName | string | Yes | Bundle name. |
+| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the application information flags in [BundleFlag](#bundleflagdeprecated).|
+| userId | number | Yes | User ID. The value must be greater than or equal to 0. |
| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)> | Yes | Callback used to return the application information. |
**Example**
@@ -133,8 +134,8 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
-| bundleName | string | Yes | Bundle name of the application. |
-| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
+| bundleName | string | Yes | Bundle name. |
+| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the application information flags in [BundleFlag](#bundleflagdeprecated).|
| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)> | Yes | Callback used to return the application information. |
**Example**
@@ -172,20 +173,21 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ---------- | ---------- | ---- | ------------------------------------------------------------ |
-| bundleFlag | BundleFlag | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflag).|
+| bundleFlag | BundleFlag | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflagdeprecated).|
| userId | number | No | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
**Return value**
| Type | Description |
| --------------------------- | -------------------------- |
-| Promise> | Promise used to return the information of all available bundles.|
+| Promise> | Promise used to return the information of all bundles.|
**Example**
```ts
let bundleFlag = 0;
let userId = 100;
+
bundle.getAllBundleInfo(bundleFlag, userId)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
@@ -215,7 +217,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
-| bundleFlag | BundleFlag | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflag).|
+| bundleFlag | BundleFlag | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflagdeprecated).|
| callback | AsyncCallback> | Yes | Callback used to return the information of all bundles. |
**Example**
@@ -252,7 +254,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description |
|------------|-------------------------------------------------------------------|-----|---------------------------------------------------------------------|
-| bundleFlag | BundleFlag | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflag).|
+| bundleFlag | BundleFlag | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflagdeprecated).|
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
| callback | AsyncCallback> | Yes | Callback used to return the information of all bundles. |
|
@@ -294,9 +296,9 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description |
| ----------- | ------------- | ---- |---------------------------------------------------------------------|
-| bundleName | string | Yes | Bundle name of the application. |
-| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflag).|
-| options | [BundleOptions](#bundleoptions) | No | Options that contain the user ID. |
+| bundleName | string | Yes | Bundle name. |
+| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflagdeprecated).|
+| options | [BundleOptions](#bundleoptionsdeprecated) | No | Options that contain the user ID. |
**Return value**
@@ -310,7 +312,7 @@ SystemCapability.BundleManager.BundleFramework
let bundleName = "com.example.myapplication";
let bundleFlags = 1;
let options = {
- "userId" : 100
+ "userId": 100
};
bundle.getBundleInfo(bundleName, bundleFlags, options)
.then((data) => {
@@ -340,11 +342,11 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
-| Name | Type | Mandatory| Description |
-| ----------- | ---------------------------------------------------------- | ---- |---------------------------------------------------------------------|
-| bundleName | string | Yes | Bundle name of the application. |
-| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflag).|
-| callback | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes | Callback used to return the bundle information. |
+| Name | Type | Mandatory| Description |
+| ----------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
+| bundleName | string | Yes | Bundle name. |
+| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflagdeprecated).|
+| callback | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes | Callback used to return the bundle information. |
**Example**
@@ -360,7 +362,6 @@ bundle.getBundleInfo(bundleName, bundleFlags, (err, data) => {
})
```
-
## bundle.getBundleInfodeprecated
> This API is deprecated since API version 9. You are advised to use [bundleManager.getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo) instead.
@@ -383,9 +384,9 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ----------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
-| bundleName | string | Yes | Bundle name of the application. |
-| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflag).|
-| options | [BundleOptions](#bundleoptions) | Yes | Includes **userId**. |
+| bundleName | string | Yes | Bundle name. |
+| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflagdeprecated).|
+| options | [BundleOptions](#bundleoptionsdeprecated) | Yes | Includes **userId**. |
| callback | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes | Callback used to return the bundle information. |
**Example**
@@ -394,7 +395,7 @@ SystemCapability.BundleManager.BundleFramework
let bundleName = "com.example.myapplication";
let bundleFlags = 1;
let options = {
- "userId" : 100
+ "userId": 100
};
bundle.getBundleInfo(bundleName, bundleFlags, options, (err, data) => {
if (err) {
@@ -504,7 +505,7 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description |
| ---------- | ------------------- | ---- | ------------------------------------- |
-| bundleName | string | Yes | Bundle name of the application.|
+| bundleName | string | Yes | Bundle name.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
**Example**
@@ -545,7 +546,7 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------------------- |
-| bundleName | string | Yes | Bundle name of the application.|
+| bundleName | string | Yes | Bundle name.|
**Return value**
@@ -589,7 +590,7 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description |
| ---------- | ------------------- | ---- |--------------------------------|
-| bundleName | string | Yes | Bundle name of the application. |
+| bundleName | string | Yes | Bundle name. |
| isEnable | boolean | Yes | Whether to enable the application. The value **true** means to enable the application, and **false** means the opposite.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
@@ -629,9 +630,9 @@ This is a system API and cannot be called by third-party applications.
**Parameters**
-| Name | Type | Mandatory| Description |
-| ---------- | ------- | ---- |------------------------------|
-| bundleName | string | Yes | Bundle name of the application. |
+| Name | Type | Mandatory| Description |
+| ---------- | ------- | ---- | ----------------------------------------------- |
+| bundleName | string | Yes | Bundle name. |
| isEnable | boolean | Yes | Whether to enable the application. The value **true** means to enable the application, and **false** means the opposite.|
**Return value**
@@ -720,7 +721,7 @@ let flag = bundle.BundleFlag.GET_ABILITY_INFO_WITH_PERMISSION;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
- abilityName : "com.example.myapplication.MainAbility"
+ abilityName : "EntryAbility"
};
bundle.getAbilityInfo(want, flag, userId).then((abilityInfo) => {
@@ -760,7 +761,7 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description |
| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ |
| permissionName | string | Yes | Name of the permission. |
-| callback | AsyncCallback<[PermissionDef](js-apis-bundle-PermissionDef)> | Yes | Callback used to return the permission details.|
+| callback | AsyncCallback<[PermissionDef](js-apis-bundle-PermissionDef.md)> | Yes | Callback used to return the permission details.|
**Example**
@@ -805,7 +806,7 @@ This is a system API and cannot be called by third-party applications.
| Type | Description |
| ------------------------------------------------------ | ------------------------------------------------------ |
-| Promise<[PermissionDef](js-apis-bundle-PermissionDef)> | Promise used to return the permission details.|
+| Promise<[PermissionDef](js-apis-bundle-PermissionDef.md)> | Promise used to return the permission details.|
**Example**
@@ -838,7 +839,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ------------------------------------------------------------ |
-| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
+| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the application information flags in [BundleFlag](#bundleflagdeprecated).|
| userId | number | No | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
**Return value**
@@ -880,7 +881,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
-| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
+| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the application information flags in [BundleFlag](#bundleflagdeprecated).|
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
| callback | AsyncCallback> | Yes | Callback used to return the application information. |
@@ -919,7 +920,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
-| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
+| bundleFlags | number | Yes | Type of information that will be returned. For details about the available enumerated values, see the application information flags in [BundleFlag](#bundleflagdeprecated).|
| callback | AsyncCallback> | Yes | Callback used to return the application information. |
**Example**
@@ -952,11 +953,11 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description |
| ---------- | ------ | ---- | ------------ |
| hapFilePath | string | Yes | Path where the HAP file is stored. The absolute path of the application and the data directory sandbox path are supported.|
-| bundleFlags | number | Yes | Flags used to specify information contained in the **BundleInfo** object that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflag).|
+| bundleFlags | number | Yes | Flags used to specify information contained in the **BundleInfo** object that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflagdeprecated).|
**Return value**
-| Type | Description |
-| -------------- | -------------------------------------- |
+| Type | Description |
+| ---------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Promise used to return the information about the bundles.|
**Example**
@@ -989,7 +990,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description |
| ---------- | ------ | ---- | ------------ |
| hapFilePath | string | Yes | Path where the HAP file is stored.. The absolute path of the application and the data directory sandbox path are supported.|
-| bundleFlags | number | Yes | Flags used to specify information contained in the **BundleInfo** object that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflag).|
+| bundleFlags | number | Yes | Flags used to specify information contained in the **BundleInfo** object that will be returned. For details about the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflagdeprecated).|
| callback| AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes | Callback used to return the information about the bundles.|
**Example**
@@ -1006,7 +1007,6 @@ bundle.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => {
})
```
-
## bundle.getAbilityInfodeprecated
> This API is deprecated since API version 9. You are advised to use [bundleManager.queryAbilityInfo](js-apis-bundleManager.md#bundlemanagerqueryabilityinfo) instead.
@@ -1029,7 +1029,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- |------------|
-| bundleName | string | Yes | Bundle name of the application. |
+| bundleName | string | Yes | Bundle name.|
| abilityName | string | Yes | Ability name.|
**Return value**
@@ -1042,7 +1042,7 @@ SystemCapability.BundleManager.BundleFramework
```ts
let bundleName = "com.example.myapplication";
-let abilityName = "com.example.myapplication.MainAbility";
+let abilityName = "EntryAbility";
bundle.getAbilityInfo(bundleName, abilityName)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
@@ -1073,7 +1073,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description |
| ----------- | ------------ | ---- |----------------------------|
-| bundleName | string | Yes | Bundle name of the application. |
+| bundleName | string | Yes | Bundle name. |
| abilityName | string | Yes | Ability name. |
| callback | AsyncCallback\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Yes | Callback used to return the ability information.|
@@ -1081,7 +1081,7 @@ SystemCapability.BundleManager.BundleFramework
```ts
let bundleName = "com.example.myapplication";
-let abilityName = "com.example.myapplication.MainAbility";
+let abilityName = "EntryAbility";
bundle.getAbilityInfo(bundleName, abilityName, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
@@ -1111,10 +1111,10 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
-| Name | Type | Mandatory | Description |
-|-------------|--------|-----|------------|
-| bundleName | string | Yes | Bundle name of the application. |
-| abilityName | string | Yes | Ability name.|
+| Name | Type | Mandatory| Description |
+| ----------- | ------ | ---- | ---------------- |
+| bundleName | string | Yes | Bundle name.|
+| abilityName | string | Yes | Ability name. |
**Return value**
@@ -1126,7 +1126,7 @@ SystemCapability.BundleManager.BundleFramework
```ts
let bundleName = "com.example.myapplication";
-let abilityName = "com.example.myapplication.MainAbility";
+let abilityName = "EntryAbility";
bundle.getAbilityLabel(bundleName, abilityName)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
@@ -1155,17 +1155,17 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
-| Name | Type | Mandatory | Description |
-|-------------|------------------------|-----|-------------------------|
-| bundleName | string | Yes | Bundle name of the application. |
-| abilityName | string | Yes | Ability name. |
+| Name | Type | Mandatory| Description |
+| ----------- | ---------------------- | ---- | ---------------------------------------------- |
+| bundleName | string | Yes | Bundle name. |
+| abilityName | string | Yes | Ability name. |
| callback | AsyncCallback\ | Yes | Callback used to return the application name.|
**Example**
```ts
let bundleName = "com.example.myapplication";
-let abilityName = "com.example.myapplication.MainAbility";
+let abilityName = "EntryAbility";
bundle.getAbilityLabel(bundleName, abilityName, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
@@ -1197,13 +1197,13 @@ SystemCapability.BundleManager.BundleFramework
| Type | Description |
| ----------------- | ------------------------- |
-| Promise\ | Promise used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
+| Promise\ | Promise used to return the result. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```ts
let bundleName = "com.example.myapplication";
-let abilityName = "com.example.myapplication.MainAbility";
+let abilityName = "EntryAbility";
bundle.getAbilityInfo(bundleName, abilityName).then((abilityInfo)=>{
bundle.isAbilityEnabled(abilityInfo).then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
@@ -1230,13 +1230,13 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------- | ---- | ----------------------- |
| info | [AbilityInfo](js-apis-bundle-AbilityInfo.md) | Yes | Ability information. |
-| callback | AsyncCallback\ | Yes | Callback used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** means that the ability is enabled, and **false** means the opposite.|
**Example**
```ts
let bundleName = "com.example.myapplication";
-let abilityName = "com.example.myapplication.MainAbility";
+let abilityName = "EntryAbility";
bundle.getAbilityInfo(bundleName, abilityName).then((abilityInfo)=>{
bundle.isAbilityEnabled(abilityInfo, (err, data) => {
if (err) {
@@ -1264,13 +1264,13 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------ |
-| bundleName | string | Yes | Bundle name of the application.|
+| bundleName | string | Yes | Bundle name.|
**Return value**
| Type | Description |
| ----------------- | ------------------------- |
-| Promise\ | Promise used to return whether the application is enabled. If the application is enabled, **true** will be returned; otherwise, **false** will be returned.|
+| Promise\ | Promise used to return the result. If the application is enabled, **true** will be returned; otherwise, **false** will be returned.|
**Example**
@@ -1300,8 +1300,8 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ---------- | ----------------------- | ---- | ------------------------ |
-| bundleName | string | Yes | Bundle name of the application.|
-| callback | AsyncCallback\ | Yes | Callback used to return whether the application is enabled. If the application is enabled, **true** will be returned; otherwise, **false** will be returned. |
+| bundleName | string | Yes | Bundle name.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result. If the application is enabled, **true** will be returned; otherwise, **false** will be returned.|
**Example**
@@ -1322,7 +1322,7 @@ bundle.isApplicationEnabled(bundleName, (err, data) => {
queryAbilityByWant(want: Want, bundleFlags: number, userId?: number): Promise>
-Obtains the ability information based on a given want. This API uses a promise to return the result.
+Obtains the ability information based on given Want. This API uses a promise to return the result.
No permission is required for obtaining the caller's own information.
@@ -1338,8 +1338,8 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | ------------------------------------- |
-| want | [Want](js-apis-application-want.md) | Yes | Want that contains the bundle name. |
-| bundleFlags | number | Yes | Ability information to be returned. For details about the available enumerated values, see the ability information flags in [BundleFlag](#bundleflag).|
+| want | [Want](js-apis-application-want.md) | Yes | Want containing the bundle name |
+| bundleFlags | number | Yes | Ability information to be returned. For details about the available enumerated values, see the ability information flags in [BundleFlag](#bundleflagdeprecated).|
| userId | number | No | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
**Return value**
@@ -1355,7 +1355,7 @@ let bundleFlags = 0;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
- abilityName : "com.example.myapplication.MainAbility"
+ abilityName : "EntryAbility"
};
bundle.queryAbilityByWant(want, bundleFlags, userId)
.then((data) => {
@@ -1373,7 +1373,7 @@ bundle.queryAbilityByWant(want, bundleFlags, userId)
queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback>): void
-Obtains the ability information of the specified user based on a given want. This API uses an asynchronous callback to return the result.
+Obtains the ability information of the specified user based on given Want. This API uses an asynchronous callback to return the result.
No permission is required for obtaining the caller's own information.
@@ -1387,12 +1387,12 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
-| Name | Type | Mandatory | Description |
-|-------------|---------------------------------------------------------------------|-----|-------------------------------------------------------------------------|
-| want | [Want](js-apis-application-want.md) | Yes | Want that contains the bundle name. |
-| bundleFlags | number | Yes | Ability information to be returned. For details about the available enumerated values, see the ability information flags in [BundleFlag](#bundleflag).|
-| userId | number | Yes | User ID. The value must be greater than or equal to 0. |
-| callback | AsyncCallback> | Yes | Callback used to return the ability information. |
+| Name | Type | Mandatory| Description |
+| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
+| want | [Want](js-apis-application-want.md) | Yes | Want containing the bundle name. |
+| bundleFlags | number | Yes | Ability information to be returned. For details about the available enumerated values, see the ability information flags in [BundleFlag](#bundleflagdeprecated).|
+| userId | number | Yes | User ID. The value must be greater than or equal to 0. |
+| callback | AsyncCallback> | Yes | Callback used to return the ability information. |
**Example**
@@ -1401,7 +1401,7 @@ let bundleFlags = 0;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
- abilityName : "com.example.myapplication.MainAbility"
+ abilityName : "EntryAbility"
};
bundle.queryAbilityByWant(want, bundleFlags, userId, (err, data) => {
if (err) {
@@ -1418,7 +1418,7 @@ bundle.queryAbilityByWant(want, bundleFlags, userId, (err, data) => {
queryAbilityByWant(want: Want, bundleFlags: number, callback: AsyncCallback>): void;
-Obtains the ability information based on a given want. This API uses an asynchronous callback to return the result.
+Obtains the ability information based on given Want. This API uses an asynchronous callback to return the result.
No permission is required for obtaining the caller's own information.
@@ -1432,11 +1432,11 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
-| Name | Type | Mandatory | Description |
-|-------------|---------------------------------------------------------------------|-----|-------------------------------------------------------------------------|
-| want | [Want](js-apis-application-want.md) | Yes | Want that contains the bundle name. |
-| bundleFlags | number | Yes | Ability information to be returned. For details about the available enumerated values, see the ability information flags in [BundleFlag](#bundleflag).|
-| callback | AsyncCallback> | Yes | Callback used to return the ability information. |
+| Name | Type | Mandatory| Description |
+| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
+| want | [Want](js-apis-application-want.md) | Yes | Want containing the bundle name. |
+| bundleFlags | number | Yes | Ability information to be returned. For details about the available enumerated values, see the ability information flags in [BundleFlag](#bundleflagdeprecated).|
+| callback | AsyncCallback> | Yes | Callback used to return the ability information. |
**Example**
@@ -1444,7 +1444,7 @@ SystemCapability.BundleManager.BundleFramework
let bundleFlags = 0;
let want = {
bundleName : "com.example.myapplication",
- abilityName : "com.example.myapplication.MainAbility"
+ abilityName : "EntryAbility"
};
bundle.queryAbilityByWant(want, bundleFlags, (err, data) => {
if (err) {
@@ -1477,7 +1477,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------ |
-| bundleName | string | Yes | Bundle name of the application.|
+| bundleName | string | Yes | Bundle name.|
**Return value**
| Type | Description |
@@ -1516,7 +1516,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------------------- | ---- | -------------------------------------------------------- |
-| bundleName | string | Yes | Bundle name of the application. |
+| bundleName | string | Yes | Bundle name. |
| callback | AsyncCallback\<[Want](js-apis-application-want.md)> | Yes | Callback used to return the **Want** object.|
**Example**
@@ -1582,9 +1582,9 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
-| Name | Type | Mandatory | Description |
-|----------|------------------------|-----|----------------------------|
-| uid | number | Yes | UID based on which the bundle name is to obtain. |
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------- | ---- | ----------------------------------------------------- |
+| uid | number | Yes | UID based on which the bundle name is to obtain. |
| callback | AsyncCallback\ | Yes | Callback used to return the bundle name.|
**Example**
@@ -1621,10 +1621,10 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
-| Name | Type | Mandatory| Description |
-| ----------- | ------ | ---- |-----------------|
-| bundleName | string | Yes | Bundle name of the application. |
-| abilityName | string | Yes | Ability name.|
+| Name | Type | Mandatory| Description |
+| ----------- | ------ | ---- | ------------------------ |
+| bundleName | string | Yes | Bundle name.|
+| abilityName | string | Yes | Ability name. |
**Return value**
| Type | Description |
@@ -1635,7 +1635,7 @@ SystemCapability.BundleManager.BundleFramework
```ts
let bundleName = "com.example.myapplication";
-let abilityName = "com.example.myapplication.MainAbility";
+let abilityName = "EntryAbility";
bundle.getAbilityIcon(bundleName, abilityName)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
@@ -1667,7 +1667,7 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory | Description |
| ----------- | ---------------------------------------- | ---- |-------------------------------------------------|
-| bundleName | string | Yes | Bundle name of the application. |
+| bundleName | string | Yes | Bundle name. |
| abilityName | string | Yes | Ability name. |
| callback | AsyncCallback\ | Yes | Callback used to return the [pixel map](js-apis-image.md).|
@@ -1675,7 +1675,7 @@ SystemCapability.BundleManager.BundleFramework
```ts
let bundleName = "com.example.myapplication";
-let abilityName = "com.example.myapplication.MainAbility";
+let abilityName = "EntryAbility";
bundle.getAbilityIcon(bundleName, abilityName, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
diff --git a/en/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md b/en/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md
index c9cc2b79ba9aed4400fdc52bd938c5e3db711b6b..a55ab990ef39072d83989526e66723eab794ca63 100644
--- a/en/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md
+++ b/en/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md
@@ -1,4 +1,4 @@
-# @ohos.enterprise.EnterpriseAdminExtensionAbility
+# @ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)
The **EnterpriseAdminExtensionAbility** module provides Extension abilities for enterprise administrators.
diff --git a/en/application-dev/reference/apis/js-apis-WorkSchedulerExtensionAbility.md b/en/application-dev/reference/apis/js-apis-WorkSchedulerExtensionAbility.md
index e7be32c9b840dbe67f99e120e3798ad5ecd9fcd4..a22f7b48a977066e085da4b9ddfcdeb24f21463f 100644
--- a/en/application-dev/reference/apis/js-apis-WorkSchedulerExtensionAbility.md
+++ b/en/application-dev/reference/apis/js-apis-WorkSchedulerExtensionAbility.md
@@ -1,4 +1,4 @@
-# Work Scheduler Callbacks
+# @ohos.WorkSchedulerExtensionAbility (Work Scheduler Callbacks)
The **WorkSchedulerExtensionAbility** module provides callbacks for Work Scheduler tasks.
diff --git a/en/application-dev/reference/apis/js-apis-ability-ability.md b/en/application-dev/reference/apis/js-apis-ability-ability.md
index 84033dd0a9d22eba5ffe275c38f078bfb0649b83..37bf04c704a91f0580fddf99b14f9f52fb94d683 100644
--- a/en/application-dev/reference/apis/js-apis-ability-ability.md
+++ b/en/application-dev/reference/apis/js-apis-ability-ability.md
@@ -1,4 +1,4 @@
-# @ohos.ability.ability
+# @ohos.ability.ability (Ability)
The **Ability** module provides all level-2 module APIs for developers to export.
diff --git a/en/application-dev/reference/apis/js-apis-ability-context.md b/en/application-dev/reference/apis/js-apis-ability-context.md
index f77fd415a1bb7dd8a7d8968f96dce2718f2873ed..d345bbb9db0739da16156ecfc0bd4fe344989149 100644
--- a/en/application-dev/reference/apis/js-apis-ability-context.md
+++ b/en/application-dev/reference/apis/js-apis-ability-context.md
@@ -14,10 +14,10 @@ This module provides APIs for accessing ability-specific resources. You can use
Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**.
```ts
-import Ability from '@ohos.app.ability.UIAbility';
+import UIAbility from '@ohos.app.ability.UIAbility';
- let context = undefined;
-class MainAbility extends Ability {
+let context = undefined;
+class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
context = this.context;
}
@@ -30,8 +30,8 @@ class MainAbility extends Ability {
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
-| abilityInfo | AbilityInfo | Yes| No| Ability information.|
-| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.|
+| abilityInfo | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes| No| Ability information.|
+| currentHapModuleInfo | [HapModuleInfo](js-apis-bundleManager-hapModuleInfo.md) | Yes| No| Information about the current HAP.|
| config | [Configuration](js-apis-application-configuration.md) | Yes| No| Configuration information.|
## AbilityContext.startAbility
@@ -40,6 +40,11 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
Starts an ability. This API uses an asynchronous callback to return the result.
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
+
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
@@ -54,13 +59,14 @@ Starts an ability. This API uses an asynchronous callback to return the result.
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
- bundleName: "com.example.myapp",
+ bundleName: "com.example.myapplication",
abilityName: "MyAbility"
};
@@ -89,6 +95,11 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
Starts an ability with the start options specified. This API uses an asynchronous callback to return the result.
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
+
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
@@ -104,15 +115,16 @@ Starts an ability with the start options specified. This API uses an asynchronou
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var options = {
windowMode: 0
@@ -142,6 +154,11 @@ startAbility(want: Want, options?: StartOptions): Promise<void>;
Starts an ability. This API uses a promise to return the result.
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
+
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
@@ -162,13 +179,14 @@ Starts an ability. This API uses a promise to return the result.
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
- bundleName: "com.example.myapp",
+ bundleName: "com.example.myapplication",
abilityName: "MyAbility"
};
var options = {
@@ -198,7 +216,12 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void;
-Starts an ability. This API uses an asynchronous callback to return the result when the ability is terminated.
+Starts an ability. After the ability is started, you can call [terminateSelfWithResult](#abilitycontextterminateselfwithresult) to terminate the ability and return the result to the caller. If an exception occurs, for example, the ability is killed, exception information is returned to the caller. This API uses an asynchronous callback to return the result.
+
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -214,15 +237,16 @@ Starts an ability. This API uses an asynchronous callback to return the result w
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
try {
@@ -248,7 +272,12 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): void;
-Starts an ability with the start options specified. This API uses an asynchronous callback to return the result when the ability is terminated.
+Starts an ability with the start options specified. After the ability is started, you can call [terminateSelfWithResult](#abilitycontextterminateselfwithresult) to terminate the ability and return the result to the caller. If an exception occurs, for example, the ability is killed, exception information is returned to the caller. This API uses an asynchronous callback to return the result.
+
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -265,15 +294,16 @@ Starts an ability with the start options specified. This API uses an asynchronou
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var options = {
windowMode: 0,
@@ -303,7 +333,12 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult>;
-Starts an ability. This API uses a promise to return the result when the ability is terminated.
+Starts an ability. After the ability is started, you can call [terminateSelfWithResult](#abilitycontextterminateselfwithresult) to terminate the ability and return the result to the caller. If an exception occurs, for example, the ability is killed, exception information is returned to the caller. This API uses a promise to return the result.
+
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -326,13 +361,14 @@ Starts an ability. This API uses a promise to return the result when the ability
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
- bundleName: "com.example.myapp",
+ bundleName: "com.example.myapplication",
abilityName: "MyAbility"
};
var options = {
@@ -361,9 +397,14 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncCallback\): void;
-Starts an ability. This API uses an asynchronous callback to return the result when the account of the ability is destroyed.
+Starts an ability with the account ID specified. This API uses an asynchronous callback to return the result when the ability is terminated.
+
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user)
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -375,22 +416,23 @@ Starts an ability. This API uses an asynchronous callback to return the result w
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | Yes| Want information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
-| callback | AsyncCallback\ | Yes| Callback used to return the result.|
+| callback | AsyncCallback\<[AbilityResult](js-apis-inner-ability-abilityResult.md)\> | Yes| Callback used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var accountId = 100;
@@ -418,9 +460,14 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\): void;
-Starts an ability with the start options specified. This API uses an asynchronous callback to return the result when the account of the ability is destroyed.
+Starts an ability with the start options and account ID specified. This API uses an asynchronous callback to return the result when the ability is terminated.
+
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user)
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -440,15 +487,16 @@ Starts an ability with the start options specified. This API uses an asynchronou
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var accountId = 100;
var options = {
@@ -479,9 +527,14 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\;
-Starts an ability with the start options specified. This API uses a promise to return the result when the account of the ability is destroyed.
+Starts an ability with the account ID specified. This API uses a promise to return the result when the ability is terminated.
+
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user)
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -499,22 +552,23 @@ Starts an ability with the start options specified. This API uses a promise to r
| Type| Description|
| -------- | -------- |
-| Promise<AbilityResult> | Promise used to return the result.|
+| Promise<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Promise used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var accountId = 100;
var options = {
@@ -543,7 +597,7 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
startServiceExtensionAbility(want: Want, callback: AsyncCallback\): void;
-Starts a new Service Extension ability. This API uses an asynchronous callback to return the result.
+Starts a ServiceExtensionAbility. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -561,15 +615,16 @@ Starts a new Service Extension ability. This API uses an asynchronous callback t
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
try {
@@ -594,7 +649,7 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
startServiceExtensionAbility(want: Want): Promise\;
-Starts a new Service Extension ability. This API uses a promise to return the result.
+Starts a ServiceExtensionAbility. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -611,15 +666,16 @@ Starts a new Service Extension ability. This API uses a promise to return the re
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
try {
@@ -644,9 +700,9 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\): void;
-Starts a new Service Extension ability with the account ID specified. This API uses an asynchronous callback to return the result.
+Starts a ServiceExtensionAbility with the account ID specified. This API uses an asynchronous callback to return the result.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user)
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -665,15 +721,16 @@ Starts a new Service Extension ability with the account ID specified. This API u
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var accountId = 100;
@@ -699,9 +756,9 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\;
-Starts a new Service Extension ability with the account ID specified. This API uses a promise to return the result.
+Starts a ServiceExtensionAbility with the account ID specified. This API uses a promise to return the result.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user)
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -719,15 +776,16 @@ Starts a new Service Extension ability with the account ID specified. This API u
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var accountId = 100;
@@ -752,7 +810,7 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
stopServiceExtensionAbility(want: Want, callback: AsyncCallback\): void;
-Stops a Service Extension ability in the same application. This API uses an asynchronous callback to return the result.
+Stops a ServiceExtensionAbility in the same application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -770,20 +828,27 @@ Stops a Service Extension ability in the same application. This API uses an asyn
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
try {
+ this.context.startAbility(want, (error) => {
+ if (error.code != 0) {
+ console.log("start ability fail, err: " + JSON.stringify(err));
+ }
+ })
+
this.context.stopServiceExtensionAbility(want, (error) => {
- if (error.code) {
+ if (error.code != 0) {
// Process service logic errors.
console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
@@ -803,7 +868,7 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
stopServiceExtensionAbility(want: Want): Promise\;
-Stops a Service Extension ability in the same application. This API uses a promise to return the result.
+Stops a ServiceExtensionAbility in the same application. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -820,18 +885,25 @@ Stops a Service Extension ability in the same application. This API uses a promi
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
try {
+ this.context.startAbility(want, (error) => {
+ if (error.code != 0) {
+ console.log("start ability fail, err: " + JSON.stringify(err));
+ }
+ })
+
this.context.stopServiceExtensionAbility(want)
.then((data) => {
// Carry out normal service processing.
@@ -853,9 +925,9 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\): void;
-Stops a Service Extension ability in the same application with the account ID specified. This API uses an asynchronous callback to return the result.
+Stops a ServiceExtensionAbility in the same application with the account ID specified. This API uses an asynchronous callback to return the result.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user)
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -874,19 +946,26 @@ Stops a Service Extension ability in the same application with the account ID sp
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var accountId = 100;
try {
+ this.context.startAbilityWithAccount(want, accountId, (error) => {
+ if (error.code != 0) {
+ console.log("start ability fail, err: " + JSON.stringify(err));
+ }
+ })
+
this.context.stopServiceExtensionAbilityWithAccount(want, accountId, (error) => {
if (error.code) {
// Process service logic errors.
@@ -908,9 +987,9 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\;
-Stops a Service Extension ability in the same application with the account ID specified. This API uses a promise to return the result.
+Stops a ServiceExtensionAbility in the same application with the account ID specified. This API uses a promise to return the result.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user)
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -928,19 +1007,26 @@ Stops a Service Extension ability in the same application with the account ID sp
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var accountId = 100;
try {
+ this.context.startAbilityWithAccount(want, accountId, (error) => {
+ if (error.code != 0) {
+ console.log("start ability fail, err: " + JSON.stringify(err));
+ }
+ })
+
this.context.stopServiceExtensionAbilityWithAccount(want, accountId)
.then((data) => {
// Carry out normal service processing.
@@ -977,7 +1063,8 @@ Terminates this ability. This API uses an asynchronous callback to return the re
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
@@ -1014,7 +1101,8 @@ Terminates this ability. This API uses a promise to return the result.
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
@@ -1034,7 +1122,7 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void;
-Terminates this ability. This API uses an asynchronous callback to return the ability result information. It is used together with **startAbilityForResult**.
+Terminates this ability. If the ability is started by calling [startAbilityForResult](#abilitycontextstartabilityforresult), the result is returned to the caller in the form of a callback when **terminateSelfWithResult** is called. Otherwise, no result is returned to the caller when **terminateSelfWithResult** is called.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -1050,7 +1138,8 @@ Terminates this ability. This API uses an asynchronous callback to return the ab
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
@@ -1088,8 +1177,7 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
## AbilityContext.terminateSelfWithResult
terminateSelfWithResult(parameter: AbilityResult): Promise<void>;
-
-Terminates this ability. This API uses a promise to return the ability result information. It is used together with **startAbilityForResult**.
+Terminates this ability. If the ability is started by calling [startAbilityForResult](#abilitycontextstartabilityforresult), the result is returned to the caller in the form of a promise when **terminateSelfWithResult** is called. Otherwise, no result is returned to the caller when **terminateSelfWithResult** is called.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -1110,7 +1198,8 @@ Terminates this ability. This API uses a promise to return the ability result in
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
@@ -1173,15 +1262,16 @@ Uses the **AbilityInfo.AbilityType.SERVICE** template to connect this ability to
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var options = {
onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
@@ -1204,9 +1294,9 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number;
-Uses the **AbilityInfo.AbilityType.SERVICE** template and account ID to connect this ability to another ability with the account ID specified.
+Uses the **AbilityInfo.AbilityType.SERVICE** template to connect this ability to another ability with the account ID specified.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user)
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -1231,15 +1321,16 @@ Uses the **AbilityInfo.AbilityType.SERVICE** template and account ID to connect
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var accountId = 100;
var options = {
@@ -1283,7 +1374,8 @@ Disconnects a connection. This API uses a promise to return the result.
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
@@ -1329,7 +1421,8 @@ Disconnects a connection. This API uses an asynchronous callback to return the r
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
@@ -1361,6 +1454,11 @@ startAbilityByCall(want: Want): Promise<Caller>;
Starts an ability in the foreground or background and obtains the caller object for communicating with the ability.
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - The rules for using this API in the same-device and cross-device scenarios are different. For details, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
+
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
@@ -1388,7 +1486,7 @@ Starts an ability in the foreground or background and obtains the caller object
var wantBackground = {
bundleName: "com.example.myservice",
moduleName: "entry",
- abilityName: "MainAbility",
+ abilityName: "EntryAbility",
deviceId: ""
};
@@ -1419,7 +1517,7 @@ Starts an ability in the foreground or background and obtains the caller object
var wantForeground = {
bundleName: "com.example.myservice",
moduleName: "entry",
- abilityName: "MainAbility",
+ abilityName: "EntryAbility",
deviceId: "",
parameters: {
"ohos.aafwk.param.callAbilityToForeground": true
@@ -1450,7 +1548,12 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
Starts an ability with the account ID specified. This API uses an asynchronous callback to return the result.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
+
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user)
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -1469,15 +1572,16 @@ Starts an ability with the account ID specified. This API uses an asynchronous c
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var accountId = 100;
@@ -1506,7 +1610,12 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
Starts an ability with the account ID and start options specified. This API uses an asynchronous callback to return the result.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
+
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user)
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -1526,15 +1635,16 @@ Starts an ability with the account ID and start options specified. This API uses
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var accountId = 100;
var options = {
@@ -1566,7 +1676,12 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
Starts an ability with the account ID specified. This API uses a promise to return the result.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
+
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user)
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -1585,15 +1700,16 @@ Starts an ability with the account ID specified. This API uses a promise to retu
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
var want = {
deviceId: "",
- bundleName: "com.extreme.test",
- abilityName: "MainAbility"
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
};
var accountId = 100;
var options = {
@@ -1618,65 +1734,6 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
}
```
-## AbilityContext.requestPermissionsFromUser
-
-requestPermissionsFromUser(permissions: Array<string>, requestCallback: AsyncCallback<PermissionRequestResult>) : void;
-
-Requests permissions from the user by displaying a dialog box. This API uses an asynchronous callback to return the result.
-
-**System capability**: SystemCapability.Ability.AbilityRuntime.Core
-
-**Parameters**
-
-| Name| Type| Mandatory| Description|
-| -------- | -------- | -------- | -------- |
-| permissions | Array<string> | Yes| Permissions to request.|
-| callback | AsyncCallback<[PermissionRequestResult](js-apis-inner-application-permissionRequestResult.md)> | Yes| Callback used to return the result.|
-
-**Example**
-
- ```ts
- var permissions=['com.example.permission']
- this.context.requestPermissionsFromUser(permissions,(result) => {
- console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
- });
-
- ```
-
-
-## AbilityContext.requestPermissionsFromUser
-
-requestPermissionsFromUser(permissions: Array<string>) : Promise<PermissionRequestResult>;
-
-Requests permissions from the user by displaying a dialog box. This API uses a promise to return the result.
-
-**System capability**: SystemCapability.Ability.AbilityRuntime.Core
-
-**Parameters**
-
-| Name| Type| Mandatory| Description|
-| -------- | -------- | -------- | -------- |
-| permissions | Array<string> | Yes| Permissions to request.|
-
-**Return value**
-
-| Type| Description|
-| -------- | -------- |
-| Promise<[PermissionRequestResult](js-apis-inner-application-permissionRequestResult.md)> | Promise used to return the result.|
-
-**Example**
-
- ```ts
- var permissions=['com.example.permission']
- this.context.requestPermissionsFromUser(permissions).then((data) => {
- console.log('success:' + JSON.stringify(data));
- }).catch((error) => {
- console.log('failed:' + JSON.stringify(error));
- });
-
- ```
-
-
## AbilityContext.setMissionLabel
setMissionLabel(label: string, callback:AsyncCallback<void>): void;
@@ -1696,7 +1753,7 @@ Sets a label for this ability in the mission. This API uses an asynchronous call
```ts
this.context.setMissionLabel("test",(result) => {
- console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
+ console.log('setMissionLabel result:' + JSON.stringify(result));
});
```
@@ -1744,7 +1801,7 @@ Sets an icon for this ability in the mission. This API uses an asynchronous call
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| icon | image.PixelMap | Yes| Icon of the ability to set.|
+| icon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| Icon of the ability to set.|
| callback | AsyncCallback\ | Yes| Callback used to return the result.|
**Example**
@@ -1786,7 +1843,7 @@ Sets an icon for this ability in the mission. This API uses a promise to return
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| icon | image.PixelMap | Yes| Icon of the ability to set.|
+| icon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| Icon of the ability to set.|
**Return value**
diff --git a/en/application-dev/reference/apis/js-apis-ability-dataUriUtils.md b/en/application-dev/reference/apis/js-apis-ability-dataUriUtils.md
index 7b041a216de98edff7ee662ff229c0e16b70470e..f1301ad877dcf5a0bd2fec5ad5be10452ee88716 100644
--- a/en/application-dev/reference/apis/js-apis-ability-dataUriUtils.md
+++ b/en/application-dev/reference/apis/js-apis-ability-dataUriUtils.md
@@ -1,4 +1,4 @@
-# @ohos.ability.dataUriUtils
+# @ohos.ability.dataUriUtils (dataUriUtils)
The **DataUriUtils** module provides APIs to process URI objects. You can use the APIs to attach an ID to the end of a given URI and obtain, delete, or update the ID attached to the end of a given URI. This module will be replaced by the **app.ability.dataUriUtils** module in the near future. You are advised to use the **[@ohos.app.ability.dataUriUtils](js-apis-app-ability-dataUriUtils.md)** module.
diff --git a/en/application-dev/reference/apis/js-apis-ability-errorCode.md b/en/application-dev/reference/apis/js-apis-ability-errorCode.md
index c6e16f3f0cbe2bd0dd18dd5ea7fd72c8a0f44fb7..dc0e8ae8928a9191f70b555e84a3f58b09e4b876 100644
--- a/en/application-dev/reference/apis/js-apis-ability-errorCode.md
+++ b/en/application-dev/reference/apis/js-apis-ability-errorCode.md
@@ -1,9 +1,9 @@
-# @ohos.ability.errorCode
+# @ohos.ability.errorCode (ErrorCode)
-The **ErrorCode** module defines the error codes that can be used when the ability is started.
-
- **NOTE**
+The **ErrorCode** module defines the error codes that may be returned when an ability is started.
+> **NOTE**
+>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
@@ -14,13 +14,13 @@ import errorCode from '@ohos.ability.errorCode'
## ErrorCode
-Defines the error codes used when the ability is started.
+Enumerates the error codes that may be returned when an ability is started.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ------------------------------ | ---- | ---------------------------------------- |
-| NO_ERROR | 0 | No error occurs. |
+| NO_ERROR | 0 | No error. |
| INVALID_PARAMETER | -1 | Invalid parameter.|
| ABILITY_NOT_FOUND | -2 | The ability is not found.|
| PERMISSION_DENY | -3 | Permission denied. |
diff --git a/en/application-dev/reference/apis/js-apis-ability-featureAbility.md b/en/application-dev/reference/apis/js-apis-ability-featureAbility.md
index 2f1b927b6191b6b87b649f1b4a85067deb705541..b527edfcf7911fec83b4e8d5a01a2761772e95f1 100644
--- a/en/application-dev/reference/apis/js-apis-ability-featureAbility.md
+++ b/en/application-dev/reference/apis/js-apis-ability-featureAbility.md
@@ -1,6 +1,6 @@
-# @ohos.ability.featureAbility
+# @ohos.ability.featureAbility (FeatureAbility)
-The **FeatureAbility** module provides a UI for interacting with users. You can use APIs of this module to start a new ability, obtain the **dataAbilityHelper**, set a Page ability, obtain the window corresponding to this ability, and connect to a Service ability.
+The **FeatureAbility** module provides APIs that enable user interaction. You can use the APIs to start or terminate an ability, obtain a **dataAbilityHelper** object, obtain the window corresponding to the current ability, and connect to or disconnect from a ServiceAbility.
> **NOTE**
>
@@ -9,7 +9,7 @@ The **FeatureAbility** module provides a UI for interacting with users. You can
## Constraints
-APIs of the **FeatureAbility** module can be called only by Page abilities.
+The APIs of the **FeatureAbility** module can be called only by PageAbilities.
## Modules to Import
@@ -23,6 +23,11 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\)
Starts an ability. This API uses an asynchronous callback to return the result.
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
+
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
@@ -48,7 +53,7 @@ featureAbility.startAbility(
deviceId: "",
bundleName: "com.example.myapplication",
/* In the FA model, abilityName consists of package and ability names. */
- abilityName: "com.example.entry.secondAbility",
+ abilityName: "com.example.myapplication.secondAbility",
uri: ""
},
},
@@ -66,6 +71,11 @@ startAbility(parameter: StartAbilityParameter): Promise\
Starts an ability. This API uses a promise to return the result.
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
+
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
@@ -74,6 +84,12 @@ Starts an ability. This API uses a promise to return the result.
| --------- | ---------------------------------------- | ---- | -------------- |
| parameter | [StartAbilityParameter](js-apis-inner-ability-startAbilityParameter.md) | Yes | Ability to start.|
+**Return value**
+
+| Type | Description |
+| ---------------------------------------- | ------- |
+| Promise\ | Promise used to return the result.|
+
**Example**
```ts
@@ -90,7 +106,7 @@ featureAbility.startAbility(
deviceId: "",
bundleName: "com.example.myapplication",
/* In the FA model, abilityName consists of package and ability names. */
- abilityName: "com.example.entry.secondAbility",
+ abilityName: "com.example.myapplication.secondAbility",
uri: ""
},
}
@@ -105,6 +121,12 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper
Obtains a **dataAbilityHelper** object.
+Observe the following when using this API:
+ - To access a DataAbility of another application, the target application must be configured with associated startup (**AssociateWakeUp** set to **true**).
+ - If an application running in the background needs to call this API to access a DataAbility, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
+
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
@@ -117,7 +139,7 @@ Obtains a **dataAbilityHelper** object.
| Type | Description |
| ----------------- | ------------------------------- |
-| DataAbilityHelper | A utility class used to help other abilities access the Data ability.|
+| [DataAbilityHelper](js-apis-inner-ability-dataAbilityHelper.md) | A utility class used to help other abilities access the Data ability.|
**Example**
@@ -132,7 +154,12 @@ var dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\): void
-Starts an ability. This API uses an asynchronous callback to return the execution result when the ability is destroyed.
+Starts an ability. After the ability is started, you can call [terminateSelfWithResult](#featureabilityterminateselfwithresult7) to terminate the ability and return the result to the caller. If an exception occurs, for example, the ability is killed, exception information is returned to the caller. This API uses an asynchronous callback to return the result.
+
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -159,7 +186,7 @@ featureAbility.startAbilityForResult(
deviceId: "",
bundleName: "com.example.myapplication",
/* In the FA model, abilityName consists of package and ability names. */
- abilityName: "com.example.entry.secondAbility",
+ abilityName: "com.example.myapplication.secondAbility",
uri:""
},
},
@@ -173,7 +200,12 @@ featureAbility.startAbilityForResult(
startAbilityForResult(parameter: StartAbilityParameter): Promise\
-Starts an ability. This API uses a promise to return the execution result when the ability is destroyed.
+Starts an ability. After the ability is started, you can call [terminateSelfWithResult](#featureabilityterminateselfwithresult7) to terminate the ability and return the result to the caller. If an exception occurs, for example, the ability is killed, exception information is returned to the caller. This API uses a promise to return the result.
+
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -187,7 +219,7 @@ Starts an ability. This API uses a promise to return the execution result when t
| Type | Description |
| ---------------------------------------- | ------- |
-| Promise\<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Promised returned with the execution result.|
+| Promise\<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Promise used to return the result.|
**Example**
@@ -205,7 +237,7 @@ featureAbility.startAbilityForResult(
deviceId: "",
bundleName: "com.example.myapplication",
/* In the FA model, abilityName consists of package and ability names. */
- abilityName: "com.example.entry.secondAbility",
+ abilityName: "com.example.myapplication.secondAbility",
uri:"",
parameters:
{
@@ -229,7 +261,7 @@ featureAbility.startAbilityForResult(
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\): void
-Destroys this Page ability, with the result code and data sent to the caller. This API uses an asynchronous callback to return the result.
+Terminates this ability. If the ability is started by calling [startAbilityForResult](#featureabilitystartabilityforresult7), the result is returned to the caller in the form of a callback when **terminateSelfWithResult** is called. Otherwise, no result is returned to the caller when **terminateSelfWithResult** is called.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -237,7 +269,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th
| Name | Type | Mandatory | Description |
| --------- | ------------------------------- | ---- | -------------- |
-| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes | Ability to start.|
+| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes | Result returned after the ability is terminated.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
**Example**
@@ -257,7 +289,7 @@ featureAbility.terminateSelfWithResult(
deviceId: "",
bundleName: "com.example.myapplication",
/* In the FA model, abilityName consists of package and ability names. */
- abilityName: "com.example.entry.secondAbility",
+ abilityName: "com.example.myapplication.secondAbility",
uri:"",
parameters: {
mykey0: 2222,
@@ -281,7 +313,7 @@ featureAbility.terminateSelfWithResult(
terminateSelfWithResult(parameter: AbilityResult): Promise\
-Destroys this Page ability, with the result code and data sent to the caller. This API uses a promise to return the result.
+Terminates this ability. If the ability is started by calling [startAbilityForResult](#featureabilitystartabilityforresult7), the result is returned to the caller in the form of a promise when **terminateSelfWithResult** is called. Otherwise, no result is returned to the caller when **terminateSelfWithResult** is called.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -289,7 +321,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th
| Name | Type | Mandatory | Description |
| --------- | ------------------------------- | ---- | ------------- |
-| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes | Ability to start.|
+| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Yes | Result returned after the ability is terminated.|
**Return value**
@@ -314,7 +346,7 @@ featureAbility.terminateSelfWithResult(
deviceId: "",
bundleName: "com.example.myapplication",
/* In the FA model, abilityName consists of package and ability names. */
- abilityName: "com.example.entry.secondAbility",
+ abilityName: "com.example.myapplication.secondAbility",
uri:"",
parameters: {
mykey0: 2222,
@@ -345,7 +377,7 @@ Checks whether the main window of this ability has the focus. This API uses an a
| Name | Type | Mandatory | Description |
| -------- | ----------------------- | ---- | ---------------------------------------- |
-| callback | AsyncCallback\ | Yes | Callback used to return the result.
Returns **true** if the main window of this ability has the focus; returns **false** otherwise.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result.
If the main window has the focus, **true** is returned. Otherwise, **false** is returned.|
**Example**
@@ -368,7 +400,7 @@ Checks whether the main window of this ability has the focus. This API uses a pr
| Type | Description |
| ----------------- | ------------------------------------- |
-| Promise\ | Returns **true** if the main window of this ability has the focus; returns **false** otherwise.|
+| Promise\ | Promise used to return the result. If the main window has the focus, **true** is returned. Otherwise, **false** is returned.|
**Example**
@@ -383,7 +415,7 @@ featureAbility.hasWindowFocus().then((data) => {
getWant(callback: AsyncCallback\): void
-Obtains the **Want** object sent from this ability. This API uses an asynchronous callback to return the result.
+Obtains the Want corresponding to the ability to start. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -391,7 +423,7 @@ Obtains the **Want** object sent from this ability. This API uses an asynchronou
| Name | Type | Mandatory | Description |
| -------- | ----------------------------- | ---- | --------- |
-| callback | AsyncCallback\<[Want](js-apis-application-want.md)> | Yes | Callback used to return the result.|
+| callback | AsyncCallback\<[Want](js-apis-application-want.md)> | Yes | Callback used to return the Want.|
**Example**
@@ -406,7 +438,7 @@ featureAbility.getWant((err, data) => {
getWant(): Promise\
-Obtains the **Want** object sent from this ability. This API uses a promise to return the result.
+Obtains the Want corresponding to the ability to start. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -414,7 +446,7 @@ Obtains the **Want** object sent from this ability. This API uses a promise to r
| Type | Description |
| ----------------------- | ---------------- |
-| Promise\<[Want](js-apis-application-want.md)> | Promise used to return the result.|
+| Promise\<[Want](js-apis-application-want.md)> | Promise used to return the Want.|
**Example**
@@ -453,7 +485,7 @@ context.getBundleName((err, data) => {
terminateSelf(callback: AsyncCallback\): void
-Destroys this Page ability, with the result code and data sent to the caller. This API uses an asynchronous callback to return the result.
+Terminates this ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -478,7 +510,7 @@ featureAbility.terminateSelf(
terminateSelf(): Promise\
-Destroys this Page ability, with the result code and data sent to the caller. This API uses a promise to return the result.
+Terminates this ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -501,7 +533,13 @@ featureAbility.terminateSelf().then((data) => {
connectAbility(request: Want, options:ConnectOptions): number
-Connects this ability to a specific Service ability. This API uses an asynchronous callback to return the result.
+Connects this ability to a ServiceAbility.
+
+Observe the following when using this API:
+ - To connect to a ServiceAbility of another application, the target application must be configured with associated startup (**AssociateWakeUp** set to **true**)..
+ - If an application running in the background needs to call this API to connect to a ServiceAbility, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -509,14 +547,14 @@ Connects this ability to a specific Service ability. This API uses an asynchrono
| Name | Type | Mandatory | Description |
| ------- | -------------- | ---- | --------------------- |
-| request | [Want](js-apis-application-want.md) | Yes | Service ability to connect.|
-| options | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | Yes | Callback used to return the result. |
+| request | [Want](js-apis-application-want.md) | Yes | ServiceAbility to connect.|
+| options | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | Yes | Connection options. |
**Return value**
| Type | Description |
| ------ | -------------------- |
-| number | ID of the Service ability connected.|
+| number | ID of the connected ServiceAbility. The ID starts from 0 and is incremented by 1 each time a connection is set up.|
**Example**
@@ -536,7 +574,7 @@ var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
- abilityName: "ServiceAbilityA",
+ abilityName: "com.ix.ServiceAbility.ServiceAbilityA",
},
{
onConnect: onConnectCallback,
@@ -550,7 +588,7 @@ var connectId = featureAbility.connectAbility(
disconnectAbility(connection: number, callback:AsyncCallback\): void
-Disconnects this ability from a specific Service ability. This API uses an asynchronous callback to return the result.
+Disconnects this ability from a specific ServiceAbility. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -558,7 +596,7 @@ Disconnects this ability from a specific Service ability. This API uses an async
| Name | Type | Mandatory | Description |
| ---------- | -------------------- | ---- | ----------------------- |
-| connection | number | Yes | ID of the Service ability to disconnect.|
+| connection | number | Yes | ID of the ServiceAbility to disconnect.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
**Example**
@@ -578,7 +616,7 @@ function onFailedCallback(code){
var connectId = featureAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
- abilityName: "ServiceAbilityA",
+ abilityName: "com.ix.ServiceAbility.ServiceAbilityA",
},
{
onConnect: onConnectCallback,
@@ -597,7 +635,7 @@ var result = featureAbility.disconnectAbility(connectId,
disconnectAbility(connection: number): Promise\
-Disconnects this ability from a specific Service ability. This API uses a promise to return the result.
+Disconnects this ability from a specific ServiceAbility. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -605,7 +643,7 @@ Disconnects this ability from a specific Service ability. This API uses a promis
| Name | Type | Mandatory | Description |
| ---------- | ------ | ---- | ----------------------- |
-| connection | number | Yes | ID of the Service ability to disconnect.|
+| connection | number | Yes | ID of the ServiceAbility to disconnect.|
**Return value**
@@ -630,7 +668,7 @@ function onFailedCallback(code){
var connectId = featureAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
- abilityName: "ServiceAbilityA",
+ abilityName: "com.ix.ServiceAbility.ServiceAbilityA",
},
{
onConnect: onConnectCallback,
@@ -659,7 +697,7 @@ Obtains the window corresponding to this ability. This API uses an asynchronous
| Name | Type | Mandatory| Description |
| -------- | ----------------------------- | ---- | ----------------------------- |
-| callback | AsyncCallback\ | Yes | Callback used to return the window.|
+| callback | AsyncCallback\<[window.Window](js-apis-window.md#window)> | Yes | Callback used to return the window.|
**Example**
@@ -681,7 +719,7 @@ Obtains the window corresponding to this ability. This API uses a promise to ret
| Type | Description |
| ----------------------- | ----------------------------- |
-| Promise\ | Promise used to return the window.|
+| Promise\<[window.Window](js-apis-window.md#window)> | Promise used to return the window.|
**Example**
@@ -693,7 +731,7 @@ featureAbility.getWindow().then((data) => {
## AbilityWindowConfiguration
-The value is obtained through the **featureAbility.AbilityWindowConfiguration** API.
+Defines the window configuration corresponding to this ability. The configuration is obtained through **featureAbility.AbilityWindowConfiguration**.
**Example**
@@ -705,18 +743,18 @@ featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED
| Name | Value | Description |
| ---------------------------------------- | ---- | ---------------------------------------- |
-| WINDOW_MODE_UNDEFINED7+ | 0 | The Page ability is in an undefined window display mode.|
-| WINDOW_MODE_FULLSCREEN7+ | 1 | The Page ability is in full screen mode. |
-| WINDOW_MODE_SPLIT_PRIMARY7+ | 100 | The Page ability is displayed in the primary window when it is in split-screen mode.|
-| WINDOW_MODE_SPLIT_SECONDARY7+ | 101 | The Page ability is displayed in the secondary window when it is in split-screen mode.|
-| WINDOW_MODE_FLOATING7+ | 102 | The Page ability is displayed in floating window mode.|
+| WINDOW_MODE_UNDEFINED7+ | 0 | The PageAbility is in an undefined window display mode.|
+| WINDOW_MODE_FULLSCREEN7+ | 1 | The PageAbility is in full screen mode. |
+| WINDOW_MODE_SPLIT_PRIMARY7+ | 100 | The PageAbility is displayed in the primary window when it is in split-screen mode.|
+| WINDOW_MODE_SPLIT_SECONDARY7+ | 101 | The PageAbility is displayed in the secondary window when it is in split-screen mode.|
+| WINDOW_MODE_FLOATING7+ | 102 | The PageAbility is displayed in floating window mode.|
## AbilityStartSetting
-The **AbilityStartSetting** attribute is an object defined as [key: string]: any. The key is a type of **AbilityStartSetting**, and the value is a type of **AbilityWindowConfiguration**.
+Defines the window attribute corresponding to this ability. The **abilityStartSetting** attribute is an object defined in the format of [**key: string]: any**, where **key** is an enumerated value of **AbilityStartSetting** and **value** is an enumerated value of **AbilityWindowConfiguration**.
-The value is obtained through the **featureAbility.AbilityStartSetting** API.
+The value is obtained through **featureAbility.AbilityStartSetting**.
**Example**
@@ -734,7 +772,7 @@ featureAbility.AbilityStartSetting.BOUNDS_KEY
## ErrorCode
-Enumerates error codes.
+Enumerates the error codes.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -743,12 +781,12 @@ Enumerates error codes.
| NO_ERROR7+ | 0 | No error occurs.|
| INVALID_PARAMETER7+ | -1 | Invalid parameter.|
| ABILITY_NOT_FOUND7+ | -2 | The ability is not found.|
-| PERMISSION_DENY7+ | -3 | The request is denied.|
+| PERMISSION_DENY7+ | -3 | Permission denied.|
## DataAbilityOperationType
-Enumerates operation types of the Data ability.
+Enumerates the operation types of a DataAbility. The DataAbility can use an enumerated value to specify the operation type when operating data in batches.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -761,23 +799,25 @@ Enumerates operation types of the Data ability.
## flags
+Enumerates the flags that specify how the Want will be handled.
+
**System capability**: SystemCapability.Ability.AbilityBase
| Name | Value | Description |
| ------------------------------------ | ---------- | ---------------------------------------- |
-| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI. |
-| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI. |
+| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Grants the permission to read the URI. |
+| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Grants the permission to write data to the URI. |
| 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 migrated to a remote device. |
+| FLAG_ABILITY_CONTINUATION | 0x00000008 | Continues the ability on a remote device. |
| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS. |
-| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates whether to enable an ability. |
-| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.
**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.
**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.
**System API**: This is a system API and cannot be called by third-party applications. |
+| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates whether the FormAbility is enabled. |
+| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Grants the permission to make the URI persistent.
**System API**: This is a system API and cannot be called by third-party applications. |
+| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Grants the permission to verify URIs by prefix matching.
**System API**: This is a system API and cannot be called by third-party applications. |
+| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Indicates the support for cross-device startup in the distributed scheduler. |
+| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the ability is started in the foreground regardless of whether the host application is started.
**System API**: This is a system API and cannot be called by third-party applications. |
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible. |
| 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) and must be used together with **flag_ABILITY_NEW_MISSION**.|
-| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on the historical 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.|
+| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on an existing mission stack. |
+| FLAG_ABILITY_MISSION_TOP | 0x20000000 | Reuses an ability instance if it is on the top of an existing mission stack; creates an ability instance otherwise.|
diff --git a/en/application-dev/reference/apis/js-apis-ability-particleAbility.md b/en/application-dev/reference/apis/js-apis-ability-particleAbility.md
index 46355b926228755520d3d215d4275af03ecd88bc..7d00454ea5ce5b0051c2fff6856f9653be89b455 100644
--- a/en/application-dev/reference/apis/js-apis-ability-particleAbility.md
+++ b/en/application-dev/reference/apis/js-apis-ability-particleAbility.md
@@ -1,6 +1,6 @@
-# @ohos.ability.particleAbility
+# @ohos.ability.particleAbility (ParticleAbility)
-The **particleAbility** module provides APIs for Service abilities. You can use the APIs to start and terminate a Particle ability, obtain a **dataAbilityHelper** object, connect the current ability to a specific Service ability, and disconnect the current ability from a specific Service ability.
+The **particleAbility** module provides APIs for operating a ServiceAbility. You can use the APIs to start and terminate a ParticleAbility, obtain a **dataAbilityHelper** object, and connect to or disconnect from a ServiceAbility.
> **NOTE**
>
@@ -21,7 +21,12 @@ import particleAbility from '@ohos.ability.particleAbility'
startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\): void
-Starts a Particle ability. This API uses an asynchronous callback to return the result.
+Starts a ParticleAbility. This API uses an asynchronous callback to return the result.
+
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -48,7 +53,7 @@ particleAbility.startAbility(
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.Data",
- abilityName: "com.example.Data.MainAbility",
+ abilityName: "EntryAbility",
uri: ""
},
},
@@ -62,7 +67,12 @@ particleAbility.startAbility(
startAbility(parameter: StartAbilityParameter): Promise\;
-Starts a Particle ability. This API uses a promise to return the result.
+Starts a ParticleAbility. This API uses a promise to return the result.
+
+Observe the following when using this API:
+ - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -94,7 +104,7 @@ particleAbility.startAbility(
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.Data",
- abilityName: "com.example. Data.MainAbility",
+ abilityName: "EntryAbility",
uri: ""
},
},
@@ -107,7 +117,7 @@ particleAbility.startAbility(
terminateSelf(callback: AsyncCallback\): void
-Terminates this Particle ability. This API uses an asynchronous callback to return the result.
+Terminates this ParticleAbility. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -133,7 +143,7 @@ particleAbility.terminateSelf(
terminateSelf(): Promise\
-Terminates this Particle ability. This API uses a promise to return the result.
+Terminates this ParticleAbility. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -161,6 +171,12 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper
Obtains a **dataAbilityHelper** object.
+Observe the following when using this API:
+ - To access a DataAbility of another application, the target application must be configured with associated startup (**AssociateWakeUp** set to **true**).
+ - If an application running in the background needs to call this API to access a DataAbility, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
+
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
@@ -173,7 +189,7 @@ Obtains a **dataAbilityHelper** object.
| Type | Description |
| ----------------- | -------------------------------------------- |
-| DataAbilityHelper | A utility class used to help other abilities access a Data ability.|
+| [DataAbilityHelper](js-apis-inner-ability-dataAbilityHelper.md) | A utility class used to help other abilities access a DataAbility.|
**Example**
@@ -222,7 +238,7 @@ let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
- abilityName: "com.example.myapplication.MainAbility"
+ abilityName: "EntryAbility"
}
],
operationType: wantAgent.OperationType.START_ABILITY,
@@ -283,7 +299,7 @@ let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
- abilityName: "com.example.myapplication.MainAbility"
+ abilityName: "EntryAbility"
}
],
operationType: wantAgent.OperationType.START_ABILITY,
@@ -349,7 +365,7 @@ particleAbility.cancelBackgroundRunning(callback);
cancelBackgroundRunning(): Promise<void>;
-Requests a continuous task from the system. This API uses a promise to return the result. You are advised to use the new API [backgroundTaskManager.stopBackgroundRunning](js-apis-backgroundTaskManager.md#backgroundtaskmanagerstopbackgroundrunning8-1).
+Requests to cancel a continuous task from the system. This API uses a promise to return the result. You are advised to use the new API [backgroundTaskManager.stopBackgroundRunning](js-apis-backgroundTaskManager.md#backgroundtaskmanagerstopbackgroundrunning8-1).
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
@@ -376,7 +392,13 @@ particleAbility.cancelBackgroundRunning().then(() => {
connectAbility(request: Want, options:ConnectOptions): number
-Connects this ability to a specific Service ability. This API uses a callback to return the result.
+Connects this ability to a specific ServiceAbility.
+
+Observe the following when using this API:
+ - To connect to a ServiceAbility of another application, the target application must be configured with associated startup (**AssociateWakeUp** set to **true**)..
+ - If an application running in the background needs to call this API to connect to a ServiceAbility, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
+ - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
+ - For details about the startup rules for the components in the FA model, see [Component Startup Rules (FA Model)](../../application-models/component-startup-rules-fa.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -384,23 +406,14 @@ Connects this ability to a specific Service ability. This API uses a callback to
| Name | Type | Mandatory| Description |
| ------- | -------------- | ---- | ---------------------------- |
-| request | [Want](js-apis-application-want.md) | Yes | Service ability to connect.|
-| options | ConnectOptions | Yes | Callback used to return the result. |
-
-
-ConnectOptions
+| request | [Want](js-apis-application-want.md) | Yes | ServiceAbility to connect.|
+| options | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | Yes | Connection options. |
-**System capability**: SystemCapability.Ability.AbilityRuntime.Core
-
-| Name | Type | Mandatory | Description |
-| ------------ | -------- | ---- | ------------------------- |
-| onConnect | function | Yes | Callback invoked when the connection is successful. |
-| onDisconnect | function | Yes | Callback invoked when the connection fails. |
-| onFailed | function | Yes | Callback invoked when **connectAbility** fails to be called.|
**Example**
```ts
+import particleAbility from '@ohos.ability.particleAbility'
import rpc from '@ohos.rpc'
function onConnectCallback(element, remote) {
@@ -439,7 +452,7 @@ particleAbility.disconnectAbility(connId).then((data) => {
disconnectAbility(connection: number, callback:AsyncCallback\): void;
-Disconnects this ability from the Service ability. This API uses a callback to return the result.
+Disconnects this ability from a specific ServiceAbility. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -452,7 +465,8 @@ Disconnects this ability from the Service ability. This API uses a callback to r
**Example**
```ts
-import rpc from '@ohos.rpc'
+import particleAbility from '@ohos.ability.particleAbility';
+import rpc from '@ohos.rpc';
function onConnectCallback(element, remote) {
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
@@ -489,7 +503,7 @@ var result = particleAbility.disconnectAbility(connId).then((data) => {
disconnectAbility(connection: number): Promise\;
-Disconnects this ability from the Service ability. This API uses a promise to return the result.
+Disconnects this ability from a specific ServiceAbility. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
@@ -502,7 +516,8 @@ Disconnects this ability from the Service ability. This API uses a promise to re
**Example**
```ts
-import rpc from '@ohos.rpc'
+import particleAbility from '@ohos.ability.particleAbility';
+import rpc from '@ohos.rpc';
function onConnectCallback(element, remote) {
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
@@ -538,7 +553,7 @@ particleAbility.disconnectAbility(connId).then((data) => {
## ErrorCode
-Enumerates error codes.
+Enumerates the error codes.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
diff --git a/en/application-dev/reference/apis/js-apis-ability-wantConstant.md b/en/application-dev/reference/apis/js-apis-ability-wantConstant.md
index 30fb8b3b970b22513f2dd520d43a11b76f66e47d..87b52688c5bec0a80bc44d9c8dcba63fe00283f2 100644
--- a/en/application-dev/reference/apis/js-apis-ability-wantConstant.md
+++ b/en/application-dev/reference/apis/js-apis-ability-wantConstant.md
@@ -1,4 +1,4 @@
-# @ohos.ability.wantConstant
+# @ohos.ability.wantConstant (wantConstant)
The **wantConstant** module provides the actions, entities, and flags used in **Want** objects.
@@ -14,7 +14,7 @@ import wantConstant from '@ohos.ability.wantConstant';
## wantConstant.Action
-Enumerates the action constants of the **Want** object.
+Enumerates the action constants of the **Want** object. **action** specifies the operation to execute.
**System capability**: SystemCapability.Ability.AbilityBase
@@ -57,7 +57,7 @@ Enumerates the action constants of the **Want** object.
## wantConstant.Entity
-Enumerates the entity constants of the **Want** object.
+Enumerates the entity constants of the **Want** object. **entity** specifies additional information of the target ability.
**System capability**: SystemCapability.Ability.AbilityBase
@@ -72,25 +72,25 @@ Enumerates the entity constants of the **Want** object.
## wantConstant.Flags
-Describes flags.
+Enumerates the flags that specify how the Want will be handled.
**System capability**: SystemCapability.Ability.AbilityBase
| Name | Value | Description |
| ------------------------------------ | ---------- | ------------------------------------------------------------ |
-| 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_READ_URI_PERMISSION | 0x00000001 | Grants the permission to read the URI. |
+| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Grants the permission to write data to the URI. |
| 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.
**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.
**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_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Grants the permission to make the URI persistent.
**System API**: This is a system API and cannot be called by third-party applications. |
+| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Grants the permission to verify URIs by prefix matching.
**System API**: This is a system API and cannot be called by third-party applications.|
+| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Indicates the support for cross-device startup in the distributed scheduler. |
+| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the ServiceAbility is started regardless of whether the host application has been started. |
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that ability continuation is reversible.
**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) and must be used together with **flag_ABILITY_NEW_MISSION**.|
-| 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.|
+| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on the history mission stack. |
+| FLAG_ABILITY_MISSION_TOP | 0x20000000 | Reuses an ability instance if it is on the top of an existing mission stack; creates an ability instance otherwise.|
diff --git a/en/application-dev/reference/apis/js-apis-abilityAccessCtrl.md b/en/application-dev/reference/apis/js-apis-abilityAccessCtrl.md
index ed59083949a8d151e7e007e9b2475d20e91446e6..88ffbc6255e15705d88259e65392fa9e4f6a3193 100644
--- a/en/application-dev/reference/apis/js-apis-abilityAccessCtrl.md
+++ b/en/application-dev/reference/apis/js-apis-abilityAccessCtrl.md
@@ -1,4 +1,4 @@
-# @ohos.abilityAccessCtrl (Ability Access Control)
+# @ohos.abilityAccessCtrl (Application Access Control)
The **AbilityAccessCtrl** module provides APIs for application permission management, including authentication, authorization, and revocation.
@@ -40,7 +40,7 @@ Implements ability access control.
checkAccessToken(tokenID: number, permissionName: Permissions): Promise<GrantStatus>
-Checks whether an application has the specified permission. This API uses a promise to return the result.
+Checks whether a permission is granted to an application. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.AccessToken
@@ -48,8 +48,8 @@ Checks whether an application has the specified permission. This API uses a prom
| Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | ------------------------------------------ |
-| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md). |
-| permissionName | Permissions | Yes | Permission to check.|
+| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
+| permissionName | Permissions | Yes | Permission to check. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
**Return value**
@@ -71,7 +71,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
-let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
+let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
try {
atManager.checkAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS").then((data) => {
console.log(`checkAccessToken success, data->${JSON.stringify(data)}`);
@@ -87,7 +87,7 @@ try {
verifyAccessTokenSync(tokenID: number, permissionName: Permissions): GrantStatus
-Verifies whether an application has the specified permission. This API returns the result synchronously.
+Verifies whether a permission is granted to an application. This API returns the result synchronously.
**System capability**: SystemCapability.Security.AccessToken
@@ -95,8 +95,8 @@ Verifies whether an application has the specified permission. This API returns t
| Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | ------------------------------------------ |
-| tokenID | number | Yes | Token ID of the application. |
-| permissionName | Permissions | Yes | Name of the permission to verify.|
+| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
+| permissionName | Permissions | Yes | Permission to verify. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
**Return value**
@@ -116,7 +116,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
```js
let atManager = abilityAccessCtrl.createAtManager();
-let tokenID = 0;
+let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let data = atManager.verifyAccessTokenSync(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
console.log(`data->${JSON.stringify(data)}`);
```
@@ -137,8 +137,8 @@ Grants a user_grant permission to an application. This API uses a promise to ret
| Name | Type | Mandatory| Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ |
-| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md). |
-| permissionName | Permissions | Yes | Name of the permission to grant.|
+| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
+| permissionName | Permissions | Yes | Permission to grant. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionFlag | number | Yes | Permission flag. The value **1** means that the permission request dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
**Return value**
@@ -165,7 +165,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
-let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
+let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let permissionFlag = 1;
try {
atManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlag).then(() => {
@@ -194,10 +194,10 @@ Grants a user_grant permission to an application. This API uses an asynchronous
| Name | Type | Mandatory| Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ |
-| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md).|
-| permissionName | Permissions | Yes | Name of the permission to grant.|
+| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
+| permissionName | Permissions | Yes | Permission to grant. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionFlag | number | Yes | Permission flag. The value **1** means that the permission request dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the permission is granted successfully, **err** is **undefine**. Otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the permission is granted successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
@@ -208,7 +208,8 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100002 | TokenId does not exist. |
| 12100003 | Permission does not exist. |
-| 12100006 | The specified application does not support the permissions granted or ungranted as specified. |
+| 12100006 | The application specified by the tokenID is not allowed to be granted with the specified permission. Either the application is a sandbox or the tokenID is from a remote device. |
+| 12100007 | Service is abnormal. |
**Example**
@@ -216,7 +217,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
-let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
+let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let permissionFlag = 1;
try {
atManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlag, (err, data) => {
@@ -247,8 +248,8 @@ Revokes a user_grant permission from an application. This API uses a promise to
| Name | Type | Mandatory| Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ |
-| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md). |
-| permissionName | Permissions | Yes | Name of the permission to revoke.|
+| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
+| permissionName | Permissions | Yes | Permission to revoke. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionFlag | number | Yes | Permission flag. The value **1** means that the permission request dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
**Return value**
@@ -275,7 +276,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
-let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
+let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let permissionFlag = 1;
try {
atManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlag).then(() => {
@@ -304,10 +305,10 @@ Revokes a user_grant permission from an application. This API uses an asynchrono
| Name | Type | Mandatory| Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ |
-| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md). |
-| permissionName | Permissions | Yes | Name of the permission to revoke.|
+| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
+| permissionName | Permissions | Yes | Permission to revoke. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionFlag | number | Yes | Permission flag. The value **1** means that the permission request dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the permission is revoked successfully, **err** is **undefine**. Otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the permission is revoked successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
@@ -318,7 +319,8 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100002 | TokenId does not exist. |
| 12100003 | Permission does not exist. |
-| 12100006 | The specified application does not support the permissions granted or ungranted as specified. |
+| 12100006 | The application specified by the tokenID is not allowed to be revoked with the specified permission. Either the application is a sandbox or the tokenID is from a remote device. |
+| 12100007 | Service is abnormal. |
**Example**
@@ -326,7 +328,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
-let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
+let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let permissionFlag = 1;
try {
atManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlag, (err, data) => {
@@ -357,8 +359,8 @@ Obtains the flags of the specified permission of an application. This API uses a
| Name | Type | Mandatory| Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ |
-| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md). |
-| permissionName | Permissions | Yes | Name of the permission to query.|
+| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
+| permissionName | Permissions | Yes | Target permission. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
**Return value**
@@ -375,7 +377,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100002 | The specified tokenID does not exist. |
| 12100003 | The specified permission does not exist. |
-| 12100006 | The operation is not allowd. Either the application is a sandbox or the tokenID is from a remote device. |
+| 12100006 | The operation is not allowed. Either the application is a sandbox or the tokenID is from a remote device. |
| 12100007 | Service is abnormal. |
**Example**
@@ -384,7 +386,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
-let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
+let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
try {
atManager.getPermissionFlags(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS").then((data) => {
console.log(`getPermissionFlags success, data->${JSON.stringify(data)}`);
@@ -525,7 +527,7 @@ try {
verifyAccessToken(tokenID: number, permissionName: Permissions): Promise<GrantStatus>
-Verifies whether an application has the specified permission. This API uses a promise to return the result.
+Verifies whether a permission is granted to an application. This API uses a promise to return the result.
> **NOTE**
You are advised to use [checkAccessToken](#checkaccesstoken9).
@@ -535,8 +537,8 @@ Verifies whether an application has the specified permission. This API uses a pr
| Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | ------------------------------------------ |
-| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md). |
-| permissionName | Permissions | Yes | Name of the permission to verify. Only valid permission names are supported.|
+| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
+| permissionName | Permissions | Yes | Permission to verify. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
**Return value**
@@ -550,18 +552,107 @@ Verifies whether an application has the specified permission. This API uses a pr
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
-let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
+let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let promise = atManager.verifyAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
promise.then(data => {
console.log(`promise: data->${JSON.stringify(data)}`);
});
```
+### requestPermissionsFromUser9+
+
+requestPermissionsFromUser(context: Context, permissions: Array<Permissions>, requestCallback: AsyncCallback<PermissionRequestResult>) : void;
+
+Requests user authorization in a dialog box. This API uses an asynchronous callback to return the result.
+
+**Model restriction**: This API can be used only in the stage model.
+
+**System capability**: SystemCapability.Security.AccessToken
+
+**Parameters**
+
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| context | Context | Yes| Ability context of the application that requests the permission.|
+| permissions | Array<Permissions> | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
+| callback | AsyncCallback<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Yes| Callback invoked to return the result.|
+
+**Error codes**
+
+For details about the error codes, see [Ability Access Control Error Codes](../errorcodes/errorcode-access-token.md).
+| ID| Error Message|
+| -------- | -------- |
+| 12100001 | Parameter invalid. |
+
+**Example**
+
+ ```js
+import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
+let atManager = abilityAccessCtrl.createAtManager();
+try {
+ atManager.requestPermissionsFromUser(this.context, ["ohos.permission.CAMERA"], (err, data)=>{
+ console.info("data:" + JSON.stringify(data));
+ console.info("data permissions:" + data.permissions);
+ console.info("data authResults:" + data.authResults);
+ });
+} catch(err) {
+ console.log(`catch err->${JSON.stringify(err)}`);
+}
+ ```
+
+### requestPermissionsFromUser9+
+
+requestPermissionsFromUser(context: Context, permissions: Array<Permissions>) : Promise<PermissionRequestResult>;
+
+Requests user authorization in a dialog box. This API uses a promise to return the result.
+
+**Model restriction**: This API can be used only in the stage model.
+
+**System capability**: SystemCapability.Security.AccessToken
+
+**Parameters**
+
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| context | Context | Yes| Ability context of the application that requests the permission.|
+| permissions | Array<Permissions> | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
+
+**Return value**
+
+| Type| Description|
+| -------- | -------- |
+| Promise<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Promise used to return the result.|
+
+**Error codes**
+
+For details about the error codes, see [Ability Access Control Error Codes](../errorcodes/errorcode-access-token.md).
+| ID| Error Message|
+| -------- | -------- |
+| 12100001 | Parameter invalid. |
+
+**Example**
+
+ ```js
+import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
+let atManager = abilityAccessCtrl.createAtManager();
+try {
+ atManager.requestPermissionsFromUser(this.context, ["ohos.permission.CAMERA"]).then((data) => {
+ console.info("data:" + JSON.stringify(data));
+ console.info("data permissions:" + data.permissions);
+ console.info("data authResults:" + data.authResults);
+ }).catch((err) => {
+ console.info("data:" + JSON.stringify(err));
+ })
+} catch(err) {
+ console.log(`catch err->${JSON.stringify(err)}`);
+}
+ ```
+
### verifyAccessToken(deprecated)
verifyAccessToken(tokenID: number, permissionName: string): Promise<GrantStatus>
-Verifies whether an application has the specified permission. This API uses a promise to return the result.
+Verifies whether a permission is granted to an application. This API uses a promise to return the result.
> NOTE
This API is deprecated since API version 9. You are advised to use [checkAccessToken](#checkaccesstoken9).
@@ -571,8 +662,8 @@ Verifies whether an application has the specified permission. This API uses a pr
| Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | ------------------------------------------ |
-| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md). |
-| permissionName | string | Yes | Name of the permission to verify.|
+| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
+| permissionName | string | Yes | Permission to check.|
**Return value**
@@ -586,7 +677,7 @@ Verifies whether an application has the specified permission. This API uses a pr
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
-let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
+let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let promise = atManager.verifyAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
promise.then(data => {
console.log(`promise: data->${JSON.stringify(data)}`);
@@ -629,4 +720,4 @@ Defines the detailed permission grant state change information.
| -------------- | ------------------------- | ---- | ---- | ------------------ |
| change | [PermissionStateChangeType](#permissionstatechangetype9) | Yes | No | Operation that triggers the permission grant state change. |
| tokenID | number | Yes | No | Token ID of the application whose permission grant state changes are subscribed.|
-| permissionName | Permissions | Yes | No | Name of the permission whose grant state is changed.|
+| permissionName | Permissions | Yes | No | permission whose grant state is changed. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
diff --git a/en/application-dev/reference/apis/js-apis-accessibility-extension-context.md b/en/application-dev/reference/apis/js-apis-accessibility-extension-context.md
deleted file mode 100644
index 9fee7500eae2ec8435f0c3bdc2b48c986b14686a..0000000000000000000000000000000000000000
--- a/en/application-dev/reference/apis/js-apis-accessibility-extension-context.md
+++ /dev/null
@@ -1,379 +0,0 @@
-# AccessibilityExtensionContext
-
-The **AccessibilityExtensionContext** module, inherited from **ExtensionContext**, provides context for **Accessibility Extension** abilities.
-
-You can use the APIs of this module to configure the concerned information, obtain root information, and inject gestures.
-
-> **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 can be used only in the stage model.
-
-## Usage
-
-Before using the **AccessibilityExtensionContext** module, you must define a child class that inherits from **AccessibilityExtensionAbility**.
-
-```js
-import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility'
-class MainAbility extends AccessibilityExtensionAbility {
- onConnect(): void {
- console.log("AxExtensionAbility onConnect");
- let axContext = this.context;
- }
-}
-```
-
-## FocusDirection
-
-Enumerates the focus directions.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-| Name | Description |
-| -------- | ------- |
-| up | Search for the next focusable item above the current item in focus.|
-| down | Search for the next focusable item below the current item in focus.|
-| left | Search for the next focusable item on the left of the current item in focus.|
-| right | Search for the next focusable item on the right of the current item in focus.|
-| forward | Search for the next focusable item before the current item in focus.|
-| backward | Search for the next focusable item after the current item in focus.|
-
-## FocusType
-
-Enumerates the focus types.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-| Name | Description |
-| ------------- | ----------- |
-| accessibility | Accessibility focus.|
-| normal | Normal focus. |
-
-## Rect
-
-Defines a rectangle.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-| Name | Type | Readable | Writable | Description |
-| ------ | ------ | ---- | ---- | --------- |
-| left | number | Yes | No | Left boundary of the rectangle.|
-| top | number | Yes | No | Top boundary of the rectangle.|
-| width | number | Yes | No | Width of the rectangle. |
-| height | number | Yes | No | Height of the rectangle. |
-
-## WindowType
-
-Enumerates the window types.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-| Name | Description |
-| ----------- | --------- |
-| application | Application window.|
-| system | System window.|
-
-## AccessibilityExtensionContext.setTargetBundleName
-
-setTargetBundleName(targetNames: Array\): Promise\;
-
-Sets the concerned target bundle.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-**Parameters**
-
-| Name | Type | Mandatory | Description |
-| ----------- | ------------------- | ---- | -------- |
-| targetNames | Array<string> | Yes | Name of the target bundle.|
-
-**Return value**
-
-| Type | Description |
-| ---------------------- | --------------------- |
-| Promise<boolean> | Promise used to return the result.|
-
-**Example**
-
-```ts
-this.context.setTargetBundleName(['com.ohos.mms']);
-```
-
-## AccessibilityExtensionContext.getFocusElement
-
-getFocusElement(isAccessibilityFocus?: boolean): Promise\;
-
-Obtains the focus element.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-**Parameters**
-
-| Name | Type | Mandatory | Description |
-| -------------------- | ------- | ---- | ------------------- |
-| isAccessibilityFocus | boolean | No | Whether the obtained focus element is an accessibility focus. The default value is **false**.|
-
-**Return value**
-
-| Type | Description |
-| ----------------------------------- | ---------------------- |
-| Promise<AccessibilityElement> | Promise used to return the current focus element.|
-
-**Example**
-
-```ts
-this.context.getFocusElement().then(focusElement => {
- console.log("AxExtensionAbility getFocusElement success");
-})
-```
-
-## AccessibilityExtensionContext.getWindowRootElement
-
-getWindowRootElement(windowId?: number): Promise\;
-
-Obtains the root element of a window.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-**Parameters**
-
-| Name | Type | Mandatory | Description |
-| -------- | ------ | ---- | --------------------------- |
-| windowId | number | No | Window for which you want to obtain the root element. If this parameter is not specified, it indicates the current active window.|
-
-**Return value**
-
-| Type | Description |
-| ----------------------------------- | ----------------------- |
-| Promise<AccessibilityElement> | Promise used to return the root element.|
-
-**Example**
-
-```ts
-this.context.getWindowRootElement().then(rootElement => {
- console.log("AxExtensionAbility getWindowRootElement success");
-})
-```
-
-## AccessibilityExtensionContext.getWindows
-
-getWindows(displayId?: number): Promise>;
-
-Obtains the list of windows visible to users.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-**Parameters**
-
-| Name | Type | Mandatory | Description |
-| --------- | ------ | ---- | ------------------------- |
-| displayId | number | No | Screen from which the window information is obtained. If this parameter is not specified, it indicates the default home screen.|
-
-**Return value**
-
-| Type | Description |
-| ---------------------------------------- | ------------------------ |
-| Promise<Array<AccessibilityElement>> | Promise used to return the window list. |
-
-**Example**
-
-```ts
-this.context.getWindows().then(windows => {
- console.log("AxExtensionAbility getWindows success");
-})
-```
-
-## AccessibilityExtensionContext.injectGesture
-
-injectGesture(gesturePath: GesturePath, callback: AsyncCallback\): void
-
-Injects a gesture.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-**Parameters**
-
-| Name | Type | Mandatory | Description |
-| ----------- | ---------------------------------------- | ---- | -------------- |
-| gesturePath | [GesturePath](js-apis-application-AccessibilityExtensionAbility.md#GesturePath) | Yes | Path of the gesture to inject. |
-| callback | AsyncCallback<void> | Yes | Callback used to return the result.|
-
-**Example**
-
-```ts
-let gesturePath = new GesturePath(100);
-for (let i = 0; i < 10; i++) {
- let gesturePoint = new GesturePosition(100, i * 200);
- gesturePath.positions.push(gesturePoint);
-}
-this.context.gestureInject(gesturePath, (result) => {
- console.info('gestureInject result: ' + result);
-})
-```
-## AccessibilityElement.attributeNames
-
-attributeNames\(): Promise\>;
-
-Obtains all attribute names of this element.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-**Return value**
-
-| Type | Description |
-| ---------------------------------------- | ------------------------ |
-| Promise<Array<T>> | Promise used to return all attribute names of the element.|
-
-**Example**
-
-```ts
-let accessibilityElement;
-try {
- accessibilityElement.attributeNames().then((values) => {
- console.log("get attribute names success");
- }).catch((err) => {
- console.log("get attribute names err: " + JSON.stringify(err));
- });
-} catch (e) {
- console.log("An unexpected error occurred. Error:" + e);
-}
-```
-
-## AccessibilityElement.attributeValue
-
-attributeValue\(attributeName: T): Promise\;
-
-Obtains the attribute value based on an attribute name.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-**Parameters**
-
-| Name | Type | Mandatory | Description |
-| ----------- | ---------------------------------------- | ---- | -------------- |
-| attributeName | T | Yes | Attribute name. |
-
-**Return value**
-
-| Type | Description |
-| ---------------------------------------- | ------------------------ |
-| Promise<Array<ElementAttributeValues[T]>> | Promise used to return the attribute value.|
-
-**Example**
-
-```ts
-let accessibilityElement;
-try {
- let attributeName = 'name';
- accessibilityElement.attributeValue(attributeName).then((value) => {
- console.log("get attribute value by name success");
- }).catch((err) => {
- console.log("get attribute value by name err: " + JSON.stringify(err));
- });
-} catch (e) {
- console.log("An unexpected error occurred. Error:" + e);
-}
-```
-
-## AccessibilityElement.actionNames
-
-actionNames(): Promise\>;
-
-Obtains the names of all actions supported by this element.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-**Return value**
-
-| Type | Description |
-| ---------------------------------------- | ------------------------ |
-| Promise<Array<string>> | Promise used to return the names of all actions supported by the element.|
-
-**Example**
-
-```ts
-let accessibilityElement;
-try {
- accessibilityElement.actionNames().then((values) => {
- console.log("get action names success");
- }).catch((err) => {
- console.log("get action names err: " + JSON.stringify(err));
- });
-} catch (e) {
- console.log("An unexpected error occurred. Error:" + e);
-}
-```
-
-## AccessibilityElement.performAction
-
-performAction(actionName: string, parameters?: object): Promise\;
-
-Performs an action based on the specified action name.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-**Parameters**
-
-| Name | Type | Mandatory | Description |
-| ----------- | ---------------------------------------- | ---- | -------------- |
-| actionName | string | Yes | Action name. |
-| parameters | object | No | Parameter required for performing the target action. |
-
-**Return value**
-
-| Type | Description |
-| ---------------------------------------- | ------------------------ |
-| Promise<Array<boolean>> | Promise used to return the result.|
-
-**Example**
-
-```ts
-let accessibilityElement;
-try {
-
- accessibilityElement.performAction('action').then((result) => {
- console.info('perform action result: ' + result);
- }).catch((err) => {
- console.log("perform action err: " + JSON.stringify(err));
- });
-} catch (e) {
- console.log("An unexpected error occurred. Error:" + e);
-}
-```
-
-## AccessibilityElement.findElement
-
-findElement(type: 'content', condition: string): Promise\>;
-
-Queries the information about this element based on the specified information type and condition.
-
-**System capability**: SystemCapability.BarrierFree.Accessibility.Core
-
-**Parameters**
-
-| Name | Type | Mandatory | Description |
-| ----------- | ---------------------------------------- | ---- | -------------- |
-| type | string | Yes | Information type. The value is fixed at **'content'**. |
-| condition | string | Yes | Search criteria. |
-
-**Return value**
-
-| Type | Description |
-| ---------------------------------------- | ------------------------ |
-| Promise<Array<T>> | Promise used to return the result.|
-
-**Example**
-
-```ts
-let accessibilityElement;
-try {
- let condition = 'keyword';
- accessibilityElement.findElement('content', condition).then((values) => {
- console.log("find element success");
- }).catch((err) => {
- console.log("find element err: " + JSON.stringify(err));
- });
-} catch (e) {
- console.log("An unexpected error occurred. Error:" + e);
-}
-```
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-ability.md b/en/application-dev/reference/apis/js-apis-app-ability-ability.md
index 59e1e229f2e8396ae11584dee80a439ea74fdf6b..cfa11ddc30560c1ffa6a03eb8efccb8ea60b6d5b 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-ability.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-ability.md
@@ -1,18 +1,12 @@
-# @ohos.app.ability.Ability
+# @ohos.app.ability.Ability (Ability Base Class)
-The **Ability** module manages the ability lifecycle and context, such as creating and destroying an ability, and dumping client information.
+This is the base class of [UIAbility](js-apis-app-ability-uiAbility.md) and [ExtensionAbility](js-apis-app-ability-extensionAbility.md). It provides the callbacks for system configuration updates and memory level updates. You cannot inherit from this base class.
> **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 can be used only in the stage model.
-## Modules to Import
-
-```ts
-import Ability from '@ohos.app.ability.Ability';
-```
-
## Ability.onConfigurationUpdate
onConfigurationUpdate(newConfig: Configuration): void;
@@ -23,40 +17,45 @@ Called when the configuration of the environment where the ability is running is
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | newConfig | [Configuration](js-apis-app-ability-configuration.md) | Yes| New configuration.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| newConfig | [Configuration](js-apis-app-ability-configuration.md) | Yes| New configuration.|
**Example**
-
```ts
- class myAbility extends Ability {
- onConfigurationUpdate(config) {
- console.log('onConfigurationUpdate, config:' + JSON.stringify(config));
- }
- }
+// You are not allowed to inherit from the top-level base class Ability. Therefore, the derived class UIAbility is used as an example.
+import UIAbility from '@ohos.app.ability.UIAbility';
+
+class MyUIAbility extends UIAbility {
+ onConfigurationUpdate(config) {
+ console.log('onConfigurationUpdate, config:' + JSON.stringify(config));
+ }
+}
```
## Ability.onMemoryLevel
onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
-Called when the system has decided to adjust the memory level. For example, this API can be used when there is not enough memory to run as many background processes as possible.
+Called when the system adjusts the memory level.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**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.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| level | [AbilityConstant.MemoryLevel](js-apis-app-ability-abilityConstant.md#abilityconstantmemorylevel) | Yes| New memory level.|
**Example**
-
+
```ts
- class myAbility extends Ability {
+// You are not allowed to inherit from the top-level base class Ability. Therefore, the derived class UIAbility is used as an example.
+import UIAbility from '@ohos.app.ability.UIAbility';
+
+class MyUIAbility extends UIAbility {
onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level));
}
- }
+}
```
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md
index 5d6c93e6e2b45b33ca9cb7ec9976435c17fd2a56..766636a7c7d4cda38cb2b71395fd3f2575e2f784 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md
@@ -1,8 +1,6 @@
-# @ohos.app.ability.AbilityConstant
+# @ohos.app.ability.AbilityConstant (AbilityConstant)
-The **AbilityConstant** module provides ability launch parameters.
-
-The parameters include the initial launch reasons, reasons for the last exit, and ability continuation results.
+The **AbilityConstant** module defines the ability-related enums, including the initial launch reasons, reasons for the last exit, ability continuation results, and window modes.
> **NOTE**
>
@@ -17,31 +15,48 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
## Attributes
+## AbilityConstant.LaunchParam
+
+Defines the parameters for starting an ability.
+
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
-| Name| Type| Readable| Writable| Description|
+| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
-| launchReason | LaunchReason| Yes| Yes| Ability launch reason.|
-| lastExitReason | LastExitReason | Yes| Yes| Reason for the last exit.|
+| launchReason | [LaunchReason](#abilityconstantlaunchreason)| Yes| Yes| Ability launch reason, which is an enumerated type.|
+| lastExitReason | [LastExitReason](#abilityconstantlastexitreason) | Yes| Yes| Reason for the last exit, which is an enumerated type.|
## AbilityConstant.LaunchReason
-Enumerates the ability launch reasons.
+Enumerates the initial ability launch reasons. You can use it together with [onCreate(want, launchParam)](js-apis-app-ability-uiAbility.md#uiabilityoncreate) of [Ability](js-apis-app-ability-uiAbility.md) to complete different operations.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | Unknown reason.|
-| START_ABILITY | 1 | Ability startup.|
-| CALL | 2 | Call.|
-| CONTINUATION | 3 | Ability continuation.|
-| APP_RECOVERY | 4 | Application recovery.|
+| START_ABILITY | 1 | The ability is started by calling [startAbility](js-apis-ability-context.md#abilitycontextstartability).|
+| CALL | 2 | The ability is started by calling [startAbilityByCall](js-apis-ability-context.md#abilitycontextstartabilitybycall).|
+| CONTINUATION | 3 | The ability is started by means of cross-device migration.|
+| APP_RECOVERY | 4 | The ability is automatically started when the application is restored from a fault.|
+
+**Example**
+```ts
+import UIAbility from '@ohos.app.ability.UIAbility';
+
+class MyAbility extends UIAbility {
+ onCreate(want, launchParam) {
+ if (launchParam.launchReason === AbilityConstant.LaunchReason.START_ABILITY) {
+ console.log("The ability has been started by the way of startAbility.");
+ }
+ }
+}
+```
## AbilityConstant.LastExitReason
-Enumerates reasons for the last exit.
+Enumerates the reasons for the last exit. You can use it together with [onCreate(want, launchParam)](js-apis-app-ability-uiAbility.md#uiabilityoncreate) of [Ability](js-apis-app-ability-uiAbility.md) to complete different operations.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -49,12 +64,25 @@ Enumerates reasons for the last exit.
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | Unknown reason.|
| ABILITY_NOT_RESPONDING | 1 | The ability does not respond.|
-| NORMAL | 2 | Normal status.|
+| NORMAL | 2 | The ability exits normally.|
+**Example**
+
+```ts
+import UIAbility from '@ohos.app.ability.UIAbility';
+
+class MyAbility extends UIAbility {
+ onCreate(want, launchParam) {
+ if (launchParam.lastExitReason === AbilityConstant.LastExitReason.ABILITY_NOT_RESPONDING) {
+ console.log("The ability has exit last because the ability was not responding.");
+ }
+ }
+}
+```
## AbilityConstant.OnContinueResult
-Enumerates ability continuation results.
+Enumerates the ability continuation results. You can use it together with [onContinue(wantParam)](js-apis-app-ability-uiAbility.md#uiabilityoncontinue) of [Ability](js-apis-app-ability-uiAbility.md) to complete different operations.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -64,9 +92,21 @@ Enumerates ability continuation results.
| REJECT | 1 | Continuation denied.|
| MISMATCH | 2 | Mismatch.|
+**Example**
+
+```ts
+import UIAbility from '@ohos.app.ability.UIAbility';
+
+class MyAbility extends UIAbility {
+ onContinue(wantParam) {
+ return AbilityConstant.OnConinueResult.AGREE;
+ }
+}
+```
+
## AbilityConstant.WindowMode
-Enumerates the window modes in which an ability can be displayed at startup.
+Enumerates the window modes in which an ability can be displayed at startup. It can be used in **startAbility()** to specify the window mode when the ability is started.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -78,36 +118,81 @@ Enumerates the window modes in which an ability can be displayed at startup.
| WINDOW_MODE_SPLIT_SECONDARY | 101 | The ability is displayed in the secondary window in split-screen mode. |
| WINDOW_MODE_FLOATING | 102 | The ability is displayed in a floating window.|
+**Example**
+
+```ts
+let want = {
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
+};
+let option = {
+ windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FULLSCREEN
+};
+
+// Ensure that the context is obtained.
+this.context.startAbility(want, option).then(()={
+ console.log("Succeed to start ability.");
+}).catch((error)=>{
+ console.log("Failed to start ability with error: " + JSON.stringify(error));
+});
+```
+
## AbilityConstant.MemoryLevel
-Enumerates the memory levels.
+Enumerates the memory levels. You can use it in [onMemoryLevel(level)](js-apis-app-ability-ability.md#abilityonmemorylevel) of [Ability](js-apis-app-ability-ability.md) to complete different operations.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value| Description |
-| --- | --- | --- |
-| MEMORY_LEVEL_MODERATE | 0 | Moderate memory usage. |
-| MEMORY_LEVEL_LOW | 1 | Low memory usage. |
+| --- | --- | --- |
+| MEMORY_LEVEL_MODERATE | 0 | Moderate memory usage.|
+| MEMORY_LEVEL_LOW | 1 | Low memory usage. |
| MEMORY_LEVEL_CRITICAL | 2 | High memory usage. |
+**Example**
+
+```ts
+import UIAbility from '@ohos.app.ability.UIAbility';
+
+class MyAbility extends UIAbility {
+ onMemoryLevel(level) {
+ if (level === AbilityConstant.MemoryLevel.MEMORY_LEVEL_CRITICAL) {
+ console.log("The memory of device is critical, please release some memory.");
+ }
+ }
+}
+```
+
## AbilityConstant.OnSaveResult
-Enumerates the result types for the operation of saving application data.
+Enumerates the result types for the operation of saving application data. You can use it in [onSaveState(reason, wantParam)](js-apis-app-ability-uiAbility.md#uiabilityonsavestate) of [Ability](js-apis-app-ability-uiAbility.md) to complete different operations.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
-| ALL_AGREE | 0 | Agreed to save the status.|
+| ALL_AGREE | 0 | Always agreed to save the status.|
| CONTINUATION_REJECT | 1 | Rejected to save the status in continuation.|
| CONTINUATION_MISMATCH | 2 | Continuation mismatch.|
| RECOVERY_AGREE | 3 | Agreed to restore the saved status.|
| RECOVERY_REJECT | 4 | Rejected to restore the saved state.|
-| ALL_REJECT | 5 | Rejected to save the status.|
+| ALL_REJECT | 5 | Always rejected to save the status.|
+
+**Example**
+
+```ts
+import UIAbility from '@ohos.app.ability.UIAbility';
+
+class MyAbility extends UIAbility {
+ onSaveState(reason, wantParam) {
+ return AbilityConstant.OnSaveResult.ALL_AGREE;
+ }
+}
+```
## AbilityConstant.StateType
-Enumerates the scenarios for saving application data.
+Enumerates the scenarios for saving application data. You can use it in [onSaveState(reason, wantParam)](js-apis-app-ability-uiAbility.md#uiabilityonsavestate) of [Ability](js-apis-app-ability-uiAbility.md) to complete different operations.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -115,3 +200,18 @@ Enumerates the scenarios for saving application data.
| ----------------------------- | ---- | ------------------------------------------------------------ |
| CONTINUATION | 0 | Saving the status in continuation.|
| APP_RECOVERY | 1 | Saving the status in application recovery.|
+
+**Example**
+
+```ts
+import UIAbility from '@ohos.app.ability.UIAbility';
+
+class MyAbility extends UIAbility {
+ onSaveState(reason, wantParam) {
+ if (reason === AbilityConstant.StateType.CONTINUATION) {
+ console.log("Save the ability data when the ability continuation.");
+ }
+ return AbilityConstant.OnSaveResult.ALL_AGREE;
+ }
+}
+```
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md
index 78fb6181c03380c6d69eb31318d1d459dec307fe..5cfa437047868a9183ae4bb4f41ff42eec47f5d7 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md
@@ -1,26 +1,27 @@
-# @ohos.app.ability.abilityDelegatorRegistry
+# @ohos.app.ability.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.
+**AbilityDelegatorRegistry**, a module of the [Test Framework](../../ability-deprecated/ability-delegator.md), is used to obtain [AbilityDelegator](js-apis-inner-application-abilityDelegator.md) and [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md) objects. **AbilityDelegator** provides APIs for creating **AbilityMonitor** objects, which can be used to listen for ability lifecycle changes. **AbilityDelegatorArgs** provides APIs for obtaining test parameters.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
+> The APIs provided by this module can be used only in the test framework.
## Modules to Import
```ts
-import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'
+import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
```
## AbilityLifecycleState
-Enumerates the ability lifecycle states.
+Enumerates the ability lifecycle states. It can be used in [getAbilityState(ability)](js-apis-inner-application-abilityDelegator.md#getabilitystate9) of [AbilityDelegator](js-apis-inner-application-abilityDelegator.md) to return different ability lifecycle states.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ------------- | ---- | --------------------------- |
-| UNINITIALIZED | 0 | The ability is in an invalid state. |
+| UNINITIALIZED | 0 | The ability is in an invalid state. |
| CREATE | 1 | The ability is created.|
| FOREGROUND | 2 | The ability is running in the foreground. |
| BACKGROUND | 3 | The ability is running in the background. |
@@ -30,7 +31,7 @@ Enumerates the ability lifecycle states.
getAbilityDelegator(): AbilityDelegator
-Obtains the **AbilityDelegator** object of the application.
+Obtains an [AbilityDelegator](js-apis-inner-application-abilityDelegator.md) object.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -38,20 +39,33 @@ Obtains the **AbilityDelegator** object of the application.
| Type | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
-| [AbilityDelegator](js-apis-inner-application-abilityDelegator.md#AbilityDelegator) | [AbilityDelegator](js-apis-inner-application-abilityDelegator.md#AbilityDelegator) object, which can be used to schedule functions related to the test framework.|
+| [AbilityDelegator](js-apis-inner-application-abilityDelegator.md#AbilityDelegator) | [AbilityDelegator](js-apis-inner-application-abilityDelegator.md#AbilityDelegator) object, which can be used to schedule the functionalities of the test framework.|
**Example**
```ts
-var abilityDelegator;
-abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
+import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
+
+let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
+
+let want = {
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility"
+};
+abilityDelegator.startAbility(want, (err) => {
+ if (err.code !== 0) {
+ console.log("Success start ability.");
+ } else {
+ console.log("Failed start ability, error: " + JSON.stringify(err));
+ }
+})
```
## AbilityDelegatorRegistry.getArguments
getArguments(): AbilityDelegatorArgs
-Obtains the **AbilityDelegatorArgs** object of the application.
+Obtains an [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md) object.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -64,8 +78,11 @@ Obtains the **AbilityDelegatorArgs** object of the application.
**Example**
```ts
-var args = AbilityDelegatorRegistry.getArguments();
+import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
+
+let args = AbilityDelegatorRegistry.getArguments();
console.info("getArguments bundleName:" + args.bundleName);
+console.info("getArguments parameters:" + JSON.stringify(args.parameters));
console.info("getArguments testCaseNames:" + args.testCaseNames);
console.info("getArguments testRunnerClassName:" + args.testRunnerClassName);
```
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md
index f3e6e08396d0b819efd6acda39218af497e83ef9..84be19350707fee37328ff8040b2986588afd2f8 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md
@@ -1,6 +1,6 @@
-# @ohos.app.ability.abilityLifecycleCallback
+# @ohos.app.ability.abilityLifecycleCallback (AbilityLifecycleCallback)
-The **AbilityLifecycleCallback** module provides callbacks, such as **onAbilityCreate**, **onWindowStageCreate**, and **onWindowStageDestroy**, to receive lifecycle state changes in the application context.
+The **AbilityLifecycleCallback** module defines the callbacks to receive lifecycle changes of [ApplicationContext](js-apis-inner-application-applicationContext.md). The callbacks include [onAbilityCreate](#abilitylifecyclecallbackonabilitycreate), [onWindowStageCreate](#abilitylifecyclecallbackonwindowstagecreate), [onWindowStageActive](#abilitylifecyclecallbackonwindowstageactive), [onWindowStageInactive](#abilitylifecyclecallbackonwindowstageinactive), [onWindowStageDestroy](#abilitylifecyclecallbackonwindowstagedestroy), [onAbilityDestroy](#abilitylifecyclecallbackonabilitydestroy), [onAbilityForeground](#abilitylifecyclecallbackonabilityforeground), [onAbilityBackground](#abilitylifecyclecallbackonabilitybackground), and [onAbilityContinue](#abilitylifecyclecallbackonabilitycontinue).
> **NOTE**
>
@@ -25,10 +25,18 @@ Called when an ability is created.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
+**Example**
+```ts
+let abilityLifecycleCallback = {
+ onAbilityCreate(ability){
+ console.log("AbilityLifecycleCallback onAbilityCreate.");
+ }
+};
+```
## AbilityLifecycleCallback.onWindowStageCreate
@@ -40,11 +48,19 @@ Called when the window stage of an ability is created.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
- | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
+| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+**Example**
+```ts
+let abilityLifecycleCallback = {
+ onWindowStageCreate(ability, windowStage){
+ console.log("AbilityLifecycleCallback onWindowStageCreate.");
+ }
+};
+```
## AbilityLifecycleCallback.onWindowStageActive
@@ -56,11 +72,19 @@ Called when the window stage of an ability gains focus.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
- | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
+| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+**Example**
+```ts
+let abilityLifecycleCallback = {
+ onWindowStageActive(ability, windowStage){
+ console.log("AbilityLifecycleCallback onWindowStageActive.");
+ }
+};
+```
## AbilityLifecycleCallback.onWindowStageInactive
@@ -72,11 +96,19 @@ Called when the window stage of an ability loses focus.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
- | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
+| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+**Example**
+```ts
+let abilityLifecycleCallback = {
+ onWindowStageInactive(ability, windowStage){
+ console.log("AbilityLifecycleCallback onWindowStageInactive.");
+ }
+};
+```
## AbilityLifecycleCallback.onWindowStageDestroy
@@ -88,11 +120,19 @@ Called when the window stage of an ability is destroyed.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
- | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
+| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+**Example**
+```ts
+let abilityLifecycleCallback = {
+ onWindowStageDestroy(ability, windowStage){
+ console.log("AbilityLifecycleCallback onWindowStageDestroy.");
+ }
+};
+```
## AbilityLifecycleCallback.onAbilityDestroy
@@ -104,10 +144,18 @@ Called when an ability is destroyed.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
+**Example**
+```ts
+let abilityLifecycleCallback = {
+ onAbilityDestroy(ability){
+ console.log("AbilityLifecycleCallback onAbilityDestroy.");
+ }
+};
+```
## AbilityLifecycleCallback.onAbilityForeground
@@ -119,10 +167,18 @@ Called when an ability is switched from the background to the foreground.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
+**Example**
+```ts
+let abilityLifecycleCallback = {
+ onAbilityForeground(ability){
+ console.log("AbilityLifecycleCallback onAbilityForeground.");
+ }
+};
+```
## AbilityLifecycleCallback.onAbilityBackground
@@ -134,10 +190,18 @@ Called when an ability is switched from the foreground to the background.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
+**Example**
+```ts
+let abilityLifecycleCallback = {
+ onAbilityBackground(ability){
+ console.log("AbilityLifecycleCallback onAbilityBackground.");
+ }
+};
+```
## AbilityLifecycleCallback.onAbilityContinue
@@ -149,63 +213,91 @@ Called when an ability is continued on another device.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [UIAbility](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
+
+**Example**
+```ts
+let abilityLifecycleCallback = {
+ onAbilityContinue(ability){
+ console.log("AbilityLifecycleCallback onAbilityContinue.");
+ }
+};
+```
+
+## Usage of AbilityLifecycleCallback
**Example**
-
-
- ```ts
- import UIAbility from "@ohos.app.ability.UIAbility";
-
- export default class MyAbility extends UIAbility {
- onCreate() {
- console.log("MyAbility onCreate")
- let AbilityLifecycleCallback = {
- onAbilityCreate(ability){
- console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
- },
- onWindowStageCreate(ability, windowStage){
- console.log("AbilityLifecycleCallback onWindowStageCreate ability:" + JSON.stringify(ability));
- console.log("AbilityLifecycleCallback onWindowStageCreate windowStage:" + JSON.stringify(windowStage));
- },
- onWindowStageActive(ability, windowStage){
- console.log("AbilityLifecycleCallback onWindowStageActive ability:" + JSON.stringify(ability));
- console.log("AbilityLifecycleCallback onWindowStageActive windowStage:" + JSON.stringify(windowStage));
- },
- onWindowStageInactive(ability, windowStage){
- console.log("AbilityLifecycleCallback onWindowStageInactive ability:" + JSON.stringify(ability));
- console.log("AbilityLifecycleCallback onWindowStageInactive windowStage:" + JSON.stringify(windowStage));
- },
- onWindowStageDestroy(ability, windowStage){
- console.log("AbilityLifecycleCallback onWindowStageDestroy ability:" + JSON.stringify(ability));
- console.log("AbilityLifecycleCallback onWindowStageDestroy windowStage:" + JSON.stringify(windowStage));
- },
- onAbilityDestroy(ability){
- console.log("AbilityLifecycleCallback onAbilityDestroy ability:" + JSON.stringify(ability));
- },
- onAbilityForeground(ability){
- console.log("AbilityLifecycleCallback onAbilityForeground ability:" + JSON.stringify(ability));
- },
- onAbilityBackground(ability){
- console.log("AbilityLifecycleCallback onAbilityBackground ability:" + JSON.stringify(ability));
- },
- onAbilityContinue(ability){
- console.log("AbilityLifecycleCallback onAbilityContinue ability:" + JSON.stringify(ability));
- }
- }
- // 1. Obtain applicationContext through the context attribute.
- let applicationContext = this.context.getApplicationContext();
- // 2. Use applicationContext to register a listener for the ability lifecycle in the application.
- let lifecycleid = applicationContext.on("abilityLifecycle", AbilityLifecycleCallback);
- console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid));
- },
- onDestroy() {
- let applicationContext = this.context.getApplicationContext();
- applicationContext.off("abilityLifecycle", lifecycleid, (error, data) => {
- console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
- });
- }
- }
- ```
+
+MyFirstAbility.ts
+```ts
+import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback";
+import AbilityStage from "@ohos.app.ability.AbilityStage";
+import UIAbility from '@ohos.app.ability.UIAbility';
+
+// Declare the ability lifecycle callbacks. A listener can be registered in applicationContext only after all the callbacks are configured.
+let abilityLifecycleCallback = {
+ onAbilityCreate(ability){
+ console.log("AbilityLifecycleCallback onAbilityCreate.");
+ },
+ onWindowStageCreate(ability, windowStage){
+ console.log("AbilityLifecycleCallback onWindowStageCreate.");
+ },
+ onWindowStageActive(ability, windowStage){
+ console.log("AbilityLifecycleCallback onWindowStageActive.");
+ },
+ onWindowStageInactive(ability, windowStage){
+ console.log("AbilityLifecycleCallback onWindowStageInactive.");
+ },
+ onWindowStageDestroy(ability, windowStage){
+ console.log("AbilityLifecycleCallback onWindowStageDestroy.");
+ },
+ onAbilityDestroy(ability){
+ console.log("AbilityLifecycleCallback onAbilityDestroy.");
+ },
+ onAbilityForeground(ability){
+ console.log("AbilityLifecycleCallback onAbilityForeground.");
+ },
+ onAbilityBackground(ability){
+ console.log("AbilityLifecycleCallback onAbilityBackground.");
+ },
+ onAbilityContinue(ability){
+ console.log("AbilityLifecycleCallback onAbilityContinue.");
+ }
+};
+
+export default class MyFirstAbility extends UIAbility {
+ onCreate() {
+ console.log("MyAbilityStage onCreate");
+ // 1. Obtain applicationContext through the context attribute.
+ let applicationContext = this.context.getApplicationContext();
+ // 2. Register the listener for the ability lifecycle changes through the applicationContext object.
+ try {
+ globalThis.lifecycleId = applicationContext.on("abilityLifecycle", abilityLifecycleCallback);
+ console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleId));
+ } catch (paramError) {
+ console.log("error: " + paramError.code + " ," + paramError.message);
+ }
+ }
+}
+```
+
+MySecondAbility.ts
+```ts
+import UIAbility from "ohos.app.ability.UIAbility";
+
+export default class MySecondAbility extends UIAbility {
+ onDestroy() {
+ let applicationContext = this.context.getApplicationContext();
+ // 3. Deregister the listener for the environment changes through the applicationContext object.
+ applicationContext.off("abilityLifecycle", globalThis.lifecycleId, (error) => {
+ if (error.code != 0) {
+ console.log("unregisterAbilityLifecycleCallback failed, error: " + JSON.stringify(error));
+ } else {
+ console.log("unregisterAbilityLifecycleCallback success.");
+ }
+ });
+ }
+}
+```
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md
index 0a191c0038f3a5811018346ffe779dc558b3ad20..f7f9c49a4cdf1c9e8c92ad8b7c8bd977df525477 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md
@@ -1,6 +1,6 @@
-# @ohos.app.ability.abilityManager
+# @ohos.app.ability.abilityManager (AbilityManager)
-The **AbilityManager** module provides APIs for obtaining, adding, and modifying ability running information and state information.
+The **AbilityManager** module provides APIs for obtaining, adding, and updating ability running information and state information.
> **NOTE**
>
@@ -10,24 +10,24 @@ The **AbilityManager** module provides APIs for obtaining, adding, and modifying
## Modules to Import
```ts
-import AbilityManager from '@ohos.app.ability.abilityManager'
+import abilityManager from '@ohos.app.ability.abilityManager';
```
## AbilityState
-Enumerates the ability states.
+Enumerates the ability states. This enum can be used together with [AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md) to return the ability state.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
-**System API**: This is a system API and cannot be called by third-party applications.
+**System API**: This enum is an internal definition of a system API and cannot be called by third-party applications.
| Name| Value| Description|
| -------- | -------- | -------- |
| INITIAL | 0 | The ability is in the initial state.|
| 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 foregrounding state. |
-| BACKGROUNDING | 12 | The ability is in the backgrounding 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
@@ -43,25 +43,42 @@ Updates the configuration. This API uses an asynchronous callback to return the
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
-| config | [Configuration](js-apis-app-ability-configuration.md) | Yes | New configuration.|
-| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+| config | [Configuration](js-apis-app-ability-configuration.md) | Yes | New configuration. You only need to configure the items to be updated.|
+| callback | AsyncCallback\ | Yes | Callback used to return the API call result. You can perform error handling or custom processing in this callback. |
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
-import abilitymanager from '@ohos.app.ability.abilityManager';
+import abilityManager from '@ohos.app.ability.abilityManager';
-var config = {
- language: 'chinese'
-}
+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.
+ displayId: 1, // The application is displayed on the display with ID 1.
+ hasPointerDevice: true, // A pointer device is connected.
+};
try {
- abilitymanager.updateConfiguration(config, () => {
- console.log('------------ updateConfiguration -----------');
- })
+ abilityManager.updateConfiguration(config, (err) => {
+ if (err.code !== 0) {
+ console.log("updateConfiguration fail, err: " + JSON.stringify(err));
+ } else {
+ console.log("updateConfiguration success.");
+ }
+ })
} catch (paramError) {
- console.log('error.code: ' + JSON.stringify(paramError.code) +
- ' error.message: ' + JSON.stringify(paramError.message));
+ console.log('error.code: ' + JSON.stringify(paramError.code)
+ + ' error.message: ' + JSON.stringify(paramError.message));
}
```
@@ -79,32 +96,45 @@ Updates the configuration. This API uses a promise to return the result.
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
-| config | [Configuration](js-apis-app-ability-configuration.md) | Yes | New configuration.|
+| config | [Configuration](js-apis-app-ability-configuration.md) | Yes | New configuration. You only need to configure the items to be updated.|
**Return value**
| Type | Description |
| ---------------------------------------- | ------- |
-| Promise\ | Promise used to return the result.|
+| Promise\ | Promise used to return the API call result. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
-import abilitymanager from '@ohos.app.ability.abilityManager';
+import abilityManager from '@ohos.app.ability.abilityManager';
-var config = {
- language: 'chinese'
-}
+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.
+ displayId: 1, // The application is displayed on the display with ID 1.
+ hasPointerDevice: true, // A pointer device is connected.
+};
try {
- abilitymanager.updateConfiguration(config).then(() => {
- console.log('updateConfiguration success');
- }).catch((err) => {
- console.log('updateConfiguration fail');
- })
+ abilityManager.updateConfiguration(config).then(() => {
+ 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));
+ console.log('error.code: ' + JSON.stringify(paramError.code)
+ + ' error.message: ' + JSON.stringify(paramError.message));
}
```
@@ -122,20 +152,32 @@ Obtains the ability running information. This API uses an asynchronous callback
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
-| callback | AsyncCallback\> | Yes | Callback used to return the result. |
+| callback | AsyncCallback\> | Yes | Callback used to return the API call result and the ability running information. You can perform error handling or custom processing in this callback. |
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
-import abilitymanager from '@ohos.app.ability.abilityManager';
+import abilityManager from '@ohos.app.ability.abilityManager';
try {
- abilitymanager.getAbilityRunningInfos((err,data) => {
- console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data));
- });
+ abilityManager.getAbilityRunningInfos((err, data) => {
+ if (err.code !== 0) {
+ console.log("getAbilityRunningInfos fail, error: " + JSON.stringify(err));
+ } else {
+ console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data));
+ }
+ });
} catch (paramError) {
- console.log('error.code: ' + JSON.stringify(paramError.code) +
- ' error.message: ' + JSON.stringify(paramError.message));
+ console.log('error.code: ' + JSON.stringify(paramError.code)
+ + ' error.message: ' + JSON.stringify(paramError.message));
}
```
@@ -153,22 +195,30 @@ Obtains the ability running information. This API uses a promise to return the r
| Type | Description |
| ---------------------------------------- | ------- |
-| Promise\> | Promise used to return the result.|
+| Promise\> | Callback used to return the API call result and the ability running information. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
-import abilitymanager from '@ohos.app.ability.abilityManager';
-
+import abilityManager from '@ohos.app.ability.abilityManager';
+
try {
- abilitymanager.getAbilityRunningInfos().then((data) => {
- console.log("getAbilityRunningInfos data: " + JSON.stringify(data))
- }).catch((err) => {
- console.log("getAbilityRunningInfos err: " + err)
- });
+ abilityManager.getAbilityRunningInfos().then((data) => {
+ console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data))
+ }).catch((err) => {
+ console.log("getAbilityRunningInfos fail, err: " + JSON.stringify(err));
+ });
} catch (paramError) {
- console.log('error.code: ' + JSON.stringify(paramError.code) +
- ' error.message: ' + JSON.stringify(paramError.message));
+ console.log('error.code: ' + JSON.stringify(paramError.code)
+ + ' error.message: ' + JSON.stringify(paramError.message));
}
```
@@ -176,7 +226,7 @@ try {
getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\>): void
-Obtains the extension running information. This API uses an asynchronous callback to return the result.
+Obtains the ExtensionAbility running information. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
@@ -186,23 +236,35 @@ Obtains the extension running information. This API uses an asynchronous callbac
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
-| upperLimit | number | Yes| Maximum number of messages that can be obtained.|
-| callback | AsyncCallback\> | Yes | Callback used to return the result. |
+| upperLimit | number | Yes| Maximum number of messages that can be obtained. The maximum value is 231-1.|
+| callback | AsyncCallback\> | Yes | Callback used to return the API call result and the ExtensionAbility running information. You can perform error handling or custom processing in this callback. |
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
-import abilitymanager from '@ohos.app.ability.abilityManager';
+import abilityManager from '@ohos.app.ability.abilityManager';
-var upperLimit = 0;
+let upperLimit = 10;
try {
- abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => {
- console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data));
- });
+ abilityManager.getExtensionRunningInfos(upperLimit, (err, data) => {
+ if (err.code !== 0) {
+ console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err));
+ } else {
+ console.log("getExtensionRunningInfos success, data: " + JSON.stringify(data));
+ }
+ });
} catch (paramError) {
- console.log('error.code: ' + JSON.stringify(paramError.code) +
- ' error.message: ' + JSON.stringify(paramError.message));
+ console.log('error.code: ' + JSON.stringify(paramError.code)
+ + ' error.message: ' + JSON.stringify(paramError.message));
}
```
@@ -210,7 +272,7 @@ try {
getExtensionRunningInfos(upperLimit: number): Promise\>
-Obtains the extension running information. This API uses a promise to return the result.
+Obtains the ExtensionAbility running information. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
@@ -220,30 +282,38 @@ Obtains the extension running information. This API uses a promise to return the
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
-| upperLimit | number | Yes| Maximum number of messages that can be obtained.|
+| upperLimit | number | Yes| Maximum number of messages that can be obtained. The maximum value is 231-1.|
**Return value**
| Type | Description |
| ---------------------------------------- | ------- |
-| Promise\> | Promise used to return the result.|
+| Promise\> | Promise used to return the API call result and the ExtensionAbility running information. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
-import abilitymanager from '@ohos.app.ability.abilityManager';
+import abilityManager from '@ohos.app.ability.abilityManager';
-var upperLimit = 0;
+let upperLimit = 10;
try {
- abilitymanager.getExtensionRunningInfos(upperLimit).then((data) => {
- console.log("getAbilityRunningInfos data: " + JSON.stringify(data));
- }).catch((err) => {
- console.log("getAbilityRunningInfos err: " + err);
- })
+ abilityManager.getExtensionRunningInfos(upperLimit).then((data) => {
+ 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));
+ console.log('error.code: ' + JSON.stringify(paramError.code)
+ + ' error.message: ' + JSON.stringify(paramError.message));
}
```
@@ -259,21 +329,28 @@ Obtains the top ability, which is the ability that has the window focus. This AP
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
-| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+| callback | AsyncCallback\<[ElementName](js-apis-bundleManager-elementName.md)> | Yes | Callback used to return the API call result and the element name of the top ability. You can perform error handling or custom processing in this callback. |
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
-import abilitymanager from '@ohos.app.ability.abilityManager';
-
-try {
- abilitymanager.getTopAbility((err,data) => {
- console.log("getTopAbility err: " + err + " data: " + JSON.stringify(data));
- });
-} catch (paramError) {
- console.log('error.code: ' + JSON.stringify(paramError.code) +
- ' error.message: ' + JSON.stringify(paramError.message));
-}
+import abilityManager from '@ohos.app.ability.abilityManager';
+
+abilityManager.getTopAbility((err, data) => {
+ if (err.code !== 0) {
+ console.log("getTopAbility fail, err: " + JSON.stringify(err));
+ } else {
+ console.log("getTopAbility success, data: " + JSON.stringify(data));
+ }
+});
```
## getTopAbility
@@ -288,21 +365,24 @@ Obtains the top ability, which is the ability that has the window focus. This AP
| Type | Description |
| ---------------------------------------- | ------- |
-| Promise\| Promise used to return the result.|
+| Promise\<[ElementName](js-apis-bundleManager-elementName.md)>| Promise used to return the API call result and the element name of the top ability. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
-import abilitymanager from '@ohos.app.ability.abilityManager';
+import abilityManager from '@ohos.app.ability.abilityManager';
-try {
- abilitymanager.getTopAbility().then((data) => {
- console.log("getTopAbility data: " + JSON.stringify(data));
- }).catch((err) => {
- console.log("getTopAbility err: " + err);
- })
-} catch (paramError) {
- console.log('error.code: ' + JSON.stringify(paramError.code) +
- ' error.message: ' + JSON.stringify(paramError.message));
-}
+abilityManager.getTopAbility().then((data) => {
+ console.log("getTopAbility success, data: " + JSON.stringify(data));
+}).catch((err) => {
+ console.log("getTopAbility fail, err: " + JSON.stringify(err));
+})
```
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md
index b1226842409c7d03c82d25d33319042a716b9d86..50feb82791f8992894641a296d6cb831fdc86680 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md
@@ -1,4 +1,4 @@
-# @ohos.app.ability.AbilityStage
+# @ohos.app.ability.AbilityStage (AbilityStage)
**AbilityStage** is a runtime class for HAP files.
@@ -25,13 +25,15 @@ Called when the application is created.
**Example**
- ```ts
- class MyAbilityStage extends AbilityStage {
- onCreate() {
- console.log("MyAbilityStage.onCreate is called")
- }
- }
- ```
+```ts
+import AbilityStage from '@ohos.app.ability.AbilityStage';
+
+class MyAbilityStage extends AbilityStage {
+ onCreate() {
+ console.log("MyAbilityStage.onCreate is called");
+ }
+}
+```
## AbilityStage.onAcceptWant
@@ -44,9 +46,9 @@ Called when a specified ability is started.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want | [Want](js-apis-app-ability-want.md) | Yes| Information about the ability to start, such as the ability name and bundle name.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability, such as the ability name and bundle name.|
**Return value**
@@ -56,14 +58,16 @@ Called when a specified ability is started.
**Example**
- ```ts
- class MyAbilityStage extends AbilityStage {
- onAcceptWant(want) {
- console.log("MyAbilityStage.onAcceptWant called");
- return "com.example.test";
- }
- }
- ```
+```ts
+import AbilityStage from '@ohos.app.ability.AbilityStage';
+
+class MyAbilityStage extends AbilityStage {
+ onAcceptWant(want) {
+ console.log("MyAbilityStage.onAcceptWant called");
+ return "com.example.test";
+ }
+}
+```
## AbilityStage.onConfigurationUpdate
@@ -82,13 +86,15 @@ Called when the global configuration is updated.
**Example**
- ```ts
- class MyAbilityStage extends AbilityStage {
- onConfigurationUpdate(config) {
- console.log('onConfigurationUpdate, language:' + config.language);
- }
- }
- ```
+```ts
+import AbilityStage from '@ohos.app.ability.AbilityStage';
+
+class MyAbilityStage extends AbilityStage {
+ onConfigurationUpdate(config) {
+ console.log('onConfigurationUpdate, language:' + config.language);
+ }
+}
+```
## AbilityStage.onMemoryLevel
@@ -106,22 +112,24 @@ Called when the system has decided to adjust the memory level. For example, this
**Example**
- ```ts
- class MyAbilityStage extends AbilityStage {
+```ts
+import AbilityStage from '@ohos.app.ability.AbilityStage';
+
+class MyAbilityStage extends AbilityStage {
onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level));
}
- }
- ```
+}
+```
## AbilityStage.context
context: AbilityStageContext;
-Describes the configuration information about the context.
+Defines the context of **AbilityStage**.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Description |
| ----------- | --------------------------- | ------------------------------------------------------------ |
-| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | Called when initialization is performed during ability startup.|
+| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | The context is obtained in the callback invoked when initialization is performed during ability startup.|
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-appManager.md b/en/application-dev/reference/apis/js-apis-app-ability-appManager.md
index b6fae35d6d03575442b1223c63cbcd4150773bb9..840a395eac9e17558918dd7466aa9e0b178b1c4d 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-appManager.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-appManager.md
@@ -1,4 +1,4 @@
-# @ohos.app.ability.appManager
+# @ohos.app.ability.appManager (appManager)
The **appManager** module implements application management. You can use the APIs of this module to query whether the application is undergoing a stability test, whether the application is running on a RAM constrained device, the memory size of the application, and information about the running process.
@@ -12,7 +12,7 @@ The **appManager** module implements application management. You can use the API
import appManager from '@ohos.app.ability.appManager';
```
-## appManager.isRunningInStabilityTest9+
+## appManager.isRunningInStabilityTest
static isRunningInStabilityTest(callback: AsyncCallback<boolean>): void
@@ -22,21 +22,34 @@ Checks whether this application is undergoing a stability test. This API uses an
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
+ | Type| Description|
+ | -------- | -------- |
+ |AsyncCallback<boolean> |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- import app from '@ohos.application.appManager';
- app.isRunningInStabilityTest((err, flag) => {
- console.log('startAbility result:' + JSON.stringify(err));
- })
- ```
+```ts
+import appManager from '@ohos.app.ability.appManager';
-## appManager.isRunningInStabilityTest9+
+appManager.isRunningInStabilityTest((err, flag) => {
+ if (err.code !== 0) {
+ console.log("isRunningInStabilityTest faile, err: " + JSON.stringify(err));
+ } else {
+ console.log("The result of isRunningInStabilityTest is:" + JSON.stringify(flag));
+ }
+})
+```
+
+
+## appManager.isRunningInStabilityTest
static isRunningInStabilityTest(): Promise<boolean>
@@ -48,18 +61,27 @@ Checks whether this application is undergoing a stability test. This API uses a
| Type| Description|
| -------- | -------- |
- | Promise<boolean> | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
+ | Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- import app from '@ohos.application.appManager';
- app.isRunningInStabilityTest().then((flag) => {
- console.log('success:' + JSON.stringify(flag));
- }).catch((error) => {
- console.log('failed:' + JSON.stringify(error));
- });
- ```
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+appManager.isRunningInStabilityTest().then((flag) => {
+ console.log("The result of isRunningInStabilityTest is:" + JSON.stringify(flag));
+}).catch((error) => {
+ console.log("error:" + JSON.stringify(error));
+});
+```
## appManager.isRamConstrainedDevice
@@ -74,17 +96,27 @@ Checks whether this application is running on a RAM constrained device. This API
| Type| Description|
| -------- | -------- |
- | Promise<boolean> | 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.|
+ | Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- app.isRamConstrainedDevice().then((data) => {
- console.log('success:' + JSON.stringify(data));
- }).catch((error) => {
- console.log('failed:' + JSON.stringify(error));
- });
- ```
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+appManager.isRamConstrainedDevice().then((data) => {
+ console.log("The result of isRamConstrainedDevice is:" + JSON.stringify(data));
+}).catch((error) => {
+ console.log("error:" + JSON.stringify(error));
+});
+```
## appManager.isRamConstrainedDevice
@@ -96,18 +128,31 @@ Checks whether this application is running on a RAM constrained device. This API
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | callback | AsyncCallback<boolean> | 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.|
+ | Type| Description|
+ | -------- | -------- |
+ | AsyncCallback<boolean> |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- app.isRamConstrainedDevice((err, data) => {
- console.log('startAbility result failed:' + JSON.stringify(err));
- console.log('startAbility result success:' + JSON.stringify(data));
- })
- ```
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+appManager.isRamConstrainedDevice((err, data) => {
+ if (err.code !== 0) {
+ console.log("isRamConstrainedDevice faile, err: " + JSON.stringify(err));
+ } else {
+ console.log("The result of isRamConstrainedDevice is:" + JSON.stringify(data));
+ }
+})
+```
## appManager.getAppMemorySize
@@ -121,17 +166,27 @@ Obtains the memory size of this application. This API uses a promise to return t
| Type| Description|
| -------- | -------- |
- | Promise<number> | Size of the application memory.|
+ | Promise<number> | Promise used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- app.getAppMemorySize().then((data) => {
- console.log('success:' + JSON.stringify(data));
- }).catch((error) => {
- console.log('failed:' + JSON.stringify(error));
- });
- ```
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+appManager.getAppMemorySize().then((data) => {
+ console.log("The size of app memory is:" + JSON.stringify(data));
+}).catch((error) => {
+ console.log("error:" + JSON.stringify(error));
+});
+```
## appManager.getAppMemorySize
@@ -143,20 +198,33 @@ Obtains the memory size of this application. This API uses an asynchronous callb
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | callback | AsyncCallback<number> | Yes| Size of the application memory.|
+ | Type| Description|
+ | -------- | -------- |
+ |AsyncCallback<number> |Callback used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- app.getAppMemorySize((err, data) => {
- console.log('startAbility result failed :' + JSON.stringify(err));
- console.log('startAbility result success:' + JSON.stringify(data));
- })
- ```
-## appManager.getProcessRunningInformation9+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+appManager.getAppMemorySize((err, data) => {
+ if (err.code !== 0) {
+ console.log("getAppMemorySize faile, err: " + JSON.stringify(err));
+ } else {
+ console.log("The size of app memory is:" + JSON.stringify(data));
+ }
+})
+```
+
+## appManager.getProcessRunningInformation
getProcessRunningInformation(): Promise\>;
@@ -172,17 +240,27 @@ Obtains information about the running processes. This API uses a promise to retu
| Type| Description|
| -------- | -------- |
-| Promise\> | Promise used to return the process information.|
+| Promise\> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- app.getProcessRunningInformation().then((data) => {
- console.log('success:' + JSON.stringify(data));
- }).catch((error) => {
- console.log('failed:' + JSON.stringify(error));
- });
- ```
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+appManager.getProcessRunningInformation().then((data) => {
+ console.log("The process running information is:" + JSON.stringify(data));
+}).catch((error) => {
+ console.log("error:" + JSON.stringify(error));
+});
+```
## appManager.getProcessRunningInformation9+
@@ -198,18 +276,31 @@ Obtains information about the running processes. This API uses an asynchronous c
**Parameters**
-| Name| Type| Mandatory| Description|
-| -------- | -------- | -------- | -------- |
-| callback | AsyncCallback\> | Yes| Callback used to return the process information.|
+| Type| Description|
+| -------- | -------- |
+|AsyncCallback\> | Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- app.getProcessRunningInformation((err, data) => {
- console.log('startAbility result failed :' + JSON.stringify(err));
- console.log('startAbility result success:' + JSON.stringify(data));
- })
- ```
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+appManager.getProcessRunningInformation((err, data) => {
+ if (err.code !== 0) {
+ console.log("getProcessRunningInformation faile, err: " + JSON.stringify(err));
+ } else {
+ console.log("The process running information is:" + JSON.stringify(data));
+ }
+})
+```
## appManager.on
@@ -227,37 +318,52 @@ Registers an observer to listen for the state changes of all applications.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| type | string | Yes| Type of the API to call.|
-| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Numeric code of the observer.|
+| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.|
+| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.|
+
+**Return value**
+
+| Type| Description|
+| --- | --- |
+| number | Digital code of the observer, which will be used in **off()** to deregister the observer.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```js
- var applicationStateObserver = {
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+let applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
- console.log('------------ onForegroundApplicationChanged -----------', appStateData);
+ console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
},
onAbilityStateChanged(abilityStateData) {
- console.log('------------ onAbilityStateChanged -----------', abilityStateData);
+ console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
},
onProcessCreated(processData) {
- console.log('------------ onProcessCreated -----------', processData);
+ console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
},
onProcessDied(processData) {
- console.log('------------ onProcessDied -----------', processData);
+ console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
},
onProcessStateChanged(processData) {
- console.log('------------ onProcessStateChanged -----------', processData);
+ console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
}
- }
- try {
- const observerCode = app.on(applicationStateObserver);
- console.log('-------- observerCode: ---------', observerCode);
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
-
- ```
+}
+try {
+ const observerId = appManager.on('applicationState', applicationStateObserver);
+ console.log(`[appManager] observerCode: ${observerId}`);
+} catch (paramError) {
+ console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `);
+}
+```
## appManager.on
@@ -275,39 +381,55 @@ Registers an observer to listen for the state changes of a specified application
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| type | string | Yes| Type of the API to call.|
-| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Numeric code of the observer.|
-| bundleNameList | Array | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.|
+| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.|
+| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.|
+| bundleNameList | `Array` | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.|
+
+**Return value**
+
+| Type| Description|
+| --- | --- |
+| number | Digital code of the observer, which will be used in **off()** to deregister the observer.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```js
- var applicationStateObserver = {
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+let applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
- console.log('------------ onForegroundApplicationChanged -----------', appStateData);
+ console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
},
onAbilityStateChanged(abilityStateData) {
- console.log('------------ onAbilityStateChanged -----------', abilityStateData);
+ console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
},
onProcessCreated(processData) {
- console.log('------------ onProcessCreated -----------', processData);
+ console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
},
onProcessDied(processData) {
- console.log('------------ onProcessDied -----------', processData);
+ console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
},
onProcessStateChanged(processData) {
- console.log('------------ onProcessStateChanged -----------', processData);
+ console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
}
- }
- var bundleNameList = ['bundleName1', 'bundleName2'];
- try {
- const observerCode = app.on("applicationState", applicationStateObserver, bundleNameList);
- console.log('-------- observerCode: ---------', observerCode);
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
- }
+}
+let bundleNameList = ['bundleName1', 'bundleName2'];
+try {
+ const observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList);
+ console.log(`[appManager] observerCode: ${observerId}`);
+} catch (paramError) {
+ console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `);
+}
+```
- ```
## appManager.off
off(type: "applicationState", observerId: number, callback: AsyncCallback\): void;
@@ -321,29 +443,68 @@ 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.
**Parameters**
-
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| type | string | Yes| Type of the API to call.|
-| observerId | number | Yes| Numeric code of the observer.|
-| callback | AsyncCallback\ | Yes| Callback used to return the result.|
+| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.|
+| observerId | number | Yes| Digital code of the observer.|
+| callback | AsyncCallback\ | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```js
- var observerId = 100;
- function unregisterApplicationStateObserverCallback(err) {
- if (err) {
- console.log('------------ unregisterApplicationStateObserverCallback ------------', err);
- }
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+let observeId = 0;
+
+// 1. Register an application state observer.
+let applicationStateObserver = {
+ onForegroundApplicationChanged(appStateData) {
+ console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
+ },
+ onAbilityStateChanged(abilityStateData) {
+ console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
+ },
+ onProcessCreated(processData) {
+ console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
+ },
+ onProcessDied(processData) {
+ console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
+ },
+ onProcessStateChanged(processData) {
+ console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
}
- try {
- app.off(observerId, unregisterApplicationStateObserverCallback);
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
+}
+let bundleNameList = ['bundleName1', 'bundleName2'];
+try {
+ observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList);
+ console.log(`[appManager] observerCode: ${observerId}`);
+} catch (paramError) {
+ console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `);
+}
+
+// 2. Deregister the application state observer.
+function unregisterApplicationStateObserverCallback(err) {
+ if (err.code !== 0) {
+ console.log("unregisterApplicationStateObserverCallback faile, err: " + JSON.stringify(err));
+ } else {
+ console.log("unregisterApplicationStateObserverCallback success.");
}
- ```
+}
+try {
+ appManager.off("applicationState", observerId, unregisterApplicationStateObserverCallback);
+} catch (paramError) {
+ console.log('error: ' + paramError.code + ', ' + paramError.message);
+}
+```
## appManager.off
@@ -361,38 +522,73 @@ Deregisters the application state observer. This API uses an asynchronous callba
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| type | string | Yes| Type of the API to call.|
-| observerId | number | Yes| Numeric code of the observer.|
+| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.|
+| observerId | number | Yes| Digital code of the observer.|
**Return value**
| Type| Description|
| -------- | -------- |
-| Promise\ | Promise used to return the result.|
+| Promise\ | Promise used to return the API call result. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```js
- var observerId = 100;
-
- try {
- app.off(observerId)
- .then((data) => {
- console.log('----------- unregisterApplicationStateObserver success ----------', data);
- })
- .catch((err) => {
- console.log('----------- unregisterApplicationStateObserver fail ----------', err);
- })
- } catch (paramError) {
- console.log('error: ' + paramError.code + ', ' + paramError.message);
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+let observeId = 0;
+
+// 1. Register an application state observer.
+let applicationStateObserver = {
+ onForegroundApplicationChanged(appStateData) {
+ console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`);
+ },
+ onAbilityStateChanged(abilityStateData) {
+ console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
+ },
+ onProcessCreated(processData) {
+ console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`);
+ },
+ onProcessDied(processData) {
+ console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`);
+ },
+ onProcessStateChanged(processData) {
+ console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`);
}
- ```
+}
+let bundleNameList = ['bundleName1', 'bundleName2'];
+try {
+ observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList);
+ console.log(`[appManager] observerCode: ${observerId}`);
+} catch (paramError) {
+ console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `);
+}
+
+// 2. Deregister the application state observer.
+try {
+ appManager.off("applicationState", observerId).then((data) => {
+ 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);
+}
+```
## appManager.getForegroundApplications
getForegroundApplications(callback: AsyncCallback\>): void;
-Obtains applications that are running in the foreground. This API uses an asynchronous callback to return the result.
+Obtains 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
@@ -400,96 +596,44 @@ Obtains applications that are running in the foreground. This API uses an asynch
**System API**: This is a system API and cannot be called by third-party applications.
-**Parameters**
-
-| Name| Type| Mandatory| Description|
-| -------- | -------- | -------- | -------- |
-| callback | AsyncCallback\> | Yes| Callback used to return the application state data.|
-
-**Example**
-
- ```js
- function getForegroundApplicationsCallback(err, data) {
- if (err) {
- console.log('--------- getForegroundApplicationsCallback fail ---------', err.code + ': ' + err.message);
- } else {
- console.log('--------- getForegroundApplicationsCallback success ---------', data)
- }
- }
- app.getForegroundApplications(getForegroundApplicationsCallback);
- ```
-
-unregisterApplicationStateObserver(observerId: number): Promise\;
-
-Deregisters the application state observer. This API uses a promise to return the result.
-
-**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
+**Error codes**
-**System capability**: SystemCapability.Ability.AbilityRuntime.Core
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
-**System API**: This is a system API and cannot be called by third-party applications.
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| observerId | number | Yes| Numeric code of the observer.|
-
-**Return value**
-
-| Type| Description|
-| -------- | -------- |
-| Promise\ | Promise used to return the result.|
+| callback | AsyncCallback\> | Yes| Callback used to return the API call result and an array holding the application state data. You can perform error handling or custom processing in this callback.|
**Example**
-
- ```ts
- var observerId = 100;
- app.unregisterApplicationStateObserver(observerId)
- .then((data) => {
- console.log('----------- unregisterApplicationStateObserver success ----------', data);
- })
- .catch((err) => {
- console.log('----------- unregisterApplicationStateObserver fail ----------', err);
- })
- ```
-
-## appManager.getForegroundApplications9+
-
-getForegroundApplications(callback: AsyncCallback\>): void;
-
-Obtains applications that are running in the foreground. This API uses an asynchronous callback to return the result.
-
-**Required permissions**: ohos.permission.GET_RUNNING_INFO
-**System capability**: SystemCapability.Ability.AbilityRuntime.Core
-
-**System API**: This is a system API and cannot be called by third-party applications.
-
-**Parameters**
-
-| Name| Type| Mandatory| Description|
-| -------- | -------- | -------- | -------- |
-| callback | AsyncCallback\> | Yes| Callback used to return the application state data.|
+```ts
+import appManager from '@ohos.app.ability.appManager';
-**Example**
-
- ```ts
- function getForegroundApplicationsCallback(err, data) {
- if (err) {
- console.log('--------- getForegroundApplicationsCallback fail ---------', err);
+function getForegroundApplicationsCallback(err, data) {
+ if (err.code !== 0) {
+ console.log("getForegroundApplicationsCallback fail, err: " + JSON.stringify(err));
} else {
- console.log('--------- getForegroundApplicationsCallback success ---------', data)
+ console.log("getForegroundApplicationsCallback success, data: " + JSON.stringify(data));
}
- }
- app.getForegroundApplications(getForegroundApplicationsCallback);
- ```
+}
+try {
+ appManager.getForegroundApplications(getForegroundApplicationsCallback);
+} catch (paramError) {
+ console.log("error: " + paramError.code + ", " + paramError.message);
+}
+```
-## appManager.getForegroundApplications9+
+## appManager.getForegroundApplications
getForegroundApplications(): Promise\>;
-Obtains applications that are running in the foreground. This API uses a promise to return the result.
+Obtains applications that are running in the foreground. This API uses a promise to return the result. The application information is defined by [AppStateData](js-apis-inner-application-appStateData.md).
**Required permissions**: ohos.permission.GET_RUNNING_INFO
@@ -501,27 +645,35 @@ Obtains applications that are running in the foreground. This API uses a promise
| Type| Description|
| -------- | -------- |
-| Promise\> | Promise used to return the application state data.|
+| Promise\> | Promise used to return an array holding the application state data|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- app.getForegroundApplications()
- .then((data) => {
- console.log('--------- getForegroundApplications success -------', data);
- })
- .catch((err) => {
- console.log('--------- getForegroundApplications fail -------', err);
- })
- ```
-
-## appManager.killProcessWithAccount9+
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+appManager.getForegroundApplications().then((data) => {
+ console.log("getForegroundApplications success, data: " + JSON.stringify(data));
+}).catch((err) => {
+ console.log("getForegroundApplications fail, err: " + JSON.stringify(err));
+})
+```
+
+## appManager.killProcessWithAccount
killProcessWithAccount(bundleName: string, accountId: number): Promise\
Kills a process by bundle name and account ID. This API uses a promise to return the result.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -529,27 +681,39 @@ Kills a process by bundle name and account ID. This API uses a promise to return
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | bundleName | string | Yes| Bundle name of an application.|
- | accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| bundleName | string | Yes| Bundle name.|
+| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
-var bundleName = 'bundleName';
-var accountId = 0;
-app.killProcessWithAccount(bundleName, accountId)
- .then((data) => {
- console.log('------------ killProcessWithAccount success ------------', data);
- })
- .catch((err) => {
- console.log('------------ killProcessWithAccount fail ------------', err);
- })
+import appManager from '@ohos.app.ability.appManager';
+
+let bundleName = 'bundleName';
+let accountId = 0;
+try {
+ appManager.killProcessWithAccount(bundleName, accountId).then(() => {
+ console.log("killProcessWithAccount success");
+ }).catch((err) => {
+ console.log("killProcessWithAccount fail, err: " + JSON.stringify(err));
+ })
+} catch (paramError) {
+ console.log("error: " + paramError.code + ", " + paramError.message);
+}
```
-## appManager.killProcessWithAccount9+
+## appManager.killProcessWithAccount
killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\): void
@@ -559,32 +723,42 @@ Kills a process by bundle name and account ID. This API uses an asynchronous cal
**System API**: This is a system API and cannot be called by third-party applications.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
- | bundleName | string | Yes| Bundle name of an application.|
+ | bundleName | string | Yes| Bundle name.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
- | callback | AsyncCallback\ | Yes| Callback used to return the result.|
+ | callback | AsyncCallback\ | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
-var bundleName = 'bundleName';
-var accountId = 0;
+import appManager from '@ohos.app.ability.appManager';
+
+let bundleName = 'bundleName';
+let accountId = 0;
function killProcessWithAccountCallback(err, data) {
- if (err) {
- console.log('------------- killProcessWithAccountCallback fail, err: --------------', err);
- } else {
- console.log('------------- killProcessWithAccountCallback success, data: --------------', data);
- }
+ if (err.code !== 0) {
+ console.log("killProcessWithAccountCallback fail, err: " + JSON.stringify(err));
+ } else {
+ console.log("killProcessWithAccountCallback success.");
+ }
}
-app.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
+appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
```
-## appManager.killProcessesByBundleName9+
+## appManager.killProcessesByBundleName
killProcessesByBundleName(bundleName: string, callback: AsyncCallback\);
@@ -600,24 +774,38 @@ Kills a process by bundle name. This API uses an asynchronous callback to return
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| bundleName | string | Yes| Bundle name of an application.|
-| callback | AsyncCallback\ | Yes| Callback used to return the result.|
+| bundleName | string | Yes| Bundle name.|
+| callback | AsyncCallback\ | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- var bundleName = 'bundleName';
- function killProcessesByBundleNameCallback(err, data) {
- if (err) {
- console.log('------------- killProcessesByBundleNameCallback fail, err: --------------', err);
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+let bundleName = 'bundleName';
+function killProcessesByBundleNameCallback(err, data) {
+ if (err.code !== 0) {
+ console.log("killProcessesByBundleNameCallback fail, err: " + JSON.stringify(err));
} else {
- console.log('------------- killProcessesByBundleNameCallback success, data: --------------', data);
+ console.log("killProcessesByBundleNameCallback success.");
}
- }
- app.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback);
- ```
+}
+try {
+ appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback);
+} catch (paramError) {
+ console.log("error: " + paramError.code + ", " + paramError.message);
+}
+```
-## appManager.killProcessesByBundleName9+
+## appManager.killProcessesByBundleName
killProcessesByBundleName(bundleName: string): Promise\;
@@ -633,7 +821,7 @@ Kills a process by bundle name. This API uses a promise to return the result.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| bundleName | string | Yes| Bundle name of an application.|
+| bundleName | string | Yes| Bundle name.|
**Return value**
@@ -641,20 +829,32 @@ Kills a process by bundle name. This API uses a promise to return the result.
| -------- | -------- |
| Promise\ | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
**Example**
-
- ```ts
-var bundleName = 'bundleName';
-app.killProcessesByBundleName(bundleName)
- .then((data) => {
- console.log('------------ killProcessesByBundleName success ------------', data);
- })
- .catch((err) => {
- console.log('------------ killProcessesByBundleName fail ------------', err);
- })
- ```
-
-## appManager.clearUpApplicationData9+
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+let bundleName = 'bundleName';
+try {
+ appManager.killProcessesByBundleName(bundleName).then((data) => {
+ console.log("killProcessesByBundleName success.");
+ }).catch((err) => {
+ console.log("killProcessesByBundleName fail, err: " + JSON.stringify(err));
+ })
+} catch (paramError) {
+ console.log("error: " + paramError.code + ", " + paramError.message);
+}
+```
+
+## appManager.clearUpApplicationData
clearUpApplicationData(bundleName: string, callback: AsyncCallback\);
@@ -670,24 +870,38 @@ Clears application data by bundle name. This API uses an asynchronous callback t
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| bundleName | string | Yes| Bundle name of an application.|
-| callback | AsyncCallback\ | Yes| Callback used to return the result.|
+| bundleName | string | Yes| Bundle name.|
+| callback | AsyncCallback\ | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- var bundleName = 'bundleName';
- function clearUpApplicationDataCallback(err, data) {
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+let bundleName = 'bundleName';
+function clearUpApplicationDataCallback(err, data) {
if (err) {
- console.log('------------- clearUpApplicationDataCallback fail, err: --------------', err);
+ console.log("clearUpApplicationDataCallback fail, err: " + JSON.stringify(err));
} else {
- console.log('------------- clearUpApplicationDataCallback success, data: --------------', data);
+ console.log("clearUpApplicationDataCallback success.");
}
- }
- app.clearUpApplicationData(bundleName, clearUpApplicationDataCallback);
- ```
+}
+try {
+ appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback);
+} catch (paramError) {
+ console.log("error: " + paramError.code + ", " + paramError.message);
+}
+```
-## appManager.clearUpApplicationData9+
+## appManager.clearUpApplicationData
clearUpApplicationData(bundleName: string): Promise\;
@@ -703,28 +917,42 @@ Clears application data by bundle name. This API uses a promise to return the re
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| bundleName | string | Yes| Bundle name of an application.|
+| bundleName | string | Yes| Bundle name.|
**Return value**
| Type| Description|
| -------- | -------- |
-| Promise\ | Promise used to return the result.|
+| Promise\ | Promise used to return the API call result. You can perform error handling or custom processing in this callback.|
+
+**Error codes**
+
+| ID| Error Message|
+| ------- | -------- |
+| 16000050 | Internal error. |
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
-
- ```ts
- var bundleName = 'bundleName';
- app.clearUpApplicationData(bundleName)
- .then((data) => {
- console.log('------------ clearUpApplicationData success ------------', data);
- })
- .catch((err) => {
- console.log('------------ clearUpApplicationData fail ------------', err);
+
+```ts
+import appManager from '@ohos.app.ability.appManager';
+
+let bundleName = 'bundleName';
+try {
+ appManager.clearUpApplicationData(bundleName).then((data) => {
+ console.log("clearUpApplicationData success.");
+ }).catch((err) => {
+ console.log("clearUpApplicationData fail, err: " + JSON.stringify(err));
})
- ```
+} catch (paramError) {
+ console.log("error: " + paramError.code + ", " + paramError.message);
+}
+```
-## ApplicationState9+
+## ApplicationState
+
+Enumerates the application states. This enum can be used together with [AbilityStateData](js-apis-inner-application-appStateData.md) to return the application state.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -738,7 +966,9 @@ Clears application data by bundle name. This API uses a promise to return the re
| STATE_BACKGROUND | 4 | State indicating that the application is running in the background. |
| STATE_DESTROY | 5 | State indicating that the application is destroyed. |
-## ProcessState9+
+## ProcessState
+
+Enumerates the process states. This enum can be used together with [ProcessData](js-apis-inner-application-processData.md) to return the process state.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md b/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md
index 6f512b4f9f32904106f9120ea2fcc1095ec732b8..e066ac119344842ffce617fd7934efa3712d895f 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md
@@ -1,6 +1,6 @@
-# @ohos.app.ability.appRecovery (Application Recovery)
+# @ohos.app.ability.appRecovery (appRecovery)
-The **appRecovery** module provides APIs for recovering failed applications.
+The **appRecovery** module provides APIs for recovering faulty applications.
> **NOTE**
>
@@ -8,13 +8,13 @@ The **appRecovery** module provides APIs for recovering failed applications.
## Modules to Import
```ts
-import appRecovery from '@ohos.app.ability.appRecovery'
+import appRecovery from '@ohos.app.ability.appRecovery';
```
## appRecovery.RestartFlag
-Enumerates the application restart options used in [enableAppRecovery](#apprecoveryenableapprecovery).
+Enumerates the application restart flags. This enum is used as an input parameter of [enableAppRecovery](#apprecoveryenableapprecovery).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -28,7 +28,7 @@ Enumerates the application restart options used in [enableAppRecovery](#apprecov
## appRecovery.SaveOccasionFlag
-Enumerates the scenarios for saving the application state, which is used in [enableAppRecovery](#apprecoveryenableapprecovery).
+Enumerates the scenarios for saving the application state. This enum is used as an input parameter of [enableAppRecovery](#apprecoveryenableapprecovery).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -39,7 +39,7 @@ Enumerates the scenarios for saving the application state, which is used in [ena
## appRecovery.SaveModeFlag
-Enumerates the application state saving modes used in [enableAppRecovery](#apprecoveryenableapprecovery).
+Enumerates the application state saving modes. This enum is used as an input parameter of [enableAppRecovery](#apprecoveryenableapprecovery).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -50,7 +50,7 @@ Enumerates the application state saving modes used in [enableAppRecovery](#appre
## appRecovery.enableAppRecovery
-enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMode?: SaveModeFlag) : void;
+enableAppRecovery(restart?: [RestartFlag](#apprecoveryrestartflag), saveOccasion?: [SaveOccasionFlag](#apprecoverysaveoccasionflag), saveMode?: [SaveModeFlag](#apprecoverysavemodeflag)) : void;
Enables application recovery.
@@ -67,9 +67,17 @@ Enables application recovery.
**Example**
```ts
-export default class MyAbilityStage extends AbilityStage {
+import appRecovery from '@ohos.app.ability.appRecovery';
+import AbilityStage from '@ohos.app.ability.AbilityStage';
+import UIAbility from '@ohos.app.ability.UIAbility';
+
+export default class MyAbility extends UIAbility {
onCreate() {
- appRecovery.enableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR, SaveModeFlag::SAVE_WITH_FILE);
+ appRecovery.enableAppRecovery(
+ appRecovery.RestartFlag::ALWAYS_RESTART,
+ appRecovery.SaveOccasionFlag::SAVE_WHEN_ERROR,
+ appRecovery.SaveModeFlag::SAVE_WITH_FILE
+ );
}
}
```
@@ -86,13 +94,21 @@ Restarts the application. This API can be used together with APIs of [errorManag
**Example**
```ts
-var observer = {
+import appRecovery from '@ohos.app.ability.appRecovery';
+import errorManager from '@ohos.app.ability.errorManager';
+
+let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
appRecovery.restartApp();
}
-}
+};
+try {
+ errorManager.on("error", observer);
+} catch (paramError) {
+ console.log("error: " + paramError.code + ", " + paramError.message);
+}
```
## appRecovery.saveAppState
@@ -107,15 +123,24 @@ Saves the application state. This API can be used together with APIs of [errorMa
| Type| Description|
| -------- | -------- |
-| boolean | Whether the saving is successful.|
+| boolean | Whether the application state is saved. The value **true** is returned if the application state is saved, and **false** is returned otherwise.|
**Example**
```ts
-var observer = {
+import appRecovery from '@ohos.app.ability.appRecovery';
+import errorManager from '@ohos.app.ability.errorManager';
+
+let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
appRecovery.saveAppState();
}
+};
+
+try {
+ errorManager.on("error", observer);
+} catch (paramError) {
+ console.log("error: " + paramError.code + ", " + paramError.message);
}
```
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-common.md b/en/application-dev/reference/apis/js-apis-app-ability-common.md
index 23184c6036f12bd3c914d7b500fece72afafc538..5cc9b61b90fb3072aacf530fdaee0ae2633f7ac0 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-common.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-common.md
@@ -1,4 +1,4 @@
-# @ohos.app.ability.common
+# @ohos.app.ability.common (Context)
The **Common** module provides all level-2 module APIs for developers to export.
@@ -15,21 +15,21 @@ import common from '@ohos.app.ability.common'
**System capability**: SystemCapability.Ability.AbilityBase
-| Name | Type | Mandatory| Description |
-| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
-| UIAbilityContext | [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md) | No | Level-2 module **UIAbilityContext**. |
-| AbilityStageContext | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | No | Level-2 module **AbilityStageContext**.|
-| ApplicationContext | [ApplicationContext](js-apis-inner-application-applicationContext.md) | No | Level-2 module **ApplicationContext**.|
-| BaseContext | [BaseContext](js-apis-inner-application-baseContext.md) | No | Level-2 module **BaseContext**.|
-| Context | [Context](js-apis-inner-application-context.md) | No | Level-2 module **Context**.|
-| ExtensionContext | [ExtensionContext](js-apis-inner-application-extensionContext.md) | No | Level-2 module **ExtensionContext**.|
-| FormExtensionContext | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | No | Level-2 module **FormExtensionContext**.|
-| AreaMode | [AreaMode](#areamode) | No | Enumerated values of **AreaMode**.|
-| EventHub | [EventHub](js-apis-inner-application-eventHub.md) | No | Level-2 module **EventHub**.|
-| PermissionRequestResult | [PermissionRequestResult](js-apis-inner-application-permissionRequestResult.md) | No | Level-2 module **PermissionRequestResult**.|
-| PacMap | [PacMap](js-apis-inner-ability-dataAbilityHelper.md#PacMap) | No | Level-2 module **PacMap**.|
-| AbilityResult | [AbilityResult](js-apis-inner-ability-abilityResult.md) | No | Level-2 module **AbilityResult**.|
-| ConnectOptions | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | No | Level-2 module **ConnectOptions**.|
+| Name | Type | Description |
+| ----------- | -------------------- | ------------------------------------------------------------ |
+| UIAbilityContext | [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md) | Level-2 module **UIAbilityContext**. |
+| AbilityStageContext | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | Level-2 module **AbilityStageContext**.|
+| ApplicationContext | [ApplicationContext](js-apis-inner-application-applicationContext.md) | Level-2 module **ApplicationContext**.|
+| BaseContext | [BaseContext](js-apis-inner-application-baseContext.md) | Level-2 module **BaseContext**.|
+| Context | [Context](js-apis-inner-application-context.md) | Level-2 module **Context**.|
+| ExtensionContext | [ExtensionContext](js-apis-inner-application-extensionContext.md) | Level-2 module **ExtensionContext**.|
+| FormExtensionContext | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | Level-2 module **FormExtensionContext**.|
+| AreaMode | [AreaMode](#areamode) | Enumerated values of **AreaMode**.|
+| EventHub | [EventHub](js-apis-inner-application-eventHub.md) | Level-2 module **EventHub**.|
+| PermissionRequestResult | [PermissionRequestResult](js-apis-inner-application-permissionRequestResult.md) | Level-2 module **PermissionRequestResult**.|
+| PacMap | [PacMap](js-apis-inner-ability-dataAbilityHelper.md#PacMap) | Level-2 module **PacMap**.|
+| AbilityResult | [AbilityResult](js-apis-inner-ability-abilityResult.md) | Level-2 module **AbilityResult**.|
+| ConnectOptions | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | Level-2 module **ConnectOptions**.|
**Example**
```ts
@@ -52,11 +52,11 @@ let connectOptions: common.ConnectOptions;
## AreaMode
-Defines the area where the file to be access is located. Each area has its own content.
+Enumerates the data encryption levels.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| --------------- | ---- | --------------- |
-| EL1 | 0 | Device-level encryption area. |
-| EL2 | 1 | User credential encryption area. The default value is **EL2**.|
+| EL1 | 0 | Device-level encryption area, which is accessible after the device is powered on. |
+| EL2 | 1 | User-level encryption area, which is accessible only after the device is powered on and the password is entered (for the first time).|
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-configuration.md b/en/application-dev/reference/apis/js-apis-app-ability-configuration.md
index 90075377af701150b8de77600ed3ae3808b50d41..88aab2d4026afac5edaf8c3c7ff58033976e3e66 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-configuration.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-configuration.md
@@ -1,4 +1,4 @@
-# @ohos.app.ability.Configuration
+# @ohos.app.ability.Configuration (Configuration)
The **Configuration** module defines environment change information.
@@ -14,34 +14,42 @@ 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.|
+| 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 | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.|
-| screenDensity | ScreenDensity | 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).|
+| 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).|
| 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.|
For details about the fields, see the **ohos.app.ability.Configuration.d.ts** file.
-**Example**
-
+**Example**
+
```ts
- let envCallback = {
- onConfigurationUpdated(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;
+ import UIAbility from '@ohos.app.ability.UIAbility';
+
+ export default class EntryAbility extends UIAbility {
+ onCreate(want, launchParam) {
+ let envCallback = {
+ onConfigurationUpdated(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;
+ }
+ };
+ try {
+ let applicationContext = this.context.getApplicationContext();
+ let callbackId = applicationContext.on("environment", envCallback);
+ console.log("callbackId: " + callbackId);
+ } catch (paramError) {
+ console.log("error: " + paramError.code + ", " + paramError.message);
+ }
}
- };
- try {
- var callbackId = applicationContext.on("environment", envCallback);
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
}
```
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-configurationConstant.md b/en/application-dev/reference/apis/js-apis-app-ability-configurationConstant.md
index 24b6b4745b1ba606cdb40c741fa2fcf10376cc06..bd56e256603930f874c9ba2c064462c8fad594a8 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-configurationConstant.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-configurationConstant.md
@@ -1,4 +1,4 @@
-# @ohos.app.ability.ConfigurationConstant
+# @ohos.app.ability.ConfigurationConstant (ConfigurationConstant)
The **ConfigurationConstant** module provides the enumerated values of the environment configuration information.
@@ -25,7 +25,7 @@ You can obtain the value of this constant by calling the **ConfigurationConstant
| COLOR_MODE_LIGHT | 1 | Light mode.|
-## ConfigurationConstant.Direction9+
+## ConfigurationConstant.Direction
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.ScreenDensity9+
+## ConfigurationConstant.ScreenDensity
You can obtain the value of this constant by calling the **ConfigurationConstant.ScreenDensity** API.
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-contextConstant.md b/en/application-dev/reference/apis/js-apis-app-ability-contextConstant.md
index dc1b5a1430c8c063de23cc87126ff891d5363b80..0c39c8fa01fe62a537614287f3d27645c8b0f354 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-contextConstant.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-contextConstant.md
@@ -1,6 +1,6 @@
-# @ohos.app.ability.contextConstant
+# @ohos.app.ability.contextConstant (ContextConstant)
-The **ContextConstant** module defines data encryption levels.
+The **ContextConstant** module defines context-related enums. Currently, it defines only the enum of data encryption levels.
> **NOTE**
>
@@ -19,7 +19,7 @@ You can obtain the value of this constant by calling the **ContextConstant.AreaM
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
-| Name| Value| Description|
+| Name| Value| Description|
| -------- | -------- | -------- |
-| EL1 | 0 | Device-level encryption area.|
-| EL2 | 1 | User credential encryption area.|
+| EL1 | 0 | Device-level encryption area, which is accessible after the device is powered on.|
+| EL2 | 1 | User-level encryption area, which is accessible only after the device is powered on and the password is entered (for the first time).|
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-dataUriUtils.md b/en/application-dev/reference/apis/js-apis-app-ability-dataUriUtils.md
index c7a6f6021594569e01519814160894fff5096c2d..9a869f051a08c4a79c9dac58e8f4dceb9dc4658b 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-dataUriUtils.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-dataUriUtils.md
@@ -1,4 +1,4 @@
-# @ohos.app.ability.dataUriUtils
+# @ohos.app.ability.dataUriUtils (DataUriUtils)
The **DataUriUtils** module provides APIs to process URI objects. You can use the APIs to attach an ID to the end of a given URI and obtain, delete, or update the ID attached to the end of a given URI.
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-environmentCallback.md b/en/application-dev/reference/apis/js-apis-app-ability-environmentCallback.md
index 1208aeb8dabdbc09b77a9395e0ad313b1bf7e8cd..0cb95a9abfd6b90f1efacc431070ef6b3397e1e6 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-environmentCallback.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-environmentCallback.md
@@ -1,4 +1,4 @@
-# @ohos.app.ability.EnvironmentCallback
+# @ohos.app.ability.EnvironmentCallback (EnvironmentCallback)
The **EnvironmentCallback** module provides the **onConfigurationUpdated** API for the application context to listen for system environment changes.
@@ -33,18 +33,18 @@ Called when the system environment changes.
```ts
-import Ability from "@ohos.application.Ability";
+import UIAbility from "@ohos.app.ability.Ability";
var callbackId;
-export default class MyAbility extends Ability {
+export default class MyAbility extends UIAbility {
onCreate() {
console.log("MyAbility onCreate")
globalThis.applicationContext = this.context.getApplicationContext();
let EnvironmentCallback = {
onConfigurationUpdated(config){
console.log("onConfigurationUpdated config:" + JSON.stringify(config));
- },
+ }
}
// 1. Obtain an applicationContext object.
let applicationContext = globalThis.applicationContext;
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-errorManager.md b/en/application-dev/reference/apis/js-apis-app-ability-errorManager.md
index f7203ef5de08d0151d65e2c65cf19b6e3855c1ea..e543a93e9ceb5af52f3cdb939a0cfd5d24145968 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-errorManager.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-errorManager.md
@@ -1,13 +1,13 @@
-# @ohos.app.ability.errorManager (Error Manager)
+# @ohos.app.ability.errorManager (ErrorManager)
-The **errorManager** module provides APIs for registering and deregistering error observers.
+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.
> **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'
```
@@ -23,19 +23,26 @@ Registers an error observer.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| type | string | Yes| Type of the API to call.|
-| observer | [ErrorObserver](./js-apis-inner-application-errorObserver.md) | Yes| Numeric code of the observer.|
+| type | string | Yes| Type of the API to call. It is fixed at **"error"**.|
+| observer | [ErrorObserver](./js-apis-inner-application-errorObserver.md) | Yes| Digital code of the observer.|
+
+**Return value**
+
+ | Type| Description|
+ | -------- | -------- |
+ | number | Index of the observer.|
**Example**
-```js
+```ts
var observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
}
}
+var observerId = -1;
try {
- errorManager.on("error", observer);
+ observerId = errorManager.on("error", observer);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
@@ -53,13 +60,13 @@ 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.|
-| observerId | number | Yes| Numeric code of the observer.|
+| type | string | Yes| Type of the API to call. It is fixed at **"error"**.|
+| observerId | number | Yes| Index of the observer returned by **on()**.|
| callback | AsyncCallback\ | Yes| Callback used to return the result.|
**Example**
-```js
+```ts
var observerId = 100;
function unregisterErrorObserverCallback(err) {
@@ -86,8 +93,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.|
-| observerId | number | Yes| Numeric code of the observer.|
+| type | string | Yes| Type of the API to call. It is fixed at **"error"**.|
+| observerId | number | Yes| Index of the observer returned by **on()**.|
**Return value**
@@ -97,7 +104,7 @@ Deregisters an error observer. This API uses a promise to return the result.
**Example**
-```js
+```ts
var observerId = 100;
try {
errorManager.off("error", observerId)
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-extensionAbility.md b/en/application-dev/reference/apis/js-apis-app-ability-extensionAbility.md
index b53881f7fdb5df90cf0a1783c04554ce93240b04..d532723b43a1c31f2b01b35799747ec689df5099 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-extensionAbility.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-extensionAbility.md
@@ -1,30 +1,10 @@
-# @ohos.app.ability.ExtensionAbility
+# @ohos.app.ability.ExtensionAbility (ExtensionAbility Base Class)
-The **ExtensionAbility** module manages the Extension ability lifecycle and context, such as creating and destroying an Extension ability, and dumping client information.
+**ExtensionAbility** is the base class for scenario-specific ExtensionAbilities. It is inherited from [Ability](js-apis-app-ability-ability.md), with no attribute or method added. You cannot inherit from this base class.
> **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 can be used only in the stage model.
-## Modules to Import
-
-```ts
-import ExtensionAbility from '@ohos.app.ability.ExtensionAbility';
-```
-
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
-
-**Example**
-
- ```ts
- class MyExtensionAbility extends ExtensionAbility {
- onConfigurationUpdated(config) {
- console.log('onConfigurationUpdated, config:' + JSON.stringify(config));
- }
-
- onMemoryLevel(level) {
- console.log('onMemoryLevel, level:' + JSON.stringify(level));
- }
- }
- ```
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-missionManager.md b/en/application-dev/reference/apis/js-apis-app-ability-missionManager.md
index 4f989652d549a118d01097b3a8ec2f5084ec0031..434fb19383e072a36352012300c2a755769d6c1f 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-missionManager.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-missionManager.md
@@ -1,15 +1,15 @@
-# @ohos.app.ability.missionManager
+# @ohos.app.ability.missionManager (missionManager)
The **missionManager** module provides APIs to lock, unlock, and clear missions, and switch a mission to the foreground.
> **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 missionManager from '@ohos.app.ability.missionManager'
+import missionManager from '@ohos.app.ability.missionManager';
```
## Required Permissions
@@ -32,19 +32,19 @@ Registers a listener to observe the mission status.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
- | listener | MissionListener | Yes| Listener to register.|
+ | listener | [MissionListener](js-apis-inner-application-missionListener.md) | Yes| Mission status listener to register.|
**Return value**
| Type| Description|
| -------- | -------- |
- | number | Returns the unique index of the mission status listener, which is created by the system and allocated when the listener is registered.|
+ | number | Index of the mission status listener, which is created by the system and allocated when the listener is registered.|
**Example**
```ts
-import Ability from '@ohos.application.Ability'
import missionManager from '@ohos.app.ability.missionManager';
+import UIAbility from '@ohos.app.ability.UIAbility';
var listener = {
onMissionCreated: function (mission) {console.log("--------onMissionCreated-------")},
@@ -52,14 +52,15 @@ var listener = {
onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")},
onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")},
onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")},
- onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")}
+ onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")},
+ onMissionLabelUpdated: function (mission) {console.log("--------onMissionLabelUpdated-------")}
};
var listenerId = -1;
-export default class MainAbility extends Ability {
+export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
- console.log("[Demo] MainAbility onCreate")
+ console.log("[Demo] EntryAbility onCreate");
globalThis.abilityWant = want;
globalThis.context = this.context;
}
@@ -74,12 +75,12 @@ export default class MainAbility extends Ability {
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
- console.log("[Demo] MainAbility onDestroy")
+ console.log("[Demo] EntryAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// The main window is created. Set a main page for this ability.
- console.log("[Demo] MainAbility onWindowStageCreate")
+ console.log("[Demo] EntryAbility onWindowStageCreate")
try {
listenerId = missionManager.on("mission", listener);
} catch (paramError) {
@@ -106,7 +107,7 @@ export default class MainAbility extends Ability {
off(type: "mission", listenerId: number, callback: AsyncCallback<void>): void;
-Deregisters a mission status listener. This API uses an asynchronous callback to return the result.
+Deregisters a mission status listener.
**Required permissions**: ohos.permission.MANAGE_MISSIONS
@@ -118,14 +119,14 @@ Deregisters a mission status listener. This API uses an asynchronous callback to
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
- | listenerId | number | Yes| Unique index of the mission status listener to unregister. It is returned by **registerMissionListener**.|
+ | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **on()**.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Example**
```ts
-import Ability from '@ohos.application.Ability'
import missionManager from '@ohos.app.ability.missionManager';
+import UIAbility from '@ohos.app.ability.UIAbility';
var listener = {
onMissionCreated: function (mission) {console.log("--------onMissionCreated-------")},
@@ -133,14 +134,15 @@ var listener = {
onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")},
onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")},
onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")},
- onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")}
+ onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")},
+ onMissionLabelUpdated: function (mission) {console.log("--------onMissionLabelUpdated-------")}
};
var listenerId = -1;
-export default class MainAbility extends Ability {
+export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
- console.log("[Demo] MainAbility onCreate")
+ console.log("[Demo] EntryAbility onCreate")
globalThis.abilityWant = want;
globalThis.context = this.context;
}
@@ -155,12 +157,12 @@ export default class MainAbility extends Ability {
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
- console.log("[Demo] MainAbility onDestroy")
+ console.log("[Demo] EntryAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// The main window is created. Set a main page for this ability.
- console.log("[Demo] MainAbility onWindowStageCreate")
+ console.log("[Demo] EntryAbility onWindowStageCreate")
try {
listenerId = missionManager.on("mission", listener);
} catch (paramError) {
@@ -199,19 +201,19 @@ Deregisters a mission status listener. This API uses a promise to return the res
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
- | listenerId | number | Yes| Unique index of the mission status listener to unregister. It is returned by **registerMissionListener**.|
+ | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **on()**.|
**Return value**
- | Type| Description|
+ | Type| Description|
| -------- | -------- |
- | Promise<void> | Promise used to return the result.|
+ | Promise<void> | Promise used to return the result.|
**Example**
```ts
-import Ability from '@ohos.application.Ability'
import missionManager from '@ohos.app.ability.missionManager';
+import UIAbility from '@ohos.app.ability.UIAbility';
var listener = {
onMissionCreated: function (mission) {console.log("--------onMissionCreated-------")},
@@ -219,14 +221,15 @@ var listener = {
onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")},
onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")},
onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")},
- onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")}
+ onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")},
+ onMissionLabelUpdated: function (mission) {console.log("--------onMissionLabelUpdated-------")}
};
var listenerId = -1;
-export default class MainAbility extends Ability {
+export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
- console.log("[Demo] MainAbility onCreate")
+ console.log("[Demo] EntryAbility onCreate")
globalThis.abilityWant = want;
globalThis.context = this.context;
}
@@ -241,12 +244,12 @@ export default class MainAbility extends Ability {
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
- console.log("[Demo] MainAbility onDestroy")
+ console.log("[Demo] EntryAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// The main window is created. Set a main page for this ability.
- console.log("[Demo] MainAbility onWindowStageCreate")
+ console.log("[Demo] EntryAbility onWindowStageCreate")
try {
listenerId = missionManager.on("mission", listener);
} catch (paramError) {
@@ -292,19 +295,28 @@ Obtains the information about a given mission. This API uses an asynchronous cal
**Example**
```ts
- import missionManager from '@ohos.app.ability.missionManager'
+ import missionManager from '@ohos.app.ability.missionManager';
+ let testMissionId = 1;
try {
- var allMissions=missionManager.getMissionInfos("",10).catch(function(err){console.log(err);});
- missionManager.getMissionInfo("", allMissions[0].missionId, (error, mission) => {
- console.log("getMissionInfo is called, error.code = " + error.code)
- console.log("mission.missionId = " + mission.missionId);
- console.log("mission.runningState = " + mission.runningState);
- console.log("mission.lockedState = " + mission.lockedState);
- console.log("mission.timestamp = " + mission.timestamp);
- console.log("mission.label = " + mission.label);
- console.log("mission.iconPath = " + mission.iconPath);
- });
+ var allMissions=await missionManager.getMissionInfos("",10).catch(function(err){console.log(err);});
+ if (allMissions && allMissions.length > 0) {
+ testMissionId = allMissions[0].missionId;
+ }
+
+ missionManager.getMissionInfo("", testMissionId, (error, mission) => {
+ if (error) {
+ console.log("getMissionInfo failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ } else {
+ console.log("mission.missionId = " + mission.missionId);
+ console.log("mission.runningState = " + mission.runningState);
+ console.log("mission.lockedState = " + mission.lockedState);
+ console.log("mission.timestamp = " + mission.timestamp);
+ console.log("mission.label = " + mission.label);
+ console.log("mission.iconPath = " + mission.iconPath);
+ }
+ });
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
@@ -338,18 +350,20 @@ Obtains the information about a given mission. This API uses a promise to return
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- try {
- var mission = missionManager.getMissionInfo("", 10).catch(function (err){
- console.log(err);
+let testMissionId = 1;
+try {
+ missionManager.getMissionInfo("", testMissionId).then((data) => {
+ console.info('getMissionInfo successfully. Data: ' + JSON.stringify(data));
+ }).catch(error => {
+ console.error('getMissionInfo failed. Cause: ' + error.message);
});
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
-
+} catch (error) {
+ console.error('getMissionInfo failed. Cause: ' + error.message);
+}
+```
## missionManager.getMissionInfos
@@ -374,13 +388,17 @@ Obtains information about all missions. This API uses an asynchronous callback t
**Example**
```ts
- import missionManager from '@ohos.app.ability.missionManager'
+ import missionManager from '@ohos.app.ability.missionManager';
try {
missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
- console.log("size = " + missions.length);
- console.log("missions = " + JSON.stringify(missions));
+ if (error) {
+ console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ } else {
+ console.log("size = " + missions.length);
+ console.log("missions = " + JSON.stringify(missions));
+ }
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
@@ -415,18 +433,19 @@ Obtains information about all missions. This API uses a promise to return the re
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- try {
- var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
- console.log(err);
+try {
+ missionManager.getMissionInfos("", 10).then((data) => {
+ console.info('getMissionInfos successfully. Data: ' + JSON.stringify(data));
+ }).catch(error => {
+ console.error('getMissionInfos failed. Cause: ' + error.message);
});
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
-
+} catch (error) {
+ console.error('getMissionInfos failed. Cause: ' + error.message);
+}
+```
## missionManager.getMissionSnapShot
@@ -449,27 +468,22 @@ Obtains the snapshot of a given mission. This API uses an asynchronous callback
| callback | AsyncCallback<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.|
**Example**
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
-
- try {
- missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
- console.log("size = " + missions.length);
- console.log("missions = " + JSON.stringify(missions));
- var id = missions[0].missionId;
-
- missionManager.getMissionSnapShot("", id, (error, snapshot) => {
- console.log("getMissionSnapShot is called, error.code = " + error.code);
- console.log("bundleName = " + snapshot.ability.bundleName);
- })
- })
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
-
+let testMissionId = 2;
+try {
+ missionManager.getMissionSnapShot("", testMissionId, (err, data) => {
+ if (err) {
+ console.error('getMissionSnapShot failed:' + err.message);
+ } else {
+ console.info('getMissionSnapShot successfully:' + JSON.stringify(data));
+ }
+ });
+} catch (err) {
+ console.error('getMissionSnapShot failed:' + err.message);
+}
+```
## missionManager.getMissionSnapShot
@@ -497,26 +511,20 @@ Obtains the snapshot of a given mission. This API uses a promise to return the r
| Promise<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Promise used to return the snapshot information obtained.|
**Example**
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
-
- try {
- var allMissions;
- missionManager.getMissionInfos("",10).then(function(res){
- allMissions=res;
- }).catch(function(err){console.log(err);});
- console.log("size = " + allMissions.length);
- console.log("missions = " + JSON.stringify(allMissions));
- var id = allMissions[0].missionId;
-
- var snapshot = missionManager.getMissionSnapShot("", id).catch(function (err){
- console.log(err);
- });
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
+let testMissionId = 2;
+try {
+ missionManager.getMissionSnapShot("", testMissionId).then((data) => {
+ console.info('getMissionSnapShot successfully. Data: ' + JSON.stringify(data));
+ }).catch(error => {
+ console.error('getMissionSnapShot failed. Cause: ' + error.message);
+ });
+} catch (error) {
+ console.error('getMissionSnapShot failed. Cause: ' + error.message);
+}
+```
## missionManager.getLowResolutionMissionSnapShot
@@ -539,27 +547,22 @@ Obtains the low-resolution snapshot of a given mission. This API uses an asynchr
| callback | AsyncCallback<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.|
**Example**
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
-
- try {
- missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
- console.log("size = " + missions.length);
- console.log("missions = " + JSON.stringify(missions));
- var id = missions[0].missionId;
-
- missionManager.getLowResolutionMissionSnapShot("", id, (error, snapshot) => {
- console.log("getLowResolutionMissionSnapShot is called, error.code = " + error.code);
- console.log("bundleName = " + snapshot.ability.bundleName);
- })
- })
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
-
+let testMissionId = 2;
+try {
+ missionManager.getLowResolutionMissionSnapShot("", testMissionId, (err, data) => {
+ if (err) {
+ console.error('getLowResolutionMissionSnapShot failed:' + err.message);
+ } else {
+ console.info('getLowResolutionMissionSnapShot successfully:' + JSON.stringify(data));
+ }
+ });
+} catch (err) {
+ console.error('getLowResolutionMissionSnapShot failed:' + err.message);
+}
+```
## missionManager.getLowResolutionMissionSnapShot
@@ -588,25 +591,20 @@ Obtains the low-resolution snapshot of a given mission. This API uses a promise
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- try {
- var allMissions;
- missionManager.getMissionInfos("",10).then(function(res){
- allMissions=res;
- }).catch(function(err){console.log(err);});
- console.log("size = " + allMissions.length);
- console.log("missions = " + JSON.stringify(allMissions));
- var id = allMissions[0].missionId;
-
- var snapshot = missionManager.getLowResolutionMissionSnapShot("", id).catch(function (err){
- console.log(err);
- });
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
+let testMissionId = 2;
+try {
+ missionManager.getLowResolutionMissionSnapShot("", testMissionId).then((data) => {
+ console.info('getLowResolutionMissionSnapShot successfully. Data: ' + JSON.stringify(data));
+ }).catch(error => {
+ console.error('getLowResolutionMissionSnapShot failed. Cause: ' + error.message);
+ });
+} catch (error) {
+ console.error('getLowResolutionMissionSnapShot failed. Cause: ' + error.message);
+}
+```
## missionManager.lockMission
@@ -630,25 +628,22 @@ Locks a given mission. This API uses an asynchronous callback to return the resu
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- try {
- missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
- console.log("size = " + missions.length);
- console.log("missions = " + JSON.stringify(missions));
- var id = missions[0].missionId;
-
- missionManager.lockMission(id).then(() => {
- console.log("lockMission is called ");
- });
+let testMissionId = 2;
+try {
+ missionManager.lockMission(testMissionId, (err, data) => {
+ if (err) {
+ console.error('lockMission failed:' + err.message);
+ } else {
+ console.info('lockMission successfully:' + JSON.stringify(data));
+ }
});
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
-
+} catch (err) {
+ console.error('lockMission failed:' + err.message);
+}
+```
## missionManager.lockMission
@@ -670,32 +665,25 @@ Locks a given mission. This API uses a promise to return the result.
**Return value**
- | Type| Description|
+ | Type| Description|
| -------- | -------- |
- | Promise<void> | Promise used to return the result.|
+ | Promise<void> | Promise used to return the result.|
**Example**
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
-
- try {
- var allMissions;
- missionManager.getMissionInfos("",10).then(function(res){
- allMissions=res;
- }).catch(function(err){console.log(err);});
- console.log("size = " + allMissions.length);
- console.log("missions = " + JSON.stringify(allMissions));
- var id = allMissions[0].missionId;
-
- missionManager.lockMission(id).catch(function (err){
- console.log(err);
+let testMissionId = 2;
+try {
+ missionManager.lockMission(testMissionId).then((data) => {
+ console.info('lockMission successfully. Data: ' + JSON.stringify(data));
+ }).catch(error => {
+ console.error('lockMission failed. Cause: ' + error.message);
});
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
-
+} catch (error) {
+ console.error('lockMission failed. Cause: ' + error.message);
+}
+```
## missionManager.unlockMission
@@ -717,26 +705,22 @@ Unlocks a given mission. This API uses an asynchronous callback to return the re
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Example**
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
-
- try {
- missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
- console.log("size = " + missions.length);
- console.log("missions = " + JSON.stringify(missions));
- var id = missions[0].missionId;
-
- missionManager.unlockMission(id).then(() => {
- console.log("unlockMission is called ");
- });
+let testMissionId = 2;
+try {
+ missionManager.unlockMission(testMissionId, (err, data) => {
+ if (err) {
+ console.error('unlockMission failed:' + err.message);
+ } else {
+ console.info('unlockMission successfully:' + JSON.stringify(data));
+ }
});
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
-
+} catch (err) {
+ console.error('unlockMission failed:' + err.message);
+}
+```
## missionManager.unlockMission
@@ -758,35 +742,26 @@ Unlocks a given mission. This API uses a promise to return the result.
**Return value**
- | Type| Description|
+ | Type| Description|
| -------- | -------- |
- | Promise<void> | Promise used to return the result.|
+ | Promise<void> | Promise used to return the result.|
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- try {
- var allMissions;
- missionManager.getMissionInfos("",10).then(function(res){
- allMissions=res;
- }).catch(function(err){console.log(err);});
- console.log("size = " + allMissions.length);
- console.log("missions = " + JSON.stringify(allMissions));
- var id = allMissions[0].missionId;
-
- missionManager.lockMission(id).catch(function (err){
- console.log(err);
- });
- missionManager.unlockMission(id).catch(function (err){
- console.log(err);
+let testMissionId = 2;
+try {
+ missionManager.unlockMission(testMissionId).then((data) => {
+ console.info('unlockMission successfully. Data: ' + JSON.stringify(data));
+ }).catch(error => {
+ console.error('unlockMission failed. Cause: ' + error.message);
});
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
-
+} catch (error) {
+ console.error('unlockMission failed. Cause: ' + error.message);
+}
+```
## missionManager.clearMission
@@ -809,24 +784,22 @@ Clears a given mission, regardless of whether it is locked. This API uses an asy
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- try {
- missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
- console.log("size = " + missions.length);
- console.log("missions = " + JSON.stringify(missions));
- var id = missions[0].missionId;
-
- missionManager.clearMission(id).then(() => {
- console.log("clearMission is called ");
- });
+let testMissionId = 2;
+try {
+ missionManager.clearMission(testMissionId, (err, data) => {
+ if (err) {
+ console.error('clearMission failed:' + err.message);
+ } else {
+ console.info('clearMission successfully:' + JSON.stringify(data));
+ }
});
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
+} catch (err) {
+ console.error('clearMission failed:' + err.message);
+}
+```
## missionManager.clearMission
@@ -849,32 +822,26 @@ Clears a given mission, regardless of whether it is locked. This API uses a prom
**Return value**
- | Type| Description|
+ | Type| Description|
| -------- | -------- |
- | Promise<void> | Promise used to return the result.|
+ | Promise<void> | Promise used to return the result.|
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- try {
- var allMissions;
- missionManager.getMissionInfos("",10).then(function(res){
- allMissions=res;
- }).catch(function(err){console.log(err);});
- console.log("size = " + allMissions.length);
- console.log("missions = " + JSON.stringify(allMissions));
- var id = allMissions[0].missionId;
-
- missionManager.clearMission(id).catch(function (err){
- console.log(err);
+let testMissionId = 2;
+try {
+ missionManager.clearMission(testMissionId).then((data) => {
+ console.info('clearMission successfully. Data: ' + JSON.stringify(data));
+ }).catch(error => {
+ console.error('clearMission failed. Cause: ' + error.message);
});
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
-
+} catch (error) {
+ console.error('clearMission failed. Cause: ' + error.message);
+}
+```
## missionManager.clearAllMissions
@@ -890,14 +857,21 @@ Clears all unlocked missions. This API uses an asynchronous callback to return t
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
-
- missionManager.clearAllMissions().then(() => {
- console.log("clearAllMissions is called ");
- });
- ```
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
+try {
+ missionManager.clearAllMissions(err => {
+ if (err) {
+ console.error('clearAllMissions failed:' + err.message);
+ } else {
+ console.info('clearAllMissions successfully.');
+ }
+ });
+} catch (err) {
+ console.error('clearAllMissions failed:' + err.message);
+}
+```
## missionManager.clearAllMissions
@@ -913,19 +887,25 @@ Clears all unlocked missions. This API uses a promise to return the result.
**Return value**
- | Type| Description|
+ | Type| Description|
| -------- | -------- |
- | Promise<void> | Promise used to return the result.|
+ | Promise<void> | Promise used to return the result.|
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
- missionManager.clearAllMissions().catch(function (err){
- console.log(err);
- });
- ```
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
+try {
+ missionManager.clearAllMissions(bundleName).then(() => {
+ console.info('clearAllMissions successfully.');
+ }).catch(err => {
+ console.error('clearAllMissions failed:' + err.message);
+ });
+} catch (err) {
+ console.error('clearAllMissions failed:' + err.message);
+}
+```
## missionManager.moveMissionToFront
@@ -948,25 +928,22 @@ Switches a given mission to the foreground. This API uses an asynchronous callba
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- try {
- missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
- console.log("size = " + missions.length);
- console.log("missions = " + JSON.stringify(missions));
- var id = missions[0].missionId;
-
- missionManager.moveMissionToFront(id).then(() => {
- console.log("moveMissionToFront is called ");
- });
+let testMissionId = 2;
+try {
+ missionManager.moveMissionToFront(testMissionId, (err, data) => {
+ if (err) {
+ console.error('moveMissionToFront failed:' + err.message);
+ } else {
+ console.info('moveMissionToFront successfully:' + JSON.stringify(data));
+ }
});
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
-
+} catch (err) {
+ console.error('moveMissionToFront failed:' + err.message);
+}
+```
## missionManager.moveMissionToFront
@@ -990,25 +967,22 @@ Switches a given mission to the foreground, with the startup parameters for the
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- try {
- missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
- console.log("size = " + missions.length);
- console.log("missions = " + JSON.stringify(missions));
- var id = missions[0].missionId;
-
- missionManager.moveMissionToFront(id,{windowMode : 101}).then(() => {
- console.log("moveMissionToFront is called ");
- });
+let testMissionId = 2;
+try {
+ missionManager.moveMissionToFront(testMissionId, {windowMode : 101}, (err, data) => {
+ if (err) {
+ console.error('moveMissionToFront failed:' + err.message);
+ } else {
+ console.info('moveMissionToFront successfully:' + JSON.stringify(data));
+ }
});
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
-
+} catch (err) {
+ console.error('moveMissionToFront failed:' + err.message);
+}
+```
## missionManager.moveMissionToFront
@@ -1031,28 +1005,23 @@ Switches a given mission to the foreground, with the startup parameters for the
**Return value**
- | Type| Description|
+ | Type| Description|
| -------- | -------- |
- | Promise<void> | Promise used to return the result.|
+ | Promise<void> | Promise used to return the result.|
**Example**
- ```ts
- import missionManager from '@ohos.app.ability.missionManager'
+```ts
+import missionManager from '@ohos.app.ability.missionManager';
- try {
- var allMissions;
- missionManager.getMissionInfos("",10).then(function(res){
- allMissions=res;
- }).catch(function(err){console.log(err);});
- console.log("size = " + allMissions.length);
- console.log("missions = " + JSON.stringify(allMissions));
- var id = allMissions[0].missionId;
-
- missionManager.moveMissionToFront(id).catch(function (err){
- console.log(err);
+let testMissionId = 2;
+try {
+ missionManager.moveMissionToFront(testMissionId).then((data) => {
+ console.info('moveMissionToFront successfully. Data: ' + JSON.stringify(data));
+ }).catch(error => {
+ console.error('moveMissionToFront failed. Cause: ' + error.message);
});
- } catch (paramError) {
- console.log("error: " + paramError.code + ", " + paramError.message);
- }
- ```
+} catch (error) {
+ console.error('moveMissionToFront failed. Cause: ' + error.message);
+}
+```
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-quickFixManager.md b/en/application-dev/reference/apis/js-apis-app-ability-quickFixManager.md
index c703726492eb8bc4ddd1211f97d95a3490a8938a..a2090ed00e60cac1b5452bf6357f47cfb3c7be2e 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-quickFixManager.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-quickFixManager.md
@@ -1,4 +1,4 @@
-# @ohos.app.ability.quickFixManager
+# @ohos.app.ability.quickFixManager (quickFixManager)
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.
@@ -36,7 +36,7 @@ Defines the quick fix information at the application level.
| Name | Type | Mandatory| Description |
| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
-| bundleName | string | Yes | Bundle name of the application. |
+| bundleName | string | Yes | Bundle name. |
| bundleVersionCode | number | Yes | Internal version number of the application. |
| bundleVersionName | string | Yes | Version number of the application that is shown to users. |
| quickFixVersionCode | number | Yes | Version code of the quick fix patch package. |
@@ -65,8 +65,6 @@ Applies a quick fix patch. This API uses an asynchronous callback to return the
**Example**
```ts
- import quickFixManager from '@ohos.app.ability.quickFixManager'
-
try {
let hapModuleQuickFixFiles = ["/data/storage/el2/base/entry.hqf"]
quickFixManager.applyQuickFix(hapModuleQuickFixFiles, (error) => {
@@ -108,8 +106,6 @@ Applies a quick fix patch. This API uses a promise to return the result.
**Example**
```ts
- import quickFixManager from '@ohos.app.ability.quickFixManager'
-
let hapModuleQuickFixFiles = ["/data/storage/el2/base/entry.hqf"]
try {
quickFixManager.applyQuickFix(hapModuleQuickFixFiles).then(() => {
@@ -136,16 +132,14 @@ Obtains the quick fix information of the application. This API uses an asynchron
**Parameters**
- | Parameter| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | bundleName | string | Yes|Bundle name of the application. |
- | callback | AsyncCallback\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | Yes| Callback used to return the quick fix information.|
+| Parameter| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| bundleName | string | Yes|Bundle name. |
+| 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"
quickFixManager.getApplicationQuickFixInfo(bundleName, (error, data) => {
@@ -174,9 +168,9 @@ Obtains the quick fix information of the application. This API uses a promise to
**Parameters**
- | Parameter| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | bundleName | string | Yes| Bundle name of the application. |
+| Parameter| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| bundleName | string | Yes| Bundle name.|
**Return value**
@@ -187,8 +181,6 @@ Obtains the quick fix information of the application. This API uses a promise to
**Example**
```ts
- import quickFixManager from '@ohos.app.ability.quickFixManager'
-
try {
let bundleName = "bundleName"
quickFixManager.getApplicationQuickFixInfo(bundleName).then((data) => {
@@ -199,4 +191,4 @@ Obtains the quick fix information of the application. This API uses a promise to
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
-```
+ ```
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-serviceExtensionAbility.md b/en/application-dev/reference/apis/js-apis-app-ability-serviceExtensionAbility.md
index 6c3e0e6e2a0e116120aa405758506d46175c3468..0efdb59d5eaed4c2b70e5ff666b0c9d63b11212f 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-serviceExtensionAbility.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-serviceExtensionAbility.md
@@ -1,10 +1,10 @@
-# @ohos.app.ability.ServiceExtensionAbility
+# @ohos.app.ability.ServiceExtensionAbility (ServiceExtensionAbility)
-The **ServiceExtensionAbility** module provides APIs for Service Extension abilities.
+The **ServiceExtensionAbility** module provides lifecycle callbacks when a ServiceExtensionAbility (background service) is created, destroyed, connected, or disconnected.
> **NOTE**
>
-> The APIs of this module are supported and deprecated since 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 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 can be used only in the stage model.
## Modules to Import
@@ -23,16 +23,16 @@ None.
**System API**: This is a system API and cannot be called by third-party applications.
-| Name| Type| Readable| Writable| Description|
+| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
-| context | [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md) | Yes| No| Service Extension context, which is inherited from **ExtensionContext**.|
+| context | [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md) | Yes| No| ServiceExtensionContext, which is inherited from **ExtensionContext**.|
## ServiceExtensionAbility.onCreate
onCreate(want: Want): void;
-Called when a Service Extension ability is created to initialize the service logic.
+Called when a ServiceExtensionAbility is created to initialize the service logic.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -40,9 +40,9 @@ Called when a Service Extension ability is created to initialize the service log
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want | [Want](js-apis-app-ability-want.md) | Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want | [Want](js-apis-app-ability-want.md) | Yes| Want information related to this ServiceExtensionAbility, including the ability name and bundle name.|
**Example**
@@ -59,7 +59,7 @@ Called when a Service Extension ability is created to initialize the service log
onDestroy(): void;
-Called when this Service Extension ability is destroyed to clear resources.
+Called when this ServiceExtensionAbility is destroyed to clear resources.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -80,7 +80,7 @@ Called when this Service Extension ability is destroyed to clear resources.
onRequest(want: Want, startId: number): void;
-Called after **onCreate** is invoked when a Service Extension ability 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()**. The value of **startId** is incremented for each ability that is started.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -88,10 +88,10 @@ Called after **onCreate** is invoked when a Service Extension ability is started
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want | [Want](js-apis-app-ability-want.md) | Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
- | startId | number | Yes| Number of ability start times. The initial value is **1**, and the value is automatically incremented for each ability started.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want | [Want](js-apis-app-ability-want.md) | Yes| Want information related to this ServiceExtensionAbility, including the ability name and bundle name.|
+| startId | number | Yes| Number of ability start times. The initial value is **1**, and the value is automatically incremented for each ability started.|
**Example**
@@ -108,7 +108,7 @@ Called after **onCreate** is invoked when a Service Extension ability is started
onConnect(want: Want): rpc.RemoteObject;
-Called after **onCreate** is invoked when a Service Extension ability is started by calling **connectAbility**. A **RemoteObject** object is returned for communication with the client.
+Called following **onCreate()** when a ServiceExtensionAbility is started by calling **connectAbility()**. A **RemoteObject** object is returned for communication between the server and client.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -116,15 +116,15 @@ Called after **onCreate** is invoked when a Service Extension ability is started
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want | [Want](js-apis-app-ability-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want | [Want](js-apis-app-ability-want.md)| Yes| Want information related to this ServiceExtensionAbility, including the ability name and bundle name.|
**Return value**
- | Type| Description|
- | -------- | -------- |
- | rpc.RemoteObject | A **RemoteObject** object used for communication with the client.|
+| Type| Description|
+| -------- | -------- |
+| rpc.RemoteObject | A **RemoteObject** object used for communication between the server and client.|
**Example**
@@ -150,7 +150,7 @@ Called after **onCreate** is invoked when a Service Extension ability is started
onDisconnect(want: Want): void;
-Called when this Service Extension ability is disconnected.
+Called when a client is disconnected from this ServiceExtensionAbility.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -158,9 +158,9 @@ Called when this Service Extension ability is disconnected.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want |[Want](js-apis-app-ability-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want |[Want](js-apis-app-ability-want.md)| Yes| Want information related to this ServiceExtensionAbility, including the ability name and bundle name.|
**Example**
@@ -176,7 +176,7 @@ Called when this Service Extension ability is disconnected.
onReconnect(want: Want): void;
-Called when this Service Extension ability is reconnected.
+Called when a new client attempts to connect to this ServiceExtensionAbility after all previous clients are disconnected. This capability is reserved.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -184,9 +184,9 @@ Called when this Service Extension ability is reconnected.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want |[Want](js-apis-app-ability-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want |[Want](js-apis-app-ability-want.md)| Yes| Want information related to this ServiceExtensionAbility, including the ability name and bundle name.|
**Example**
@@ -202,7 +202,7 @@ Called when this Service Extension ability is reconnected.
onConfigurationUpdate(newConfig: Configuration): void;
-Called when the configuration of this Service Extension ability is updated.
+Called when the configuration of this ServiceExtensionAbility is updated.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -210,9 +210,9 @@ Called when the configuration of this Service Extension ability is updated.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | newConfig | [Configuration](js-apis-app-ability-configuration.md) | Yes| New configuration.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| newConfig | [Configuration](js-apis-app-ability-configuration.md) | Yes| New configuration.|
**Example**
@@ -236,9 +236,9 @@ Dumps the client information.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | params | Array\ | Yes| Parameters in the form of a command.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| params | Array\ | Yes| Parameters in the form of a command.|
**Example**
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md b/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md
index fc5215fe400919172a7c2f2dd7c5a567e44acae3..3e95fbf541e7ed79834673c2ca97b1398bc73989 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md
@@ -1,6 +1,6 @@
-# @ohos.app.ability.StartOptions
+# @ohos.app.ability.StartOptions (StartOptions)
-The **StartOptions** module implements ability startup options.
+**StartOptions** is used as an input parameter of [startAbility()](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability-1) to specify the window mode of an ability.
> **NOTE**
>
@@ -21,4 +21,4 @@ import StartOptions from '@ohos.app.ability.StartOptions';
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| [windowMode](js-apis-application-abilityConstant.md#abilityconstantwindowmode) | number | No| Window mode.|
-| displayId | number | No| Display ID.|
+| displayId | number | No| Display ID. The default value is **0**, indicating the current display.|
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-uiAbility.md b/en/application-dev/reference/apis/js-apis-app-ability-uiAbility.md
index cce8b81738f29586417ae5f9814da2448f053e17..38d9f5428c37873ae9f786ed0f391142f30a011b 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-uiAbility.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-uiAbility.md
@@ -1,11 +1,9 @@
-# @ohos.app.ability.UIAbility
+# @ohos.app.ability.UIAbility (UIAbility)
-The **Ability** module manages the ability lifecycle and context, such as creating and destroying an ability, and dumping client information.
+UIAbility is an application component that has the UI. The **UIAbility** module provides lifecycle callback such as component creation, destruction, and foreground/background switching. It also provides the following capabilities related to component collaboration:
-This module provides the following common ability-related functions:
-
-- [Caller](#caller): implements sending of sequenceable data to the target ability when an ability (caller ability) invokes the target ability (callee ability).
-- [Callee](#callee): implements callbacks for registration and deregistration of caller notifications.
+- [Caller](#caller): an object returned by [startAbilityByCall](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartabilitybycall). The CallerAbility (caller) uses this object to communicate with the CalleeAbility (callee).
+- [Callee](#callee): an internal object of UIAbility. The CalleeAbility (callee) uses this object to communicate with the CallerAbility (caller).
> **NOTE**
>
@@ -15,39 +13,39 @@ This module provides the following common ability-related functions:
## Modules to Import
```ts
-import Ability from '@ohos.app.ability.UIAbility';
+import UIAbility from '@ohos.app.ability.UIAbility';
```
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
-| Name| Type| Readable| Writable| Description|
+| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
-| context | [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md) | Yes| No| Context of an ability.|
-| launchWant | [Want](js-apis-app-ability-want.md) | Yes| No| Parameters for starting the ability.|
-| lastRequestWant | [Want](js-apis-app-ability-want.md) | Yes| No| Parameters used when the ability was started last time.|
-| callee | [Callee](#callee) | Yes| No| Object that invokes the stub service.|
+| context | [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md) | Yes| No| Context of the UIAbility.|
+| launchWant | [Want](js-apis-app-ability-want.md) | Yes| No| Parameters for starting the UIAbility.|
+| lastRequestWant | [Want](js-apis-app-ability-want.md) | Yes| No| Parameters used when the UIAbility was started last time.|
+| callee | [Callee](#callee) | Yes| No| Object that invokes the stub service.|
-## Ability.onCreate
+## UIAbility.onCreate
onCreate(want: Want, param: AbilityConstant.LaunchParam): void;
-Called to initialize the service logic when an ability is created.
+Called to initialize the service logic when a UIAbility is created.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want | [Want](js-apis-app-ability-want.md) | Yes| Information related to this ability, including the ability name and bundle name.|
- | param | AbilityConstant.LaunchParam | Yes| Parameters for starting the ability, and the reason for the last abnormal exit.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want | [Want](js-apis-app-ability-want.md) | Yes| Information related to this UIAbility, including the ability name and bundle name.|
+| param | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | Yes| Parameters for starting the UIAbility, and the reason for the last abnormal exit.|
**Example**
```ts
- class myAbility extends Ability {
+ class MyUIAbility extends UIAbility {
onCreate(want, param) {
console.log('onCreate, want:' + want.abilityName);
}
@@ -55,24 +53,24 @@ Called to initialize the service logic when an ability is created.
```
-## Ability.onWindowStageCreate
+## UIAbility.onWindowStageCreate
onWindowStageCreate(windowStage: window.WindowStage): void
-Called when a **WindowStage** is created for this ability.
+Called when a **WindowStage** is created for this UIAbility.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | windowStage | window.WindowStage | Yes| **WindowStage** information.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** information.|
**Example**
```ts
- class myAbility extends Ability {
+ class MyUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate');
}
@@ -80,18 +78,18 @@ Called when a **WindowStage** is created for this ability.
```
-## Ability.onWindowStageDestroy
+## UIAbility.onWindowStageDestroy
onWindowStageDestroy(): void
-Called when the **WindowStage** is destroyed for this ability.
+Called when the **WindowStage** is destroyed for this UIAbility.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
```ts
- class myAbility extends Ability {
+ class MyUIAbility extends UIAbility {
onWindowStageDestroy() {
console.log('onWindowStageDestroy');
}
@@ -99,24 +97,24 @@ Called when the **WindowStage** is destroyed for this ability.
```
-## Ability.onWindowStageRestore
+## UIAbility.onWindowStageRestore
onWindowStageRestore(windowStage: window.WindowStage): void
-Called when the **WindowStage** is restored during the migration of this ability, which is a multi-instance ability.
+Called when the **WindowStage** is restored during the migration of this UIAbility, which is a multi-instance ability.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | windowStage | window.WindowStage | Yes| **WindowStage** information.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** information.|
**Example**
```ts
- class myAbility extends Ability {
+ class MyUIAbility extends UIAbility {
onWindowStageRestore(windowStage) {
console.log('onWindowStageRestore');
}
@@ -124,18 +122,18 @@ Called when the **WindowStage** is restored during the migration of this ability
```
-## Ability.onDestroy
+## UIAbility.onDestroy
onDestroy(): void;
-Called when this ability is destroyed to clear resources.
+Called when this UIAbility is destroyed to clear resources.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
```ts
- class myAbility extends Ability {
+ class MyUIAbility extends UIAbility {
onDestroy() {
console.log('onDestroy');
}
@@ -143,18 +141,18 @@ Called when this ability is destroyed to clear resources.
```
-## Ability.onForeground
+## UIAbility.onForeground
onForeground(): void;
-Called when this ability is switched from the background to the foreground.
+Called when this UIAbility is switched from the background to the foreground.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
```ts
- class myAbility extends Ability {
+ class MyUIAbility extends UIAbility {
onForeground() {
console.log('onForeground');
}
@@ -162,18 +160,18 @@ Called when this ability is switched from the background to the foreground.
```
-## Ability.onBackground
+## UIAbility.onBackground
onBackground(): void;
-Called when this ability is switched from the foreground to the background.
+Called when this UIAbility is switched from the foreground to the background.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
```ts
- class myAbility extends Ability {
+ class MyUIAbility extends UIAbility {
onBackground() {
console.log('onBackground');
}
@@ -181,7 +179,7 @@ Called when this ability is switched from the foreground to the background.
```
-## Ability.onContinue
+## UIAbility.onContinue
onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
@@ -191,21 +189,21 @@ Called to save data during the ability migration preparation process.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | wantParam | {[key: string]: any} | Yes| **want** parameter.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| wantParam | {[key: string]: any} | Yes| **want** parameter.|
**Return value**
- | Type| Description|
- | -------- | -------- |
- | AbilityConstant.OnContinueResult | Continuation result.|
+| Type| Description|
+| -------- | -------- |
+| [AbilityConstant.OnContinueResult](js-apis-app-ability-abilityConstant.md#abilityconstantoncontinueresult) | Continuation result.|
**Example**
```ts
- import AbilityConstant from "@ohos.application.AbilityConstant"
- class myAbility extends Ability {
+ import AbilityConstant from "@ohos.app.ability.AbilityConstant"
+ class MyUIAbility extends UIAbility {
onContinue(wantParams) {
console.log('onContinue');
wantParams["myData"] = "my1234567";
@@ -215,32 +213,33 @@ Called to save data during the ability migration preparation process.
```
-## Ability.onNewWant
+## UIAbility.onNewWant
onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;
-Called when the ability startup mode is set to singleton.
+Called when a new Want is passed in and this UIAbility is started again.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want | [Want](js-apis-application-want.md) | Yes| Want parameters, such as the ability name and bundle name.|
- | launchParams | AbilityConstant.LaunchParam | Yes| Reason for the ability startup and the last abnormal exit.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want | [Want](js-apis-app-ability-want.md) | Yes| Want information, such as the ability name and bundle name.|
+| launchParams | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | Yes| Reason for the UIAbility startup and the last abnormal exit.|
**Example**
```ts
- class myAbility extends Ability {
- onNewWant(want) {
+ class MyUIAbility extends UIAbility {
+ onNewWant(want, launchParams) {
console.log('onNewWant, want:' + want.abilityName);
+ console.log('onNewWant, launchParams:' + JSON.stringify(launchParams));
}
}
```
-## Ability.onDump
+## UIAbility.onDump
onDump(params: Array\): Array\;
@@ -250,14 +249,14 @@ Dumps client information.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | params | Array\ | Yes| Parameters in the form of a command.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| params | Array\ | Yes| Parameters in the form of a command.|
**Example**
```ts
- class myAbility extends Ability {
+ class MyUIAbility extends UIAbility {
onDump(params) {
console.log('dump, params:' + JSON.stringify(params));
return ["params"]
@@ -266,33 +265,33 @@ Dumps client information.
```
-## Ability.onSaveState
+## UIAbility.onSaveState
onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: any}): AbilityConstant.OnSaveResult;
-Called when the framework automatically saves the ability state in the case of an application fault. This API is used together with [appRecovery](js-apis-app-ability-appRecovery.md).
+Called when the framework automatically saves the UIAbility state in the case of an application fault. This API is used together with [appRecovery](js-apis-app-ability-appRecovery.md). If automatic state saving is enabled, **onSaveState** is called to save the state of this UIAbility.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | reason | [AbilityConstant.StateType](js-apis-application-abilityConstant.md#abilityconstantstatetype) | Yes| Reason for triggering the callback to save the ability state.|
- | wantParam | {[key: string]: any} | Yes| **want** parameter.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| reason | [AbilityConstant.StateType](js-apis-app-ability-abilityConstant.md#abilityconstantstatetype) | Yes| Reason for triggering the callback to save the UIAbility state.|
+| wantParam | {[key: string]: any} | Yes| **want** parameter.|
**Return value**
- | Type| Description|
- | -------- | -------- |
- | AbilityConstant.OnSaveResult | Whether the ability state is saved.|
+| Type| Description|
+| -------- | -------- |
+| [AbilityConstant.OnSaveResult](js-apis-app-ability-abilityConstant.md#abilityconstantonsaveresult) | Whether the UIAbility state is saved.|
**Example**
```ts
-import AbilityConstant from '@ohos.application.AbilityConstant'
+import AbilityConstant from '@ohos.app.ability.AbilityConstant'
-class myAbility extends Ability {
+class MyUIAbility extends UIAbility {
onSaveState(reason, wantParam) {
console.log('onSaveState');
wantParam["myData"] = "my1234567";
@@ -305,7 +304,7 @@ class myAbility extends Ability {
## Caller
-Implements sending of sequenceable data to the target ability when an ability (caller ability) invokes the target ability (callee ability).
+Implements sending of sequenceable data to the target ability when the CallerAbility invokes the target ability (CalleeAbility).
## Caller.call
@@ -317,29 +316,29 @@ Sends sequenceable data to the target ability.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
- | data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
+| data | [rpc.Sequenceable](js-apis-rpc.md#sequenceabledeprecated) | Yes| Sequenceable data. You need to customize the data.|
**Return value**
- | Type| Description|
- | -------- | -------- |
- | Promise<void> | Promise used to return a response.|
+| Type| Description|
+| -------- | -------- |
+| Promise<void> | Promise used to return a response.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
- import Ability from '@ohos.app.ability.UIAbility';
- class MyMessageAble{ // Custom sequenceable data structure
+ class MyMessageAble{ // Custom sequenceable data structure.
name:""
str:""
num: 1
@@ -360,13 +359,13 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
return true;
}
};
- var method = 'call_Function'; // Notification message string negotiated by the two abilities
+ var method = 'call_Function'; // Notification message string negotiated by the two abilities.
var caller;
- export default class MainAbility extends Ability {
+ export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
- this.context.startAbilityByCall({
+ this.context.startUIAbilityByCall({
bundleName: "com.example.myservice",
- abilityName: "MainAbility",
+ abilityName: "MainUIAbility",
deviceId: ""
}).then((obj) => {
caller = obj;
@@ -398,28 +397,28 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
- | data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
+| data | [rpc.Sequenceable](js-apis-rpc.md#sequenceabledeprecated) | Yes| Sequenceable data. You need to customize the data.|
**Return value**
- | Type| Description|
- | -------- | -------- |
- | Promise<rpc.MessageParcel> | Promise used to return the sequenceable data from the target ability.|
+| Type| Description|
+| -------- | -------- |
+| Promise<[rpc.MessageParcel](js-apis-rpc.md#sequenceabledeprecated)> | Promise used to return the sequenceable data from the target ability.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
- import Ability from '@ohos.app.ability.UIAbility';
class MyMessageAble{
name:""
str:""
@@ -443,11 +442,11 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
};
var method = 'call_Function';
var caller;
- export default class MainAbility extends Ability {
+ export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
- this.context.startAbilityByCall({
+ this.context.startUIAbilityByCall({
bundleName: "com.example.myservice",
- abilityName: "MainAbility",
+ abilityName: "MainUIAbility",
deviceId: ""
}).then((obj) => {
caller = obj;
@@ -491,13 +490,12 @@ Releases the caller interface of the target ability.
**Example**
```ts
- import Ability from '@ohos.app.ability.UIAbility';
var caller;
- export default class MainAbility extends Ability {
+ export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
- this.context.startAbilityByCall({
+ this.context.startUIAbilityByCall({
bundleName: "com.example.myservice",
- abilityName: "MainAbility",
+ abilityName: "MainUIAbility",
deviceId: ""
}).then((obj) => {
caller = obj;
@@ -525,20 +523,19 @@ Registers a callback that is invoked when the stub on the target ability is disc
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | callback | OnReleaseCallBack | Yes| Callback used for the **onRelease** API.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| callback | [OnReleaseCallBack](#onreleasecallback) | Yes| Callback used for the **onRelease** API.|
**Example**
```ts
- import Ability from '@ohos.application.Ability';
var caller;
- export default class MainAbility extends Ability {
+ export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
- this.context.startAbilityByCall({
+ this.context.startUIAbilityByCall({
bundleName: "com.example.myservice",
- abilityName: "MainAbility",
+ abilityName: "MainUIAbility",
deviceId: ""
}).then((obj) => {
caller = obj;
@@ -568,28 +565,28 @@ Registers a callback that is invoked when the stub on the target ability is disc
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | type | string | Yes| Event type. The value is fixed at **release**.|
- | callback | OnReleaseCallback | Yes| Callback used for the **onRelease** API.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| type | string | Yes| Event type. The value is fixed at **release**.|
+| callback | [OnReleaseCallBack](#onreleasecallback) | Yes| Callback used for the **onRelease** API.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
- import Ability from '@ohos.app.ability.UIAbility';
var caller;
- export default class MainAbility extends Ability {
+ export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
- this.context.startAbilityByCall({
+ this.context.startUIAbilityByCall({
bundleName: "com.example.myservice",
- abilityName: "MainAbility",
+ abilityName: "MainUIAbility",
deviceId: ""
}).then((obj) => {
caller = obj;
@@ -624,22 +621,22 @@ Registers a caller notification callback, which is invoked when the target abili
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | method | string | Yes| Notification message string negotiated between the two abilities.|
- | callback | CalleeCallback | Yes| JS notification synchronization callback of the **rpc.MessageParcel** type. The callback must return at least one empty **rpc.Sequenceable** object. Otherwise, the function execution fails.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| method | string | Yes| Notification message string negotiated between the two abilities.|
+| callback | [CalleeCallback](#calleecallback) | Yes| JS notification synchronization callback of the [rpc.MessageParcel](js-apis-rpc.md#messageparceldeprecated) type. The callback must return at least one empty [rpc.Sequenceable](js-apis-rpc.md#sequenceabledeprecated) object. Otherwise, the function execution fails.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
- import Ability from '@ohos.app.ability.UIAbility';
class MyMessageAble{
name:""
str:""
@@ -668,7 +665,7 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
pdata.readSequenceable(msg);
return new MyMessageAble("test1", "Callee test");
}
- export default class MainAbility extends Ability {
+ export default class MainUIAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('Callee onCreate is called');
try {
@@ -691,24 +688,24 @@ Deregisters a caller notification callback, which is invoked when the target abi
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | method | string | Yes| Registered notification message string.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| method | string | Yes| Registered notification message string.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
-For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
+
+For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
- import Ability from '@ohos.app.ability.UIAbility';
var method = 'call_Function';
- export default class MainAbility extends Ability {
+ export default class MainUIAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('Callee onCreate is called');
try {
@@ -727,9 +724,9 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
-| Name| Readable| Writable| Type| Description|
+| Name| Readable| Writable| Type| Description|
| -------- | -------- | -------- | -------- | -------- |
-| (msg: string) | Yes| No| function | Prototype of the listener function registered by the caller.|
+| (msg: string) | Yes| No| function | Prototype of the listener function registered by the caller.|
## CalleeCallback
@@ -737,6 +734,6 @@ For other IDs, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
-| Name| Readable| Writable| Type| Description|
+| Name| Readable| Writable| Type| Description|
| -------- | -------- | -------- | -------- | -------- |
-| (indata: rpc.MessageParcel) | Yes| No| rpc.Sequenceable | Prototype of the listener function registered by the callee.|
+| (indata: [rpc.MessageParcel](js-apis-rpc.md#messageparceldeprecated)) | Yes| No| [rpc.Sequenceable](js-apis-rpc.md#sequenceabledeprecated) | Prototype of the listener function registered by the callee.|
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-want.md b/en/application-dev/reference/apis/js-apis-app-ability-want.md
index c7bd4f6e9693c9bcc7ac71286e204f4d0b5005a8..c96e29d90f3a10a563df41bc8a545cb42dfdeba4 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-want.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-want.md
@@ -1,6 +1,6 @@
-# @ohos.app.ability.Want
+# @ohos.app.ability.Want (Want)
-Want is a carrier for information transfer between objects (application components). Want can be used as a parameter of **startAbility** to specify a startup target and information that needs to be carried during startup, for example, **bundleName** and **abilityName**, which respectively indicate the bundle name of the target ability and the ability name in the bundle. When ability A needs to start ability B and transfer some data to ability B, it can use Want a carrier to transfer the data.
+Want is a carrier for information transfer between objects (application components). Want can be used as a parameter of **startAbility** to specify a startup target and information that needs to be carried during startup, for example, **bundleName** and **abilityName**, which respectively indicate the bundle name of the target ability and the ability name in the bundle. When UIAbility A needs to start UIAbility B and transfer some data to UIAbility B, it can use Want a carrier to transfer the data.
> **NOTE**
>
@@ -18,26 +18,26 @@ import Want from '@ohos.app.ability.Want';
| Name | Type | Mandatory| Description |
| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
-| 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.|
+| 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.|
| 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.|
-| uri | string | No | URI information to match. If **uri** is specified in a **Want** object, the **Want** object 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. |
-| flags | number | No | How the **Want** object will be handled. By default, numbers are 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:
**ohos.aafwk.callerPid**: PID of the caller.
**ohos.aafwk.param.callerToken**: token of the caller.
**ohos.aafwk.param.callerUid**: UID in [bundleInfo](js-apis-bundle-BundleInfo.md#bundleinfo-1), that is, the application UID in the bundle information. |
-| entities | Array\ | No | Additional category information (such as browser and video player) of the target ability. It is a supplement to **action** in implicit Want and is used to filter ability types. |
-| moduleName | string | No | Module to which the ability belongs.|
+| [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\ | 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:
- **ohos.aafwk.callerPid**: PID of the caller.
- **ohos.aafwk.param.callerToken**: token of the caller.
- **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.
For example, **wantConstant.Flags.FLAG_ABILITY_CONTINUATION** specifies whether to start the ability in cross-device migration scenarios.|
**Example**
-- Basic usage
+- Basic usage (called in a UIAbility object, where context in the example is the context object of the UIAbility).
```ts
- var want = {
+ let want = {
"deviceId": "", // An empty deviceId indicates the local device.
- "bundleName": "com.extreme.test",
- "abilityName": "MainAbility",
+ "bundleName": "com.example.myapplication",
+ "abilityName": "FuncAbility",
"moduleName": "entry" // moduleName is optional.
};
this.context.startAbility(want, (error) => {
@@ -46,13 +46,13 @@ import Want from '@ohos.app.ability.Want';
})
```
-- Data is transferred through user-defined fields. The following data types are supported:
+- 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):
* String
```ts
let want = {
- bundleName: "com.example.demo",
- abilityName: "com.example.demo.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "FuncAbility",
parameters: {
keyForString: "str",
},
@@ -61,8 +61,8 @@ import Want from '@ohos.app.ability.Want';
* Number
```ts
let want = {
- bundleName: "com.example.demo",
- abilityName: "com.example.demo.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "FuncAbility",
parameters: {
keyForInt: 100,
keyForDouble: 99.99,
@@ -72,8 +72,8 @@ import Want from '@ohos.app.ability.Want';
* Boolean
```ts
let want = {
- bundleName: "com.example.demo",
- abilityName: "com.example.demo.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "FuncAbility",
parameters: {
keyForBool: true,
},
@@ -82,8 +82,8 @@ import Want from '@ohos.app.ability.Want';
* Object
```ts
let want = {
- bundleName: "com.example.demo",
- abilityName: "com.example.demo.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "FuncAbility",
parameters: {
keyForObject: {
keyForObjectString: "str",
@@ -97,8 +97,8 @@ import Want from '@ohos.app.ability.Want';
* Array
```ts
let want = {
- bundleName: "com.example.demo",
- abilityName: "com.example.demo.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "FuncAbility",
parameters: {
keyForArrayString: ["str1", "str2", "str3"],
keyForArrayInt: [100, 200, 300, 400],
@@ -109,26 +109,28 @@ import Want from '@ohos.app.ability.Want';
```
* File descriptor (FD)
```ts
- import fileio from '@ohos.fileio';
- var fd;
- try {
- fd = fileio.openSync("/data/storage/el2/base/haps/pic.png");
- } catch(e) {
- console.log("openSync fail:" + JSON.stringify(e));
+ 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}
}
- var 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}
- }
- };
- 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)
- })
+ };
+ 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)
+ })
```
-
+- For more details and examples, see [Want](../../application-models/want-overview.md).
+
+
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-wantAgent.md b/en/application-dev/reference/apis/js-apis-app-ability-wantAgent.md
index 3a73d862541383d93b8944d5b57326656ca50b4c..43b95743b25c34bdae9457c1e1ed1cf01f8e986e 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-wantAgent.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-wantAgent.md
@@ -1,4 +1,4 @@
-# @ohos.app.ability.wantAgent
+# @ohos.app.ability.wantAgent (WantAgent)
The **app.ability.WantAgent** module provides APIs for creating and comparing **WantAgent** objects, and obtaining the user ID and bundle name of a **WantAgent** object. You are advised to use this module, since it will replace the [@ohos.wantAgent](js-apis-wantAgent.md) module in the near future.
diff --git a/en/application-dev/reference/apis/js-apis-app-ability-wantConstant.md b/en/application-dev/reference/apis/js-apis-app-ability-wantConstant.md
index ece4baa69e5d3b2883e971655e2367e23acf7812..4d7a483eab8a55c91d4dbb89287fa611f980ef34 100644
--- a/en/application-dev/reference/apis/js-apis-app-ability-wantConstant.md
+++ b/en/application-dev/reference/apis/js-apis-app-ability-wantConstant.md
@@ -1,4 +1,4 @@
-# @ohos.app.ability.wantConstant
+# @ohos.app.ability.wantConstant (wantConstant)
The **wantConstant** module provides the actions, entities, and flags used in **Want** objects.
@@ -14,7 +14,7 @@ import wantConstant from '@ohos.app.ability.wantConstant';
## wantConstant.Action
-Enumerates the action constants of the **Want** object.
+Enumerates the action constants of the **Want** object. **action** specifies the operation to execute.
**System capability**: SystemCapability.Ability.AbilityBase
@@ -44,7 +44,7 @@ Enumerates the action constants of the **Want** object.
| 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 | ohos.action.fileSelect | Action of selecting a file. |
-| PARAMS_STREAM | ability.params.stream | URI of the data stream associated with the target when the data is sent. | |
+| PARAMS_STREAM | ability.params.stream | URI of the data stream associated with the target when the data is sent. |
| ACTION_APP_ACCOUNT_AUTH | account.appAccount.action.auth | Action of providing the authentication service. |
| ACTION_MARKET_DOWNLOAD | ohos.want.action.marketDownload | Action of downloading an application from the application market.
**System API**: This is a system API and cannot be called by third-party applications. |
| ACTION_MARKET_CROWDTEST | ohos.want.action.marketCrowdTest | Action of crowdtesting an application from the application market.
**System API**: This is a system API and cannot be called by third-party applications. |
@@ -56,7 +56,7 @@ Enumerates the action constants of the **Want** object.
## wantConstant.Entity
-Enumerates the entity constants of the **Want** object.
+Enumerates the entity constants of the **Want** object. **entity** specifies additional information of the target ability.
**System capability**: SystemCapability.Ability.AbilityBase
@@ -71,7 +71,7 @@ Enumerates the entity constants of the **Want** object.
## wantConstant.Flags
-Describes flags.
+ Enumerates the flags that specify how the Want will be handled.
**System capability**: SystemCapability.Ability.AbilityBase
@@ -79,17 +79,4 @@ Describes flags.
| ------------------------------------ | ---------- | ------------------------------------------------------------ |
| 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_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.
**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.
**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.
**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) and must be used together with **flag_ABILITY_NEW_MISSION**.|
-| 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.|
diff --git a/en/application-dev/reference/apis/js-apis-app-form-formBindingData.md b/en/application-dev/reference/apis/js-apis-app-form-formBindingData.md
index bf3f9cbb803b4bed60bba43d88813e6acf38fcb2..51637975d72ea807f428f235aec90310f69b197f 100644
--- a/en/application-dev/reference/apis/js-apis-app-form-formBindingData.md
+++ b/en/application-dev/reference/apis/js-apis-app-form-formBindingData.md
@@ -1,4 +1,4 @@
-# @ohos.app.form.formBindingData
+# @ohos.application.formBindingData (formBindingData)
The **FormBindingData** module provides APIs for widget data binding. You can use the APIs to create a **FormBindingData** object and obtain related information.
@@ -48,20 +48,17 @@ Creates a **FormBindingData** object.
**Example**
```ts
-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);
+import fs from '@ohos.file.fs';
+import formBindingData from '@ohos.app.form.formBindingData';
+
+try {
+ let fd = fs.openSync('/path/to/form.png')
let obj = {
"temperature": "21°",
- "formImages": {"image": fd}
+ "formImages": { "image": fd }
};
- try {
- formBindingData.createFormBindingData(obj);
- } catch (error) {
- console.log(`catch err->${JSON.stringify(err)}`);
- }
-})
+ formBindingData.createFormBindingData(obj);
+} catch (error) {
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
+}
```
diff --git a/en/application-dev/reference/apis/js-apis-app-form-formExtensionAbility.md b/en/application-dev/reference/apis/js-apis-app-form-formExtensionAbility.md
index c2bedd6d4dc1b50b6575120b88c0ab88423e7846..ef4e93e215b868013f025722737472735a1016f7 100644
--- a/en/application-dev/reference/apis/js-apis-app-form-formExtensionAbility.md
+++ b/en/application-dev/reference/apis/js-apis-app-form-formExtensionAbility.md
@@ -1,6 +1,6 @@
-# @ohos.app.form.FormExtensionAbility
+# @ohos.app.form.FormExtensionAbility (FormExtensionAbility)
-The **FormExtensionAbility** module provides APIs related to Form Extension abilities.
+The **FormExtensionAbility** module provides lifecycle callbacks invoked when a widget is created, destroyed, or updated.
> **NOTE**
>
@@ -17,9 +17,9 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
**System capability**: SystemCapability.Ability.Form
-| Name | Type | Readable| Writable| Description |
-| ------- | ------------------------------------------------------- | ---- | ---- | --------------------------------------------------- |
-| context | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | Yes | No | Context of the **FormExtensionAbility**. This context is inherited from **ExtensionContext**.|
+| Name | Type | Readable| Writable| Description |
+| ------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
+| context | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | Yes | No | Context of the FormExtensionAbility. This context is inherited from [ExtensionContext](js-apis-inner-application-extensionContext.md).|
## onAddForm
@@ -33,7 +33,7 @@ Called to notify the widget provider that a **Form** instance (widget) has been
| Name| Type | Mandatory| Description |
| ------ | -------------------------------------- | ---- | ------------------------------------------------------------ |
-| want | [Want](js-apis-application-want.md) | Yes | Information related to the Extension ability, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.|
+| want | [Want](js-apis-application-want.md) | Yes | Want information related to the FormExtensionAbility, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.|
**Return value**
@@ -45,17 +45,19 @@ Called to notify the widget provider that a **Form** instance (widget) has been
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
+import formBindingData from '@ohos.app.form.formBindingData';
+
export default class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm(want) {
console.log('FormExtensionAbility onAddForm, want:' + want.abilityName);
let dataObj1 = {
- temperature:"11c",
- "time":"11:00"
+ temperature: "11c",
+ "time": "11:00"
};
let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1;
}
-}
+};
```
## onCastToNormalForm
@@ -75,18 +77,20 @@ Called to notify the widget provider that a temporary widget has been converted
**Example**
```ts
+import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
+
export default class MyFormExtensionAbility extends FormExtensionAbility {
onCastToNormalForm(formId) {
console.log('FormExtensionAbility onCastToNormalForm, formId:' + formId);
}
-}
+};
```
## onUpdateForm
onUpdateForm(formId: string): void
-Called to notify the widget provider that a widget has been updated. After obtaining the latest data, the caller invokes **updateForm** of the [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) class to update the widget data.
+Called to notify the widget provider that a widget has been updated. After obtaining the latest data, your application should call [updateForm](js-apis-app-form-formProvider.md#updateform) of **formProvider** to update the widget data.
**System capability**: SystemCapability.Ability.Form
@@ -99,17 +103,24 @@ Called to notify the widget provider that a widget has been updated. After obtai
**Example**
```ts
-import formBindingData from '@ohos.app.form.formBindingData'
+import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
+import formBindingData from '@ohos.app.form.formBindingData';
+import formProvider from '@ohos.app.form.formProvider';
+
export default class MyFormExtensionAbility extends FormExtensionAbility {
onUpdateForm(formId) {
console.log('FormExtensionAbility onUpdateForm, formId:' + formId);
- let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
- this.context.updateForm(formId, obj2).then((data)=>{
+ let obj2 = formBindingData.createFormBindingData({
+ temperature: "22c",
+ time: "22:00"
+ });
+ formProvider.updateForm(formId, obj2).then((data) => {
console.log('FormExtensionAbility context updateForm, data:' + data);
}).catch((error) => {
- console.error('Operation updateForm failed. Cause: ' + error);});
- }
-}
+ console.error('Operation updateForm failed. Cause: ' + error);
+ });
+ }
+};
```
## onChangeFormVisibility
@@ -129,21 +140,28 @@ Called to notify the widget provider of the change of visibility.
**Example**
```ts
+import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData'
+import formProvider from '@ohos.app.form.formProvider';
+
export default class MyFormExtensionAbility extends FormExtensionAbility {
onChangeFormVisibility(newStatus) {
- console.log('FormExtensionAbility onChangeFormVisibility, newStatus:' + newStatus);
- let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
-
- for (let key in newStatus) {
- console.log('FormExtensionAbility onChangeFormVisibility, key:' + key + ", value=" + newStatus[key]);
- this.context.updateForm(key, obj2).then((data)=>{
+ console.log('FormExtensionAbility onChangeFormVisibility, newStatus:' + newStatus);
+ let obj2 = formBindingData.createFormBindingData({
+ temperature: "22c",
+ time: "22:00"
+ });
+
+ for (let key in newStatus) {
+ console.log('FormExtensionAbility onChangeFormVisibility, key:' + key + ", value=" + newStatus[key]);
+ formProvider.updateForm(key, obj2).then((data) => {
console.log('FormExtensionAbility context updateForm, data:' + data);
- }).catch((error) => {
- console.error('Operation updateForm failed. Cause: ' + error);});
+ }).catch((error) => {
+ console.error('Operation updateForm failed. Cause: ' + error);
+ });
}
}
-}
+};
```
## onFormEvent
@@ -164,11 +182,13 @@ Called to instruct the widget provider to receive and process the widget event.
**Example**
```ts
-export default class MyFormExtension extends FormExtensionAbility {
+import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
+
+export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
console.log('FormExtensionAbility onFormEvent, formId:' + formId + ", message:" + message);
}
-}
+};
```
## onRemoveForm
@@ -188,11 +208,13 @@ Called to notify the widget provider that a **Form** instance (widget) has been
**Example**
```ts
+import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
+
export default class MyFormExtensionAbility extends FormExtensionAbility {
onRemoveForm(formId) {
console.log('FormExtensionAbility onRemoveForm, formId:' + formId);
}
-}
+};
```
## onConfigurationUpdate
@@ -207,16 +229,18 @@ Called when the configuration of the environment where the ability is running is
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| newConfig | [Configuration](js-apis-configuration.md) | Yes| New configuration.|
+| newConfig | [Configuration](js-apis-application-configuration.md) | Yes| New configuration.|
**Example**
```ts
-class MyFormExtensionAbility extends FormExtensionAbility {
+import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
+
+export default class MyFormExtensionAbility extends FormExtensionAbility {
onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, config:' + JSON.stringify(config));
}
-}
+};
```
## onAcquireFormState
@@ -236,13 +260,15 @@ Called when the widget provider receives the status query result of a widget. By
**Example**
```ts
+import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formInfo from '@ohos.app.form.formInfo';
-class MyFormExtensionAbility extends FormExtensionAbility {
+
+export default class MyFormExtensionAbility extends FormExtensionAbility {
onAcquireFormState(want) {
console.log('FormExtensionAbility onAcquireFormState, want:' + want);
return formInfo.FormState.UNKNOWN;
}
-}
+};
```
## onShareForm
@@ -270,14 +296,16 @@ Called by the widget provider to receive shared widget data.
**Example**
```ts
-class MyFormExtensionAbility extends FormExtensionAbility {
+import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
+
+export default class MyFormExtensionAbility extends FormExtensionAbility {
onShareForm(formId) {
console.log('FormExtensionAbility onShareForm, formId:' + formId);
let wantParams = {
- "temperature":"20",
- "time":"2022-8-8 09:59",
+ "temperature": "20",
+ "time": "2022-8-8 09:59",
};
return wantParams;
}
-}
+};
```
diff --git a/en/application-dev/reference/apis/js-apis-app-form-formHost.md b/en/application-dev/reference/apis/js-apis-app-form-formHost.md
index 826050a278af8fa031a54ddcbf701b8759e4132a..e78cf3647a1298ed77b4993d811393ede4e2e5b6 100644
--- a/en/application-dev/reference/apis/js-apis-app-form-formHost.md
+++ b/en/application-dev/reference/apis/js-apis-app-form-formHost.md
@@ -1,6 +1,6 @@
-# @ohos.app.form.formHost
+# @ohos.app.form.formHost (formHost)
-The **FormHost** module provides APIs related to the widget host, which is an application that displays the widget content and controls the position where the widget is displayed. You can use the APIs to delete, release, and update widgets installed by the same user, and obtain widget information and status.
+The **formHost** module provides APIs related to the widget host, which is an application that displays the widget content and controls the position where the widget is displayed. You can use the APIs to delete, release, and update widgets installed by the same user, and obtain widget information and status.
> **NOTE**
>
@@ -28,31 +28,32 @@ Deletes a widget. After this API is called, the application can no longer use th
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formId | string | Yes | Widget ID.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is deleted, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is deleted, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = "12400633174999288";
- formHost.deleteForm(formId, (error, data) => {
+ let formId = "12400633174999288";
+ formHost.deleteForm(formId, (error) => {
if (error) {
- console.log('formHost deleteForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
} else {
console.log('formHost deleteForm success');
}
});
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
-
```
## deleteForm
@@ -82,21 +83,23 @@ Deletes a widget. After this API is called, the application can no longer use th
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Parameters**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = "12400633174999288";
+ let formId = "12400633174999288";
formHost.deleteForm(formId).then(() => {
console.log('formHost deleteForm success');
}).catch((error) => {
- console.log('formHost deleteForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -115,27 +118,29 @@ Releases a widget. After this API is called, the application can no longer use t
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formId | string | Yes | Widget ID.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is released, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is released, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = "12400633174999288";
- formHost.releaseForm(formId, (error, data) => {
+ let formId = "12400633174999288";
+ formHost.releaseForm(formId, (error) => {
if (error) {
- console.log('formHost releaseForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -155,27 +160,29 @@ Releases a widget. After this API is called, the application can no longer use t
| -------------- | ------ | ---- | ----------- |
| formId | string | Yes | Widget ID. |
| isReleaseCache | boolean | Yes | Whether to release the cache.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is released, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is released, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = "12400633174999288";
- formHost.releaseForm(formId, true, (error, data) => {
+ let formId = "12400633174999288";
+ formHost.releaseForm(formId, true, (error) => {
if (error) {
- console.log('formHost releaseForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -206,21 +213,23 @@ Releases a widget. After this API is called, the application can no longer use t
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = "12400633174999288";
+ let formId = "12400633174999288";
formHost.releaseForm(formId, true).then(() => {
console.log('formHost releaseForm success');
}).catch((error) => {
- console.log('formHost releaseForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -239,27 +248,29 @@ Requests a widget update. This API uses an asynchronous callback to return the r
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formId | string | Yes | Widget ID.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is updated, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is updated, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = "12400633174999288";
- formHost.requestForm(formId, (error, data) => {
+ let formId = "12400633174999288";
+ formHost.requestForm(formId, (error) => {
if (error) {
- console.log('formHost requestForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -289,21 +300,23 @@ Requests a widget update. This API uses a promise to return the result.
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = "12400633174999288";
+ let formId = "12400633174999288";
formHost.requestForm(formId).then(() => {
console.log('formHost requestForm success');
}).catch((error) => {
- console.log('formHost requestForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -323,27 +336,29 @@ Converts a temporary widget to a normal one. This API uses an asynchronous callb
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formId | string | Yes | Widget ID.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is converted to a normal one, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is converted to a normal one, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = "12400633174999288";
- formHost.castToNormalForm(formId, (error, data) => {
+ let formId = "12400633174999288";
+ formHost.castToNormalForm(formId, (error) => {
if (error) {
- console.log('formHost castTempForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -373,21 +388,23 @@ Converts a temporary widget to a normal one. This API uses a promise to return t
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = "12400633174999288";
+ let formId = "12400633174999288";
formHost.castToNormalForm(formId).then(() => {
console.log('formHost castTempForm success');
}).catch((error) => {
- console.log('formHost castTempForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -406,27 +423,29 @@ Instructs the widget framework to make a widget visible. After this API is calle
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs. |
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget visible, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget visible, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = ["12400633174999288"];
- formHost.notifyVisibleForms(formId, (error, data) => {
+ let formId = ["12400633174999288"];
+ formHost.notifyVisibleForms(formId, (error) => {
if (error) {
- console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -456,21 +475,23 @@ Instructs the widget framework to make a widget visible. After this API is calle
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = ["12400633174999288"];
+ let formId = ["12400633174999288"];
formHost.notifyVisibleForms(formId).then(() => {
console.log('formHost notifyVisibleForms success');
}).catch((error) => {
- console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -489,27 +510,29 @@ Instructs the widget framework to make a widget invisible. After this API is cal
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget invisible, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget invisible, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = ["12400633174999288"];
- formHost.notifyInvisibleForms(formId, (error, data) => {
+ let formId = ["12400633174999288"];
+ formHost.notifyInvisibleForms(formId, (error) => {
if (error) {
- console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -539,21 +562,23 @@ Instructs the widget framework to make a widget invisible. After this API is cal
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = ["12400633174999288"];
+ let formId = ["12400633174999288"];
formHost.notifyInvisibleForms(formId).then(() => {
console.log('formHost notifyInvisibleForms success');
}).catch((error) => {
- console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -572,27 +597,29 @@ Instructs the widget framework to make a widget updatable. After this API is cal
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs. |
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget updatable, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget updatable, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = ["12400633174999288"];
- formHost.enableFormsUpdate(formId, (error, data) => {
+ let formId = ["12400633174999288"];
+ formHost.enableFormsUpdate(formId, (error) => {
if (error) {
- console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -622,21 +649,23 @@ Instructs the widget framework to make a widget updatable. After this API is cal
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = ["12400633174999288"];
+ let formId = ["12400633174999288"];
formHost.enableFormsUpdate(formId).then(() => {
console.log('formHost enableFormsUpdate success');
}).catch((error) => {
- console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -655,27 +684,29 @@ Instructs the widget framework to make a widget not updatable. After this API is
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs. |
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget not updatable, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget not updatable, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = ["12400633174999288"];
- formHost.disableFormsUpdate(formId, (error, data) => {
+ let formId = ["12400633174999288"];
+ formHost.disableFormsUpdate(formId, (error) => {
if (error) {
- console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -705,21 +736,23 @@ Instructs the widget framework to make a widget not updatable. After this API is
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = ["12400633174999288"];
+ let formId = ["12400633174999288"];
formHost.disableFormsUpdate(formId).then(() => {
console.log('formHost disableFormsUpdate success');
}).catch((error) => {
- console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -735,20 +768,21 @@ Checks whether the system is ready. This API uses an asynchronous callback to re
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the check is successful, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the check is successful, **error** is undefined; otherwise, **error** is an error object.|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = "12400633174999288";
formHost.isSystemReady((error, data) => {
if (error) {
- console.log('formHost isSystemReady, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -769,15 +803,16 @@ Checks whether the system is ready. This API uses a promise to return the result
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formId = "12400633174999288";
formHost.isSystemReady().then(() => {
console.log('formHost isSystemReady success');
}).catch((error) => {
- console.log('formHost isSystemReady, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -795,21 +830,23 @@ Obtains the widget information provided by all applications on the device. This
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| callback | AsyncCallback<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **err** is undefined and **data** is the information obtained; otherwise, **err** is an error object.|
+| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
formHost.getAllFormsInfo((error, data) => {
if (error) {
- console.log('formHost getAllFormsInfo, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
} else {
console.log('formHost getAllFormsInfo, data:' + JSON.stringify(data));
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -825,21 +862,23 @@ Obtains the widget information provided by all applications on the device. This
**Return value**
-| Type | Description |
-| :------------ | :---------------------------------- |
-| Promise<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Promise used to return the information obtained.|
+| Type | Description |
+| :----------------------------------------------------------- | :---------------------------------- |
+| Promise<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Promise used to return the information obtained.|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
formHost.getAllFormsInfo().then((data) => {
- console.log('formHost getAllFormsInfo data:' + JSON.stringify(data));
+ console.log('formHost getAllFormsInfo data:' + JSON.stringify(data));
}).catch((error) => {
- console.log('formHost getAllFormsInfo, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -857,29 +896,31 @@ Obtains the widget information provided by a given application on the device. Th
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| bundleName | string | Yes| Bundle name of the application.|
-| callback | AsyncCallback<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **err** is undefined and **data** is the information obtained; otherwise, **err** is an error object.|
+| bundleName | string | Yes| Bundle name of the application.|
+| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
formHost.getFormsInfo("com.example.ohos.formjsdemo", (error, data) => {
if (error) {
- console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
} else {
console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -897,30 +938,32 @@ Obtains the widget information provided by a given application on the device. Th
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| bundleName | string | Yes| Bundle name of the application.|
+| bundleName | string | Yes| Bundle name of the application.|
| moduleName | string | Yes| Module name.|
-| callback | AsyncCallback<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **err** is undefined and **data** is the information obtained; otherwise, **err** is an error object.|
+| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
formHost.getFormsInfo("com.example.ohos.formjsdemo", "entry", (error, data) => {
if (error) {
- console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
} else {
- console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
+ console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -938,33 +981,35 @@ Obtains the widget information provided by a given application on the device. Th
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| bundleName | string | Yes| Bundle name of the application.|
+| bundleName | string | Yes| Bundle name of the application.|
| moduleName | string | No| Module name.|
**Return value**
-| Type | Description |
-| :------------ | :---------------------------------- |
-| Promise<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Promise used to return the information obtained.|
+| Type | Description |
+| :----------------------------------------------------------- | :---------------------------------- |
+| Promise<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Promise used to return the information obtained.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
formHost.getFormsInfo("com.example.ohos.formjsdemo", "entry").then((data) => {
console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
}).catch((error) => {
- console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -983,22 +1028,24 @@ Deletes invalid widgets from the list. This API uses an asynchronous callback to
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of valid widget IDs.|
-| callback | AsyncCallback<number> | Yes| Callback used to return the result. If the invalid widgets are deleted, **err** is undefined and **data** is the number of widgets deleted; otherwise, **err** is an error object.|
+| callback | AsyncCallback<number> | Yes| Callback used to return the result. If the invalid widgets are deleted, **error** is undefined and **data** is the number of widgets deleted; otherwise, **error** is an error object.|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formIds = new Array("12400633174999288", "12400633174999289");
+ let formIds = new Array("12400633174999288", "12400633174999289");
formHost.deleteInvalidForms(formIds, (error, data) => {
if (error) {
- console.log('formHost deleteInvalidForms, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
} else {
console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data));
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -1027,15 +1074,17 @@ Deletes invalid widgets from the list. This API uses a promise to return the res
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
try {
- var formIds = new Array("12400633174999288", "12400633174999289");
+ let formIds = new Array("12400633174999288", "12400633174999289");
formHost.deleteInvalidForms(formIds).then((data) => {
console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data));
}).catch((error) => {
- console.log('formHost deleteInvalidForms, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -1053,20 +1102,22 @@ Obtains the widget state. This API uses an asynchronous callback to return the r
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| want | [Want](js-apis-application-want.md) | Yes | **Want** information carried to query the widget state.|
-| callback | AsyncCallback<[FormStateInfo](js-apis-app-form-formInfo.md#formstateinfo)> | Yes| Callback used to return the result. If the widget state is obtained, **err** is undefined and **data** is the widget state obtained; otherwise, **err** is an error object.|
+| want | [Want](js-apis-application-want.md) | Yes | **Want** information carried to query the widget state. The information must contain the bundle name, ability name, module name, widget name, and widget dimensions.|
+| callback | AsyncCallback<[formInfo.FormStateInfo](js-apis-app-form-formInfo.md#formstateinfo)> | Yes| Callback used to return the result. If the widget state is obtained, **error** is undefined and **data** is the widget state obtained; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-var want = {
+import formHost from '@ohos.app.form.formHost';
+
+let want = {
"deviceId": "",
"bundleName": "ohos.samples.FormApplication",
"abilityName": "FormAbility",
@@ -1079,13 +1130,13 @@ var want = {
try {
formHost.acquireFormState(want, (error, data) => {
if (error) {
- console.log('formHost acquireFormState, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
} else {
console.log('formHost acquireFormState, data:' + JSON.stringify(data));
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -1103,25 +1154,27 @@ Obtains the widget state. This API uses a promise to return the result.
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| want | [Want](js-apis-application-want.md) | Yes | **Want** information carried to query the widget state.|
+| want | [Want](js-apis-application-want.md) | Yes | **Want** information carried to query the widget state. The information must contain the bundle name, ability name, module name, widget name, and widget dimensions.|
**Return value**
| Type | Description |
| :------------ | :---------------------------------- |
-| Promise<[FormStateInfo](js-apis-app-form-formInfo.md#formstateinfo)> | Promise used to return the widget state obtained.|
+| Promise<[formInfo.FormStateInfo](js-apis-app-form-formInfo.md#formstateinfo)> | Promise used to return the widget state obtained.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-var want = {
+import formHost from '@ohos.app.form.formHost';
+
+let want = {
"deviceId": "",
"bundleName": "ohos.samples.FormApplication",
"abilityName": "FormAbility",
@@ -1135,10 +1188,10 @@ try {
formHost.acquireFormState(want).then((data) => {
console.log('formHost acquireFormState, data:' + JSON.stringify(data));
}).catch((error) => {
- console.log('formHost acquireFormState, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -1160,6 +1213,8 @@ Subscribes to widget uninstall events. This API uses an asynchronous callback to
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
let callback = function(formId) {
console.log('formHost on formUninstall, formId:' + formId);
}
@@ -1179,11 +1234,13 @@ Unsubscribes from widget uninstall events. This API uses an asynchronous callbac
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| type | string | Yes | Event type. The value **formUninstall** indicates a widget uninstallation event.|
-| callback | Callback<string> | No| Callback used to return the widget ID. If it is left unspecified, it indicates the callback for all the events that have been subscribed.|
+| callback | Callback<string> | No| Callback used to return the widget ID. If it is left unspecified, it indicates the callback for all the events that have been subscribed.
The value must be the same as that in **on("formUninstall")**.|
**Example**
```ts
+import formHost from '@ohos.app.form.formHost';
+
let callback = function(formId) {
console.log('formHost on formUninstall, formId:' + formId);
}
@@ -1206,27 +1263,29 @@ Instructs the widgets to make themselves visible. This API uses an asynchronous
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs.|
| isVisible | boolean | Yes | Whether to make the widgets visible.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.app.form.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
try {
- formHost.notifyFormsVisible(formIds, true, (error, data) => {
+ formHost.notifyFormsVisible(formIds, true, (error) => {
if (error) {
- console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -1257,21 +1316,23 @@ Instructs the widgets to make themselves visible. This API uses a promise to ret
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.app.form.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
try {
formHost.notifyFormsVisible(formIds, true).then(() => {
console.log('formHost notifyFormsVisible success');
}).catch((error) => {
- console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -1291,27 +1352,29 @@ Instructs the widgets to enable or disable updates. This API uses an asynchronou
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs.|
| isEnableUpdate | boolean | Yes | Whether to make the widgets updatable.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.app.form.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
try {
- formHost.notifyFormsEnableUpdate(formIds, true, (error, data) => {
+ formHost.notifyFormsEnableUpdate(formIds, true, (error) => {
if (error) {
- console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -1342,21 +1405,23 @@ Instructs the widgets to enable or disable updates. This API uses a promise to r
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.app.form.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
try {
formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
console.log('formHost notifyFormsEnableUpdate success');
}).catch((error) => {
- console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
## shareForm
@@ -1375,29 +1440,30 @@ Shares a specified widget with a remote device. This API uses an asynchronous ca
| ------ | ------ | ---- | ------- |
| formId | string | Yes | Widget ID.|
| deviceId | string | Yes | Remote device ID.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is shared, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is shared, **error** is undefined; otherwise, **error** is an error object.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
-
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-var formId = "12400633174999288";
-var deviceId = "EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2";
+import formHost from '@ohos.app.form.formHost';
+
+let formId = "12400633174999288";
+let deviceId = "EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2";
try {
- formHost.shareForm(formId, deviceId, (error, data) => {
+ formHost.shareForm(formId, deviceId, (error) => {
if (error) {
- console.log('formHost shareForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
}
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -1428,22 +1494,24 @@ Shares a specified widget with a remote device. This API uses a promise to retur
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
-**Parameters**
+**Example**
```ts
-var formId = "12400633174999288";
-var deviceId = "EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2";
+import formHost from '@ohos.app.form.formHost';
+
+let formId = "12400633174999288";
+let deviceId = "EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2";
try {
formHost.shareForm(formId, deviceId).then(() => {
console.log('formHost shareForm success');
}).catch((error) => {
- console.log('formHost shareForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
@@ -1451,6 +1519,8 @@ try {
notifyFormsPrivacyProtected(formIds: Array\, isProtected: boolean, callback: AsyncCallback\): void
+Notifies that the privacy protection status of the specified widgets changes. This API uses an asynchronous callback to return the result.
+
**Required permissions**: ohos.permission.REQUIRE_FORM
**System capability**: SystemCapability.Ability.Form
@@ -1459,20 +1529,75 @@ notifyFormsPrivacyProtected(formIds: Array\, isProtected: boolean, callb
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| formId | string | Yes | Widget ID.|
-| deviceId | string | Yes | Remote device ID.|
+| formIds | Array\ | Yes | ID of the widgets.|
+| isProtected | boolean | Yes | Whether privacy protection is enabled.|
+| callback | AsyncCallback\ | Yes| Callback used to return the result. If privacy protection is set successfully, **error** is undefined; otherwise, **error** is an error object.|
+
+**Error codes**
+
+| Error Code ID | Error Message |
+| ------------------------------------------------------------ | ------------------ |
+| 401 | Incorrect input parameter.|
+| For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).| |
+
+**Example**
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.app.form.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
+try {
+ formHost.notifyFormsPrivacyProtected(formIds, true, (error) => {
+ if (error) {
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
+ }
+ });
+} catch(error) {
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
+}
+```
+
+## notifyFormsPrivacyProtected
+
+function notifyFormsPrivacyProtected(formIds: Array\, isProtected: boolean): Promise\;
+
+Notifies that the privacy protection status of the specified widgets changes. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.REQUIRE_FORM
+
+**System capability**: SystemCapability.Ability.Form
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| ----------- | --------------- | ---- | -------------------------------- |
+| formIds | Array\ | Yes | ID of the widgets.|
+| isProtected | boolean | Yes | Whether privacy protection is enabled. |
+
+**Return value**
+
+| Type | Description |
+| ------------------- | ------------------------- |
+| Promise<void> | Promise that returns no value.|
+
+**Error codes**
+
+| Error Code ID | Error Message |
+| ------------------------------------------------------------ | ------------------ |
+| 401 | Incorrect input parameter.|
+| For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).| |
+
+```ts
+import formHost from '@ohos.app.form.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
try {
formHost.notifyFormsPrivacyProtected(formIds, true).then(() => {
- console.log('formHost shareForm success');
+ console.log('formHost notifyFormsPrivacyProtected success');
}).catch((error) => {
- console.log('formHost shareForm, error:' + JSON.stringify(error));
+ console.log(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
-
-
\ No newline at end of file
diff --git a/en/application-dev/reference/apis/js-apis-app-form-formInfo.md b/en/application-dev/reference/apis/js-apis-app-form-formInfo.md
index 5f1ff73b163ffd2c1c5b0feeb1c26a4f3f60cb78..84b40a57a56038b89ddf7ee06caef5f492e252f0 100644
--- a/en/application-dev/reference/apis/js-apis-app-form-formInfo.md
+++ b/en/application-dev/reference/apis/js-apis-app-form-formInfo.md
@@ -1,6 +1,6 @@
-# @ohos.app.form.formInfo
+# @ohos.app.form.formInfo (formInfo)
-The **FormInfo** module provides widget information and state.
+The **formInfo** module provides types and enums related to the widget information and state.
> **NOTE**
>
@@ -20,8 +20,8 @@ Describes widget information.
| Name | Type | Readable | Writable | Description |
| ----------- | -------- | -------- | -------------------- | ------------------------------------------------------------ |
-| bundleName | string | Yes | No | Name of the bundle to which the widget belongs. |
-| moduleName | string | Yes | No | Name of the module to which the widget belongs. |
+| bundleName | string | Yes | No | Name of the bundle to which the widget belongs. |
+| moduleName | string | Yes | No | Name of the module to which the widget belongs. |
| abilityName | string | Yes | No | Name of the ability to which the widget belongs. |
| name | string | Yes | No | Widget name. |
| description | string | Yes | No | Description of the widget. |
@@ -30,11 +30,11 @@ Describes widget information.
| colorMode | [ColorMode](#colormode) | Yes | No | Color mode of the widget. |
| isDefault | boolean | Yes | No | Whether the widget is the default one. |
| updateEnabled | boolean | Yes | No | Whether the widget is updatable. |
-| formVisibleNotify | string | Yes | No | Whether to send a notification when the widget is visible. |
-| relatedBundleName | string | Yes | No | Name of the associated bundle to which the widget belongs. |
+| formVisibleNotify | boolean | Yes | No | Whether to send a notification when the widget is visible. |
+| relatedBundleName | string | Yes | No | Name of the associated bundle to which the widget belongs. |
| scheduledUpdateTime | string | Yes | No | Time when the widget was updated. |
| formConfigAbility | string | Yes | No | Configuration ability of the widget, that is, the ability corresponding to the option in the selection box displayed when the widget is long pressed. |
-| updateDuration | string | Yes | No | Update period of the widget.|
+| updateDuration | number | Yes | No | Update period of the widget.|
| defaultDimension | number | Yes | No | Default dimension of the widget. |
| supportDimensions | Array<number> | Yes | No | Dimensions supported by the widget. For details, see [FormDimension](#formdimension). |
| customizeData | {[key: string]: [value: string]} | Yes | No | Custom data of the widget. |
@@ -100,8 +100,8 @@ Enumerates the widget parameters.
| WIDTH_KEY | "ohos.extra.param.key.form_width" | Widget width. |
| HEIGHT_KEY | "ohos.extra.param.key.form_height" | Widget height. |
| TEMPORARY_KEY | "ohos.extra.param.key.form_temporary" | Temporary widget. |
-| ABILITY_NAME_KEY | "ohos.extra.param.key.ability_name" | Ability name. |
-| DEVICE_ID_KEY | "ohos.extra.param.key.device_id" | Device ID.
**System API**: This is a system API. |
+| ABILITY_NAME_KEY | "ohos.extra.param.key.ability_name" | Ability name. |
+| DEVICE_ID_KEY | "ohos.extra.param.key.device_id" | Device ID. |
| BUNDLE_NAME_KEY | "ohos.extra.param.key.bundle_name" | Key that specifies the target bundle name.|
## FormDimension
@@ -125,9 +125,9 @@ Defines the widget information filter. Only the widget information that meets th
**System capability**: SystemCapability.Ability.Form
-| Name | Description |
-| ----------- | ------------ |
-| moduleName | Only the information about the widget whose **moduleName** is the same as the provided value is returned.|
+| Name | Type | Description |
+| ----------- | ---- | ------------ |
+| moduleName | string | Optional. Only the information about the widget whose **moduleName** is the same as the provided value is returned.
If this parameter is not set, **moduleName** is not used for filtering. |
## VisibilityType
diff --git a/en/application-dev/reference/apis/js-apis-app-form-formProvider.md b/en/application-dev/reference/apis/js-apis-app-form-formProvider.md
index 392f053b31f4fdb51033abb04a83514b8d3cfbd8..d61484f86b36bafd74ded1860272ac1a4b86089a 100644
--- a/en/application-dev/reference/apis/js-apis-app-form-formProvider.md
+++ b/en/application-dev/reference/apis/js-apis-app-form-formProvider.md
@@ -1,4 +1,4 @@
-# @ohos.app.form.formProvider
+# @ohos.app.form.formProvider (formProvider)
The **FormProvider** module provides APIs related to the widget provider. You can use the APIs to update a widget, set the next refresh time for a widget, obtain widget information, and request a widget release.
@@ -31,23 +31,25 @@ Sets the next refresh time for a widget. This API uses an asynchronous callback
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-var formId = "12400633174999288";
+import formProvider from '@ohos.app.form.formProvider';
+
+let formId = "12400633174999288";
try {
formProvider.setFormNextRefreshTime(formId, 5, (error, data) => {
if (error) {
- console.log('formProvider setFormNextRefreshTime, error:' + JSON.stringify(error));
+ console.log(`callback error, code: ${error.code}, message: ${error.message})`);
} else {
console.log(`formProvider setFormNextRefreshTime success`);
}
});
} catch (error) {
- console.log("error" + JSON.stringify(error))
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
```
@@ -76,21 +78,23 @@ Sets the next refresh time for a widget. This API uses a promise to return the r
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-var formId = "12400633174999288";
+import formProvider from '@ohos.app.form.formProvider';
+
+let formId = "12400633174999288";
try {
formProvider.setFormNextRefreshTime(formId, 5).then(() => {
- console.log('formProvider setFormNextRefreshTime success');
+ console.log(`formProvider setFormNextRefreshTime success`);
}).catch((error) => {
- console.log('formProvider setFormNextRefreshTime, error:' + JSON.stringify(error));
+ console.log(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
```
@@ -114,25 +118,27 @@ Updates a widget. This API uses an asynchronous callback to return the result.
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
import formBindingData from '@ohos.application.formBindingData';
-var formId = "12400633174999288";
+import formProvider from '@ohos.app.form.formProvider';
+
+let formId = "12400633174999288";
try {
let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
formProvider.updateForm(formId, obj, (error, data) => {
if (error) {
- console.log('formProvider updateForm, error:' + JSON.stringify(error));
+ console.log(`callback error, code: ${error.code}, message: ${error.message})`);
} else {
console.log(`formProvider updateForm success`);
}
});
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
```
@@ -161,23 +167,25 @@ Updates a widget. This API uses a promise to return the result.
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
import formBindingData from '@ohos.application.formBindingData';
-var formId = "12400633174999288";
-let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
+import formProvider from '@ohos.app.form.formProvider';
+
+let formId = "12400633174999288";
+let obj = formBindingData.createFormBindingData({ temperature: "22c", time: "22:00" });
try {
formProvider.updateForm(formId, obj).then(() => {
- console.log('formProvider updateForm success');
+ console.log(`formProvider updateForm success`);
}).catch((error) => {
- console.log('formProvider updateForm, error:' + JSON.stringify(error));
+ console.log(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
```
@@ -193,29 +201,31 @@ Obtains the application's widget information on the device. This API uses an asy
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| callback | AsyncCallback<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the information obtained.|
+| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the information obtained.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
+import formProvider from '@ohos.app.form.formProvider';
+
try {
formProvider.getFormsInfo((error, data) => {
if (error) {
- console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
+ console.log(`callback error, code: ${error.code}, message: ${error.message})`);
} else {
- console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
+ console.log('formProvider getFormsInfo, data: ' + JSON.stringify(data));
}
});
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
```
## getFormsInfo
@@ -231,33 +241,35 @@ Obtains the application's widget information that meets a filter criterion on th
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| filter | [formInfo.FormInfoFilter](js-apis-app-form-formInfo.md#forminfofilter) | Yes| Filter criterion.|
-| callback | AsyncCallback<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the information obtained.|
+| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the information obtained.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-import formInfo from '@ohos.application.formInfo';
-const filter : formInfo.FormInfoFilter = {
- // get info of forms belong to module entry.
- moduleName : "entry"
+import formInfo from '@ohos.app.form.formInfo';
+import formProvider from '@ohos.app.form.formProvider';
+
+const filter: formInfo.FormInfoFilter = {
+ // get info of forms belong to module entry.
+ moduleName: "entry"
};
try {
formProvider.getFormsInfo(filter, (error, data) => {
if (error) {
- console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
+ console.log(`callback error, code: ${error.code}, message: ${error.message})`);
} else {
- console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
+ console.log('formProvider getFormsInfo, data: ' + JSON.stringify(data));
}
});
-} catch(error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+} catch (error) {
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
```
@@ -279,31 +291,33 @@ Obtains the application's widget information on the device. This API uses a prom
| Type | Description |
| :------------ | :---------------------------------- |
-| Promise<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Promise used to return the information obtained.|
+| Promise<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Promise used to return the information obtained.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-import formInfo from '@ohos.application.formInfo';
-const filter : formInfo.FormInfoFilter = {
- // get info of forms belong to module entry.
- moduleName : "entry"
+import formInfo from '@ohos.app.form.formInfo';
+import formProvider from '@ohos.app.form.formProvider';
+
+const filter: formInfo.FormInfoFilter = {
+ // get info of forms belong to module entry.
+ moduleName: "entry"
};
try {
formProvider.getFormsInfo(filter).then((data) => {
console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
}).catch((error) => {
- console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
+ console.log(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
```
@@ -322,21 +336,23 @@ Requests to publish a widget carrying data to the widget host. This API uses an
| Name| Type | Mandatory| Description |
| ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
| want | [Want](js-apis-application-want.md) | Yes | Request used for publishing. The following fields must be included:
Information about the target widget.
**abilityName**: ability of the target widget.
**parameters**:
"ohos.extra.param.key.form_dimension"
"ohos.extra.param.key.form_name"
"ohos.extra.param.key.module_name" |
-| formBindingData.FormBindingData | [FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | Yes | Data used for creating the widget.|
+| formBindingData | [formBindingData.FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | Yes | Data used for creating the widget.|
| callback | AsyncCallback<string> | Yes| Callback used to return the widget ID.|
**Error codes**
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
import formBindingData from '@ohos.application.formBindingData';
-var want = {
+import formProvider from '@ohos.app.form.formProvider';
+
+let want = {
abilityName: "FormAbility",
parameters: {
"ohos.extra.param.key.form_dimension": 2,
@@ -345,16 +361,16 @@ var want = {
}
};
try {
- let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
+ let obj = formBindingData.createFormBindingData({ temperature: "22c", time: "22:00" });
formProvider.requestPublishForm(want, obj, (error, data) => {
if (error) {
- console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
+ console.log(`callback error, code: ${error.code}, message: ${error.message})`);
} else {
console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
}
});
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
```
@@ -379,13 +395,15 @@ Requests to publish a widget to the widget host. This API uses an asynchronous c
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-var want = {
+import formProvider from '@ohos.app.form.formProvider';
+
+let want = {
abilityName: "FormAbility",
parameters: {
"ohos.extra.param.key.form_dimension": 2,
@@ -396,15 +414,14 @@ var want = {
try {
formProvider.requestPublishForm(want, (error, data) => {
if (error) {
- console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
+ console.log(`callback error, code: ${error.code}, message: ${error.message})`);
} else {
console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
}
});
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
-
```
## requestPublishForm
@@ -422,7 +439,7 @@ Requests to publish a widget to the widget host. This API uses a promise to retu
| Name | Type | Mandatory| Description |
| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-want.md) | Yes | Request used for publishing. The following fields must be included:
Information about the target widget.
**abilityName**: ability of the target widget.
**parameters**:
"ohos.extra.param.key.form_dimension"
"ohos.extra.param.key.form_name"
"ohos.extra.param.key.module_name" |
-| formBindingData.FormBindingData | [FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | No | Data used for creating the widget. |
+| formBindingData | [formBindingData.FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | No | Data used for creating the widget. |
**Return value**
@@ -434,13 +451,15 @@ Requests to publish a widget to the widget host. This API uses a promise to retu
| Error Code ID| Error Message|
| -------- | -------- |
-| 401 | If the input parameter is not valid parameter. |
-For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
+| 401 | Incorrect input parameter.|
+|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
**Example**
```ts
-var want = {
+import formProvider from '@ohos.app.form.formProvider';
+
+let want = {
abilityName: "FormAbility",
parameters: {
"ohos.extra.param.key.form_dimension": 2,
@@ -452,10 +471,10 @@ try {
formProvider.requestPublishForm(want).then((data) => {
console.log('formProvider requestPublishForm success, form ID is :' + JSON.stringify(data));
}).catch((error) => {
- console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
+ console.log(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
```
@@ -478,37 +497,38 @@ Checks whether a widget can be published to the widget host. This API uses an as
**Example**
```ts
+import formProvider from '@ohos.app.form.formProvider';
+
try {
formProvider.isRequestPublishFormSupported((error, isSupported) => {
- if (error) {
- console.log('formProvider isRequestPublishFormSupported, error:' + JSON.stringify(error));
- } else {
- if (isSupported) {
- var want = {
- abilityName: "FormAbility",
- parameters: {
- "ohos.extra.param.key.form_dimension": 2,
- "ohos.extra.param.key.form_name": "widget",
- "ohos.extra.param.key.module_name": "entry"
- }
- };
- try {
- formProvider.requestPublishForm(want, (error, data) => {
- if (error) {
- console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
- } else {
- console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
+ if (error) {
+ console.log(`callback error, code: ${error.code}, message: ${error.message})`);
+ } else {
+ if (isSupported) {
+ var want = {
+ abilityName: "FormAbility",
+ parameters: {
+ "ohos.extra.param.key.form_dimension": 2,
+ "ohos.extra.param.key.form_name": "widget",
+ "ohos.extra.param.key.module_name": "entry"
}
- });
- } catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ };
+ try {
+ formProvider.requestPublishForm(want, (error, data) => {
+ if (error) {
+ console.log(`callback error, code: ${error.code}, message: ${error.message})`);
+ } else {
+ console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
+ }
+ });
+ } catch (error) {
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
+ }
}
-
}
- }
-});
+ });
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
```
@@ -531,34 +551,33 @@ Checks whether a widget can be published to the widget host. This API uses a pro
**Example**
```ts
+import formProvider from '@ohos.app.form.formProvider';
+
try {
formProvider.isRequestPublishFormSupported().then((isSupported) => {
if (isSupported) {
var want = {
- abilityName: "FormAbility",
- parameters: {
- "ohos.extra.param.key.form_dimension": 2,
- "ohos.extra.param.key.form_name": "widget",
- "ohos.extra.param.key.module_name": "entry"
- }
+ abilityName: "FormAbility",
+ parameters: {
+ "ohos.extra.param.key.form_dimension": 2,
+ "ohos.extra.param.key.form_name": "widget",
+ "ohos.extra.param.key.module_name": "entry"
+ }
};
try {
formProvider.requestPublishForm(want).then((data) => {
console.log('formProvider requestPublishForm success, form ID is :' + JSON.stringify(data));
}).catch((error) => {
- console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
+ console.log(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
-
}
}).catch((error) => {
- console.log('formProvider isRequestPublishFormSupported, error:' + JSON.stringify(error));
+ console.log(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
- console.log(`catch err->${JSON.stringify(error)}`);
+ console.log(`catch error, code: ${error.code}, message: ${error.message})`);
}
```
-
-
\ No newline at end of file
diff --git a/en/application-dev/reference/apis/js-apis-appControl.md b/en/application-dev/reference/apis/js-apis-appControl.md
index 1cb94f68880afc18137b22ed6f73ed3350caffb4..06b334d58cad8e7dd26a45c0344cfa48e1fdf0d6 100644
--- a/en/application-dev/reference/apis/js-apis-appControl.md
+++ b/en/application-dev/reference/apis/js-apis-appControl.md
@@ -1,4 +1,4 @@
-# appControl
+# @ohos.bundle.appControl (appControl)
The **appControl** module provides APIs for setting, obtaining, and deleting the disposed status of an application. An application in the disposed state is forbidden to run. When a user clicks the application icon on the home screen, the corresponding page is displayed based on the disposal intent.
@@ -30,7 +30,7 @@ Sets the disposed status for an application. This API uses a promise to return t
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | --------------------------------------- |
-| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
+| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
| disposedWant | Want | Yes| Disposal intent of the application.|
**Return value**
@@ -81,7 +81,7 @@ Sets the disposed status for an application. This API uses an asynchronous callb
| Name | Type | Mandatory | Description |
| ----------- | ------------------------------- | ---- | --------------------------------------- |
-| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
+| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
| disposedWant | Want | Yes| Disposal intent of the application.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
@@ -128,7 +128,7 @@ Obtains the disposed status of an application. This API uses a promise to return
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | --------------------------------------- |
-| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
+| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
**Return value**
@@ -177,7 +177,7 @@ Obtains the disposed status of an application. This API uses an asynchronous cal
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | --------------------------------------- |
-| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
+| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the disposed status obtained; otherwise, **err** is an error object. |
**Error codes**
@@ -222,7 +222,7 @@ Deletes the disposed status for an application. This API uses a promise to retur
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | --------------------------------------- |
-| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
+| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
**Return value**
@@ -271,7 +271,7 @@ Deletes the disposed status for an application. This API uses an asynchronous ca
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | --------------------------------------- |
-| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
+| appId | string | Yes | ID of the target application.
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
**Error codes**
diff --git a/en/application-dev/reference/apis/js-apis-application-ability.md b/en/application-dev/reference/apis/js-apis-application-ability.md
index 8c1c83988c352d24ac4bc7d64b61d53f3378156a..efba928564b2c9aa34e35b2af7485674ea99274d 100644
--- a/en/application-dev/reference/apis/js-apis-application-ability.md
+++ b/en/application-dev/reference/apis/js-apis-application-ability.md
@@ -1,4 +1,4 @@
-# @ohos.application.Ability
+# @ohos.application.Ability (Ability)
The **Ability** module manages the ability lifecycle and context, such as creating and destroying an ability, and dumping client information.
@@ -15,7 +15,7 @@ This module provides the following common ability-related functions:
## Modules to Import
```ts
-import Ability from '@ohos.application.Ability';
+import UIAbility from '@ohos.app.ability.UIAbility';
```
## Attributes
@@ -47,7 +47,7 @@ Called to initialize the service logic when an ability is created.
**Example**
```ts
- class myAbility extends Ability {
+ export default class EntryAbility extends UIAbility {
onCreate(want, param) {
console.log('onCreate, want:' + want.abilityName);
}
@@ -67,7 +67,7 @@ Called when a **WindowStage** is created for this ability.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
- | windowStage | window.WindowStage | Yes| **WindowStage** information.|
+ | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** information.|
**Example**
@@ -111,7 +111,7 @@ Called when the **WindowStage** is restored during the migration of this ability
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
- | windowStage | window.WindowStage | Yes| **WindowStage** information.|
+ | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** information.|
**Example**
@@ -219,23 +219,24 @@ Called to save data during the ability migration preparation process.
onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;
-Called when the ability startup mode is set to singleton.
+Called when a new Want is passed in and this UIAbility is started again.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want | [Want](js-apis-application-want.md) | Yes| Want parameters, such as the ability name and bundle name.|
- | launchParams | AbilityConstant.LaunchParam | Yes| Reason for the ability startup and the last abnormal exit.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want | [Want](js-apis-application-want.md) | Yes| Want information, such as the ability name and bundle name.|
+| launchParams | AbilityConstant.LaunchParam | Yes| Reason for the ability startup and the last abnormal exit.|
**Example**
```ts
class myAbility extends Ability {
- onNewWant(want) {
+ onNewWant(want, launchParams) {
console.log('onNewWant, want:' + want.abilityName);
+ console.log('onNewWant, launchParams:' + JSON.stringify(launchParams));
}
}
```
@@ -388,8 +389,9 @@ Sends sequenceable data to the target ability.
**Example**
```ts
- import Ability from '@ohos.application.Ability';
- class MyMessageAble{ // Custom sequenceable data structure
+ import UIAbility from '@ohos.app.ability.UIAbility';
+
+ class MyMessageAble{ // Custom sequenceable data structure.
name:""
str:""
num: 1
@@ -412,11 +414,11 @@ Sends sequenceable data to the target ability.
};
var method = 'call_Function'; // Notification message string negotiated by the two abilities
var caller;
- export default class MainAbility extends Ability {
+ export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
- abilityName: "MainAbility",
+ abilityName: "EntryAbility",
deviceId: ""
}).then((obj) => {
caller = obj;
@@ -472,7 +474,8 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
**Example**
```ts
- import Ability from '@ohos.application.Ability';
+ import UIAbility from '@ohos.app.ability.UIAbility';
+
class MyMessageAble{
name:""
str:""
@@ -496,11 +499,11 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
};
var method = 'call_Function';
var caller;
- export default class MainAbility extends Ability {
+ export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
- abilityName: "MainAbility",
+ abilityName: "EntryAbility",
deviceId: ""
}).then((obj) => {
caller = obj;
@@ -543,14 +546,17 @@ Releases the caller interface of the target ability.
**Example**
+
```ts
- import Ability from '@ohos.application.Ability';
+ import UIAbility from '@ohos.app.ability.UIAbility';
+
var caller;
- export default class MainAbility extends Ability {
+
+ export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
- abilityName: "MainAbility",
+ abilityName: "EntryAbility",
deviceId: ""
}).then((obj) => {
caller = obj;
@@ -585,13 +591,15 @@ Registers a callback that is invoked when the stub on the target ability is disc
**Example**
```ts
- import Ability from '@ohos.application.Ability';
+ import UIAbility from '@ohos.app.ability.UIAbility';
+
var caller;
- export default class MainAbility extends Ability {
+
+ export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
- abilityName: "MainAbility",
+ abilityName: "EntryAbility",
deviceId: ""
}).then((obj) => {
caller = obj;
@@ -642,7 +650,7 @@ Registers a caller notification callback, which is invoked when the target abili
**Example**
```ts
- import Ability from '@ohos.application.Ability';
+ import UIAbility from '@ohos.app.ability.UIAbility';
class MyMessageAble{
name:""
str:""
@@ -671,7 +679,7 @@ Registers a caller notification callback, which is invoked when the target abili
pdata.readSequenceable(msg);
return new MyMessageAble("test1", "Callee test");
}
- export default class MainAbility extends Ability {
+ export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('Callee onCreate is called');
try {
@@ -710,9 +718,11 @@ Deregisters a caller notification callback, which is invoked when the target abi
**Example**
```ts
- import Ability from '@ohos.application.Ability';
+ import UIAbility from '@ohos.app.ability.UIAbility';
+
var method = 'call_Function';
- export default class MainAbility extends Ability {
+
+ export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('Callee onCreate is called');
try {
@@ -724,7 +734,7 @@ Deregisters a caller notification callback, which is invoked when the target abi
}
}
```
-
+
## OnReleaseCallBack
(msg: string): void;
diff --git a/en/application-dev/reference/apis/js-apis-application-abilityConstant.md b/en/application-dev/reference/apis/js-apis-application-abilityConstant.md
index c97e344590f1bdd6b0d0242c1b61003053908e37..70d679e5f44e1089e91ff7377b687ded761e29e6 100644
--- a/en/application-dev/reference/apis/js-apis-application-abilityConstant.md
+++ b/en/application-dev/reference/apis/js-apis-application-abilityConstant.md
@@ -1,12 +1,10 @@
-# @ohos.application.AbilityConstant
+# @ohos.application.AbilityConstant (AbilityConstant)
-The **AbilityConstant** module provides ability launch parameters.
-
-The parameters include the initial launch reasons, reasons for the last exit, and ability continuation results.
+The **AbilityConstant** module defines the ability-related enums, including the initial launch reasons, reasons for the last exit, ability continuation results, and window modes.
> **NOTE**
>
-> The APIs of this module are supported and deprecated since API version 9. You are advised to use [@ohos.app.ability.AbilityConstant](js-apis-app-ability-abilityConstant.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 9 and are deprecated in versions later than API version 9. You are advised to use [@ohos.app.ability.AbilityConstant](js-apis-app-ability-abilityConstant.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
@@ -21,12 +19,12 @@ import AbilityConstant from '@ohos.application.AbilityConstant';
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
-| launchReason | LaunchReason| Yes| Yes| Ability launch reason.|
-| lastExitReason | LastExitReason | Yes| Yes| Reason for the last exit.|
+| launchReason | [LaunchReason](#abilityconstantlaunchreason)| Yes| Yes| Ability launch reason.|
+| lastExitReason | [LastExitReason](#abilityconstantlastexitreason) | Yes| Yes| Reason for the last exit.|
## AbilityConstant.LaunchReason
-Enumerates ability launch reasons.
+Enumerates the initial ability launch reasons.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -41,7 +39,7 @@ Enumerates ability launch reasons.
## AbilityConstant.LastExitReason
-Enumerates reasons for the last exit.
+Enumerates the reasons for the last exit.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -54,7 +52,7 @@ Enumerates reasons for the last exit.
## AbilityConstant.OnContinueResult
-Enumerates ability continuation results.
+Enumerates the ability continuation results.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
diff --git a/en/application-dev/reference/apis/js-apis-application-abilityDelegatorRegistry.md b/en/application-dev/reference/apis/js-apis-application-abilityDelegatorRegistry.md
index c58eae8878a6df52715e9b4ec06738aeef34bf01..ae72afeca2e3214d00a785c0639793e8df47d715 100644
--- a/en/application-dev/reference/apis/js-apis-application-abilityDelegatorRegistry.md
+++ b/en/application-dev/reference/apis/js-apis-application-abilityDelegatorRegistry.md
@@ -1,10 +1,10 @@
-# @ohos.application.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.
> **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 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.
## Modules to Import
diff --git a/en/application-dev/reference/apis/js-apis-application-abilityLifecycleCallback.md b/en/application-dev/reference/apis/js-apis-application-abilityLifecycleCallback.md
index cd4a4db73667651bae07a865d0a088321cda0ce6..040448220bb9da59779f0d449c43a59d8ab920bd 100644
--- a/en/application-dev/reference/apis/js-apis-application-abilityLifecycleCallback.md
+++ b/en/application-dev/reference/apis/js-apis-application-abilityLifecycleCallback.md
@@ -1,10 +1,10 @@
-# @ohos.application.AbilityLifecycleCallback
+# @ohos.application.AbilityLifecycleCallback (AbilityLifecycleCallback)
-The **AbilityLifecycleCallback** module provides callbacks, such as **onAbilityCreate**, **onWindowStageCreate**, and **onWindowStageDestroy**, to receive lifecycle state changes in the application context.
+The **AbilityLifecycleCallback** module provides callbacks, such as **onAbilityCreate**, **onWindowStageCreate**, and **onWindowStageDestroy**, to receive lifecycle state changes in the application context. These callbacks can be used as an input parameter of [registerAbilityLifecycleCallback](js-apis-inner-application-applicationContext.md#applicationcontextregisterabilitylifecyclecallback).
> **NOTE**
>
-> The APIs of this module are supported and deprecated since API version 9. You are advised to use [@ohos.app.ability.AbilityLifecycleCallback](js-apis-app-ability-abilityLifecycleCallback.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 9 and are deprecated in versions later than API version 9. You are advised to use [@ohos.app.ability.AbilityLifecycleCallback](js-apis-app-ability-abilityLifecycleCallback.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.
@@ -25,9 +25,9 @@ Called when an ability is created.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
## AbilityLifecycleCallback.onWindowStageCreate
@@ -40,10 +40,10 @@ Called when the window stage of an ability is created.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
- | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onWindowStageActive
@@ -56,10 +56,10 @@ Called when the window stage of an ability gains focus.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
- | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onWindowStageInactive
@@ -72,10 +72,10 @@ Called when the window stage of an ability loses focus.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
- | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onWindowStageDestroy
@@ -88,10 +88,10 @@ Called when the window stage of an ability is destroyed.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
- | windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
## AbilityLifecycleCallback.onAbilityDestroy
@@ -104,9 +104,9 @@ Called when an ability is destroyed.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
## AbilityLifecycleCallback.onAbilityForeground
@@ -119,9 +119,9 @@ Called when an ability is switched from the background to the foreground.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
## AbilityLifecycleCallback.onAbilityBackground
@@ -134,9 +134,9 @@ Called when an ability is switched from the foreground to the background.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
## AbilityLifecycleCallback.onAbilityContinue
@@ -149,64 +149,64 @@ Called when an ability is continued on another device.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| ability | [Ability](js-apis-application-ability.md#Ability) | Yes| **Ability** object.|
**Example**
-
```ts
import AbilityStage from "@ohos.application.AbilityStage";
-var lifecycleid;
+var lifecycleId;
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage onCreate")
- let AbilityLifecycleCallback = {
- onAbilityCreate(ability){
- console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
+ let AbilityLifecycleCallback = {
+ onAbilityCreate(ability) {
+ console.log("onAbilityCreate ability:" + JSON.stringify(ability));
},
- onWindowStageCreate(ability, windowStage){
- console.log("AbilityLifecycleCallback onWindowStageCreate ability:" + JSON.stringify(ability));
- console.log("AbilityLifecycleCallback onWindowStageCreate windowStage:" + JSON.stringify(windowStage));
+ onWindowStageCreate(ability, windowStage) {
+ console.log("onWindowStageCreate ability:" + JSON.stringify(ability));
+ console.log("onWindowStageCreate windowStage:" + JSON.stringify(windowStage));
},
- onWindowStageActive(ability, windowStage){
- console.log("AbilityLifecycleCallback onWindowStageActive ability:" + JSON.stringify(ability));
- console.log("AbilityLifecycleCallback onWindowStageActive windowStage:" + JSON.stringify(windowStage));
+ onWindowStageActive(ability, windowStage) {
+ console.log("onWindowStageActive ability:" + JSON.stringify(ability));
+ console.log("onWindowStageActive windowStage:" + JSON.stringify(windowStage));
},
- onWindowStageInactive(ability, windowStage){
- console.log("AbilityLifecycleCallback onWindowStageInactive ability:" + JSON.stringify(ability));
- console.log("AbilityLifecycleCallback onWindowStageInactive windowStage:" + JSON.stringify(windowStage));
+ onWindowStageInactive(ability, windowStage) {
+ console.log("onWindowStageInactive ability:" + JSON.stringify(ability));
+ console.log("onWindowStageInactive windowStage:" + JSON.stringify(windowStage));
},
- onWindowStageDestroy(ability, windowStage){
- console.log("AbilityLifecycleCallback onWindowStageDestroy ability:" + JSON.stringify(ability));
- console.log("AbilityLifecycleCallback onWindowStageDestroy windowStage:" + JSON.stringify(windowStage));
+ onWindowStageDestroy(ability, windowStage) {
+ console.log("onWindowStageDestroy ability:" + JSON.stringify(ability));
+ console.log("onWindowStageDestroy windowStage:" + JSON.stringify(windowStage));
},
- onAbilityDestroy(ability){
- console.log("AbilityLifecycleCallback onAbilityDestroy ability:" + JSON.stringify(ability));
+ onAbilityDestroy(ability) {
+ console.log("onAbilityDestroy ability:" + JSON.stringify(ability));
},
- onAbilityForeground(ability){
- console.log("AbilityLifecycleCallback onAbilityForeground ability:" + JSON.stringify(ability));
+ onAbilityForeground(ability) {
+ console.log("onAbilityForeground ability:" + JSON.stringify(ability));
},
- onAbilityBackground(ability){
- console.log("AbilityLifecycleCallback onAbilityBackground ability:" + JSON.stringify(ability));
+ onAbilityBackground(ability) {
+ console.log("onAbilityBackground ability:" + JSON.stringify(ability));
},
- onAbilityContinue(ability){
- console.log("AbilityLifecycleCallback onAbilityContinue ability:" + JSON.stringify(ability));
+ onAbilityContinue(ability) {
+ console.log("onAbilityContinue ability:" + JSON.stringify(ability));
}
}
// 1. Obtain applicationContext through the context attribute.
let applicationContext = this.context.getApplicationContext();
// 2. Use applicationContext to register a listener for the ability lifecycle in the application.
- lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
- console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid));
+ lifecycleId = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
+ console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleId));
}
+
onDestroy() {
let applicationContext = this.context.getApplicationContext();
- applicationContext.unregisterAbilityLifecycleCallback(lifecycleid, (error, data) => {
- console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
+ applicationContext.unregisterAbilityLifecycleCallback(lifecycleId, (error, data) => {
+ console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
});
}
}
diff --git a/en/application-dev/reference/apis/js-apis-application-abilityManager.md b/en/application-dev/reference/apis/js-apis-application-abilityManager.md
index cf7f8da5870889e80853b396a433932afc895679..e509a1b5d13a2d0d20b8d6dee4efee9487c5ee92 100644
--- a/en/application-dev/reference/apis/js-apis-application-abilityManager.md
+++ b/en/application-dev/reference/apis/js-apis-application-abilityManager.md
@@ -1,16 +1,16 @@
-# @ohos.application.abilityManager
+# @ohos.application.abilityManager (AbilityManager)
The **AbilityManager** module provides APIs for obtaining, adding, and modifying ability running information and state information.
> **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 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 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
@@ -26,8 +26,8 @@ Enumerates the ability states.
| INITIAL | 0 | The ability is in the initial state.|
| 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 foregrounding state. |
-| BACKGROUNDING | 12 | The ability is in the backgrounding 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
@@ -49,13 +49,11 @@ Updates the configuration. This API uses an asynchronous callback to return the
**Example**
```ts
-import abilitymanager from '@ohos.application.abilityManager';
-
var config = {
language: 'chinese'
}
-abilitymanager.updateConfiguration(config, () => {
+abilityManager.updateConfiguration(config, () => {
console.log('------------ updateConfiguration -----------');
})
```
@@ -85,13 +83,11 @@ Updates the configuration. This API uses a promise to return the result.
**Example**
```ts
-import abilitymanager from '@ohos.application.abilityManager';
-
var config = {
language: 'chinese'
}
-abilitymanager.updateConfiguration(config).then(() => {
+abilityManager.updateConfiguration(config).then(() => {
console.log('updateConfiguration success');
}).catch((err) => {
console.log('updateConfiguration fail');
@@ -112,14 +108,12 @@ Obtains the ability running information. This API uses an asynchronous callback
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
-| callback | AsyncCallback\> | Yes | Callback used to return the result. |
+| callback | AsyncCallback\> | Yes | Callback used to return the result. |
**Example**
```ts
-import abilitymanager from '@ohos.application.abilityManager';
-
-abilitymanager.getAbilityRunningInfos((err,data) => {
+abilityManager.getAbilityRunningInfos((err,data) => {
console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
```
@@ -138,14 +132,12 @@ Obtains the ability running information. This API uses a promise to return the r
| Type | Description |
| ---------------------------------------- | ------- |
-| Promise\> | Promise used to return the result.|
+| Promise\> | Promise used to return the result.|
**Example**
```ts
-import abilitymanager from '@ohos.application.abilityManager';
-
-abilitymanager.getAbilityRunningInfos().then((data) => {
+abilityManager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data))
}).catch((err) => {
console.log("getAbilityRunningInfos err: " + err)
@@ -167,16 +159,14 @@ Obtains the extension running information. This API uses an asynchronous callbac
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| upperLimit | number | Yes| Maximum number of messages that can be obtained.|
-| callback | AsyncCallback\> | Yes | Callback used to return the result. |
+| callback | AsyncCallback\> | Yes | Callback used to return the result. |
**Example**
```ts
-import abilitymanager from '@ohos.application.abilityManager';
-
var upperLimit = 0;
-abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => {
+abilityManager.getExtensionRunningInfos(upperLimit, (err,data) => {
console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
```
@@ -201,16 +191,14 @@ Obtains the extension running information. This API uses a promise to return the
| Type | Description |
| ---------------------------------------- | ------- |
-| Promise\> | Promise used to return the result.|
+| Promise\> | Promise used to return the result.|
**Example**
```ts
-import abilitymanager from '@ohos.application.abilityManager';
-
var upperLimit = 0;
-abilitymanager.getExtensionRunningInfos(upperLimit).then((data) => {
+abilityManager.getExtensionRunningInfos(upperLimit).then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data));
}).catch((err) => {
console.log("getAbilityRunningInfos err: " + err);
@@ -229,14 +217,12 @@ Obtains the top ability, which is the ability that has the window focus. This AP
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
-| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+| callback | AsyncCallback\<[ElementName](js-apis-bundleManager-elementName.md)> | Yes | Callback used to return the result. |
**Example**
```ts
-import abilitymanager from '@ohos.application.abilityManager';
-
-abilitymanager.getTopAbility((err,data) => {
+abilityManager.getTopAbility((err,data) => {
console.log("getTopAbility err: " + err + " data: " + JSON.stringify(data));
});
```
@@ -253,14 +239,12 @@ Obtains the top ability, which is the ability that has the window focus. This AP
| Type | Description |
| ---------------------------------------- | ------- |
-| Promise\| Promise used to return the result.|
+| Promise\<[ElementName](js-apis-bundleManager-elementName.md)>| Promise used to return the result.|
**Example**
```ts
-import abilitymanager from '@ohos.application.abilityManager';
-
-abilitymanager.getTopAbility().then((data) => {
+abilityManager.getTopAbility().then((data) => {
console.log("getTopAbility data: " + JSON.stringify(data));
}).catch((err) => {
console.log("getTopAbility err: " + err);
diff --git a/en/application-dev/reference/apis/js-apis-application-abilityStage.md b/en/application-dev/reference/apis/js-apis-application-abilityStage.md
index 45227a89b2a6ed8d01997b8c699f8fc8c320b955..1421dcd723028b9a7f052e76e2534f1ea7c4017a 100644
--- a/en/application-dev/reference/apis/js-apis-application-abilityStage.md
+++ b/en/application-dev/reference/apis/js-apis-application-abilityStage.md
@@ -1,4 +1,4 @@
-# @ohos.application.AbilityStage
+# @ohos.application.AbilityStage (AbilityStage)
**AbilityStage** is a runtime class for HAP files.
@@ -38,21 +38,21 @@ Called when the application is created.
onAcceptWant(want: Want): string;
-Called when a specified ability is started.
+Called when a UIAbility is started.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want | [Want](js-apis-application-want.md) | Yes| Information about the ability to start, such as the ability name and bundle name.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want | [Want](js-apis-application-want.md) | Yes| Want information about the target UIAbility, such as the ability name and bundle name.|
**Return value**
- | Type| Description|
- | -------- | -------- |
- | string | Returns an ability ID. If this ability has been started, no new instance is created and the ability is placed at the top of the stack. Otherwise, a new instance is created and started.|
+| Type| Description|
+| -------- | -------- |
+| string | Returns a UIAbility ID. If this UIAbility has been started, no new instance is created and the UIAbility is placed at the top of the stack. Otherwise, a new instance is created and started.|
**Example**
@@ -76,9 +76,9 @@ Called when the global configuration is updated.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | config | [Configuration](js-apis-application-configuration.md) | Yes| Callback invoked when the global configuration is updated. The global configuration indicates the configuration of the environment where the application is running and includes the language and color mode.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| config | [Configuration](js-apis-application-configuration.md) | Yes| Callback invoked when the global configuration is updated. The global configuration indicates the configuration of the environment where the application is running and includes the language and color mode.|
**Example**
@@ -100,9 +100,9 @@ Called when the system has decided to adjust the memory level. For example, this
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | level | [AbilityConstant.MemoryLevel](js-apis-application-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.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| level | [AbilityConstant.MemoryLevel](js-apis-application-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**
@@ -118,10 +118,10 @@ Called when the system has decided to adjust the memory level. For example, this
context: AbilityStageContext;
-Describes the configuration information about the context.
+Defines the **Context** object of **AbilityStage**.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
-| Name | Type | Description |
-| ----------- | --------------------------- | ------------------------------------------------------------ |
-| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | Called when initialization is performed during ability startup.|
+| Name | Type | Description |
+| ------- | ------------------------------------------------------------ | -------------------------- |
+| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | **Context** object of AbilityStage.|
diff --git a/en/application-dev/reference/apis/js-apis-application-appManager.md b/en/application-dev/reference/apis/js-apis-application-appManager.md
index a3f97be529cfef048393d37907a257fddf10b0bf..591f5ec77a34ef2eb36979a00b9553241b33ddb3 100644
--- a/en/application-dev/reference/apis/js-apis-application-appManager.md
+++ b/en/application-dev/reference/apis/js-apis-application-appManager.md
@@ -1,4 +1,4 @@
-# @ohos.application.appManager
+# @ohos.application.appManager (appManager)
The **appManager** module implements application management. You can use the APIs of this module to query whether the application is undergoing a stability test, whether the application is running on a RAM constrained device, the memory size of the application, and information about the running process.
@@ -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.isRunningInStabilityTest8+
@@ -29,9 +29,9 @@ Checks whether this application is undergoing a stability test. This API uses an
**Example**
```ts
- import app from '@ohos.application.appManager';
- app.isRunningInStabilityTest((err, flag) => {
- console.log('startAbility result:' + JSON.stringify(err));
+ appManager.isRunningInStabilityTest((err, flag) => {
+ console.log('error:' + JSON.stringfy(err));
+ console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag));
})
```
@@ -53,11 +53,10 @@ Checks whether this application is undergoing a stability test. This API uses a
**Example**
```ts
- import app from '@ohos.application.appManager';
- app.isRunningInStabilityTest().then((flag) => {
- console.log('success:' + JSON.stringify(flag));
+ appManager.isRunningInStabilityTest().then((flag) => {
+ console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag));
}).catch((error) => {
- console.log('failed:' + JSON.stringify(error));
+ console.log('error:' + JSON.stringify(error));
});
```
@@ -79,10 +78,10 @@ Checks whether this application is running on a RAM constrained device. This API
**Example**
```ts
- app.isRamConstrainedDevice().then((data) => {
- console.log('success:' + JSON.stringify(data));
+ appManager.isRamConstrainedDevice().then((data) => {
+ console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data));
}).catch((error) => {
- console.log('failed:' + JSON.stringify(error));
+ console.log('error:' + JSON.stringify(error));
});
```
@@ -103,9 +102,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Example**
```ts
- app.isRamConstrainedDevice((err, data) => {
- console.log('startAbility result failed:' + JSON.stringify(err));
- console.log('startAbility result success:' + JSON.stringify(data));
+ appManager.isRamConstrainedDevice((err, data) => {
+ console.log('error:' + JSON.stringify(err));
+ console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data));
})
```
@@ -126,10 +125,10 @@ Obtains the memory size of this application. This API uses a promise to return t
**Example**
```ts
- app.getAppMemorySize().then((data) => {
- console.log('success:' + JSON.stringify(data));
+ appManager.getAppMemorySize().then((data) => {
+ console.log('The size of app memory is:' + JSON.stringify(data));
}).catch((error) => {
- console.log('failed:' + JSON.stringify(error));
+ console.log('error:' + JSON.stringify(error));
});
```
@@ -150,9 +149,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb
**Example**
```ts
- app.getAppMemorySize((err, data) => {
- console.log('startAbility result failed :' + JSON.stringify(err));
- console.log('startAbility result success:' + JSON.stringify(data));
+ appManager.getAppMemorySize((err, data) => {
+ console.log('error:' + JSON.stringify(err));
+ console.log('The size of app memory is:' + JSON.stringify(data));
})
```
## appManager.getProcessRunningInfos(deprecated)
@@ -171,15 +170,15 @@ Obtains information about the running processes. This API uses a promise to retu
| Type| Description|
| -------- | -------- |
-| Promise\> | Promise used to return the process information.|
+| Promise\> | Promise used to return the process information.|
**Example**
```ts
- app.getProcessRunningInfos().then((data) => {
- console.log('success:' + JSON.stringify(data));
+ appManager.getProcessRunningInfos().then((data) => {
+ console.log('The process running infos is:' + JSON.stringify(data));
}).catch((error) => {
- console.log('failed:' + JSON.stringify(error));
+ console.log('error:' + JSON.stringify(error));
});
```
@@ -199,14 +198,14 @@ Obtains information about the running processes. This API uses an asynchronous c
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| callback | AsyncCallback\> | Yes| Obtains information about the running processes. This API uses a promise to return the result.|
+| callback | AsyncCallback\> | Yes| Obtains information about the running processes. This API uses a promise to return the result.|
**Example**
```ts
- app.getProcessRunningInfos((err, data) => {
- console.log('startAbility result failed :' + JSON.stringify(err));
- console.log('startAbility result success:' + JSON.stringify(data));
+ appManager.getProcessRunningInfos((err, data) => {
+ console.log('error:' + JSON.stringify(err));
+ console.log('The process running infos is:' + JSON.stringify(data));
})
```
@@ -229,10 +228,10 @@ Obtains information about the running processes. This API uses a promise to retu
**Example**
```ts
- app.getProcessRunningInformation().then((data) => {
- console.log('success:' + JSON.stringify(data));
+ appManager.getProcessRunningInformation().then((data) => {
+ console.log('The process running info is:' + JSON.stringify(data));
}).catch((error) => {
- console.log('failed:' + JSON.stringify(error));
+ console.log('error:' + JSON.stringify(error));
});
```
@@ -255,9 +254,9 @@ Obtains information about the running processes. This API uses an asynchronous c
**Example**
```ts
- app.getProcessRunningInformation((err, data) => {
- console.log('startAbility result failed :' + JSON.stringify(err));
- console.log('startAbility result success:' + JSON.stringify(data));
+ appManager.getProcessRunningInformation((err, data) => {
+ console.log('error:' + JSON.stringify(err));
+ console.log('The process running info is:' + JSON.stringify(data));
})
```
@@ -299,7 +298,7 @@ Registers an observer to listen for the state changes of all applications.
console.log('------------ onProcessStateChanged -----------', processData);
}
}
- const observerCode = app.registerApplicationStateObserver(applicationStateObserver);
+ const observerCode = appManager.registerApplicationStateObserver(applicationStateObserver);
console.log('-------- observerCode: ---------', observerCode);
```
@@ -343,7 +342,7 @@ Registers an observer to listen for the state changes of a specified application
}
}
var bundleNameList = ['bundleName1', 'bundleName2'];
- const observerCode = app.registerApplicationStateObserver(applicationStateObserver, bundleNameList);
+ const observerCode = appManager.registerApplicationStateObserver(applicationStateObserver, bundleNameList);
console.log('-------- observerCode: ---------', observerCode);
```
## appManager.unregisterApplicationStateObserver8+
@@ -359,7 +358,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.
**Parameters**
-
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observerId | number | Yes| Numeric code of the observer.|
@@ -375,7 +374,7 @@ Deregisters the application state observer. This API uses an asynchronous callba
console.log('------------ unregisterApplicationStateObserverCallback ------------', err);
}
}
- app.unregisterApplicationStateObserver(observerId, unregisterApplicationStateObserverCallback);
+ appManager.unregisterApplicationStateObserver(observerId, unregisterApplicationStateObserverCallback);
```
## appManager.unregisterApplicationStateObserver8+
@@ -407,7 +406,7 @@ Deregisters the application state observer. This API uses a promise to return th
```ts
var observerId = 100;
- app.unregisterApplicationStateObserver(observerId)
+ appManager.unregisterApplicationStateObserver(observerId)
.then((data) => {
console.log('----------- unregisterApplicationStateObserver success ----------', data);
})
@@ -420,8 +419,8 @@ Deregisters the application state observer. This API uses a promise to return th
getForegroundApplications(callback: AsyncCallback\>): void;
-Obtains applications that are running in the foreground. This API uses an asynchronous callback to return the result.
-
+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
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -432,7 +431,7 @@ Obtains applications that are running in the foreground. This API uses an asynch
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| callback | AsyncCallback\> | Yes| Callback used to return the application state data.|
+| callback | AsyncCallback\> | Yes| Callback used to return the application information.|
**Example**
@@ -444,14 +443,14 @@ Obtains applications that are running in the foreground. This API uses an asynch
console.log('--------- getForegroundApplicationsCallback success ---------', data)
}
}
- app.getForegroundApplications(getForegroundApplicationsCallback);
+ appManager.getForegroundApplications(getForegroundApplicationsCallback);
```
## appManager.getForegroundApplications8+
getForegroundApplications(): Promise\>;
-Obtains applications that are running in the foreground. This API uses a promise to return the result.
+Obtains information about the applications that are running in the foreground. This API uses a promise to return the result. The application information is defined by [AppStateData](js-apis-inner-application-appStateData.md).
**Required permissions**: ohos.permission.GET_RUNNING_INFO
@@ -463,12 +462,12 @@ Obtains applications that are running in the foreground. This API uses a promise
| Type| Description|
| -------- | -------- |
-| Promise\> | Promise used to return the application state data.|
+| Promise\> | Promise used to return the application information.|
**Example**
```ts
- app.getForegroundApplications()
+ appManager.getForegroundApplications()
.then((data) => {
console.log('--------- getForegroundApplications success -------', data);
})
@@ -483,7 +482,7 @@ killProcessWithAccount(bundleName: string, accountId: number): Promise\
Kills a process by bundle name and account ID. This API uses a promise to return the result.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
@@ -491,17 +490,17 @@ Kills a process by bundle name and account ID. This API uses a promise to return
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | bundleName | string | Yes| Bundle name of an application.|
- | accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| bundleName | string | Yes| Bundle name.|
+| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
**Example**
```ts
var bundleName = 'bundleName';
var accountId = 0;
-app.killProcessWithAccount(bundleName, accountId)
+appManager.killProcessWithAccount(bundleName, accountId)
.then((data) => {
console.log('------------ killProcessWithAccount success ------------', data);
})
@@ -521,15 +520,15 @@ Kills a process by bundle name and account ID. This API uses an asynchronous cal
**System API**: This is a system API and cannot be called by third-party applications.
-**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
+**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | bundleName | string | Yes| Bundle name of an application.|
- | accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
- | callback | AsyncCallback\ | Yes| Callback used to return the result.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| bundleName | string | Yes| Bundle name.|
+| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
+| callback | AsyncCallback\ | Yes| Callback used to return the result.|
**Example**
@@ -543,7 +542,7 @@ function killProcessWithAccountCallback(err, data) {
console.log('------------- killProcessWithAccountCallback success, data: --------------', data);
}
}
-app.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
+appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
```
## appManager.killProcessesByBundleName8+
@@ -562,7 +561,7 @@ Kills a process by bundle name. This API uses an asynchronous callback to return
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| bundleName | string | Yes| Bundle name of an application.|
+| bundleName | string | Yes| Bundle name.|
| callback | AsyncCallback\ | Yes| Callback used to return the result.|
**Example**
@@ -576,7 +575,7 @@ Kills a process by bundle name. This API uses an asynchronous callback to return
console.log('------------- killProcessesByBundleNameCallback success, data: --------------', data);
}
}
- app.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback);
+ appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback);
```
## appManager.killProcessesByBundleName8+
@@ -595,7 +594,7 @@ Kills a process by bundle name. This API uses a promise to return the result.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| bundleName | string | Yes| Bundle name of an application.|
+| bundleName | string | Yes| Bundle name.|
**Return value**
@@ -604,10 +603,10 @@ Kills a process by bundle name. This API uses a promise to return the result.
| Promise\ | Promise used to return the result.|
**Example**
-
+
```ts
- var bundleName = 'bundleName';
- app.killProcessesByBundleName(bundleName)
+ var bundleName = 'com.example.myapplication';
+ appManager.killProcessesByBundleName(bundleName)
.then((data) => {
console.log('------------ killProcessesByBundleName success ------------', data);
})
@@ -632,7 +631,7 @@ Clears application data by bundle name. This API uses an asynchronous callback t
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| bundleName | string | Yes| Bundle name of an application.|
+| bundleName | string | Yes| Bundle name.|
| callback | AsyncCallback\ | Yes| Callback used to return the result.|
**Example**
@@ -646,7 +645,7 @@ Clears application data by bundle name. This API uses an asynchronous callback t
console.log('------------- clearUpApplicationDataCallback success, data: --------------', data);
}
}
- app.clearUpApplicationData(bundleName, clearUpApplicationDataCallback);
+ appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback);
```
## appManager.clearUpApplicationData8+
@@ -665,7 +664,7 @@ Clears application data by bundle name. This API uses a promise to return the re
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| bundleName | string | Yes| Bundle name of an application.|
+| bundleName | string | Yes| Bundle name.|
**Return value**
@@ -677,7 +676,7 @@ Clears application data by bundle name. This API uses a promise to return the re
```ts
var bundleName = 'bundleName';
- app.clearUpApplicationData(bundleName)
+ appManager.clearUpApplicationData(bundleName)
.then((data) => {
console.log('------------ clearUpApplicationData success ------------', data);
})
diff --git a/en/application-dev/reference/apis/js-apis-application-configuration.md b/en/application-dev/reference/apis/js-apis-application-configuration.md
index 1fbb65c4ae5cbe676db6d5ddad5bdacf305df5bb..81870036a845c61f852f671616f63c12f92851b8 100644
--- a/en/application-dev/reference/apis/js-apis-application-configuration.md
+++ b/en/application-dev/reference/apis/js-apis-application-configuration.md
@@ -1,9 +1,8 @@
-# @ohos.application.Configuration
+# @ohos.application.Configuration (Configuration)
The **Configuration** module defines environment change information.
> **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.
diff --git a/en/application-dev/reference/apis/js-apis-application-configurationConstant.md b/en/application-dev/reference/apis/js-apis-application-configurationConstant.md
index 316244503def8d44c09fb10c7bbe164730239eae..dabe32b2f9d166dbce68b94c204b82f78b0090de 100644
--- a/en/application-dev/reference/apis/js-apis-application-configurationConstant.md
+++ b/en/application-dev/reference/apis/js-apis-application-configurationConstant.md
@@ -1,4 +1,4 @@
-# @ohos.application.ConfigurationConstant
+# @ohos.application.ConfigurationConstant (ConfigurationConstant)
The **ConfigurationConstant** module provides the enumerated values of the environment configuration information.
@@ -18,11 +18,11 @@ You can obtain the value of this constant by calling the **ConfigurationConstant
**System capability**: SystemCapability.Ability.AbilityBase
-| Name| Value| Description|
+| Name| Value| Description|
| -------- | -------- | -------- |
-| COLOR_MODE_NOT_SET | -1 | Unspecified color mode.|
-| COLOR_MODE_DARK | 0 | Dark mode.|
-| COLOR_MODE_LIGHT | 1 | Light mode.|
+| COLOR_MODE_NOT_SET | -1 | Unspecified color mode.|
+| COLOR_MODE_DARK | 0 | Dark mode.|
+| COLOR_MODE_LIGHT | 1 | Light mode.|
## ConfigurationConstant.Direction9+
@@ -31,11 +31,11 @@ You can obtain the value of this constant by calling the **ConfigurationConstant
**System capability**: SystemCapability.Ability.AbilityBase
-| Name| Value| Description|
+| Name| Value| Description|
| -------- | -------- | -------- |
-| DIRECTION_NOT_SET | -1 | Unspecified direction.|
-| DIRECTION_VERTICAL | 0 | Vertical direction.|
-| DIRECTION_HORIZONTAL | 1 | Horizontal direction.|
+| DIRECTION_NOT_SET | -1 | Unspecified direction.|
+| DIRECTION_VERTICAL | 0 | Vertical direction.|
+| DIRECTION_HORIZONTAL | 1 | Horizontal direction.|
## ConfigurationConstant.ScreenDensity9+
@@ -44,12 +44,12 @@ You can obtain the value of this constant by calling the **ConfigurationConstant
**System capability**: SystemCapability.Ability.AbilityBase
-| Name| Value| Description|
+| 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 | 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.|
diff --git a/en/application-dev/reference/apis/js-apis-application-context.md b/en/application-dev/reference/apis/js-apis-application-context.md
index 88a5c84c617f675c93ea2f43de62625294025ca6..d42e522c14266de6ca53fff7370c68de14c34d36 100644
--- a/en/application-dev/reference/apis/js-apis-application-context.md
+++ b/en/application-dev/reference/apis/js-apis-application-context.md
@@ -1,4 +1,4 @@
-# @ohos.application.context
+# @ohos.application.context (Context)
The **Context** module provides all level-2 module APIs for developers to export.
diff --git a/en/application-dev/reference/apis/js-apis-application-environmentCallback.md b/en/application-dev/reference/apis/js-apis-application-environmentCallback.md
index e1d2033c652d413ddac9933e32c3c53c1372f443..d4c25269235da3b95e4f230c084d92c1df047269 100644
--- a/en/application-dev/reference/apis/js-apis-application-environmentCallback.md
+++ b/en/application-dev/reference/apis/js-apis-application-environmentCallback.md
@@ -1,10 +1,10 @@
-# @ohos.application.EnvironmentCallback
+# @ohos.application.EnvironmentCallback (EnvironmentCallback)
-The **EnvironmentCallback** module provides the **onConfigurationUpdated** API for the application context to listen for system environment changes.
+The **EnvironmentCallback** module provides APIs, such as **onConfigurationUpdated** and **onMemoryLevel**, for the application context to listen for system environment changes.
> **NOTE**
>
-> The APIs of this module are supported and deprecated since 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 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 can be used only in the stage model.
@@ -25,18 +25,32 @@ Called when the system environment changes.
**Parameters**
-| Name| Type| Mandatory| Description|
-| -------- | -------- | -------- | -------- |
-| config | [Configuration](js-apis-application-configuration.md) | Yes| **Configuration** object after the change.|
+ | Name| Type| Mandatory| Description|
+ | -------- | -------- | -------- | -------- |
+ | config | [Configuration](js-apis-application-configuration.md) | Yes| **Configuration** object after the change.|
-**Example**
+## 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
-import Ability from "@ohos.application.Ability";
+import UIAbility from '@ohos.app.ability.UIAbility';
var callbackId;
-export default class MyAbility extends Ability {
+export default class EntryAbility extends UIAbility {
onCreate() {
console.log("MyAbility onCreate")
globalThis.applicationContext = this.context.getApplicationContext();
@@ -44,6 +58,9 @@ export default class MyAbility extends Ability {
onConfigurationUpdated(config){
console.log("onConfigurationUpdated config:" + JSON.stringify(config));
},
+ onMemoryLevel(level){
+ console.log("onMemoryLevel level:" + level);
+ }
}
// 1. Obtain an applicationContext object.
let applicationContext = globalThis.applicationContext;
diff --git a/en/application-dev/reference/apis/js-apis-application-errorManager.md b/en/application-dev/reference/apis/js-apis-application-errorManager.md
index b1a98049c70502462a6225a63efd642c164ca60c..c1eaa2d35e90966795e4b98f4b75cffc0570e855 100644
--- a/en/application-dev/reference/apis/js-apis-application-errorManager.md
+++ b/en/application-dev/reference/apis/js-apis-application-errorManager.md
@@ -1,10 +1,10 @@
-# @ohos.application.errorManager (Error Manager)
+# @ohos.application.errorManager (ErrorManager)
-The **errorManager** module provides APIs for registering and deregistering error observers.
+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.
+> 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.errorManager](js-apis-app-ability-errorManager.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
diff --git a/en/application-dev/reference/apis/js-apis-application-extensionAbility.md b/en/application-dev/reference/apis/js-apis-application-extensionAbility.md
index 055980e455acb5fd56ece9d4a1a582c7868b1646..f18b293edd8d7a4f65684bc38df4fe48498fa11b 100644
--- a/en/application-dev/reference/apis/js-apis-application-extensionAbility.md
+++ b/en/application-dev/reference/apis/js-apis-application-extensionAbility.md
@@ -1,6 +1,6 @@
-# @ohos.application.ExtensionAbility
+# @ohos.application.ExtensionAbility (ExtensionAbility)
-The **ExtensionAbility** module manages the Extension ability lifecycle and context, such as creating and destroying an Extension ability, and dumping client information.
+The **ExtensionAbility** module manages the ExtensionAbility lifecycle and context, such as creating and destroying an ExtensionAbility, and dumping client information.
> **NOTE**
>
diff --git a/en/application-dev/reference/apis/js-apis-application-formBindingData.md b/en/application-dev/reference/apis/js-apis-application-formBindingData.md
index f0cdf74799a4373cfe61446191166a1e2ca0a014..5fbc52c95dc9e573947fb9820f00100a76a06f22 100644
--- a/en/application-dev/reference/apis/js-apis-application-formBindingData.md
+++ b/en/application-dev/reference/apis/js-apis-application-formBindingData.md
@@ -1,4 +1,4 @@
-# @ohos.application.formBindingData
+# @ohos.application.formBindingData (formBindingData)
The **FormBindingData** module provides APIs for widget data binding. You can use the APIs to create a **FormBindingData** object and obtain related information.
@@ -48,16 +48,17 @@ Creates a **FormBindingData** object.
**Example**
```ts
-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);
+import formBindingData from @ohos.application.formBindingData;
+import fs from '@ohos.file.fs';
+
+try {
+ let fd = fs.openSync('/path/to/form.png')
let obj = {
"temperature": "21°",
- "formImages": {"image": fd}
+ "formImages": { "image": fd }
};
- let formBindingDataObj = formBindingData.createFormBindingData(obj);
-})
+ formBindingData.createFormBindingData(obj);
+} catch (error.code) {
+ console.log('catch error, error:' + JSON.stringify(error));
+}
```
diff --git a/en/application-dev/reference/apis/js-apis-application-formError.md b/en/application-dev/reference/apis/js-apis-application-formError.md
index 7a9a6618cd4906b2a4894f8cdfd8c796beefc905..4ca6eecb8cfae8ddbad623262b8a1c7c9ff515ff 100644
--- a/en/application-dev/reference/apis/js-apis-application-formError.md
+++ b/en/application-dev/reference/apis/js-apis-application-formError.md
@@ -1,6 +1,6 @@
-# @ohos.application.formError
+# @ohos.application.formError (formError)
-The **FormError** module provides error codes for widgets.
+The **formError** module provides error codes for widgets.
> **NOTE**
>
@@ -50,5 +50,3 @@ SystemCapability.Ability.Form
| ERR_FORM_DUPLICATE_ADDED | 31 | The widget has been added. |
| ERR_IN_RECOVERY | 36 | Failed to overwrite the widget data. |
| ERR_DISTRIBUTED_SCHEDULE_FAILED9+ | 37 | The distributed scheduler failed.
**System API**: This is a system API. |
-
-
\ No newline at end of file
diff --git a/en/application-dev/reference/apis/js-apis-application-formExtension.md b/en/application-dev/reference/apis/js-apis-application-formExtension.md
index a01e08710907030edfc7f0b1d04927282f5bc387..fcde831bc20ca03c224b977271f40b69f1ad0569 100644
--- a/en/application-dev/reference/apis/js-apis-application-formExtension.md
+++ b/en/application-dev/reference/apis/js-apis-application-formExtension.md
@@ -1,4 +1,4 @@
-# @ohos.application.FormExtension
+# @ohos.application.FormExtension (FormExtension)
The **FormExtension** module provides APIs related to Form Extension abilities.
diff --git a/en/application-dev/reference/apis/js-apis-application-formHost.md b/en/application-dev/reference/apis/js-apis-application-formHost.md
index 8b44dbf345b717b3cf1433392fd82907b6caab5f..11da810effa714b8aaf37e35d3c0566556281ebf 100644
--- a/en/application-dev/reference/apis/js-apis-application-formHost.md
+++ b/en/application-dev/reference/apis/js-apis-application-formHost.md
@@ -1,11 +1,11 @@
-# @ohos.application.formHost
+# @ohos.application.formHost (formHost)
-The **FormHost** module provides APIs related to the widget host, which is an application that displays the widget content and controls the position where the widget is displayed. You can use the APIs to delete, release, and update widgets installed by the same user, and obtain widget information and status.
+The **formHost** module provides APIs related to the widget host, which is an application that displays the widget content and controls the position where the widget is displayed. You can use the APIs to delete, release, and update widgets installed by the same user, and obtain widget information and status.
> **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 [FormHost](js-apis-app-form-formHost.md) instead.
+> This module is deprecated since API version 9. You are advised to use [formHost](js-apis-app-form-formHost.md) instead.
> The APIs provided by this module are system APIs.
## Modules to Import
@@ -34,10 +34,12 @@ Deletes a widget. After this API is called, the application can no longer use th
**Example**
```ts
-var formId = "12400633174999288";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
formHost.deleteForm(formId, (error, data) => {
if (error.code) {
- console.log('formHost deleteForm, error:' + JSON.stringify(error));
+ console.error('formHost deleteForm, error:' + JSON.stringify(error));
}
});
```
@@ -67,11 +69,13 @@ Deletes a widget. After this API is called, the application can no longer use th
**Parameters**
```ts
-var formId = "12400633174999288";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
formHost.deleteForm(formId).then(() => {
console.log('formHost deleteForm success');
}).catch((error) => {
- console.log('formHost deleteForm, error:' + JSON.stringify(error));
+ console.error('formHost deleteForm, error:' + JSON.stringify(error));
});
```
@@ -95,10 +99,14 @@ Releases a widget. After this API is called, the application can no longer use t
**Example**
```ts
-var formId = "12400633174999288";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
formHost.releaseForm(formId, (error, data) => {
if (error.code) {
- console.log('formHost releaseForm, error:' + JSON.stringify(error));
+ console.error('formHost releaseForm, error:' + JSON.stringify(error));
+ } else {
+ console.log('formHost releaseForm success');
}
});
```
@@ -124,10 +132,14 @@ Releases a widget. After this API is called, the application can no longer use t
**Example**
```ts
-var formId = "12400633174999288";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
formHost.releaseForm(formId, true, (error, data) => {
if (error.code) {
- console.log('formHost releaseForm, error:' + JSON.stringify(error));
+ console.error('formHost releaseForm, error:' + JSON.stringify(error));
+ } else {
+ console.log('formHost releaseForm success');
}
});
```
@@ -158,11 +170,13 @@ Releases a widget. After this API is called, the application can no longer use t
**Example**
```ts
-var formId = "12400633174999288";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
formHost.releaseForm(formId, true).then(() => {
console.log('formHost releaseForm success');
}).catch((error) => {
- console.log('formHost releaseForm, error:' + JSON.stringify(error));
+ console.error('formHost releaseForm, error:' + JSON.stringify(error));
});
```
@@ -186,10 +200,12 @@ Requests a widget update. This API uses an asynchronous callback to return the r
**Example**
```ts
-var formId = "12400633174999288";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
formHost.requestForm(formId, (error, data) => {
if (error.code) {
- console.log('formHost requestForm, error:' + JSON.stringify(error));
+ console.error('formHost requestForm, error:' + JSON.stringify(error));
}
});
```
@@ -219,11 +235,13 @@ Requests a widget update. This API uses a promise to return the result.
**Example**
```ts
-var formId = "12400633174999288";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
formHost.requestForm(formId).then(() => {
console.log('formHost requestForm success');
}).catch((error) => {
- console.log('formHost requestForm, error:' + JSON.stringify(error));
+ console.error('formHost requestForm, error:' + JSON.stringify(error));
});
```
@@ -242,15 +260,17 @@ Converts a temporary widget to a normal one. This API uses an asynchronous callb
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formId | string | Yes | Widget ID.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is converted to a normal one, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is converted to a normal one, **error** is undefined; otherwise, **error** is an error object.|
**Example**
```ts
-var formId = "12400633174999288";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
formHost.castTempForm(formId, (error, data) => {
if (error.code) {
- console.log('formHost castTempForm, error:' + JSON.stringify(error));
+ console.error('formHost castTempForm, error:' + JSON.stringify(error));
}
});
```
@@ -280,11 +300,13 @@ Converts a temporary widget to a normal one. This API uses a promise to return t
**Example**
```ts
-var formId = "12400633174999288";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
formHost.castTempForm(formId).then(() => {
console.log('formHost castTempForm success');
}).catch((error) => {
- console.log('formHost castTempForm, error:' + JSON.stringify(error));
+ console.error('formHost castTempForm, error:' + JSON.stringify(error));
});
```
@@ -303,15 +325,17 @@ Instructs the widget framework to make a widget visible. After this API is calle
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs. |
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget visible, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget visible, **error** is undefined; otherwise, **error** is an error object.|
**Example**
```ts
-var formId = ["12400633174999288"];
+import formHost from '@ohos.application.formHost';
+
+let formId = ["12400633174999288"];
formHost.notifyVisibleForms(formId, (error, data) => {
if (error.code) {
- console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error));
+ console.error('formHost notifyVisibleForms, error:' + JSON.stringify(error));
}
});
```
@@ -341,11 +365,13 @@ Instructs the widget framework to make a widget visible. After this API is calle
**Example**
```ts
-var formId = ["12400633174999288"];
+import formHost from '@ohos.application.formHost';
+
+let formId = ["12400633174999288"];
formHost.notifyVisibleForms(formId).then(() => {
console.log('formHost notifyVisibleForms success');
}).catch((error) => {
- console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error));
+ console.error('formHost notifyVisibleForms, error:' + JSON.stringify(error));
});
```
@@ -364,15 +390,17 @@ Instructs the widget framework to make a widget invisible. After this API is cal
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget invisible, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget invisible, **error** is undefined; otherwise, **error** is an error object.|
**Example**
```ts
-var formId = ["12400633174999288"];
+import formHost from '@ohos.application.formHost';
+
+let formId = ["12400633174999288"];
formHost.notifyInvisibleForms(formId, (error, data) => {
if (error.code) {
- console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
+ console.error('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
}
});
```
@@ -402,11 +430,13 @@ Instructs the widget framework to make a widget invisible. After this API is cal
**Example**
```ts
-var formId = ["12400633174999288"];
+import formHost from '@ohos.application.formHost';
+
+let formId = ["12400633174999288"];
formHost.notifyInvisibleForms(formId).then(() => {
console.log('formHost notifyInvisibleForms success');
}).catch((error) => {
- console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
+ console.error('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
});
```
@@ -425,15 +455,17 @@ Instructs the widget framework to make a widget updatable. After this API is cal
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs. |
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget updatable, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget updatable, **error** is undefined; otherwise, **error** is an error object.|
**Example**
```ts
-var formId = ["12400633174999288"];
+import formHost from '@ohos.application.formHost';
+
+let formId = ["12400633174999288"];
formHost.enableFormsUpdate(formId, (error, data) => {
if (error.code) {
- console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error));
+ console.error('formHost enableFormsUpdate, error:' + JSON.stringify(error));
}
});
```
@@ -463,11 +495,13 @@ Instructs the widget framework to make a widget updatable. After this API is cal
**Example**
```ts
-var formId = ["12400633174999288"];
+import formHost from '@ohos.application.formHost';
+
+let formId = ["12400633174999288"];
formHost.enableFormsUpdate(formId).then(() => {
console.log('formHost enableFormsUpdate success');
}).catch((error) => {
- console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error));
+ console.error('formHost enableFormsUpdate, error:' + JSON.stringify(error));
});
```
@@ -486,15 +520,17 @@ Instructs the widget framework to make a widget not updatable. After this API is
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs. |
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget not updatable, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget not updatable, **error** is undefined; otherwise, **error** is an error object.|
**Example**
```ts
-var formId = ["12400633174999288"];
+import formHost from '@ohos.application.formHost';
+
+let formId = ["12400633174999288"];
formHost.disableFormsUpdate(formId, (error, data) => {
if (error.code) {
- console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error));
+ console.error('formHost disableFormsUpdate, error:' + JSON.stringify(error));
}
});
```
@@ -524,11 +560,13 @@ Instructs the widget framework to make a widget not updatable. After this API is
**Example**
```ts
-var formId = ["12400633174999288"];
+import formHost from '@ohos.application.formHost';
+
+let formId = ["12400633174999288"];
formHost.disableFormsUpdate(formId).then(() => {
console.log('formHost disableFormsUpdate success');
}).catch((error) => {
- console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error));
+ console.error('formHost disableFormsUpdate, error:' + JSON.stringify(error));
});
```
@@ -544,15 +582,17 @@ Checks whether the system is ready. This API uses an asynchronous callback to re
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the check is successful, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the check is successful, **error** is undefined; otherwise, **error** is an error object.|
**Example**
```ts
-var formId = "12400633174999288";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
formHost.isSystemReady((error, data) => {
if (error.code) {
- console.log('formHost isSystemReady, error:' + JSON.stringify(error));
+ console.error('formHost isSystemReady, error:' + JSON.stringify(error));
}
});
```
@@ -574,11 +614,13 @@ Checks whether the system is ready. This API uses a promise to return the result
**Example**
```ts
-var formId = "12400633174999288";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
formHost.isSystemReady().then(() => {
console.log('formHost isSystemReady success');
}).catch((error) => {
- console.log('formHost isSystemReady, error:' + JSON.stringify(error));
+ console.error('formHost isSystemReady, error:' + JSON.stringify(error));
});
```
@@ -596,14 +638,16 @@ Obtains the widget information provided by all applications on the device. This
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| callback | AsyncCallback<Array<[FormInfo](js-apis-application-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **err** is undefined and **data** is the information obtained; otherwise, **err** is an error object.|
+| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-application-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.|
**Example**
```ts
+import formHost from '@ohos.application.formHost';
+
formHost.getAllFormsInfo((error, data) => {
if (error.code) {
- console.log('formHost getAllFormsInfo, error:' + JSON.stringify(error));
+ console.error('formHost getAllFormsInfo, error:' + JSON.stringify(error));
} else {
console.log('formHost getAllFormsInfo, data:' + JSON.stringify(data));
}
@@ -624,15 +668,17 @@ Obtains the widget information provided by all applications on the device. This
| Type | Description |
| :------------ | :---------------------------------- |
-| Promise<Array<[FormInfo](js-apis-application-formInfo.md)>> | Promise used to return the information obtained.|
+| Promise<Array<[formInfo.FormInfo](js-apis-application-formInfo.md)>> | Promise used to return the information obtained.|
**Example**
```ts
+ import formHost from '@ohos.application.formHost';
+
formHost.getAllFormsInfo().then((data) => {
- console.log('formHost getAllFormsInfo data:' + JSON.stringify(data));
+ console.log('formHost getAllFormsInfo data:' + JSON.stringify(data));
}).catch((error) => {
- console.log('formHost getAllFormsInfo, error:' + JSON.stringify(error));
+ console.error('formHost getAllFormsInfo, error:' + JSON.stringify(error));
});
```
@@ -650,15 +696,17 @@ Obtains the widget information provided by a given application on the device. Th
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| bundleName | string | Yes| Bundle name of the application.|
-| callback | AsyncCallback<Array<[FormInfo](js-apis-application-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **err** is undefined and **data** is the information obtained; otherwise, **err** is an error object.|
+| bundleName | string | Yes| Bundle name of the application.|
+| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-application-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.|
**Example**
```ts
+import formHost from '@ohos.application.formHost';
+
formHost.getFormsInfo("com.example.ohos.formjsdemo", (error, data) => {
if (error.code) {
- console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
+ console.error('formHost getFormsInfo, error:' + JSON.stringify(error));
} else {
console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
}
@@ -679,18 +727,20 @@ Obtains the widget information provided by a given application on the device. Th
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| bundleName | string | Yes| Bundle name of the application.|
+| bundleName | string | Yes| Bundle name of the application.|
| moduleName | string | Yes| Module name.|
-| callback | AsyncCallback<Array<[FormInfo](js-apis-application-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **err** is undefined and **data** is the information obtained; otherwise, **err** is an error object.|
+| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-application-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.|
**Example**
```ts
+import formHost from '@ohos.application.formHost';
+
formHost.getFormsInfo("com.example.ohos.formjsdemo", "entry", (error, data) => {
if (error.code) {
- console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
+ console.error('formHost getFormsInfo, error:' + JSON.stringify(error));
} else {
- console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
+ console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
}
});
```
@@ -709,22 +759,24 @@ Obtains the widget information provided by a given application on the device. Th
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| bundleName | string | Yes| Bundle name of the application.|
+| bundleName | string | Yes| Bundle name of the application.|
| moduleName | string | No| Module name.|
**Return value**
| Type | Description |
| :------------ | :---------------------------------- |
-| Promise<Array<[FormInfo](js-apis-application-formInfo.md)>> | Promise used to return the information obtained.|
+| Promise<Array<[formInfo.FormInfo](js-apis-application-formInfo.md)>> | Promise used to return the information obtained.|
**Example**
```ts
+ import formHost from '@ohos.application.formHost';
+
formHost.getFormsInfo("com.example.ohos.formjsdemo", "entry").then((data) => {
console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
}).catch((error) => {
- console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
+ console.error('formHost getFormsInfo, error:' + JSON.stringify(error));
});
```
@@ -743,15 +795,17 @@ Deletes invalid widgets from the list. This API uses an asynchronous callback to
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of valid widget IDs.|
-| callback | AsyncCallback<number> | Yes| Callback used to return the result. If the invalid widgets are deleted, **err** is undefined and **data** is the number of widgets deleted; otherwise, **err** is an error object.|
+| callback | AsyncCallback<number> | Yes| Callback used to return the result. If the invalid widgets are deleted, **error** is undefined and **data** is the number of widgets deleted; otherwise, **error** is an error object.|
**Example**
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.application.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
formHost.deleteInvalidForms(formIds, (error, data) => {
if (error.code) {
- console.log('formHost deleteInvalidForms, error:' + JSON.stringify(error));
+ console.error('formHost deleteInvalidForms, error:' + JSON.stringify(error));
} else {
console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data));
}
@@ -783,11 +837,13 @@ Deletes invalid widgets from the list. This API uses a promise to return the res
**Example**
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.application.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
formHost.deleteInvalidForms(formIds).then((data) => {
console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data));
}).catch((error) => {
- console.log('formHost deleteInvalidForms, error:' + JSON.stringify(error));
+ console.error('formHost deleteInvalidForms, error:' + JSON.stringify(error));
});
```
@@ -805,13 +861,15 @@ Obtains the widget state. This API uses an asynchronous callback to return the r
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| want | [Want](js-apis-application-want.md) | Yes | **Want** information carried to query the widget state.|
-| callback | AsyncCallback<[FormStateInfo](js-apis-application-formInfo.md#formstateinfo)> | Yes| Callback used to return the result. If the widget state is obtained, **err** is undefined and **data** is the widget state obtained; otherwise, **err** is an error object.|
+| want | [Want](js-apis-application-want.md) | Yes | **Want** information carried to query the widget state. The information must contain the bundle name, ability name, module name, widget name, and widget dimensions.|
+| callback | AsyncCallback<[formInfo.FormStateInfo](js-apis-application-formInfo.md#formstateinfo)> | Yes| Callback used to return the result. If the widget state is obtained, **error** is undefined and **data** is the widget state obtained; otherwise, **error** is an error object.|
**Example**
```ts
-var want = {
+import formHost from '@ohos.application.formHost';
+
+let want = {
"deviceId": "",
"bundleName": "ohos.samples.FormApplication",
"abilityName": "FormAbility",
@@ -823,7 +881,7 @@ var want = {
};
formHost.acquireFormState(want, (error, data) => {
if (error.code) {
- console.log('formHost acquireFormState, error:' + JSON.stringify(error));
+ console.error('formHost acquireFormState, error:' + JSON.stringify(error));
} else {
console.log('formHost acquireFormState, data:' + JSON.stringify(data));
}
@@ -855,7 +913,9 @@ Obtains the widget state. This API uses a promise to return the result.
**Example**
```ts
-var want = {
+import formHost from '@ohos.application.formHost';
+
+let want = {
"deviceId": "",
"bundleName": "ohos.samples.FormApplication",
"abilityName": "FormAbility",
@@ -868,7 +928,7 @@ var want = {
formHost.acquireFormState(want).then((data) => {
console.log('formHost acquireFormState, data:' + JSON.stringify(data));
}).catch((error) => {
- console.log('formHost acquireFormState, error:' + JSON.stringify(error));
+ console.error('formHost acquireFormState, error:' + JSON.stringify(error));
});
```
@@ -890,6 +950,8 @@ Subscribes to widget uninstall events. This API uses an asynchronous callback to
**Example**
```ts
+import formHost from '@ohos.application.formHost';
+
let callback = function(formId) {
console.log('formHost on formUninstall, formId:' + formId);
}
@@ -909,11 +971,13 @@ Unsubscribes from widget uninstall events. This API uses an asynchronous callbac
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| type | string | Yes | Event type. The value **formUninstall** indicates a widget uninstallation event.|
-| callback | Callback<string> | No| Callback used to return the widget ID. If it is left unspecified, it indicates the callback for all the events that have been subscribed.|
+| callback | Callback<string> | No| Callback used to return the widget ID. If it is left unspecified, it indicates the callback for all the events that have been subscribed.
The value must be the same as that in **on("formUninstall")**.|
**Example**
```ts
+import formHost from '@ohos.application.formHost';
+
let callback = function(formId) {
console.log('formHost on formUninstall, formId:' + formId);
}
@@ -936,15 +1000,17 @@ Instructs the widgets to make themselves visible. This API uses an asynchronous
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs.|
| isVisible | boolean | Yes | Whether to make the widgets visible.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **error** is undefined; otherwise, **error** is an error object.|
**Example**
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.application.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
formHost.notifyFormsVisible(formIds, true, (error, data) => {
if (error.code) {
- console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error));
+ console.error('formHost notifyFormsVisible, error:' + JSON.stringify(error));
}
});
```
@@ -975,11 +1041,13 @@ Instructs the widgets to make themselves visible. This API uses a promise to ret
**Example**
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.application.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
formHost.notifyFormsVisible(formIds, true).then(() => {
console.log('formHost notifyFormsVisible success');
}).catch((error) => {
- console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error));
+ console.error('formHost notifyFormsVisible, error:' + JSON.stringify(error));
});
```
@@ -999,15 +1067,17 @@ Instructs the widgets to enable or disable updates. This API uses an asynchronou
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes | List of widget IDs.|
| isEnableUpdate | boolean | Yes | Whether to make the widgets updatable.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **error** is undefined; otherwise, **error** is an error object.|
**Example**
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.application.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
formHost.notifyFormsEnableUpdate(formIds, true, (error, data) => {
if (error.code) {
- console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
+ console.error('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
}
});
```
@@ -1038,11 +1108,13 @@ Instructs the widgets to enable or disable updates. This API uses a promise to r
**Example**
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.application.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
console.log('formHost notifyFormsEnableUpdate success');
}).catch((error) => {
- console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
+ console.error('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
});
```
## shareForm9+
@@ -1051,7 +1123,7 @@ shareForm(formId: string, deviceId: string, callback: AsyncCallback<void>)
Shares a specified widget with a remote device. This API uses an asynchronous callback to return the result.
-**Required permissions**: ohos.permission.REQUIRE_FORM
+**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.DISTRIBUTED_DATASYNC
**System capability**: SystemCapability.Ability.Form
@@ -1061,16 +1133,18 @@ Shares a specified widget with a remote device. This API uses an asynchronous ca
| ------ | ------ | ---- | ------- |
| formId | string | Yes | Widget ID.|
| deviceId | string | Yes | Remote device ID.|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is shared, **err** is undefined; otherwise, **err** is an error object.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is shared, **error** is undefined; otherwise, **error** is an error object.|
**Example**
```ts
-var formId = "12400633174999288";
-var deviceId = "EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
+let deviceId = "EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2";
formHost.shareForm(formId, deviceId, (error, data) => {
if (error.code) {
- console.log('formHost shareForm, error:' + JSON.stringify(error));
+ console.error('formHost shareForm, error:' + JSON.stringify(error));
}
});
```
@@ -1101,18 +1175,22 @@ Shares a specified widget with a remote device. This API uses a promise to retur
**Parameters**
```ts
-var formId = "12400633174999288";
-var deviceId = "EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2";
+import formHost from '@ohos.application.formHost';
+
+let formId = "12400633174999288";
+let deviceId = "EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2";
formHost.shareForm(formId, deviceId).then(() => {
console.log('formHost shareForm success');
}).catch((error) => {
- console.log('formHost shareForm, error:' + JSON.stringify(error));
+ console.error('formHost shareForm, error:' + JSON.stringify(error));
});
```
## notifyFormsPrivacyProtected9+
-notifyFormsPrivacyProtected(formIds: Array\, isProtected: boolean, callback: AsyncCallback\): void
+notifyFormsPrivacyProtected(formIds: Array<string>, isProtected: boolean, callback: AsyncCallback<void>): void
+
+Notifies that the privacy protection status of the specified widgets changes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.REQUIRE_FORM
@@ -1126,10 +1204,51 @@ notifyFormsPrivacyProtected(formIds: Array\, isProtected: boolean, callb
| deviceId | string | Yes | Remote device ID.|
```ts
-var formIds = new Array("12400633174999288", "12400633174999289");
+import formHost from '@ohos.application.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
formHost.notifyFormsPrivacyProtected(formIds, true).then(() => {
console.log('formHost shareForm success');
}).catch((error) => {
- console.log('formHost shareForm, error:' + JSON.stringify(error));
+ console.error('formHost shareForm, error:' + JSON.stringify(error));
});
```
+
+## notifyFormsPrivacyProtected
+
+function notifyFormsPrivacyProtected(formIds: Array<string>, isProtected: boolean): Promise<void>;
+
+Notifies that the privacy protection status of the specified widgets changes. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.REQUIRE_FORM
+
+**System capability**: SystemCapability.Ability.Form
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| ----------- | --------------- | ---- | -------------------------------- |
+| formIds | Array<string> | Yes | ID of the widgets.|
+| isProtected | boolean | Yes | Whether privacy protection is enabled. |
+
+**Return value**
+
+| Type | Description |
+| ------------------- | ------------------------- |
+| Promise<void> | Promise that returns no value.|
+
+
+```ts
+import formHost from '@ohos.application.formHost';
+
+let formIds = new Array("12400633174999288", "12400633174999289");
+try {
+ formHost.notifyFormsPrivacyProtected(formIds, true).then(() => {
+ console.log('formHost notifyFormsPrivacyProtected success');
+ }).catch((error) => {
+ console.log('formHost notifyFormsPrivacyProtected, error:' + JSON.stringify(error));
+ });
+} catch(error) {
+ console.log('formHost notifyFormsPrivacyProtected, error:' + JSON.stringify(error));
+}
+```
diff --git a/en/application-dev/reference/apis/js-apis-application-formInfo.md b/en/application-dev/reference/apis/js-apis-application-formInfo.md
index de5bd8f6b24e7bd1f6e3fe66b4f4122c9a570d16..df591cea222b9bdbc98c4d108a4151a8aa1c69cb 100644
--- a/en/application-dev/reference/apis/js-apis-application-formInfo.md
+++ b/en/application-dev/reference/apis/js-apis-application-formInfo.md
@@ -1,11 +1,11 @@
-# @ohos.application.formInfo
+# @ohos.application.formInfo (formInfo)
-The **FormInfo** module provides widget information and state.
+The **formInfo** module provides types and enums related to the widget information and state.
> **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 [FormInfo](js-apis-app-form-formInfo.md) instead.
+> This module is deprecated since API version 9. You are advised to use [formInfo](js-apis-app-form-formInfo.md) instead.
## Modules to Import
@@ -21,9 +21,9 @@ Describes widget information.
| Name | Type | Readable | Writable | Description |
| ----------- | -------- |-------- | -------------------- | ------------------------------------------------------------ |
-| bundleName | string | Yes | No | Name of the bundle to which the widget belongs. |
+| bundleName | string | Yes | No | Name of the bundle to which the widget belongs. |
| moduleName | string | Yes | No | Name of the module to which the widget belongs. |
-| abilityName | string | Yes | No | Name of the ability to which the widget belongs. |
+| abilityName | string | Yes | No | Name of the ability to which the widget belongs. |
| name | string | Yes | No | Widget name. |
| description | string | Yes | No | Description of the widget. |
| type | [FormType](#formtype) | Yes | No | Type of the widget. Currently, only JS widgets are supported.|
@@ -31,11 +31,11 @@ Describes widget information.
| colorMode | [ColorMode](#colormode) | Yes | No | Color mode of the widget. |
| isDefault | boolean | Yes | No | Whether the widget is the default one. |
| updateEnabled | boolean | Yes | No | Whether the widget is updatable. |
-| formVisibleNotify | string | Yes | No | Whether to send a notification when the widget is visible. |
-| relatedBundleName | string | Yes | No | Name of the associated bundle to which the widget belongs. |
+| formVisibleNotify | boolean | Yes | No | Whether to send a notification when the widget is visible. |
+| relatedBundleName | string | Yes | No | Name of the associated bundle to which the widget belongs. |
| scheduledUpdateTime | string | Yes | No | Time when the widget was updated. |
| formConfigAbility | string | Yes | No | Configuration ability of the widget. |
-| updateDuration | string | Yes | No | Update period of the widget.|
+| updateDuration | number | Yes | No | Update period of the widget.|
| defaultDimension | number | Yes | No | Default dimension of the widget. |
| supportDimensions | Array<number> | Yes | No | Dimensions supported by the widget. |
| customizeData | {[key: string]: [value: string]} | Yes | No | Custom data of the widget. |
@@ -102,7 +102,7 @@ Enumerates the widget parameters.
| HEIGHT_KEY | "ohos.extra.param.key.form_height" | Widget height. |
| TEMPORARY_KEY | "ohos.extra.param.key.form_temporary" | Temporary widget. |
| ABILITY_NAME_KEY9+ | "ohos.extra.param.key.ability_name" | Ability name. |
-| DEVICE_ID_KEY9+ | "ohos.extra.param.key.device_id" | Device ID.
**System API**: This is a system API. |
+| DEVICE_ID_KEY9+ | "ohos.extra.param.key.device_id" | Device ID. |
| BUNDLE_NAME_KEY9+ | "ohos.extra.param.key.bundle_name" | Key that specifies the target bundle name.|
## FormDimension9+
@@ -117,18 +117,7 @@ Enumerates the widget dimensions.
| Dimension_2_2 9+ | 2 | 2 x 2. |
| Dimension_2_4 9+ | 3 | 2 x 4. |
| Dimension_4_4 9+ | 4 | 4 x 4. |
-| Dimension_2_1 9+ | 5 | 2 x 1. |
-
-## VisibilityType
-
-Enumerates the visibility types of the widget.
-
-**System capability**: SystemCapability.Ability.Form
-
-| Name | Value | Description |
-| ----------- | ---- | ------------ |
-| FORM_VISIBLE9+ | 1 | The card is visible. |
-| FORM_INVISIBLE9+ | 2 | The card is invisible.|
+| Dimension_2_1 9+ | 5 | 2 x 1. |
## FormInfoFilter9+
@@ -138,7 +127,7 @@ Defines the widget information filter. Only the widget information that meets th
| Name | Description |
| ----------- | ------------ |
-| moduleName9+ | Only the information about the widget whose **moduleName** is the same as the provided value is returned.|
+| moduleName9+ | Optional. Only the information about the widget whose **moduleName** is the same as the provided value is returned.
If this parameter is not set, **moduleName** is not used for filtering.|
## VisibilityType9+
diff --git a/en/application-dev/reference/apis/js-apis-application-formProvider.md b/en/application-dev/reference/apis/js-apis-application-formProvider.md
index 05318bda39a220c15a328368fd5bf54c29f0ad05..4d604ff7295eb9903d450bc96f9c00fde253ee11 100644
--- a/en/application-dev/reference/apis/js-apis-application-formProvider.md
+++ b/en/application-dev/reference/apis/js-apis-application-formProvider.md
@@ -1,10 +1,10 @@
-# @ohos.application.formProvider
+# @ohos.application.formProvider (formProvider)
The **FormProvider** module provides APIs related to the widget provider. You can use the APIs to update a widget, set the next refresh time for a widget, obtain widget information, and request a widget release.
> **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 [FormProvider](js-apis-app-form-formProvider.md) instead.
+> This module is deprecated since API version 9. You are advised to use [formProvider](js-apis-app-form-formProvider.md) instead.
## Modules to Import
@@ -31,11 +31,13 @@ Sets the next refresh time for a widget. This API uses an asynchronous callback
**Example**
```ts
- var formId = "12400633174999288";
+ import formProvider from '@ohos.app.form.formProvider';
+
+ let formId = "12400633174999288";
formProvider.setFormNextRefreshTime(formId, 5, (error, data) => {
- if (error.code) {
- console.log('formProvider setFormNextRefreshTime, error:' + JSON.stringify(error));
- }
+ if (error.code) {
+ console.log('formProvider setFormNextRefreshTime, error:' + JSON.stringify(error));
+ }
});
```
@@ -63,11 +65,13 @@ Sets the next refresh time for a widget. This API uses a promise to return the r
**Example**
```ts
- var formId = "12400633174999288";
+ import formProvider from '@ohos.app.form.formProvider';
+
+ let formId = "12400633174999288";
formProvider.setFormNextRefreshTime(formId, 5).then(() => {
- console.log('formProvider setFormNextRefreshTime success');
+ console.log('formProvider setFormNextRefreshTime success');
}).catch((error) => {
- console.log('formProvider setFormNextRefreshTime, error:' + JSON.stringify(error));
+ console.log('formProvider setFormNextRefreshTime, error:' + JSON.stringify(error));
});
```
@@ -84,19 +88,21 @@ Updates a widget. This API uses an asynchronous callback to return the result.
| Name| Type | Mandatory| Description |
| ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
| formId | string | Yes | ID of the widget to update.|
- | formBindingData.FormBindingData | [FormBindingData](js-apis-application-formBindingData.md#formbindingdata) | Yes | Data to be used for the update. |
+ | formBindingData | [formBindingData.FormBindingData](js-apis-application-formBindingData.md#formbindingdata) | Yes | Data to be used for the update. |
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Example**
```ts
import formBindingData from '@ohos.application.formBindingData';
- var formId = "12400633174999288";
+ import formProvider from '@ohos.app.form.formProvider';
+
+ let formId = "12400633174999288";
let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
formProvider.updateForm(formId, obj, (error, data) => {
- if (error.code) {
- console.log('formProvider updateForm, error:' + JSON.stringify(error));
- }
+ if (error.code) {
+ console.log('formProvider updateForm, error:' + JSON.stringify(error));
+ }
});
```
@@ -113,7 +119,7 @@ Updates a widget. This API uses a promise to return the result.
| Name| Type | Mandatory| Description |
| ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
| formId | string | Yes | ID of the widget to update.|
- | formBindingData.FormBindingData | [FormBindingData](js-apis-application-formBindingData.md#formbindingdat) | Yes | Data to be used for the update. |
+ | formBindingData | [formBindingData.FormBindingData](js-apis-application-formBindingData.md#formbindingdata) | Yes | Data to be used for the update. |
**Return value**
@@ -125,12 +131,14 @@ Updates a widget. This API uses a promise to return the result.
```ts
import formBindingData from '@ohos.application.formBindingData';
- var formId = "12400633174999288";
+ import formProvider from '@ohos.app.form.formProvider';
+
+ let formId = "12400633174999288";
let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
formProvider.updateForm(formId, obj).then(() => {
- console.log('formProvider updateForm success');
+ console.log('formProvider updateForm success');
}).catch((error) => {
- console.log('formProvider updateForm, error:' + JSON.stringify(error));
+ console.log('formProvider updateForm, error:' + JSON.stringify(error));
});
```
@@ -146,17 +154,19 @@ Obtains the application's widget information on the device. This API uses an asy
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
-| callback | AsyncCallback<Array<[FormInfo](./js-apis-application-formInfo.md#forminfo-1)>> | Yes| Callback used to return the information obtained.|
+| callback | AsyncCallback<Array<[formInfo.FormInfo](./js-apis-application-formInfo.md#forminfo-1)>> | Yes| Callback used to return the information obtained.|
**Example**
```ts
+import formProvider from '@ohos.app.form.formProvider';
+
formProvider.getFormsInfo((error, data) => {
- if (error.code) {
- console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
- } else {
- console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
- }
+ if (error.code) {
+ console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
+ } else {
+ console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
+ }
});
```
## getFormsInfo9+
@@ -172,22 +182,24 @@ Obtains the application's widget information that meets a filter criterion on th
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- |
| filter | [formInfo.FormInfoFilter](./js-apis-application-formInfo.md#forminfofilter) | Yes| Filter criterion.|
-| callback | AsyncCallback<Array<[FormInfo](./js-apis-application-formInfo.md#forminfo-1)>> | Yes| Callback used to return the information obtained.|
+| callback | AsyncCallback<Array<[formInfo.FormInfo](./js-apis-application-formInfo.md#forminfo-1)>> | Yes| Callback used to return the information obtained.|
**Example**
```ts
import formInfo from '@ohos.application.formInfo';
+import formProvider from '@ohos.app.form.formProvider';
+
const filter : formInfo.FormInfoFilter = {
- // get info of forms belong to module entry.
- moduleName : "entry"
+ // get info of forms belong to module entry.
+ moduleName : "entry"
};
formProvider.getFormsInfo(filter, (error, data) => {
- if (error.code) {
- console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
- } else {
- console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
- }
+ if (error.code) {
+ console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
+ } else {
+ console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
+ }
});
```
@@ -209,20 +221,22 @@ Obtains the application's widget information on the device. This API uses a prom
| Type | Description |
| :------------ | :---------------------------------- |
-| Promise<Array<[FormInfo](./js-apis-application-formInfo.md#forminfo-1)>> | Promise used to return the information obtained.|
+| Promise<Array<[formInfo.FormInfo](./js-apis-application-formInfo.md#forminfo-1)>> | Promise used to return the information obtained.|
**Example**
```ts
import formInfo from '@ohos.application.formInfo';
+import formProvider from '@ohos.app.form.formProvider';
+
const filter : formInfo.FormInfoFilter = {
- // get info of forms belong to module entry.
- moduleName : "entry"
+ // get info of forms belong to module entry.
+ moduleName : "entry"
};
formProvider.getFormsInfo(filter).then((data) => {
- console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
+ console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
}).catch((error) => {
- console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
+ console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
});
```
@@ -241,28 +255,29 @@ Requests to publish a widget carrying data to the widget host. This API uses an
| Name| Type | Mandatory| Description |
| ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
| want | [Want](js-apis-application-want.md) | Yes | Request used for publishing. The following fields must be included:
Information about the target widget.
**abilityName**: ability of the target widget.
**parameters**:
"ohos.extra.param.key.form_dimension"
"ohos.extra.param.key.form_name"
"ohos.extra.param.key.module_name" |
-| formBindingData.FormBindingData | [FormBindingData](js-apis-application-formBindingData.md#formbindingdata) | Yes | Data used for creating the widget.|
+| formBindingData | [formBindingData.FormBindingData](js-apis-application-formBindingData.md#formbindingdata) | Yes | Data used for creating the widget.|
| callback | AsyncCallback<string> | Yes| Callback used to return the widget ID.|
**Example**
```ts
import formBindingData from '@ohos.application.formBindingData';
- var want = {
- abilityName: "FormAbility",
- parameters: {
- "ohos.extra.param.key.form_dimension": 2,
- "ohos.extra.param.key.form_name": "widget",
- "ohos.extra.param.key.module_name": "entry"
- }
+ import formProvider from '@ohos.app.form.formProvider';
+ let want = {
+ abilityName: "FormAbility",
+ parameters: {
+ "ohos.extra.param.key.form_dimension": 2,
+ "ohos.extra.param.key.form_name": "widget",
+ "ohos.extra.param.key.module_name": "entry"
+ }
};
let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
formProvider.requestPublishForm(want, obj, (error, data) => {
- if (error.code) {
- console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
- } else {
- console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
- }
+ if (error.code) {
+ console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
+ } else {
+ console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
+ }
});
```
@@ -286,20 +301,22 @@ Requests to publish a widget to the widget host. This API uses an asynchronous c
**Example**
```ts
- var want = {
- abilityName: "FormAbility",
- parameters: {
- "ohos.extra.param.key.form_dimension": 2,
- "ohos.extra.param.key.form_name": "widget",
- "ohos.extra.param.key.module_name": "entry"
- }
+ import formProvider from '@ohos.app.form.formProvider';
+
+ let want = {
+ abilityName: "FormAbility",
+ parameters: {
+ "ohos.extra.param.key.form_dimension": 2,
+ "ohos.extra.param.key.form_name": "widget",
+ "ohos.extra.param.key.module_name": "entry"
+ }
};
formProvider.requestPublishForm(want, (error, data) => {
- if (error.code) {
- console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
- } else {
- console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
- }
+ if (error.code) {
+ console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
+ } else {
+ console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
+ }
});
```
@@ -318,7 +335,7 @@ Requests to publish a widget to the widget host. This API uses a promise to retu
| Name | Type | Mandatory| Description |
| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-want.md) | Yes | Request used for publishing. The following fields must be included:
Information about the target widget.
**abilityName**: ability of the target widget.
**parameters**:
"ohos.extra.param.key.form_dimension"
"ohos.extra.param.key.form_name"
"ohos.extra.param.key.module_name" |
-| formBindingData.FormBindingData | [FormBindingData](js-apis-application-formBindingData.md#formbindingdata) | No | Data used for creating the widget. |
+| formBindingData | [formBindingData.FormBindingData](js-apis-application-formBindingData.md#formbindingdata) | Yes | Data used for creating the widget.|
**Return value**
@@ -329,18 +346,20 @@ Requests to publish a widget to the widget host. This API uses a promise to retu
**Example**
```ts
- var want = {
- abilityName: "FormAbility",
- parameters: {
- "ohos.extra.param.key.form_dimension": 2,
- "ohos.extra.param.key.form_name": "widget",
- "ohos.extra.param.key.module_name": "entry"
- }
+ import formProvider from '@ohos.app.form.formProvider';
+
+ let want = {
+ abilityName: "FormAbility",
+ parameters: {
+ "ohos.extra.param.key.form_dimension": 2,
+ "ohos.extra.param.key.form_name": "widget",
+ "ohos.extra.param.key.module_name": "entry"
+ }
};
formProvider.requestPublishForm(want).then((data) => {
- console.log('formProvider requestPublishForm success, form ID is :' + JSON.stringify(data));
+ console.log('formProvider requestPublishForm success, form ID is :' + JSON.stringify(data));
}).catch((error) => {
- console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
+ console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
});
```
@@ -368,13 +387,13 @@ formProvider.isRequestPublishFormSupported((error, isSupported) => {
console.log('formProvider isRequestPublishFormSupported, error:' + JSON.stringify(error));
} else {
if (isSupported) {
- var want = {
- abilityName: "FormAbility",
- parameters: {
- "ohos.extra.param.key.form_dimension": 2,
- "ohos.extra.param.key.form_name": "widget",
- "ohos.extra.param.key.module_name": "entry"
- }
+ let want = {
+ abilityName: "FormAbility",
+ parameters: {
+ "ohos.extra.param.key.form_dimension": 2,
+ "ohos.extra.param.key.form_name": "widget",
+ "ohos.extra.param.key.module_name": "entry"
+ }
};
formProvider.requestPublishForm(want, (error, data) => {
if (error.code) {
@@ -409,13 +428,13 @@ Checks whether a widget can be published to the widget host. This API uses a pro
```ts
formProvider.isRequestPublishFormSupported().then((isSupported) => {
if (isSupported) {
- var want = {
- abilityName: "FormAbility",
- parameters: {
+ let want = {
+ abilityName: "FormAbility",
+ parameters: {
"ohos.extra.param.key.form_dimension": 2,
"ohos.extra.param.key.form_name": "widget",
"ohos.extra.param.key.module_name": "entry"
- }
+ }
};
formProvider.requestPublishForm(want).then((data) => {
console.log('formProvider requestPublishForm success, form ID is :' + JSON.stringify(data));
diff --git a/en/application-dev/reference/apis/js-apis-application-missionManager.md b/en/application-dev/reference/apis/js-apis-application-missionManager.md
index c30dda422ded7148e35ebab1cc26804290bc1ea6..17de66e19334dce9663017c3df9c18b575e14bd7 100644
--- a/en/application-dev/reference/apis/js-apis-application-missionManager.md
+++ b/en/application-dev/reference/apis/js-apis-application-missionManager.md
@@ -1,10 +1,10 @@
-# @ohos.application.missionManager
+# @ohos.application.missionManager (missionManager)
The **missionManager** module provides APIs to lock, unlock, and clear missions, and switch a mission to the foreground.
> **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 APIs of this module are supported since API version 8 and deprecated since API version 9. You are advised to use [@ohos.app.ability.missionManager](js-apis-app-ability-missionManager.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
@@ -32,13 +32,13 @@ Registers a listener to observe the mission status.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
- | listener | [MissionListener](js-apis-inner-application-missionListener.md) | Yes| Listener to register.|
+ | listener | [MissionListener](js-apis-inner-application-missionListener.md) | Yes| Mission status listener to register.|
**Return value**
| Type| Description|
| -------- | -------- |
- | number | Returns the unique index of the mission status listener, which is created by the system and allocated when the listener is registered.|
+ | number | Index of the mission status listener, which is created by the system and allocated when the listener is registered.|
**Example**
@@ -73,7 +73,7 @@ Deregisters a mission status listener. This API uses an asynchronous callback to
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
- | listenerId | number | Yes| Unique index of the mission status listener to unregister. It is returned by **registerMissionListener**.|
+ | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **registerMissionListener()**.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Example**
@@ -113,7 +113,7 @@ Deregisters a mission status listener. This API uses a promise to return the res
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
- | listenerId | number | Yes| Unique index of the mission status listener to unregister. It is returned by **registerMissionListener**.|
+ | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **registerMissionListener()**.|
**Return value**
@@ -169,7 +169,12 @@ Obtains the information about a given mission. This API uses an asynchronous cal
var allMissions=missionManager.getMissionInfos("",10).catch(function(err){console.log(err);});
missionManager.getMissionInfo("", allMissions[0].missionId, (error, mission) => {
- console.log("getMissionInfo is called, error.code = " + error.code)
+ if (error.code) {
+ console.log("getMissionInfo failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ return;
+ }
+
console.log("mission.missionId = " + mission.missionId);
console.log("mission.runningState = " + mission.runningState);
console.log("mission.lockedState = " + mission.lockedState);
@@ -242,7 +247,11 @@ Obtains information about all missions. This API uses an asynchronous callback t
import missionManager from '@ohos.application.missionManager'
missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
+ if (error.code) {
+ console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ return;
+ }
console.log("size = " + missions.length);
console.log("missions = " + JSON.stringify(missions));
})
@@ -311,14 +320,22 @@ Obtains the snapshot of a given mission. This API uses an asynchronous callback
import missionManager from '@ohos.application.missionManager'
missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
+ if (error.code) {
+ console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ return;
+ }
console.log("size = " + missions.length);
console.log("missions = " + JSON.stringify(missions));
var id = missions[0].missionId;
missionManager.getMissionSnapShot("", id, (error, snapshot) => {
- console.log("getMissionSnapShot is called, error.code = " + error.code);
- console.log("bundleName = " + snapshot.ability.bundleName);
+ if (error.code) {
+ console.log("getMissionSnapShot failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ return;
+ }
+ console.log("bundleName = " + snapshot.ability.bundleName);
})
})
```
@@ -393,14 +410,22 @@ Obtains the low-resolution snapshot of a given mission. This API uses an asynchr
import missionManager from '@ohos.application.missionManager'
missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
+ if (error.code) {
+ console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ return;
+ }
console.log("size = " + missions.length);
console.log("missions = " + JSON.stringify(missions));
var id = missions[0].missionId;
missionManager.getLowResolutionMissionSnapShot("", id, (error, snapshot) => {
- console.log("getLowResolutionMissionSnapShot is called, error.code = " + error.code);
- console.log("bundleName = " + snapshot.ability.bundleName);
+ if (error.code) {
+ console.log("getLowResolutionMissionSnapShot failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ return;
+ }
+ console.log("bundleName = " + snapshot.ability.bundleName);
})
})
```
@@ -475,7 +500,11 @@ Locks a given mission. This API uses an asynchronous callback to return the resu
import missionManager from '@ohos.application.missionManager'
missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
+ if (error.code) {
+ console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ return;
+ }
console.log("size = " + missions.length);
console.log("missions = " + JSON.stringify(missions));
var id = missions[0].missionId;
@@ -554,7 +583,11 @@ Unlocks a given mission. This API uses an asynchronous callback to return the re
import missionManager from '@ohos.application.missionManager'
missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
+ if (error.code) {
+ console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ return;
+ }
console.log("size = " + missions.length);
console.log("missions = " + JSON.stringify(missions));
var id = missions[0].missionId;
@@ -637,7 +670,11 @@ Clears a given mission, regardless of whether it is locked. This API uses an asy
import missionManager from '@ohos.application.missionManager'
missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
+ if (error.code) {
+ console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ return;
+ }
console.log("size = " + missions.length);
console.log("missions = " + JSON.stringify(missions));
var id = missions[0].missionId;
@@ -768,7 +805,11 @@ Switches a given mission to the foreground. This API uses an asynchronous callba
import missionManager from '@ohos.application.missionManager'
missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
+ if (error.code) {
+ console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ return;
+ }
console.log("size = " + missions.length);
console.log("missions = " + JSON.stringify(missions));
var id = missions[0].missionId;
@@ -806,7 +847,11 @@ Switches a given mission to the foreground, with the startup parameters for the
import missionManager from '@ohos.application.missionManager'
missionManager.getMissionInfos("", 10, (error, missions) => {
- console.log("getMissionInfos is called, error.code = " + error.code);
+ if (error.code) {
+ console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) +
+ "error.message:" + JSON.stringify(error.message));
+ return;
+ }
console.log("size = " + missions.length);
console.log("missions = " + JSON.stringify(missions));
var id = missions[0].missionId;
diff --git a/en/application-dev/reference/apis/js-apis-application-serviceExtensionAbility.md b/en/application-dev/reference/apis/js-apis-application-serviceExtensionAbility.md
index ba59d9a6ea78434939ee99a6e25b3c2945874532..beb8c007b0fa58bdae058ac554c96425bdf93bd5 100644
--- a/en/application-dev/reference/apis/js-apis-application-serviceExtensionAbility.md
+++ b/en/application-dev/reference/apis/js-apis-application-serviceExtensionAbility.md
@@ -1,10 +1,13 @@
-# @ohos.application.ServiceExtensionAbility
+# @ohos.application.ServiceExtensionAbility (ServiceExtensionAbility)
The **ServiceExtensionAbility** module provides APIs for Service Extension abilities.
> **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
@@ -23,9 +26,9 @@ None.
**System API**: This is a system API and cannot be called by third-party applications.
-| Name| Type| Readable| Writable| Description|
+| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
-| context | [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md) | Yes| No| Service Extension context, which is inherited from **ExtensionContext**.|
+| context | [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md) | Yes| No| Service Extension context, which is inherited from **ExtensionContext**.|
## ServiceExtensionAbility.onCreate
@@ -40,9 +43,9 @@ Called when a Service Extension ability is created to initialize the service log
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want | [Want](js-apis-application-want.md) | Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want | [Want](js-apis-application-want.md) | Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
**Example**
@@ -88,10 +91,10 @@ Called after **onCreate** is invoked when a Service Extension ability is started
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want | [Want](js-apis-application-want.md) | Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
- | startId | number | Yes| Number of ability start times. The initial value is **1**, and the value is automatically incremented for each ability started.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want | [Want](js-apis-application-want.md) | Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
+| startId | number | Yes| Number of ability start times. The initial value is **1**, and the value is automatically incremented for each ability started.|
**Example**
@@ -116,15 +119,15 @@ Called after **onCreate** is invoked when a Service Extension ability is started
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want | [Want](js-apis-application-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want | [Want](js-apis-application-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
**Return value**
- | Type| Description|
- | -------- | -------- |
- | rpc.RemoteObject | A **RemoteObject** object used for communication with the client.|
+| Type| Description|
+| -------- | -------- |
+| rpc.RemoteObject | A **RemoteObject** object used for communication with the client.|
**Example**
@@ -158,9 +161,9 @@ Called when this Service Extension ability is disconnected.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want |[Want](js-apis-application-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want |[Want](js-apis-application-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
**Example**
@@ -184,9 +187,9 @@ Called when this Service Extension ability is reconnected.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | want |[Want](js-apis-application-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| want |[Want](js-apis-application-want.md)| Yes| Want information related to this Service Extension ability, including the ability name and bundle name.|
**Example**
@@ -210,9 +213,9 @@ Called when the configuration of this Service Extension ability is updated.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | config | [Configuration](js-apis-application-configuration.md) | Yes| New configuration.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| config | [Configuration](js-apis-application-configuration.md) | Yes| New configuration.|
**Example**
@@ -236,9 +239,9 @@ Dumps the client information.
**Parameters**
- | Name| Type| Mandatory| Description|
- | -------- | -------- | -------- | -------- |
- | params | Array\ | Yes| Parameters in the form of a command.|
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| params | Array\ | Yes| Parameters in the form of a command.|
**Example**
diff --git a/en/application-dev/reference/apis/js-apis-application-startOptions.md b/en/application-dev/reference/apis/js-apis-application-startOptions.md
index 40ad2a516377faf476cfe688914afe3cd3eccb6c..7634b276495d98e18bc7ec966f3483e526dd3ba3 100644
--- a/en/application-dev/reference/apis/js-apis-application-startOptions.md
+++ b/en/application-dev/reference/apis/js-apis-application-startOptions.md
@@ -1,10 +1,10 @@
-# @ohos.application.StartOptions
+# @ohos.application.StartOptions (StartOptions)
The **StartOptions** module implements ability startup options.
> **NOTE**
>
-> The APIs of this module are supported and deprecated since API version 9. You are advised to use [@ohos.app.ability.StartOptions](js-apis-app-ability-startOptions.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 9 and are deprecated in versions later than API version 9. You are advised to use [@ohos.app.ability.StartOptions](js-apis-app-ability-startOptions.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
diff --git a/en/application-dev/reference/apis/js-apis-application-staticSubscriberExtensionAbility.md b/en/application-dev/reference/apis/js-apis-application-staticSubscriberExtensionAbility.md
index b9086a6ce6cbd42c53730baa1531255c0d383ba9..5fc9b0999940310b10bf7b4e7227d5651153eb50 100644
--- a/en/application-dev/reference/apis/js-apis-application-staticSubscriberExtensionAbility.md
+++ b/en/application-dev/reference/apis/js-apis-application-staticSubscriberExtensionAbility.md
@@ -1,10 +1,11 @@
-# @ohos.application.StaticSubscriberExtensionAbility
+# @ohos.application.StaticSubscriberExtensionAbility (StaticSubscriberExtensionAbility)
The **StaticSubscriberExtensionAbility** module provides Extension abilities for static subscribers.
> **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 can be used only in the stage model.
## Modules to Import
@@ -26,9 +27,10 @@ Callback of the common event of a static subscriber.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| event | [CommonEventData](js-apis-commonEvent.md#commoneventdata) | Yes| Common event of a static subscriber.|
+| event | [CommonEventData](js-apis-commonEventManager.md#commoneventdata) | Yes| Common event of a static subscriber.|
-**Example**
+**Example**
+
```ts
var StaticSubscriberExtensionAbility = requireNapi("application.StaticSubscriberExtensionAbility")
{
diff --git a/en/application-dev/reference/apis/js-apis-application-testRunner.md b/en/application-dev/reference/apis/js-apis-application-testRunner.md
index 688774a0d4b840e19e398624be41ac85c07c8f37..d2146524c0c5249374e21c95762438d35dc48c35 100644
--- a/en/application-dev/reference/apis/js-apis-application-testRunner.md
+++ b/en/application-dev/reference/apis/js-apis-application-testRunner.md
@@ -1,4 +1,4 @@
-# @ohos.application.testRunner
+# @ohos.application.testRunner (TestRunner)
The **TestRunner** module provides a test framework. You can use the APIs of this module to prepare the unit test environment and run test cases.
diff --git a/en/application-dev/reference/apis/js-apis-application-want.md b/en/application-dev/reference/apis/js-apis-application-want.md
index 620885945b572e8129e4f8c61b156ef658a6805d..44cc01a00c5057488b45a5a6a38cc02adbf1cbc2 100644
--- a/en/application-dev/reference/apis/js-apis-application-want.md
+++ b/en/application-dev/reference/apis/js-apis-application-want.md
@@ -1,10 +1,10 @@
-# @ohos.application.Want
+# @ohos.application.Want (Want)
-Want is a carrier for information transfer between objects (application components). Want can be used as a parameter of **startAbility** to specify a startup target and information that needs to be carried during startup, for example, **bundleName** and **abilityName**, which respectively indicate the bundle name of the target ability and the ability name in the bundle. When ability A needs to start ability B and transfer some data to ability B, it can use Want a carrier to transfer the data.
+Want is a carrier for information transfer between objects (application components). Want can be used as a parameter of **startAbility()** to specify a startup target and information that needs to be carried during startup, for example, **bundleName** and **abilityName**, which respectively indicate the bundle name of the target ability and the ability name in the bundle. When ability A needs to start ability B and transfer some data to ability B, it can use Want a carrier to transfer the data.
> **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 APIs of this module are supported since API version 8 and deprecated since API version 9. You are advised to use [Want](js-apis-app-ability-want.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
@@ -18,26 +18,26 @@ import Want from '@ohos.application.Want';
| Name | Type | Mandatory| Description |
| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
-| 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.|
+| 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.|
| 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.|
| uri | string | No | URI information to match. If **uri** is specified in a **Want** object, the **Want** object 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. |
| flags | number | No | How the **Want** object will be handled. By default, numbers are 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 attribute and use it together with **uri** or **parameters** to specify the operation to be performed on the data. |
+| action | string | No | Action to take, such as viewing and sharing application details. In implicit **Want**, you can define this attribute and use it together with **uri** or **parameters** to specify the operation to be performed on the data. For details, see [action](js-apis-app-ability-wantConstant.md#wantConstant.Action). 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). |
| parameters | {[key: string]: any} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:
**ohos.aafwk.callerPid**: PID of the caller.
**ohos.aafwk.param.callerToken**: token of the caller.
**ohos.aafwk.param.callerUid**: UID in [bundleInfo](js-apis-bundle-BundleInfo.md#bundleinfo-1), that is, the application UID in the bundle information. |
-| entities | Array\ | No | Additional category information (such as browser and video player) of the target ability. It is a supplement to **action** in implicit **Want** and is used to filter ability types. |
+| entities | Array\ | 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. For details, see [entity](js-apis-app-ability-wantConstant.md#wantConstant.Entity). |
| moduleName9+ | string | No | Module to which the ability belongs.|
**Example**
-- Basic usage
+- Basic usage (called in a UIAbility object, where context in the example is the context object of the UIAbility).
```ts
- var want = {
+ let want = {
"deviceId": "", // An empty deviceId indicates the local device.
- "bundleName": "com.extreme.test",
- "abilityName": "MainAbility",
+ "bundleName": "com.example.myapplication",
+ "abilityName": "EntryAbility",
"moduleName": "entry" // moduleName is optional.
};
this.context.startAbility(want, (error) => {
@@ -46,13 +46,13 @@ import Want from '@ohos.application.Want';
})
```
-- Data is transferred through user-defined fields. The following data types are supported:
+- 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):
* String
```ts
let want = {
- bundleName: "com.example.demo",
- abilityName: "com.example.demo.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility",
parameters: {
keyForString: "str",
},
@@ -61,8 +61,8 @@ import Want from '@ohos.application.Want';
* Number
```ts
let want = {
- bundleName: "com.example.demo",
- abilityName: "com.example.demo.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility",
parameters: {
keyForInt: 100,
keyForDouble: 99.99,
@@ -72,8 +72,8 @@ import Want from '@ohos.application.Want';
* Boolean
```ts
let want = {
- bundleName: "com.example.demo",
- abilityName: "com.example.demo.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility",
parameters: {
keyForBool: true,
},
@@ -82,8 +82,8 @@ import Want from '@ohos.application.Want';
* Object
```ts
let want = {
- bundleName: "com.example.demo",
- abilityName: "com.example.demo.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility",
parameters: {
keyForObject: {
keyForObjectString: "str",
@@ -97,8 +97,8 @@ import Want from '@ohos.application.Want';
* Array
```ts
let want = {
- bundleName: "com.example.demo",
- abilityName: "com.example.demo.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility",
parameters: {
keyForArrayString: ["str1", "str2", "str3"],
keyForArrayInt: [100, 200, 300, 400],
@@ -110,16 +110,16 @@ import Want from '@ohos.application.Want';
* File descriptor (FD)
```ts
import fileio from '@ohos.fileio';
- var fd;
+ let fd;
try {
fd = fileio.openSync("/data/storage/el2/base/haps/pic.png");
} catch(e) {
console.log("openSync fail:" + JSON.stringify(e));
}
- var want = {
+ let want = {
"deviceId": "", // An empty deviceId indicates the local device.
- "bundleName": "com.extreme.test",
- "abilityName": "MainAbility",
+ "bundleName": "com.example.myapplication",
+ "abilityName": "EntryAbility",
"moduleName": "entry", // moduleName is optional.
"parameters": {
"keyFd":{"type":"FD", "value":fd}
@@ -131,4 +131,6 @@ import Want from '@ohos.application.Want';
})
```
+- For more details and examples, see [Want](../../application-models/want-overview.md).
+
diff --git a/en/application-dev/reference/apis/js-apis-application-windowExtensionAbility.md b/en/application-dev/reference/apis/js-apis-application-windowExtensionAbility.md
index 882578cc316716db9f2f8a3c1d355e6a07b292db..bd6d74bbcbbdb4b0d29ccad209b012a11f44c9af 100644
--- a/en/application-dev/reference/apis/js-apis-application-windowExtensionAbility.md
+++ b/en/application-dev/reference/apis/js-apis-application-windowExtensionAbility.md
@@ -1,4 +1,5 @@
-# Window Extension Ability
+# @ohos.application.WindowExtensionAbility (WindowExtensionAbility)
+
**WindowExtensionAbility** inherits from **ExtensionAbility**. The content in a **WindowExtensionAbility** object can be displayed as an ability component in other application windows.
> **NOTE**
diff --git a/en/application-dev/reference/apis/js-apis-arraylist.md b/en/application-dev/reference/apis/js-apis-arraylist.md
index f6334ff328c76de2d9be97b9ad430065819e53c9..ebf538d3b5508c1ee26aa77d4db01aa995239c3b 100644
--- a/en/application-dev/reference/apis/js-apis-arraylist.md
+++ b/en/application-dev/reference/apis/js-apis-arraylist.md
@@ -1,7 +1,6 @@
# @ohos.util.ArrayList (Linear Container ArrayList)
> **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.
**ArrayList** is a linear data structure that is implemented based on arrays. **ArrayList** can dynamically adjust the capacity based on project requirements. It increases the capacity by 50% each time.
@@ -42,7 +41,7 @@ A constructor used to create an **ArrayList** instance.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -77,7 +76,7 @@ Adds an element at the end of this container.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -113,12 +112,12 @@ Inserts an element at the specified position in this container.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The insert method cannot be bound. |
-| 10200001 | The parameter value is out of range. |
+| 10200001 | The value of index is out of range. |
**Example**
@@ -151,7 +150,7 @@ Checks whether this container has the specified element.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -188,7 +187,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -230,7 +229,7 @@ Obtains the index of the last occurrence of the specified element in this contai
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -272,12 +271,12 @@ Removes an element with the specified position from this container.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. |
-| 10200001 | The parameter value is out of range. |
+| 10200001 | The value of index is out of range. |
**Example**
@@ -313,7 +312,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -347,12 +346,12 @@ Removes from this container all of the elements within a range, including the el
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByRange method cannot be bound. |
-| 10200001 | The parameter value is out of range. |
+| 10200001 | The value of fromIndex or toIndex is out of range. |
**Example**
@@ -391,7 +390,7 @@ callbackfn
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -426,7 +425,7 @@ Uses a callback to traverse the elements in this container and obtain their posi
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| callbackFn | function | Yes| Callback invoked to traverse the elements in the container.|
+| callbackFn | function | Yes| Callback invoked for the replacement.|
| thisArg | Object | No| Value to use when the callback is invoked.|
callbackfn
@@ -439,7 +438,7 @@ callbackfn
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -481,7 +480,7 @@ comparator
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -523,12 +522,12 @@ Obtains elements within a range in this container, including the element at the
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The subArrayList method cannot be bound. |
-| 10200001 | The parameter value is out of range. |
+| 10200001 | The value of fromIndex or toIndex is out of range. |
**Example**
@@ -553,7 +552,7 @@ Clears this container and sets its length to **0**.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -587,7 +586,7 @@ Clones this container and returns a copy. The modification to the copy does not
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -620,7 +619,7 @@ Obtains the capacity of this container.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -653,7 +652,7 @@ Converts this container into an array.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -686,7 +685,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -719,7 +718,7 @@ Increases the capacity of this container.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -747,7 +746,7 @@ Trims the capacity of this container to its current length.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
@@ -780,7 +779,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
-For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
+For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
diff --git a/en/application-dev/reference/apis/js-apis-avsession.md b/en/application-dev/reference/apis/js-apis-avsession.md
index 94ba3b3ca01982070588760ebdd757db7ee8d13b..5552792aadadd04fca72d4fe88ffdfc8219b3ec9 100644
--- a/en/application-dev/reference/apis/js-apis-avsession.md
+++ b/en/application-dev/reference/apis/js-apis-avsession.md
@@ -41,8 +41,8 @@ Creates a media session. This API uses a promise to return the result. An abilit
| --------------------------------- | ------------------------------------------------------------ |
| Promise<[AVSession](#avsession)\> | Promise used to return the media session obtained, which can be used to obtain the session ID, set the metadata and playback state information, and send key events.|
-**Error codes**
+**Error codes**
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -84,7 +84,6 @@ Creates a media session. This API uses an asynchronous callback to return the re
| callback | AsyncCallback<[AVSession](#avsession)\> | Yes | Callback used to return the media session obtained, which can be used to obtain the session ID, set the metadata and playback state information, and send key events.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -129,7 +128,6 @@ Obtains the descriptors of all sessions. This API uses a promise to return the r
| Promise\\>\> | Promise used to return an array of **AVSessionDescriptor** objects, each of which is read only.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -170,7 +168,6 @@ Obtains the descriptors of all sessions. This API uses an asynchronous callback
| callback | AsyncCallback\>\> | Yes | Callback used to return an array of **AVSessionDescriptor** objects, each of which is read only.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -219,7 +216,6 @@ Creates a session controller based on the session ID. Multiple session controlle
| Promise<[AVSessionController](#avsessioncontroller)\> | Promise used to return the session controller created, which can be used to obtain the session ID,
send commands and events to sessions, and obtain metadata and playback state information.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -272,7 +268,6 @@ Creates a session controller based on the session ID. Multiple session controlle
| callback | AsyncCallback<[AVSessionController](#avsessioncontroller)\> | Yes | Callback used to return the session controller created, which can be used to obtain the session ID,
send commands and events to sessions, and obtain metadata and playback state information.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -335,7 +330,6 @@ Before calling this API, import the **ohos.multimedia.audio** module to obtain t
| Promise | Promise used to return the result. If the cast is successful, no value is returned; otherwise, an error object is returned.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -388,7 +382,6 @@ Before calling this API, import the **ohos.multimedia.audio** module to obtain t
| callback | AsyncCallback | Yes | Callback used to return the result. If the casting is successful, **err** is **undefined**; otherwise, **err** is an error object. |
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -440,7 +433,6 @@ Subscribes to session creation, session destruction, and top session change even
| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes | Callback used to report the session descriptor. |
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -489,7 +481,6 @@ Unsubscribes from session creation, session destruction, and top session change
| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **session** parameter in the callback describes a media session. The callback parameter is optional. If it is not specified, the specified event is no longer listened for all sessions. |
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -520,7 +511,6 @@ Subscribes to session service death events.
| callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. |
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -551,7 +541,6 @@ Unsubscribes from session service death events.
| callback | callback: () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The callback parameter is optional. If it is not specified, the specified event is no longer listened for all sessions. |
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -589,7 +578,6 @@ Sends a system key event to the top session. This API uses a promise to return t
| Promise | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -632,7 +620,6 @@ Sends a system key event to the top session. This API uses an asynchronous callb
| callback | AsyncCallback | Yes | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -680,7 +667,6 @@ Sends a system control command to the top session. This API uses a promise to re
| Promise | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -735,7 +721,6 @@ Sends a system control command to the top session. This API uses an asynchronous
| callback | AsyncCallback | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -812,7 +797,6 @@ Sets session metadata. This API uses a promise to return the result.
| Promise | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -862,7 +846,6 @@ Sets session metadata. This API uses an asynchronous callback to return the resu
| callback | AsyncCallback | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -919,7 +902,6 @@ Sets information related to the session playback state. This API uses a promise
| Promise | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -961,7 +943,6 @@ Sets information related to the session playback state. This API uses an asynchr
| callback | AsyncCallback | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object. |
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1010,7 +991,6 @@ Sets a launcher ability. This API uses a promise to return the result.
| Promise | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1028,8 +1008,8 @@ let wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
- bundleName: "com.neu.setResultOnAbilityResultTest1",
- abilityName: "com.example.test.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
@@ -1076,7 +1056,6 @@ Sets a launcher ability. This API uses an asynchronous callback to return the re
| callback | AsyncCallback | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1094,8 +1073,8 @@ let wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
- bundleName: "com.neu.setResultOnAbilityResultTest1",
- abilityName: "com.example.test.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "EntryAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
@@ -1143,7 +1122,6 @@ Obtains the controller corresponding to this session. This API uses a promise to
| Promise<[AVSessionController](#avsessioncontroller)> | Promise used to return the session controller.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1178,7 +1156,6 @@ Obtains the controller corresponding to this session. This API uses an asynchron
| callback | AsyncCallback<[AVSessionController](#avsessioncontroller)\> | Yes | Callback used to return the session controller.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1215,7 +1192,6 @@ Obtains information about the output device for this session. This API uses a pr
| Promise<[OutputDeviceInfo](#outputdeviceinfo)> | Promise used to return the output device information.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1248,7 +1224,6 @@ Obtains information about the output device for this session. This API uses an a
| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo)\> | Yes | Callback used to return the information obtained.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1283,7 +1258,6 @@ Activates this session. A session can be used only after being activated. This A
| Promise | Promise used to return the result. If the session is activated, no value is returned; otherwise, an error object is returned.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1316,7 +1290,6 @@ Activates this session. A session can be used only after being activated. This A
| callback | AsyncCallback | Yes | Callback used to return the result. If the session is activated, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1351,7 +1324,6 @@ Deactivates this session. You can use [activate](#activate) to activate the sess
| Promise | Promise used to return the result. If the session is deactivated, no value is returned; otherwise, an error object is returned.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1386,7 +1358,6 @@ Deactivates this session. You can use [activate](#activate) to activate the sess
| callback | AsyncCallback | Yes | Callback used to return the result. If the session is deactivated, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1421,7 +1392,6 @@ Destroys this session. This API uses a promise to return the result.
| Promise | Promise used to return the result. If the session is destroyed, no value is returned; otherwise, an error object is returned.|
**Error codes**
-
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
| ID| Error Message|
@@ -1455,7 +1425,6 @@ Destroys this session. This API uses an asynchronous callback to return the resu
| callback | AsyncCallback