“2ea1d13f64efdf49319e86c87d9ba38c30902782”上不存在“arch/arm/include/uapi/asm/mman.h”
未验证 提交 9134693d 编写于 作者: O openharmony_ci 提交者: Gitee

!13494 翻译完成 12832+12653+12413+13291+13268

Merge pull request !13494 from ester.zhou/C2-0111
# CommonEvent # @ohos.commonEvent
The **CommonEvent** module provides common event capabilities, including the capabilities to publish, subscribe to, and unsubscribe from common events, as well obtaining and setting the common event result code and result data. The **CommonEvent** module provides common event capabilities, including the capabilities to publish, subscribe to, and unsubscribe from common events, as well obtaining and setting the common event result code and result data.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The APIs provided by this module are no longer maintained since API version 9. You are advised to use [@ohos.commonEventManager](js-apis-commonEventManager.md).
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -14,7 +15,7 @@ import CommonEvent from '@ohos.commonEvent'; ...@@ -14,7 +15,7 @@ import CommonEvent from '@ohos.commonEvent';
## Support ## Support
Provides the event types supported by the **CommonEvent** module. The name and value indicate the macro and name of a common event, respectively. The table below lists the event types supported by the **CommonEvent** module. The name and value indicate the macro and name of a common event, respectively.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -168,7 +169,7 @@ Provides the event types supported by the **CommonEvent** module. The name and v ...@@ -168,7 +169,7 @@ Provides the event types supported by the **CommonEvent** module. The name and v
| COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the foundation is ready. | | COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the foundation is ready. |
| COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | - | Indicates the common event that the airplane mode of the device has changed. | | COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | - | Indicates the common event that the airplane mode of the device has changed. |
| COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | - | Indicates the common event of screen splitting. | | COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | - | Indicates the common event of screen splitting. |
| COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has changed. | | COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has been updated. |
| COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | - | Indicates the common event that the SPN displayed has been updated. | | COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | - | Indicates the common event that the SPN displayed has been updated. |
| COMMON_EVENT_QUICK_FIX_APPLY_RESULT <sup>9+<sup> | usual.event.QUICK_FIX_APPLY_RESULT | - | Indicates the common event that a quick fix is applied to the application. | | COMMON_EVENT_QUICK_FIX_APPLY_RESULT <sup>9+<sup> | usual.event.QUICK_FIX_APPLY_RESULT | - | Indicates the common event that a quick fix is applied to the application. |
...@@ -192,7 +193,7 @@ Publishes a common event. This API uses an asynchronous callback to return the r ...@@ -192,7 +193,7 @@ Publishes a common event. This API uses an asynchronous callback to return the r
```js ```js
// Callback for common event publication // Callback for common event publication
function PublishCallBack(err) { function publishCallBack(err) {
if (err.code) { if (err.code) {
console.error("publish failed " + JSON.stringify(err)); console.error("publish failed " + JSON.stringify(err));
} else { } else {
...@@ -201,7 +202,7 @@ function PublishCallBack(err) { ...@@ -201,7 +202,7 @@ function PublishCallBack(err) {
} }
// Publish a common event. // Publish a common event.
CommonEvent.publish("event", PublishCallBack); CommonEvent.publish("event", publishCallBack);
``` ```
...@@ -229,12 +230,12 @@ Publishes a common event with given attributes. This API uses an asynchronous ca ...@@ -229,12 +230,12 @@ Publishes a common event with given attributes. This API uses an asynchronous ca
// Attributes of a common event. // Attributes of a common event.
let options = { let options = {
code: 0, // Result code of the common event. code: 0, // Result code of the common event.
data: "initial data";// Result data of the common event. data: "initial data",// Result data of the common event.
isOrdered: true // The common event is an ordered one. isOrdered: true // The common event is an ordered one.
} }
// Callback for common event publication // Callback for common event publication
function PublishCallBack(err) { function publishCallBack(err) {
if (err.code) { if (err.code) {
console.error("publish failed " + JSON.stringify(err)); console.error("publish failed " + JSON.stringify(err));
} else { } else {
...@@ -243,7 +244,7 @@ function PublishCallBack(err) { ...@@ -243,7 +244,7 @@ function PublishCallBack(err) {
} }
// Publish a common event. // Publish a common event.
CommonEvent.publish("event", options, PublishCallBack); CommonEvent.publish("event", options, publishCallBack);
``` ```
...@@ -270,7 +271,7 @@ Publishes a common event to a specific user. This API uses an asynchronous callb ...@@ -270,7 +271,7 @@ Publishes a common event to a specific user. This API uses an asynchronous callb
```js ```js
// Callback for common event publication // Callback for common event publication
function PublishAsUserCallBack(err) { function publishAsUserCallBack(err) {
if (err.code) { if (err.code) {
console.error("publishAsUser failed " + JSON.stringify(err)); console.error("publishAsUser failed " + JSON.stringify(err));
} else { } else {
...@@ -282,7 +283,7 @@ function PublishAsUserCallBack(err) { ...@@ -282,7 +283,7 @@ function PublishAsUserCallBack(err) {
let userId = 100; let userId = 100;
// Publish a common event. // Publish a common event.
CommonEvent.publishAsUser("event", userId, PublishAsUserCallBack); CommonEvent.publishAsUser("event", userId, publishAsUserCallBack);
``` ```
...@@ -313,11 +314,11 @@ Publishes a common event with given attributes to a specific user. This API uses ...@@ -313,11 +314,11 @@ Publishes a common event with given attributes to a specific user. This API uses
// Attributes of a common event. // Attributes of a common event.
let options = { let options = {
code: 0, // Result code of the common event. code: 0, // Result code of the common event.
data: "initial data";// Result data of the common event. data: "initial data",// Result data of the common event.
} }
// Callback for common event publication // Callback for common event publication
function PublishAsUserCallBack(err) { function publishAsUserCallBack(err) {
if (err.code) { if (err.code) {
console.error("publishAsUser failed " + JSON.stringify(err)); console.error("publishAsUser failed " + JSON.stringify(err));
} else { } else {
...@@ -329,7 +330,7 @@ function PublishAsUserCallBack(err) { ...@@ -329,7 +330,7 @@ function PublishAsUserCallBack(err) {
let userId = 100; let userId = 100;
// Publish a common event. // Publish a common event.
CommonEvent.publishAsUser("event", userId, options, PublishAsUserCallBack); CommonEvent.publishAsUser("event", userId, options, publishAsUserCallBack);
``` ```
...@@ -361,7 +362,7 @@ let subscribeInfo = { ...@@ -361,7 +362,7 @@ let subscribeInfo = {
}; };
// Callback for subscriber creation. // Callback for subscriber creation.
function CreateSubscriberCallBack(err, commonEventSubscriber) { function createSubscriberCallBack(err, commonEventSubscriber) {
if (err.code) { if (err.code) {
console.error("createSubscriber failed " + JSON.stringify(err)); console.error("createSubscriber failed " + JSON.stringify(err));
} else { } else {
...@@ -371,7 +372,7 @@ function CreateSubscriberCallBack(err, commonEventSubscriber) { ...@@ -371,7 +372,7 @@ function CreateSubscriberCallBack(err, commonEventSubscriber) {
} }
// Create a subscriber. // Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); CommonEvent.createSubscriber(subscribeInfo, createSubscriberCallBack);
``` ```
...@@ -442,7 +443,7 @@ let subscribeInfo = { ...@@ -442,7 +443,7 @@ let subscribeInfo = {
}; };
// Callback for common event subscription. // Callback for common event subscription.
function SubscribeCallBack(err, data) { function subscribeCallBack(err, data) {
if (err.code) { if (err.code) {
console.error("subscribe failed " + JSON.stringify(err)); console.error("subscribe failed " + JSON.stringify(err));
} else { } else {
...@@ -451,19 +452,19 @@ function SubscribeCallBack(err, data) { ...@@ -451,19 +452,19 @@ function SubscribeCallBack(err, data) {
} }
// Callback for subscriber creation. // Callback for subscriber creation.
function CreateSubscriberCallBack(err, commonEventSubscriber) { function createSubscriberCallBack(err, commonEventSubscriber) {
if (err.code) { if (err.code) {
console.error("createSubscriber failed " + JSON.stringify(err)); console.error("createSubscriber failed " + JSON.stringify(err));
} else { } else {
console.info("createSubscriber"); console.info("createSubscriber");
subscriber = commonEventSubscriber; subscriber = commonEventSubscriber;
// Subscribe to a common event. // Subscribe to a common event.
CommonEvent.subscribe(subscriber, SubscribeCallBack); CommonEvent.subscribe(subscriber, subscribeCallBack);
} }
} }
// Create a subscriber. // Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); CommonEvent.createSubscriber(subscribeInfo, createSubscriberCallBack);
``` ```
...@@ -494,7 +495,7 @@ let subscribeInfo = { ...@@ -494,7 +495,7 @@ let subscribeInfo = {
}; };
// Callback for common event subscription. // Callback for common event subscription.
function SubscribeCallBack(err, data) { function subscribeCallBack(err, data) {
if (err.code) { if (err.code) {
console.info("subscribe failed " + JSON.stringify(err)); console.info("subscribe failed " + JSON.stringify(err));
} else { } else {
...@@ -503,19 +504,19 @@ function SubscribeCallBack(err, data) { ...@@ -503,19 +504,19 @@ function SubscribeCallBack(err, data) {
} }
// Callback for subscriber creation. // Callback for subscriber creation.
function CreateSubscriberCallBack(err, commonEventSubscriber) { function createSubscriberCallBack(err, commonEventSubscriber) {
if (err.code) { if (err.code) {
console.info("createSubscriber failed " + JSON.stringify(err)); console.info("createSubscriber failed " + JSON.stringify(err));
} else { } else {
console.info("createSubscriber"); console.info("createSubscriber");
subscriber = commonEventSubscriber; subscriber = commonEventSubscriber;
// Subscribe to a common event. // Subscribe to a common event.
CommonEvent.subscribe(subscriber, SubscribeCallBack); CommonEvent.subscribe(subscriber, subscribeCallBack);
} }
} }
// Callback for common event unsubscription. // Callback for common event unsubscription.
function UnsubscribeCallBack(err) { function unsubscribeCallBack(err) {
if (err.code) { if (err.code) {
console.info("unsubscribe failed " + JSON.stringify(err)); console.info("unsubscribe failed " + JSON.stringify(err));
} else { } else {
...@@ -524,10 +525,10 @@ function UnsubscribeCallBack(err) { ...@@ -524,10 +525,10 @@ function UnsubscribeCallBack(err) {
} }
// Create a subscriber. // Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); CommonEvent.createSubscriber(subscribeInfo, createSubscriberCallBack);
// Unsubscribe from the common event. // Unsubscribe from the common event.
CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); CommonEvent.unsubscribe(subscriber, unsubscribeCallBack);
``` ```
## CommonEventSubscriber ## CommonEventSubscriber
...@@ -841,7 +842,6 @@ isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void ...@@ -841,7 +842,6 @@ isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void
Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result. Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**Parameters** **Parameters**
...@@ -872,7 +872,6 @@ isOrderedCommonEvent(): Promise\<boolean> ...@@ -872,7 +872,6 @@ isOrderedCommonEvent(): Promise\<boolean>
Checks whether this common event is an ordered one. This API uses a promise to return the result. Checks whether this common event is an ordered one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**Return value** **Return value**
...@@ -899,7 +898,6 @@ isStickyCommonEvent(callback: AsyncCallback\<boolean>): void ...@@ -899,7 +898,6 @@ isStickyCommonEvent(callback: AsyncCallback\<boolean>): void
Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result. Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**Parameters** **Parameters**
...@@ -930,7 +928,6 @@ isStickyCommonEvent(): Promise\<boolean> ...@@ -930,7 +928,6 @@ isStickyCommonEvent(): Promise\<boolean>
Checks whether this common event is a sticky one. This API uses a promise to return the result. Checks whether this common event is a sticky one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**Return value** **Return value**
...@@ -1233,39 +1230,45 @@ subscriber.finishCommonEvent().then(() => { ...@@ -1233,39 +1230,45 @@ subscriber.finishCommonEvent().then(() => {
## CommonEventData ## CommonEventData
Describes the common event data body.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
| Name | Readable| Writable| Type | Description | | Name | Type | Readable| Writable| Description |
| ---------- | ---- | ---- | -------------------- | ------------------------------------------------------- | | ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- |
| event | Yes | No | string | Name of the common event that is being received. | | event | string | Yes | No | Name of the common event that is being received. |
| bundleName | Yes | No | string | Bundle name. | | bundleName | string | Yes | No | Bundle name. |
| code | Yes | No | number | Result code of the common event, which is used to transfer data of the int type. | | code | number | Yes | No | Result code of the common event, which is used to transfer data of the int type. |
| data | Yes | No | string | Custom result data of the common event, which is used to transfer data of the string type.| | data | string | Yes | No | Custom result data of the common event, which is used to transfer data of the string type.|
| parameters | Yes | No | {[key: string]: any} | Additional information about the common event. | | parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
## CommonEventPublishData ## CommonEventPublishData
Describes the data body published by a common event, including the common event content and attributes.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
| Name | Readable| Writable| Type | Description | | Name | Type | Readable| Writable| Description |
| --------------------- | ---- | ---- | -------------------- | ---------------------------- | | --------------------- | -------------------- | ---- | ---- | ---------------------------- |
| bundleName | Yes | No | string | Bundle name. | | bundleName | string | Yes | No | Bundle name. |
| code | Yes | No | number | Result code of the common event. | | code | number | Yes | No | Result code of the common event. |
| data | Yes | No | string | Custom result data of the common event.| | data | string | Yes | No | Custom result data of the common event.|
| subscriberPermissions | Yes | No | Array\<string> | Permissions required for subscribers to receive the common event. | | subscriberPermissions | Array\<string> | Yes | No | Permissions required for subscribers to receive the common event. |
| isOrdered | Yes | No | boolean | Whether the common event is an ordered one. | | isOrdered | boolean | Yes | No | Whether the common event is an ordered one. |
| isSticky | Yes | No | boolean | Whether the common event is a sticky one. | | isSticky | boolean | Yes | No | Whether the common event is a sticky one. Only system applications and system services are allowed to send sticky events.|
| parameters | Yes | No | {[key: string]: any} | Additional information about the common event. | | parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
## CommonEventSubscribeInfo ## CommonEventSubscribeInfo
Provides the subscriber information.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
| Name | Readable| Writable| Type | Description | | Name | Type | Readable| Writable| Description |
| ------------------- | ---- | ---- | -------------- | ------------------------------------------------------------ | | ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| events | Yes | No | Array\<string> | Name of the common event to publish. | | events | Array\<string> | Yes | No | Name of the common event to publish. |
| publisherPermission | Yes | No | string | Permissions required for publishers to publish the common event. | | publisherPermission | string | Yes | No | Permissions required for publishers to publish the common event. |
| publisherDeviceId | Yes | No | string | Device ID. The value must be the ID of an existing device on the same network. | | publisherDeviceId | string | Yes | No | Device ID. The value must be the ID of an existing device on the same network. |
| userId | Yes | No | number | User ID. The default value is the ID of the current user. If this parameter is specified, the value must be an existing user ID in the system.| | userId | number | Yes | No | User ID. The default value is the ID of the current user. If this parameter is specified, the value must be an existing user ID in the system.|
| priority | Yes | No | number | Subscriber priority. The value ranges from -100 to 1000. | | priority | number | Yes | No | Subscriber priority. The value ranges from -100 to +1000. |
# @ohos.commonEventManager
The **CommonEventManager** module provides common event capabilities, including the capabilities to publish, subscribe to, and unsubscribe from common events, as well obtaining and setting the common event result code and result data.
> **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 CommonEventManager from '@ohos.commonEventManager';
```
## Support
The table below lists the event types supported by the **CommonEventManager** module. The name and value indicate the macro and name of a common event, respectively.
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Value | Subscriber Permission | Description |
| ------------ | ------------------ | ---------------------- | -------------------- |
| COMMON_EVENT_BOOT_COMPLETED | usual.event.BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the user has finished booting and the system has been loaded. |
| COMMON_EVENT_LOCKED_BOOT_COMPLETED | usual.event.LOCKED_BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the user has finished booting and the system has been loaded but the screen is still locked. |
| COMMON_EVENT_SHUTDOWN | usual.event.SHUTDOWN | - | Indicates the common event that the device is being shut down and the final shutdown will proceed. |
| COMMON_EVENT_BATTERY_CHANGED | usual.event.BATTERY_CHANGED | - | Indicates the common event that the charging state, level, and other information about the battery have changed. |
| COMMON_EVENT_BATTERY_LOW | usual.event.BATTERY_LOW | - | Indicates the common event that the battery level is low. |
| COMMON_EVENT_BATTERY_OKAY | usual.event.BATTERY_OKAY | - | Indicates the common event that the battery exits the low state. |
| COMMON_EVENT_POWER_CONNECTED | usual.event.POWER_CONNECTED | - | Indicates the common event that the device is connected to an external power supply. |
| COMMON_EVENT_POWER_DISCONNECTED | usual.event.POWER_DISCONNECTED | - | Indicates the common event that the device is disconnected from the external power supply. |
| COMMON_EVENT_SCREEN_OFF | usual.event.SCREEN_OFF | - | Indicates the common event that the device screen is off and the device is sleeping. |
| COMMON_EVENT_SCREEN_ON | usual.event.SCREEN_ON | - | Indicates the common event that the device screen is on and the device is in interactive state. |
| COMMON_EVENT_THERMAL_LEVEL_CHANGED | usual.event.THERMAL_LEVEL_CHANGED | - | Indicates the common event that the device's thermal level has changed. |
| COMMON_EVENT_USER_PRESENT | usual.event.USER_PRESENT | - | Indicates the common event that the user unlocks the device. |
| COMMON_EVENT_TIME_TICK | usual.event.TIME_TICK | - | Indicates the common event that the system time has changed. |
| COMMON_EVENT_TIME_CHANGED | usual.event.TIME_CHANGED | - | Indicates the common event that the system time is set. |
| COMMON_EVENT_DATE_CHANGED | usual.event.DATE_CHANGED | - | Indicates the common event that the system time has changed. |
| COMMON_EVENT_TIMEZONE_CHANGED | usual.event.TIMEZONE_CHANGED | - | Indicates the common event that the system time zone has changed. |
| COMMON_EVENT_CLOSE_SYSTEM_DIALOGS | usual.event.CLOSE_SYSTEM_DIALOGS | - | Indicates the common event that a user closes a temporary system dialog box. |
| COMMON_EVENT_PACKAGE_ADDED | usual.event.PACKAGE_ADDED | - | Indicates the common event that a new application package has been installed on the device. |
| COMMON_EVENT_PACKAGE_REPLACED | usual.event.PACKAGE_REPLACED | - | Indicates the common event that a later version of an installed application package has replaced the previous one on the device. |
| COMMON_EVENT_MY_PACKAGE_REPLACED | usual.event.MY_PACKAGE_REPLACED | - | Indicates the common event that a later version of your application package has replaced the previous one.
| COMMON_EVENT_PACKAGE_REMOVED | usual.event.PACKAGE_REMOVED | - | Indicates the common event that an installed application has been uninstalled from the device with the application data retained. |
| COMMON_EVENT_BUNDLE_REMOVED | usual.event.BUNDLE_REMOVED | - | Indicates the common event that an installed bundle has been uninstalled from the device with the application data retained. |
| COMMON_EVENT_PACKAGE_FULLY_REMOVED | usual.event.PACKAGE_FULLY_REMOVED | - | Indicates the common event that an installed application, including both the application data and code, has been completely uninstalled from the device. |
| COMMON_EVENT_PACKAGE_CHANGED | usual.event.PACKAGE_CHANGED | - | Indicates the common event that an application package has been changed (for example, a component in the package has been enabled or disabled). |
| COMMON_EVENT_PACKAGE_RESTARTED | usual.event.PACKAGE_RESTARTED | - | Indicates the common event that the user has restarted the application package and killed all its processes. |
| COMMON_EVENT_PACKAGE_DATA_CLEARED | usual.event.PACKAGE_DATA_CLEARED | - | Indicates the common event that the user has cleared the application package data. |
| COMMON_EVENT_PACKAGE_CACHE_CLEARED<sup>9+</sup> | usual.event.PACKAGE_CACHE_CLEARED | - | Indicates the common event that the user has cleared the application package data. |
| COMMON_EVENT_PACKAGES_SUSPENDED | usual.event.PACKAGES_SUSPENDED | - | Indicates the common event that application packages have been suspended. |
| COMMON_EVENT_PACKAGES_UNSUSPENDED | usual.event.PACKAGES_UNSUSPENDED | - | Indicates the common event that application package has not been suspended. |
| COMMON_EVENT_MY_PACKAGE_SUSPENDED | usual.event.MY_PACKAGE_SUSPENDED | - | Indicates the common event that an application package has been suspended. |
| COMMON_EVENT_MY_PACKAGE_UNSUSPENDED | usual.event.MY_PACKAGE_UNSUSPENDED | - | Indicates the common event that application package has not been suspended. |
| COMMON_EVENT_UID_REMOVED | usual.event.UID_REMOVED | - | Indicates the common event that a user ID has been removed from the system. |
| COMMON_EVENT_PACKAGE_FIRST_LAUNCH | usual.event.PACKAGE_FIRST_LAUNCH | - | Indicates the common event that an installed application is started for the first time. |
| COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION | usual.event.PACKAGE_NEEDS_VERIFICATION | - | Indicates the common event that an application requires system verification. |
| COMMON_EVENT_PACKAGE_VERIFIED | usual.event.PACKAGE_VERIFIED | - | Indicates the common event that an application has been verified by the system. |
| COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE | usual.event.EXTERNAL_APPLICATIONS_AVAILABLE | - | Indicates the common event that applications installed on the external storage become available for the system. |
| COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE | usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE | - | Indicates the common event that applications installed on the external storage become unavailable for the system. |
| COMMON_EVENT_CONFIGURATION_CHANGED | usual.event.CONFIGURATION_CHANGED | - | Indicates the common event that the device state (for example, orientation and locale) has changed. |
| COMMON_EVENT_LOCALE_CHANGED | usual.event.LOCALE_CHANGED | - | Indicates the common event that the device locale has changed. |
| COMMON_EVENT_MANAGE_PACKAGE_STORAGE | usual.event.MANAGE_PACKAGE_STORAGE | - | Indicates the common event that the device storage is insufficient. |
| COMMON_EVENT_DRIVE_MODE | common.event.DRIVE_MODE | - | Indicates the common event that the system is in driving mode. |
| COMMON_EVENT_HOME_MODE | common.event.HOME_MODE | - | Indicates the common event that the system is in home mode. |
| COMMON_EVENT_OFFICE_MODE | common.event.OFFICE_MODE | - | Indicates the common event that the system is in office mode. |
| COMMON_EVENT_USER_STARTED | usual.event.USER_STARTED | - | Indicates the common event that the user has been started. |
| COMMON_EVENT_USER_BACKGROUND | usual.event.USER_BACKGROUND | - | Indicates the common event that the user has been brought to the background. |
| COMMON_EVENT_USER_FOREGROUND | usual.event.USER_FOREGROUND | - | Indicates the common event that the user has been brought to the foreground. |
| COMMON_EVENT_USER_SWITCHED | usual.event.USER_SWITCHED | ohos.permission.MANAGE_LOCAL_ACCOUNTS | Indicates the common event that user switching is happening. |
| COMMON_EVENT_USER_STARTING | usual.event.USER_STARTING | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | Indicates the common event that the user is going to be started. |
| COMMON_EVENT_USER_UNLOCKED | usual.event.USER_UNLOCKED | - | Indicates the common event that the credential-encrypted storage has been unlocked for the current user when the device is unlocked after being restarted. |
| COMMON_EVENT_USER_STOPPING | usual.event.USER_STOPPING | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | Indicates the common event that the user is going to be stopped. |
| COMMON_EVENT_USER_STOPPED | usual.event.USER_STOPPED | - | Indicates the common event that the user has been stopped. |
| COMMON_EVENT_DISTRIBUTED_ACCOUNT_LOGIN | usual.event.DISTRIBUTED_ACCOUNT_LOGIN | - | Indicates the action of successful login using a distributed account. |
| COMMON_EVENT_DISTRIBUTED_ACCOUNT_LOGOUT | usual.event.DISTRIBUTED_ACCOUNT_LOGOUT | - | Indicates the action of successful logout of a distributed account. |
| COMMON_EVENT_DISTRIBUTED_ACCOUNT_TOKEN_INVALID | usual.event.DISTRIBUTED_ACCOUNT_TOKEN_INVALID | - | Indicates the action when the token of a distributed account is invalid. |
| COMMON_EVENT_DISTRIBUTED_ACCOUNT_LOGOFF | usual.event.DISTRIBUTED_ACCOUNT_LOGOFF | - | Indicates the action of deregistering a distributed account. |
| COMMON_EVENT_WIFI_POWER_STATE | usual.event.wifi.POWER_STATE | - | Indicates the common event about the Wi-Fi network state, such as enabled and disabled. |
| COMMON_EVENT_WIFI_SCAN_FINISHED | usual.event.wifi.SCAN_FINISHED | ohos.permission.LOCATION | Indicates the common event that the Wi-Fi access point has been scanned and proven to be available. |
| COMMON_EVENT_WIFI_RSSI_VALUE | usual.event.wifi.RSSI_VALUE | ohos.permission.GET_WIFI_INFO | Indicates the common event that the Wi-Fi signal strength (RSSI) has changed. |
| COMMON_EVENT_WIFI_CONN_STATE | usual.event.wifi.CONN_STATE | - | Indicates the common event that the Wi-Fi connection state has changed. |
| COMMON_EVENT_WIFI_HOTSPOT_STATE | usual.event.wifi.HOTSPOT_STATE | - | Indicates the common event about the Wi-Fi hotspot state, such as enabled or disabled. |
| COMMON_EVENT_WIFI_AP_STA_JOIN | usual.event.wifi.WIFI_HS_STA_JOIN | ohos.permission.GET_WIFI_INFO | Indicates the common event that a client has joined the Wi-Fi hotspot of the current device. |
| COMMON_EVENT_WIFI_AP_STA_LEAVE | usual.event.wifi.WIFI_HS_STA_LEAVE | ohos.permission.GET_WIFI_INFO |Indicates the common event that a client has disconnected from the Wi-Fi hotspot of the current device. |
| COMMON_EVENT_WIFI_MPLINK_STATE_CHANGE | usual.event.wifi.mplink.STATE_CHANGE | ohos.permission.MPLINK_CHANGE_STATE | Indicates the common event that the state of MPLINK (an enhanced Wi-Fi feature) has changed. |
| COMMON_EVENT_WIFI_P2P_CONN_STATE | usual.event.wifi.p2p.CONN_STATE_CHANGE | ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION | Indicates the common event that the Wi-Fi P2P connection state has changed. |
| COMMON_EVENT_WIFI_P2P_STATE_CHANGED | usual.event.wifi.p2p.STATE_CHANGE | ohos.permission.GET_WIFI_INFO | Indicates the common event about the Wi-Fi P2P state, such as enabled and disabled. |
| COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED | usual.event.wifi.p2p.DEVICES_CHANGE | ohos.permission.GET_WIFI_INFO | Indicates the common event about the status change of Wi-Fi P2P peer devices. |
| COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED | usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE | ohos.permission.GET_WIFI_INFO | Indicates the common event about the Wi-Fi P2P discovery status change. |
| COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED | usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE | ohos.permission.GET_WIFI_INFO | Indicates the common event about the status change of the Wi-Fi P2P local device. |
| COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED | usual.event.wifi.p2p.GROUP_STATE_CHANGED | ohos.permission.GET_WIFI_INFO | Indicates the common event that the Wi-Fi P2P group information has changed. |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfree.ag.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event about the connection state of Bluetooth handsfree communication. |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CURRENT_DEVICE_UPDATE | usual.event.bluetooth.handsfree.ag.CURRENT_DEVICE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the device connected to the Bluetooth handsfree is active. |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfree.ag.AUDIO_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the connection state of Bluetooth A2DP has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event about the connection state of Bluetooth A2DP. |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CURRENT_DEVICE_UPDATE | usual.event.bluetooth.a2dpsource.CURRENT_DEVICE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the device connected using Bluetooth A2DP is active. |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_PLAYING_STATE_UPDATE | usual.event.bluetooth.a2dpsource.PLAYING_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the playing state of Bluetooth A2DP has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the AVRCP connection state of Bluetooth A2DP has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE | usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the audio codec state of Bluetooth A2DP has changed. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED | usual.event.bluetooth.remotedevice.DISCOVERED | ohos.permission.LOCATION and ohos.permission.USE_BLUETOOTH | Indicates the common event that a remote Bluetooth device is discovered. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CLASS_VALUE_UPDATE | usual.event.bluetooth.remotedevice.CLASS_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the Bluetooth class of a remote Bluetooth device has changed. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_CONNECTED | usual.event.bluetooth.remotedevice.ACL_CONNECTED | ohos.permission.USE_BLUETOOTH | Indicates the common event that a low-ACL connection has been established with a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED | usual.event.bluetooth.remotedevice.ACL_DISCONNECTED | ohos.permission.USE_BLUETOOTH | Indicates the common event that a low-ACL connection has been disconnected from a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE | usual.event.bluetooth.remotedevice.NAME_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the friendly name of a remote Bluetooth device is retrieved for the first time or is changed since the last retrieval. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE | usual.event.bluetooth.remotedevice.PAIR_STATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the connection state of a remote Bluetooth device has changed. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_BATTERY_VALUE_UPDATE | usual.event.bluetooth.remotedevice.BATTERY_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the battery level of a remote Bluetooth device is retrieved for the first time or is changed since the last retrieval. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT | usual.event.bluetooth.remotedevice.SDP_RESULT | - | Indicates the common event about the SDP state of a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_UUID_VALUE | usual.event.bluetooth.remotedevice.UUID_VALUE | ohos.permission.DISCOVER_BLUETOOTH | Indicates the common event about the UUID connection state of a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_REQ | usual.event.bluetooth.remotedevice.PAIRING_REQ | ohos.permission.DISCOVER_BLUETOOTH | Indicates the common event about the pairing request from a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL | usual.event.bluetooth.remotedevice.PAIRING_CANCEL | - | Indicates the common event that Bluetooth pairing is canceled. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ | usual.event.bluetooth.remotedevice.CONNECT_REQ | - | Indicates the common event about the connection request from a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY | usual.event.bluetooth.remotedevice.CONNECT_REPLY | - | Indicates the common event about the response to the connection request from a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL | usual.event.bluetooth.remotedevice.CONNECT_CANCEL | - | Indicates the common event that the connection to a remote Bluetooth device has been canceled. |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE | - | Indicates the common event that the connection state of a Bluetooth handsfree has changed. |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE | - | Indicates the common event that the audio state of a Bluetooth handsfree has changed. |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT | usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT | - | Indicates the common event that the audio gateway state of a Bluetooth handsfree has changed. |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE | - | Indicates the common event that the calling state of a Bluetooth handsfree has changed. |
| COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE | usual.event.bluetooth.host.STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the state of a Bluetooth adapter has been changed, for example, Bluetooth has been enabled or disabled. |
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE | usual.event.bluetooth.host.REQ_DISCOVERABLE | - | Indicates the common event about the request for the user to allow Bluetooth device scanning. |
| COMMON_EVENT_BLUETOOTH_HOST_REQ_ENABLE | usual.event.bluetooth.host.REQ_ENABLE | ohos.permission.USE_BLUETOOTH | Indicates the common event about the request for the user to enable Bluetooth. |
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISABLE | usual.event.bluetooth.host.REQ_DISABLE | ohos.permission.USE_BLUETOOTH | Indicates the common event about the request for the user to disable Bluetooth. |
| COMMON_EVENT_BLUETOOTH_HOST_SCAN_MODE_UPDATE | usual.event.bluetooth.host.SCAN_MODE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the Bluetooth scanning mode of a device has changed. |
| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_STARTED | usual.event.bluetooth.host.DISCOVERY_STARTED | ohos.permission.USE_BLUETOOTH | Indicates the common event that the Bluetooth scanning has been started on the device. |
| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_FINISHED | usual.event.bluetooth.host.DISCOVERY_FINISHED | ohos.permission.USE_BLUETOOTH | Indicates the common event that the Bluetooth scanning is finished on the device. |
| COMMON_EVENT_BLUETOOTH_HOST_NAME_UPDATE | usual.event.bluetooth.host.NAME_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the Bluetooth adapter name of the device has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsink.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the connection state of Bluetooth A2DP Sink has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_PLAYING_STATE_UPDATE | usual.event.bluetooth.a2dpsink.PLAYING_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the playing state of Bluetooth A2DP Sink has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_AUDIO_STATE_UPDATE | usual.event.bluetooth.a2dpsink.AUDIO_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the audio state of Bluetooth A2DP Sink has changed. |
| COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED | usual.event.nfc.action.ADAPTER_STATE_CHANGED | - | Indicates the common event that the state of the device's NFC adapter has changed. |
| COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED | usual.event.nfc.action.RF_FIELD_ON_DETECTED | ohos.permission.MANAGE_SECURE_SETTINGS | Indicates the action of a common event that the NFC RF field is detected to be in the enabled state. |
| COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED | usual.event.nfc.action.RF_FIELD_OFF_DETECTED | ohos.permission.MANAGE_SECURE_SETTINGS | Indicates the common event that the NFC RF field is detected to be in the disabled state. |
| COMMON_EVENT_DISCHARGING | usual.event.DISCHARGING | - | Indicates the common event that the system stops charging the battery. |
| COMMON_EVENT_CHARGING | usual.event.CHARGING | - | Indicates the common event that the system starts charging the battery. |
| COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED | usual.event.DEVICE_IDLE_MODE_CHANGED | - | Indicates the common event that the system idle mode has changed. |
| COMMON_EVENT_POWER_SAVE_MODE_CHANGED | usual.event.POWER_SAVE_MODE_CHANGED | - | Indicates the common event that the power saving mode of the system has changed. |
| COMMON_EVENT_USER_ADDED | usual.event.USER_ADDED | ohos.permission.MANAGE_LOCAL_ACCOUNTS | Indicates the common event that a user has been added to the system. |
| COMMON_EVENT_USER_REMOVED | usual.event.USER_REMOVED | ohos.permission.MANAGE_LOCAL_ACCOUNTS | Indicates the common event that a user has been removed from the system. |
| COMMON_EVENT_ABILITY_ADDED | usual.event.ABILITY_ADDED | ohos.permission.LISTEN_BUNDLE_CHANGE | Indicates the common event that an ability has been added. |
| COMMON_EVENT_ABILITY_REMOVED | usual.event.ABILITY_REMOVED | ohos.permission.LISTEN_BUNDLE_CHANGE | Indicates the common event that an ability has been removed. |
| COMMON_EVENT_ABILITY_UPDATED | usual.event.ABILITY_UPDATED | ohos.permission.LISTEN_BUNDLE_CHANGE | Indicates the common event that an ability has been updated. |
| COMMON_EVENT_LOCATION_MODE_STATE_CHANGED | usual.event.location.MODE_STATE_CHANGED | - | Indicates the common event that the location mode of the system has changed. |
| COMMON_EVENT_IVI_SLEEP | common.event.IVI_SLEEP | - | Indicates the common event that the in-vehicle infotainment (IVI) system of a vehicle is sleeping. |
| COMMON_EVENT_IVI_PAUSE | common.event.IVI_PAUSE | - | Indicates the common event that the IVI system of a vehicle has entered sleep mode and the playing application is instructed to stop playback. |
| COMMON_EVENT_IVI_STANDBY | common.event.IVI_STANDBY | - | Indicates the common event that a third-party application is instructed to pause the current work. |
| COMMON_EVENT_IVI_LASTMODE_SAVE | common.event.IVI_LASTMODE_SAVE | - | Indicates the common event that a third-party application is instructed to save its last mode. |
| COMMON_EVENT_IVI_VOLTAGE_ABNORMAL | common.event.IVI_VOLTAGE_ABNORMAL | - | Indicates the common event that the voltage of the vehicle's power system is abnormal. |
| COMMON_EVENT_IVI_HIGH_TEMPERATURE | common.event.IVI_HIGH_TEMPERATURE | - | Indicates the common event that the temperature of the IVI system is high. |
| COMMON_EVENT_IVI_EXTREME_TEMPERATURE | common.event.IVI_EXTREME_TEMPERATURE | - | Indicates the common event that the temperature of the IVI system is extremely high. |
| COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL | common.event.IVI_TEMPERATURE_ABNORMAL | - | Indicates the common event that the IVI system has an extreme temperature. |
| COMMON_EVENT_IVI_VOLTAGE_RECOVERY | common.event.IVI_VOLTAGE_RECOVERY | - | Indicates the common event that the voltage of the vehicle's power system is restored to normal. |
| COMMON_EVENT_IVI_TEMPERATURE_RECOVERY | common.event.IVI_TEMPERATURE_RECOVERY | - | Indicates the common event that the temperature of the IVI system is restored to normal. |
| COMMON_EVENT_IVI_ACTIVE | common.event.IVI_ACTIVE | - | Indicates the common event that the battery service is active. |
|COMMON_EVENT_USB_STATE<sup>9+</sup> | usual.event.hardware.usb.action.USB_STATE | - | Indicates a common event indicating that the USB device status changes. |
|COMMON_EVENT_USB_PORT_CHANGED<sup>9+</sup> | usual.event.hardware.usb.action.USB_PORT_CHANGED | - | Indicates the public event that the USB port status of the user device changes. |
| COMMON_EVENT_USB_DEVICE_ATTACHED | usual.event.hardware.usb.action.USB_DEVICE_ATTACHED | - | Indicates the common event that a USB device has been attached when the user device functions as a USB host. |
| COMMON_EVENT_USB_DEVICE_DETACHED | usual.event.hardware.usb.action.USB_DEVICE_DETACHED | - | Indicates the common event that a USB device has been detached when the user device functions as a USB host. |
| COMMON_EVENT_USB_ACCESSORY_ATTACHED | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED | - | Indicates the common event that a USB accessory was attached. |
| COMMON_EVENT_USB_ACCESSORY_DETACHED | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED | - | Indicates the common event that a USB accessory was detached. |
| COMMON_EVENT_DISK_REMOVED | usual.event.data.DISK_REMOVED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was removed. |
| COMMON_EVENT_DISK_UNMOUNTED | usual.event.data.DISK_UNMOUNTED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was unmounted. |
| COMMON_EVENT_DISK_MOUNTED | usual.event.data.DISK_MOUNTED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was mounted. |
| COMMON_EVENT_DISK_BAD_REMOVAL | usual.event.data.DISK_BAD_REMOVAL | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was removed without being unmounted. |
| COMMON_EVENT_DISK_UNMOUNTABLE | usual.event.data.DISK_UNMOUNTABLE | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device becomes unmountable. |
| COMMON_EVENT_DISK_EJECT | usual.event.data.DISK_EJECT | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was ejected. |
| COMMON_EVENT_VOLUME_REMOVED<sup>9+<sup> | usual.event.data.VOLUME_REMOVED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was removed. |
| COMMON_EVENT_VOLUME_UNMOUNTED<sup>9+<sup> | usual.event.data.VOLUME_UNMOUNTED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was unmounted. |
| COMMON_EVENT_VOLUME_MOUNTED<sup>9+<sup> | usual.event.data.VOLUME_MOUNTED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was mounted. |
| COMMON_EVENT_VOLUME_BAD_REMOVAL<sup>9+<sup> | usual.event.data.VOLUME_BAD_REMOVAL | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was removed without being unmounted. |
| COMMON_EVENT_VOLUME_EJECT<sup>9+<sup> | usual.event.data.VOLUME_EJECT | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was ejected. |
| COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED | usual.event.data.VISIBLE_ACCOUNTS_UPDATED | ohos.permission.GET_APP_ACCOUNTS | Indicates the common event that the account visibility changed. |
| COMMON_EVENT_ACCOUNT_DELETED | usual.event.data.ACCOUNT_DELETED | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | Indicates the common event that the account was deleted. |
| COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the foundation is ready. |
| COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | - | Indicates the common event that the airplane mode of the device has changed. |
| COMMON_EVENT_SPLIT_SCREEN | usual.event.SPLIT_SCREEN | ohos.permission.RECEIVER_SPLIT_SCREEN | Indicates the common event of screen splitting. |
| COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has been updated. |
| COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | - | Indicates the common event that the SPN displayed has been updated. |
| COMMON_EVENT_QUICK_FIX_APPLY_RESULT <sup>9+<sup> | usual.event.QUICK_FIX_APPLY_RESULT | - | Indicates the common event that a quick fix is applied to the application. |
## CommonEventManager.publish
publish(event: string, callback: AsyncCallback\<void>): void
Publishes a common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------- |
| event | string | Yes | Name of the common event to publish.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Error codes**
For details about the error codes, see [Event Error Codes](../errorcodes/errorcode-CommonEventService.md).
|ID |Error Message |
|-----------|--------------------|
|1500004 |not System services or System app|
|1500007 |message send error|
|1500008 |CEMS error|
|1500009 |system error|
**Example**
```ts
// Callback for common event publication
function publishCallBack(err) {
if (err) {
console.error("publish failed " + JSON.stringify(err));
} else {
console.info("publish");
}
}
// Publish a common event.
try {
CommonEventManager.publish("event", publishCallBack);
} catch(err) {
console.error('publish failed, catch error' + JSON.stringify(err));
}
```
## CommonEventManager.publish
publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\<void>): void
Publishes a common event with given attributes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | Yes | Name of the common event to publish. |
| options | [CommonEventPublishData](#commoneventpublishdata) | Yes | Attributes of the common event to publish.|
| callback | syncCallback\<void> | Yes | Callback used to return the result. |
**Error codes**
|ID |Error Message |
|-----------|--------------------|
|1500004 |not System services or System app|
|1500007 |message send error|
|1500008 |CEMS error|
|1500009 |system error|
**Example**
```ts
// Attributes of a common event.
var options = {
code: 0, // Result code of the common event.
data: "initial data",// Result data of the common event.
isOrdered: true // The common event is an ordered one.
}
// Callback for common event publication
function publishCallBack(err) {
if (err) {
console.error("publish failed " + JSON.stringify(err));
} else {
console.info("publish");
}
}
// Publish a common event.
try {
CommonEventManager.publish("event", options, publishCallBack);
} catch (err) {
console.error('publish failed, catch error' + JSON.stringify(err));
}
```
## CommonEventManager.publishAsUser<sup>
publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): void
Publishes a common event to a specific user. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------------- |
| event | string | Yes | Name of the common event to publish. |
| userId | number | Yes | User ID.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Error codes**
|ID |Error Message |
|-----------|--------------------|
|1500004 |not System services or System app|
|1500007 |message send error|
|1500008 |CEMS error|
|1500009 |system error|
**Example**
```ts
// Callback for common event publication
function publishAsUserCallBack(err) {
if (err) {
console.error("publishAsUser failed " + JSON.stringify(err));
} else {
console.info("publishAsUser");
}
}
// Specify the user to whom the common event will be published.
var userId = 100;
// Publish a common event.
try {
CommonEventManager.publishAsUser("event", userId, publishAsUserCallBack);
} catch (err) {
console.error('publishAsUser failed, catch error' + JSON.stringify(err));
}
```
## CommonEventManager.publishAsUser
publishAsUser(event: string, userId: number, options: CommonEventPublishData, callback: AsyncCallback\<void>): void
Publishes a common event with given attributes to a specific user. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | Yes | Name of the common event to publish. |
| userId | number | Yes| User ID.|
| options | [CommonEventPublishData](#commoneventpublishdata) | Yes | Attributes of the common event to publish.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Error codes**
|ID |Error Message |
|-----------|--------------------|
|1500004 |not System services or System app|
|1500007 |message send error|
|1500008 |CEMS error|
|1500009 |system error|
**Example**
```ts
// Attributes of a common event.
var options = {
code: 0, // Result code of the common event.
data: "initial data",// Result data of the common event.
}
// Callback for common event publication
function publishAsUserCallBack(err) {
if (err) {
console.error("publishAsUser failed " + JSON.stringify(err));
} else {
console.info("publishAsUser");
}
}
// Specify the user to whom the common event will be published.
var userId = 100;
// Publish a common event.
try {
CommonEventManager.publishAsUser("event", userId, options, publishAsUserCallBack);
} catch (err) {
console.error('publishAsUser failed, catch error' + JSON.stringify(err));
}
```
## CommonEventManager.createSubscriber
createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\<CommonEventSubscriber>): void
Creates a subscriber. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------------------------------------ | ---- | -------------------------- |
| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes | Subscriber information. |
| callback | AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | Yes | Callback used to return the result.|
**Example**
```ts
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information.
var subscribeInfo = {
events: ["event"]
};
// Callback for subscriber creation.
function createSubscriberCallBack(err, commonEventSubscriber) {
if(!err) {
console.info("createSubscriber");
subscriber = commonEventSubscriber;
} else {
console.error("createSubscriber failed " + JSON.stringify(err));
}
}
// Create a subscriber.
try {
CommonEventManager.createSubscriber(subscribeInfo, createSubscriberCallBack);
} catch (err) {
console.error('createSubscriber failed, catch error' + JSON.stringify(err));
}
```
## CommonEventManager.createSubscriber
createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventSubscriber>
Creates a subscriber. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ----------------------------------------------------- | ---- | -------------- |
| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes | Subscriber information.|
**Return value**
| Type | Description |
| --------------------------------------------------------- | ---------------- |
| Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | Promise used to return the subscriber object.|
**Example**
```ts
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information.
var subscribeInfo = {
events: ["event"]
};
// Create a subscriber.
try {
CommonEventManager.createSubscriber(subscribeInfo).then((commonEventSubscriber) => {
console.info("createSubscriber");
subscriber = commonEventSubscriber;
}).catch((err) => {
console.error("createSubscriber failed " + JSON.stringify(err));
});
} catch(err) {
console.error('createSubscriber failed, catch error' + JSON.stringify(err));
}
```
## CommonEventManager.subscribe
subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEventData>): void
Subscribes to common events. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ---------------------------------------------------- | ---- | -------------------------------- |
| subscriber | [CommonEventSubscriber](#commoneventsubscriber) | Yes | Subscriber object. |
| callback | AsyncCallback\<[CommonEventData](#commoneventdata)> | Yes | Callback used to return the result.|
**Example**
```ts
// Subscriber information.
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information.
var subscribeInfo = {
events: ["event"]
};
// Callback for common event subscription.
function SubscribeCallBack(err, data) {
if (err.code) {
console.error("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribe ");
}
}
// Callback for subscriber creation.
function createSubscriberCallBack(err, commonEventSubscriber) {
if(!err) {
console.info("createSubscriber");
subscriber = commonEventSubscriber;
// Subscribe to a common event.
try {
CommonEventManager.subscribe(subscriber, SubscribeCallBack);
} catch (err) {
console.error("createSubscriber failed " + JSON.stringify(err));
}
} else {
console.error("createSubscriber failed " + JSON.stringify(err));
}
}
// Create a subscriber.
try {
CommonEventManager.createSubscriber(subscribeInfo, createSubscriberCallBack);
} catch (err) {
console.error('createSubscriber failed, catch error' + JSON.stringify(err));
}
```
## CommonEventManager.unsubscribe
unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>): void
Unsubscribes from common events. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ----------------------------------------------- | ---- | ------------------------ |
| subscriber | [CommonEventSubscriber](#commoneventsubscriber) | Yes | Subscriber object. |
| callback | AsyncCallback\<void> | No | Callback used to return the result.|
**Example**
```ts
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information.
var subscribeInfo = {
events: ["event"]
};
// Callback for common event subscription.
function subscribeCallBack(err, data) {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribe");
}
}
// Callback for subscriber creation.
function createSubscriberCallBack(err, commonEventSubscriber) {
if (err) {
console.info("createSubscriber failed " + JSON.stringify(err));
} else {
console.info("createSubscriber");
subscriber = commonEventSubscriber;
// Subscribe to a common event.
try {
CommonEventManager.subscribe(subscriber, subscribeCallBack);
} catch(err) {
console.info("subscribe failed " + JSON.stringify(err));
}
}
}
// Callback for common event unsubscription.
function unsubscribeCallBack(err) {
if (err) {
console.info("unsubscribe failed " + JSON.stringify(err));
} else {
console.info("unsubscribe");
}
}
// Create a subscriber.
try {
CommonEventManager.createSubscriber(subscribeInfo, createSubscriberCallBack);
} catch (err) {
console.info("createSubscriber failed " + JSON.stringify(err));
}
// Unsubscribe from the common event.
try {
CommonEventManager.unsubscribe(subscriber, unsubscribeCallBack);
} catch (err) {
console.info("unsubscribe failed " + JSON.stringify(err));
}
```
## CommonEventSubscriber
### getCode
getCode(callback: AsyncCallback\<number>): void
Obtains the result code of this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------ |
| callback | AsyncCallback\<number> | Yes | Callback used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for result code obtaining of an ordered common event.
function getCodeCallback(err, Code) {
if (err.code) {
console.error("getCode failed " + JSON.stringify(err));
} else {
console.info("getCode " + JSON.stringify(Code));
}
}
subscriber.getCode(getCodeCallback);
```
### getCode
getCode(): Promise\<number>
Obtains the result code of this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<number> | Promise used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.getCode().then((Code) => {
console.info("getCode " + JSON.stringify(Code));
}).catch((err) => {
console.error("getCode failed " + JSON.stringify(err));
});
```
### setCode
setCode(code: number, callback: AsyncCallback\<void>): void
Sets the result code for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | Yes | Result code of the common event. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for result code setting of an ordered common event.
function setCodeCallback(err) {
if (err.code) {
console.error("setCode failed " + JSON.stringify(err));
} else {
console.info("setCode");
}
}
subscriber.setCode(1, setCodeCallback);
```
### setCode
setCode(code: number): Promise\<void>
Sets the result code for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| code | number | Yes | Result code of the common event.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.setCode(1).then(() => {
console.info("setCode");
}).catch((err) => {
console.error("setCode failed " + JSON.stringify(err));
});
```
### getData
getData(callback: AsyncCallback\<string>): void
Obtains the result data of this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the result data.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for result data obtaining of an ordered common event.
function getDataCallback(err, Data) {
if (err.code) {
console.error("getData failed " + JSON.stringify(err));
} else {
console.info("getData " + JSON.stringify(Data));
}
}
subscriber.getData(getDataCallback);
```
### getData
getData(): Promise\<string>
Obtains the result data of this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | ------------------ |
| Promise\<string> | Promise used to return the result data.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.getData().then((Data) => {
console.info("getData " + JSON.stringify(Data));
}).catch((err) => {
console.error("getData failed " + JSON.stringify(err));
});
```
### setData
setData(data: string, callback: AsyncCallback\<void>): void
Sets the result data for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| data | string | Yes | Result data of the common event. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for result data setting of an ordered common event
function setDataCallback(err) {
if (err.code) {
console.error("setData failed " + JSON.stringify(err));
} else {
console.info("setData");
}
}
subscriber.setData("publish_data_changed", setDataCallback);
```
### setData
setData(data: string): Promise\<void>
Sets the result data for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------- |
| data | string | Yes | Result data of the common event.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.setData("publish_data_changed").then(() => {
console.info("setData");
}).catch((err) => {
console.error("setData failed " + JSON.stringify(err));
});
```
### setCodeAndData
setCodeAndData(code: number, data: string, callback:AsyncCallback\<void>): void
Sets the result code and result data for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | Yes | Result code of the common event. |
| data | string | Yes | Result data of the common event. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for result code and result data setting of an ordered common event.
function setCodeDataCallback(err) {
if (err.code) {
console.error("setCodeAndData failed " + JSON.stringify(err));
} else {
console.info("setCodeDataCallback");
}
}
subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCallback);
```
### setCodeAndData
setCodeAndData(code: number, data: string): Promise\<void>
Sets the result code and result data for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------- |
| code | number | Yes | Result code of the common event.|
| data | string | Yes | Result data of the common event.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.setCodeAndData(1, "publish_data_changed").then(() => {
console.info("setCodeAndData");
}).catch((err) => {
console.info("setCodeAndData failed " + JSON.stringify(err));
});
```
### isOrderedCommonEvent
isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void
Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The value **true** means that the common event is an ordered one; and **false** means the opposite.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is an ordered one.
function isOrderedCallback(err, isOrdered) {
if (err.code) {
console.error("isOrderedCommonEvent failed " + JSON.stringify(err));
} else {
console.info("isOrdered " + JSON.stringify(isOrdered));
}
}
subscriber.isOrderedCommonEvent(isOrderedCallback);
```
### isOrderedCommonEvent
isOrderedCommonEvent(): Promise\<boolean>
Checks whether this common event is an ordered one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | -------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the common event is an ordered one; and **false** means the opposite.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.isOrderedCommonEvent().then((isOrdered) => {
console.info("isOrdered " + JSON.stringify(isOrdered));
}).catch((err) => {
console.error("isOrdered failed " + JSON.stringify(err));
});
```
### isStickyCommonEvent
isStickyCommonEvent(callback: AsyncCallback\<boolean>): void
Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The value **true** means that the common event is a sticky one; and **false** means the opposite.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is a sticky one.
function isStickyCallback(err, isSticky) {
if (err.code) {
console.error("isStickyCommonEvent failed " + JSON.stringify(err));
} else {
console.info("isSticky " + JSON.stringify(isSticky));
}
}
subscriber.isStickyCommonEvent(isStickyCallback);
```
### isStickyCommonEvent
isStickyCommonEvent(): Promise\<boolean>
Checks whether this common event is a sticky one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | -------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the common event is a sticky one; and **false** means the opposite.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.isStickyCommonEvent().then((isSticky) => {
console.info("isSticky " + JSON.stringify(isSticky));
}).catch((err) => {
console.error("isSticky failed " + JSON.stringify(err));
});
```
### abortCommonEvent
abortCommonEvent(callback: AsyncCallback\<void>): void
Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for common event aborting.
function abortCallback(err) {
if (err.code) {
console.error("abortCommonEvent failed " + JSON.stringify(err));
} else {
console.info("abortCommonEvent");
}
}
subscriber.abortCommonEvent(abortCallback);
```
### abortCommonEvent
abortCommonEvent(): Promise\<void>
Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.abortCommonEvent().then(() => {
console.info("abortCommonEvent");
}).catch((err) => {
console.error("abortCommonEvent failed " + JSON.stringify(err));
});
```
### clearAbortCommonEvent
clearAbortCommonEvent(callback: AsyncCallback\<void>): void
Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for clearing the aborted state of the current common event.
function clearAbortCallback(err) {
if (err.code) {
console.error("clearAbortCommonEvent failed " + JSON.stringify(err));
} else {
console.info("clearAbortCommonEvent");
}
}
subscriber.clearAbortCommonEvent(clearAbortCallback);
```
### clearAbortCommonEvent
clearAbortCommonEvent(): Promise\<void>
Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.clearAbortCommonEvent().then(() => {
console.info("clearAbortCommonEvent");
}).catch((err) => {
console.error("clearAbortCommonEvent failed " + JSON.stringify(err));
});
```
### getAbortCommonEvent
getAbortCommonEvent(callback: AsyncCallback\<boolean>): void
Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The value **true** means that the ordered common event is in the aborted state; and **false** means the opposite.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is in the aborted state.
function getAbortCallback(err, AbortCommonEvent) {
if (err.code) {
console.error("getAbortCommonEvent failed " + JSON.stringify(err));
} else {
console.info("AbortCommonEvent " + AbortCommonEvent)
}
}
subscriber.getAbortCommonEvent(getAbortCallback);
```
### getAbortCommonEvent
getAbortCommonEvent(): Promise\<boolean>
Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | ---------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the ordered common event is in the aborted state; and **false** means the opposite.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.getAbortCommonEvent().then((AbortCommonEvent) => {
console.info("AbortCommonEvent " + JSON.stringify(AbortCommonEvent));
}).catch((err) => {
console.error("getAbortCommonEvent failed " + JSON.stringify(err));
});
```
### getSubscribeInfo
getSubscribeInfo(callback: AsyncCallback\<CommonEventSubscribeInfo>): void
Obtains the subscriber information. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Yes | Callback used to return the subscriber information.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for subscriber information obtaining.
function getSubscribeInfoCallback(err, SubscribeInfo) {
if (err.code) {
console.error("getSubscribeInfo failed " + JSON.stringify(err));
} else {
console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo));
}
}
subscriber.getSubscribeInfo(getSubscribeInfoCallback);
```
### getSubscribeInfo
getSubscribeInfo(): Promise\<CommonEventSubscribeInfo>
Obtains the subscriber information. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ---------------------- |
| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Promise used to return the subscriber information.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.getSubscribeInfo().then((SubscribeInfo) => {
console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo));
}).catch((err) => {
console.error("getSubscribeInfo failed " + JSON.stringify(err));
});
```
### finishCommonEvent<sup>9+</sup>
finishCommonEvent(callback: AsyncCallback\<void\>): void
Finishes this ordered common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback returned after the ordered common event is finished.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
// Callback for ordered common event finishing.
function finishCommonEventCallback(err) {
if (err.code) {
console.error("finishCommonEvent failed " + JSON.stringify(err));
} else {
console.info("FinishCommonEvent");
}
}
subscriber.finishCommonEvent(finishCommonEventCallback);
```
### finishCommonEvent<sup>9+</sup>
finishCommonEvent(): Promise\<void\>
Finishes this ordered common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
var subscriber; // Subscriber object successfully created.
subscriber.finishCommonEvent().then(() => {
console.info("FinishCommonEvent");
}).catch((err) => {
console.error("finishCommonEvent failed " + JSON.stringify(err));
});
```
## CommonEventData
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- |
| event | string | Yes | No | Name of the common event that is being received. |
| bundleName | string | Yes | No | Bundle name. |
| code | number | Yes | No | Result code of the common event, which is used to transfer data of the int type. |
| data | string | Yes | No | Custom result data of the common event, which is used to transfer data of the string type.|
| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
## CommonEventPublishData
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| --------------------- | -------------------- | ---- | ---- | ---------------------------- |
| bundleName | string | Yes | No | Bundle name. |
| code | number | Yes | No | Result code of the common event. |
| data | string | Yes | No | Custom result data of the common event.|
| subscriberPermissions | Array\<string> | Yes | No | Permissions required for subscribers to receive the common event. |
| isOrdered | boolean | Yes | No | Whether the common event is an ordered one. |
| isSticky | boolean | Yes | No | Whether the common event is a sticky one. Only system applications and system services are allowed to send sticky events.|
| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
## CommonEventSubscribeInfo
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| events | Array\<string> | Yes | No | Name of the common event to publish. |
| publisherPermission | string | Yes | No | Permissions required for publishers to publish the common event. |
| publisherDeviceId | string | Yes | No | Device ID. The value must be the ID of an existing device on the same network. |
| userId | number | Yes | No | User ID. The default value is the ID of the current user. If this parameter is specified, the value must be an existing user ID in the system.|
| priority | number | Yes | No | Subscriber priority. The value ranges from -100 to +1000. |
...@@ -804,7 +804,7 @@ router.replace({ ...@@ -804,7 +804,7 @@ router.replace({
}); });
``` ```
## router.replace<sup>(deprecated)</sup> ## router.replace<sup>(deprecated)</sup>
replace(options: RouterOptions, mode: RouterMode): void replace(options: RouterOptions, mode: RouterMode): void
......
# Web # Web
The **<Web\>** component can be used to display web pages.
> **NOTE** > **NOTE**
> >
> - This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. > - This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
> - You can preview how this component looks on a real device. The preview is not yet available in the DevEco Studio Previewer. > - You can preview how this component looks on a real device. The preview is not yet available in the DevEco Studio Previewer.
The **<Web\>** component can be used to display web pages.
## Required Permissions ## Required Permissions
To use online resources, the application must have the **ohos.permission.INTERNET** permission. For details about how to apply for a permission, see [Declaring Permissions](../../security/accesstoken-guidelines.md). To use online resources, the application must have the **ohos.permission.INTERNET** permission. For details about how to apply for a permission, see [Declaring Permissions](../../security/accesstoken-guidelines.md).
...@@ -25,9 +25,9 @@ Web(options: { src: ResourceStr, controller: WebController | WebviewController}) ...@@ -25,9 +25,9 @@ Web(options: { src: ResourceStr, controller: WebController | WebviewController})
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------- | ------------------------------- | ---- | ------- | | ---------- | ---------------------------------------- | ---- | ------- |
| src | [ResourceStr](ts-types.md) | Yes | Address of a web page resource.| | src | [ResourceStr](ts-types.md) | Yes | Address of a web page resource.|
| controller | [WebController](#webcontroller) or WebviewController |Yes | Controller. | | controller | [WebController](#webcontroller) \| [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller) | Yes | Controller. |
**Example** **Example**
...@@ -88,7 +88,7 @@ Web(options: { src: ResourceStr, controller: WebController | WebviewController}) ...@@ -88,7 +88,7 @@ Web(options: { src: ResourceStr, controller: WebController | WebviewController})
## Attributes ## Attributes
The **\<Web>** component has network attributes. Only the following universal attributes are supported: [width](ts-universal-attributes-size.md#Attributes), [height](ts-universal-attributes-size.md#attributes), [padding](ts-universal-attributes-size.md#Attributes), [margin](ts-universal-attributes-size.md#attributes), and [border](ts-universal-attributes-border.md#attributes).
### domStorageAccess ### domStorageAccess
...@@ -99,7 +99,7 @@ Sets whether to enable the DOM Storage API. By default, this feature is disabled ...@@ -99,7 +99,7 @@ Sets whether to enable the DOM Storage API. By default, this feature is disabled
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ---------------- | ------- | ---- | ---- | ------------------------------------ | | ---------------- | ------- | ---- | ----- | ------------------------------------ |
| domStorageAccess | boolean | Yes | false | Whether to enable the DOM Storage API.| | domStorageAccess | boolean | Yes | false | Whether to enable the DOM Storage API.|
**Example** **Example**
...@@ -123,12 +123,12 @@ Sets whether to enable the DOM Storage API. By default, this feature is disabled ...@@ -123,12 +123,12 @@ Sets whether to enable the DOM Storage API. By default, this feature is disabled
fileAccess(fileAccess: boolean) fileAccess(fileAccess: boolean)
Sets whether to enable access to the file system in the application. Access to the files in **rawfile** specified through [$rawfile(filepath/filename)](../../quick-start/resource-categories-and-access.md) are not affected by the setting. Sets whether to enable access to the file system in the application. This setting does not affect the access to the files specified through [$rawfile(filepath/filename)](../../quick-start/resource-categories-and-access.md).
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ---------- | ------- | ---- | ---- | ---------------------------------------- | | ---------- | ------- | ---- | ---- | ---------------------- |
| fileAccess | boolean | Yes | true | Whether to enable access to the file system in the application. By default, this feature is enabled.| | fileAccess | boolean | Yes | true | Whether to enable access to the file system in the application. By default, this feature is enabled.|
**Example** **Example**
...@@ -148,35 +148,6 @@ Sets whether to enable access to the file system in the application. Access to t ...@@ -148,35 +148,6 @@ Sets whether to enable access to the file system in the application. Access to t
} }
``` ```
### fileFromUrlAccess<sup>9+</sup>
fileFromUrlAccess(fileFromUrlAccess: boolean)
Sets whether to allow the use of JavaScript scripts on web pages for access to content in the application file system. By default, this feature is disabled. Access to the files in **rawfile** specified through [$rawfile(filepath/filename)](../../quick-start/resource-categories-and-access.md) are not affected by the setting.
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
| ----------------- | ------- | ---- | ----- | ---------------------------------------- |
| fileFromUrlAccess | boolean | Yes | false | Whether to allow the use of JavaScript scripts on web pages for access to content in the application file system. By default, this feature is disabled.|
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.fileFromUrlAccess(true)
}
}
}
```
### imageAccess ### imageAccess
imageAccess(imageAccess: boolean) imageAccess(imageAccess: boolean)
...@@ -187,7 +158,7 @@ Sets whether to enable automatic image loading. By default, this feature is enab ...@@ -187,7 +158,7 @@ Sets whether to enable automatic image loading. By default, this feature is enab
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ----------- | ------- | ---- | ---- | --------------- | | ----------- | ------- | ---- | ---- | --------------- |
| imageAccess | boolean | Yes | true | Whether to enable automatic image loading. By default, this feature is enabled.| | imageAccess | boolean | Yes | true | Whether to enable automatic image loading.|
**Example** **Example**
```ts ```ts
...@@ -210,16 +181,16 @@ Sets whether to enable automatic image loading. By default, this feature is enab ...@@ -210,16 +181,16 @@ Sets whether to enable automatic image loading. By default, this feature is enab
javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Array\<string\>, javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Array\<string\>,
controller: WebController | WebviewController}) controller: WebController | WebviewController})
Injects a JavaScript object into the window. Methods of this object can be invoked in the window. The parameters cannot be updated. Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. The parameters cannot be updated.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ---------- | --------------- | ---- | ---- | ------------------------- | | ---------- | ---------------------------------------- | ---- | ---- | ------------------------- |
| object | object | Yes | - | Object to be registered. Methods can be declared, but attributes cannot. | | object | object | Yes | - | Object to be registered. Methods can be declared, but attributes cannot. |
| name | string | Yes | - | Name of the object to be registered, which is the same as that invoked in the window.| | name | string | Yes | - | Name of the object to be registered, which is the same as that invoked in the window.|
| methodList | Array\<string\> | Yes | - | Methods of the JavaScript object to be registered at the application side. | | methodList | Array\<string\> | Yes | - | Methods of the JavaScript object to be registered at the application side. |
| controller | [WebController](#webcontroller) or WebviewController | Yes | - | Controller. | | controller | [WebController](#webcontroller) or [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | Yes | - | Controller. |
**Example** **Example**
...@@ -326,7 +297,7 @@ Sets whether to enable loading of HTTP and HTTPS hybrid content can be loaded. B ...@@ -326,7 +297,7 @@ Sets whether to enable loading of HTTP and HTTPS hybrid content can be loaded. B
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| --------- | --------------------------- | ---- | ---- | --------- | | --------- | --------------------------- | ---- | -------------- | --------- |
| mixedMode | [MixedMode](#mixedmode)| Yes | MixedMode.None | Mixed content to load.| | mixedMode | [MixedMode](#mixedmode)| Yes | MixedMode.None | Mixed content to load.|
**Example** **Example**
...@@ -443,7 +414,7 @@ Sets whether to enable database access. By default, this feature is disabled. ...@@ -443,7 +414,7 @@ Sets whether to enable database access. By default, this feature is disabled.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------------- | ------- | ---- | ---- | ----------------- | | -------------- | ------- | ---- | ----- | ----------------- |
| databaseAccess | boolean | Yes | false | Whether to enable database access.| | databaseAccess | boolean | Yes | false | Whether to enable database access.|
**Example** **Example**
...@@ -472,7 +443,7 @@ Sets whether to enable geolocation access. By default, this feature is enabled. ...@@ -472,7 +443,7 @@ Sets whether to enable geolocation access. By default, this feature is enabled.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------------- | ------- | ---- | ---- | ----------------- | | ----------------- | ------- | ---- | ---- | --------------- |
| geolocationAccess | boolean | Yes | true | Whether to enable geolocation access.| | geolocationAccess | boolean | Yes | true | Whether to enable geolocation access.|
**Example** **Example**
...@@ -496,13 +467,13 @@ Sets whether to enable geolocation access. By default, this feature is enabled. ...@@ -496,13 +467,13 @@ Sets whether to enable geolocation access. By default, this feature is enabled.
mediaPlayGestureAccess(access: boolean) mediaPlayGestureAccess(access: boolean)
Sets whether a manual click is required for video playback. Sets whether video playback must be started by user gestures. This API is not applicable to videos that do not have an audio track or whose audio track is muted.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| --------- | ------ | ---- | ---- | --------- | | ------ | ------- | ---- | ---- | ----------------- |
| access | boolean | Yes | true | Whether a manual click is required for video playback.| | access | boolean | Yes | true | Whether video playback must be started by user gestures.|
**Example** **Example**
...@@ -531,7 +502,7 @@ Sets whether to enable the multi-window permission. ...@@ -531,7 +502,7 @@ Sets whether to enable the multi-window permission.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------------- | ------- | ---- | ---- | ----------------- | | ----------- | ------- | ---- | ----- | ------------ |
| multiWindow | boolean | Yes | false | Whether to enable the multi-window permission.| | multiWindow | boolean | Yes | false | Whether to enable the multi-window permission.|
**Example** **Example**
...@@ -560,7 +531,7 @@ Sets the cache mode. ...@@ -560,7 +531,7 @@ Sets the cache mode.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| --------- | --------------------------- | ---- | ---- | --------- | | --------- | --------------------------- | ---- | ----------------- | --------- |
| cacheMode | [CacheMode](#cachemode)| Yes | CacheMode.Default | Cache mode to set.| | cacheMode | [CacheMode](#cachemode)| Yes | CacheMode.Default | Cache mode to set.|
**Example** **Example**
...@@ -590,7 +561,7 @@ Sets the text zoom ratio of the page. The default value is **100**, which indica ...@@ -590,7 +561,7 @@ Sets the text zoom ratio of the page. The default value is **100**, which indica
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ------------ | ------ | ---- | ---- | --------------- | | ------------- | ------ | ---- | ---- | --------------- |
| textZoomRatio | number | Yes | 100 | Text zoom ratio to set.| | textZoomRatio | number | Yes | 100 | Text zoom ratio to set.|
**Example** **Example**
...@@ -620,7 +591,7 @@ Sets the scale factor of the entire page. The default value is 100%. ...@@ -620,7 +591,7 @@ Sets the scale factor of the entire page. The default value is 100%.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ------------ | ------ | ---- | ---- | --------------- | | ------- | ------ | ---- | ---- | --------------- |
| percent | number | Yes | 100 | Scale factor of the entire page.| | percent | number | Yes | 100 | Scale factor of the entire page.|
**Example** **Example**
...@@ -680,7 +651,7 @@ Sets whether to enable web debugging. ...@@ -680,7 +651,7 @@ Sets whether to enable web debugging.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| --------- | ------ | ---- | ---- | --------- | | ------------------ | ------- | ---- | ----- | ------------- |
| webDebuggingAccess | boolean | Yes | false | Whether to enable web debugging.| | webDebuggingAccess | boolean | Yes | false | Whether to enable web debugging.|
**Example** **Example**
...@@ -701,10 +672,6 @@ Sets whether to enable web debugging. ...@@ -701,10 +672,6 @@ Sets whether to enable web debugging.
} }
``` ```
> **NOTE**<br>
>
> Only the following universal attributes are supported: [width](ts-universal-attributes-size.md#Attributes), [height](ts-universal-attributes-size.md#attributes), [padding](ts-universal-attributes-size.md#Attributes), [margin](ts-universal-attributes-size.md#attributes), and [border](ts-universal-attributes-border.md#attributes).
## Events ## Events
The universal events are not supported. The universal events are not supported.
...@@ -721,7 +688,7 @@ Triggered when **alert()** is invoked to display an alert dialog box on the web ...@@ -721,7 +688,7 @@ Triggered when **alert()** is invoked to display an alert dialog box on the web
| ------- | --------------------- | --------------- | | ------- | --------------------- | --------------- |
| url | string | URL of the web page where the dialog box is displayed.| | url | string | URL of the web page where the dialog box is displayed.|
| message | string | Message displayed in the dialog box. | | message | string | Message displayed in the dialog box. |
| result | [JsResult](#jsresult) | The user's operation. | | result | [JsResult](#jsresult) | User operation. |
**Return value** **Return value**
...@@ -771,7 +738,7 @@ Triggered when **alert()** is invoked to display an alert dialog box on the web ...@@ -771,7 +738,7 @@ Triggered when **alert()** is invoked to display an alert dialog box on the web
onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResult }) => boolean) onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)
Triggered when the current page is about to exit after the user refreshes or closes the page. If the user refreshes the page, this callback is invoked only when the page has obtained focus. Triggered when this page is about to exit after the user refreshes or closes the page. This callback is triggered only when the page has obtained focus.
**Parameters** **Parameters**
...@@ -779,7 +746,7 @@ Triggered when the current page is about to exit after the user refreshes or clo ...@@ -779,7 +746,7 @@ Triggered when the current page is about to exit after the user refreshes or clo
| ------- | --------------------- | --------------- | | ------- | --------------------- | --------------- |
| url | string | URL of the web page where the dialog box is displayed.| | url | string | URL of the web page where the dialog box is displayed.|
| message | string | Message displayed in the dialog box. | | message | string | Message displayed in the dialog box. |
| result | [JsResult](#jsresult) | The user's operation. | | result | [JsResult](#jsresult) | User operation. |
**Return value** **Return value**
...@@ -840,7 +807,7 @@ Triggered when **confirm()** is invoked by the web page. ...@@ -840,7 +807,7 @@ Triggered when **confirm()** is invoked by the web page.
| ------- | --------------------- | --------------- | | ------- | --------------------- | --------------- |
| url | string | URL of the web page where the dialog box is displayed.| | url | string | URL of the web page where the dialog box is displayed.|
| message | string | Message displayed in the dialog box. | | message | string | Message displayed in the dialog box. |
| result | [JsResult](#jsresult) | The user's operation. | | result | [JsResult](#jsresult) | User operation. |
**Return value** **Return value**
...@@ -900,7 +867,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul ...@@ -900,7 +867,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
| ------- | --------------------- | --------------- | | ------- | --------------------- | --------------- |
| url | string | URL of the web page where the dialog box is displayed.| | url | string | URL of the web page where the dialog box is displayed.|
| message | string | Message displayed in the dialog box. | | message | string | Message displayed in the dialog box. |
| result | [JsResult](#jsresult) | The user's operation. | | result | [JsResult](#jsresult) | User operation. |
**Return value** **Return value**
...@@ -1084,7 +1051,7 @@ Triggered when an HTTP error (the response code is greater than or equal to 400) ...@@ -1084,7 +1051,7 @@ Triggered when an HTTP error (the response code is greater than or equal to 400)
| Name | Type | Description | | Name | Type | Description |
| ------- | ---------------------------------------- | --------------- | | ------- | ---------------------------------------- | --------------- |
| request | [WebResourceRequest](#webresourcerequest) | Encapsulation of a web page request. | | request | [WebResourceRequest](#webresourcerequest) | Encapsulation of a web page request. |
| error | [WebResourceError](#webresourceerror) | Encapsulation of a web page resource loading error.| | response | [WebResourceResponse](#webresourceresponse) | Encapsulation of a resource response.|
**Example** **Example**
...@@ -1263,7 +1230,7 @@ Triggered when loading of the web page is complete. This API is used by an appli ...@@ -1263,7 +1230,7 @@ Triggered when loading of the web page is complete. This API is used by an appli
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ----------- | ------- | --------------------------------- | | ----------- | ------- | ---------------------------------------- |
| url | string | URL to be accessed. | | url | string | URL to be accessed. |
| isRefreshed | boolean | Whether the page is reloaded. The value **true** means that the page is reloaded by invoking the [refresh](#refresh) API, and **false** means the opposite.| | isRefreshed | boolean | Whether the page is reloaded. The value **true** means that the page is reloaded by invoking the [refresh](#refresh) API, and **false** means the opposite.|
...@@ -1287,7 +1254,7 @@ Triggered when loading of the web page is complete. This API is used by an appli ...@@ -1287,7 +1254,7 @@ Triggered when loading of the web page is complete. This API is used by an appli
} }
``` ```
### onRenderExited ### onRenderExited<sup>9+</sup>
onRenderExited(callback: (event?: { renderExitReason: RenderExitReason }) => void) onRenderExited(callback: (event?: { renderExitReason: RenderExitReason }) => void)
...@@ -1335,7 +1302,7 @@ Triggered to process an HTML form whose input type is **file**, in response to t ...@@ -1335,7 +1302,7 @@ Triggered to process an HTML form whose input type is **file**, in response to t
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ----------------------------------- | | ------- | ---------------------------------------- |
| boolean | The value **true** means that the pop-up window provided by the system is displayed. The value **false** means that the default web pop-up window is displayed.| | boolean | The value **true** means that the pop-up window provided by the system is displayed. The value **false** means that the default web pop-up window is displayed.|
**Example** **Example**
...@@ -1384,7 +1351,7 @@ Invoked to notify the **\<Web>** component of the URL of the loaded resource fil ...@@ -1384,7 +1351,7 @@ Invoked to notify the **\<Web>** component of the URL of the loaded resource fil
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ---- | ---------------------------------------- | --------- | | ---- | ------ | -------------- |
| url | string | URL of the loaded resource file.| | url | string | URL of the loaded resource file.|
**Example** **Example**
...@@ -1416,7 +1383,7 @@ Invoked when the display ratio of this page changes. ...@@ -1416,7 +1383,7 @@ Invoked when the display ratio of this page changes.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ---- | ---------------------------------------- | --------- | | -------- | ------ | ------------ |
| oldScale | number | Display ratio of the page before the change.| | oldScale | number | Display ratio of the page before the change.|
| newScale | number | Display ratio of the page after the change.| | newScale | number | Display ratio of the page after the change.|
...@@ -1494,7 +1461,7 @@ Invoked when the **\<Web>** component is about to access a URL. This API is used ...@@ -1494,7 +1461,7 @@ Invoked when the **\<Web>** component is about to access a URL. This API is used
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------------- | --------------------------- | | ---------------------------------------- | ---------------------------------------- |
| [WebResourceResponse](#webresourceresponse) | If response data is returned, the data is loaded based on the response data. If no response data is returned, null is returned, indicating that the data is loaded in the original mode.| | [WebResourceResponse](#webresourceresponse) | If response data is returned, the data is loaded based on the response data. If no response data is returned, null is returned, indicating that the data is loaded in the original mode.|
**Example** **Example**
...@@ -1554,7 +1521,7 @@ Invoked when an HTTP authentication request is received. ...@@ -1554,7 +1521,7 @@ Invoked when an HTTP authentication request is received.
| Name | Type | Description | | Name | Type | Description |
| ------- | ------------------------------------ | ---------------- | | ------- | ------------------------------------ | ---------------- |
| handler | [HttpAuthHandler](#httpauthhandler9) | The user's operation. | | handler | [HttpAuthHandler](#httpauthhandler9) | User operation. |
| host | string | Host to which HTTP authentication credentials apply.| | host | string | Host to which HTTP authentication credentials apply.|
| realm | string | Realm to which HTTP authentication credentials apply. | | realm | string | Realm to which HTTP authentication credentials apply. |
...@@ -1622,9 +1589,9 @@ Invoked when an SSL error occurs during resource loading. ...@@ -1622,9 +1589,9 @@ Invoked when an SSL error occurs during resource loading.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ------- | ------------------------------------ | ---------------- | | ------- | ------------------------------------ | -------------- |
| handler | [SslErrorHandler](#sslerrorhandler9) | The user's operation.| | handler | [SslErrorHandler](#sslerrorhandler9) | User operation.|
| error | [SslError](#sslerror9) | Error code.| | error | [SslError](#sslerror9) | Error code. |
**Example** **Example**
...@@ -1668,19 +1635,19 @@ Invoked when an SSL error occurs during resource loading. ...@@ -1668,19 +1635,19 @@ Invoked when an SSL error occurs during resource loading.
### onClientAuthenticationRequest<sup>9+</sup> ### onClientAuthenticationRequest<sup>9+</sup>
onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationHandler, host : string, port : number, keyTypes : Array\<string>, issuers : Array\<string>}) => void) onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationHandler, host : string, port : number, keyTypes : Array<string>, issuers : Array<string>}) => void)
Invoked when an SSL client certificate request is received. Invoked when an SSL client certificate request is received.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ------- | ------------------------------------ | ---------------- | | -------- | ---------------------------------------- | --------------- |
| handler | [ClientAuthenticationHandler](#clientauthenticationhandler9) | The user's operation.| | handler | [ClientAuthenticationHandler](#clientauthenticationhandler9) | User operation. |
| host | string | Host name of the server that requests a certificate.| | host | string | Host name of the server that requests a certificate. |
| port | number | Port number of the server that requests a certificate.| | port | number | Port number of the server that requests a certificate. |
| keyTypes| Array\<string> | Acceptable asymmetric private key types.| | keyTypes | Array<string> | Acceptable asymmetric private key types. |
| issuers | Array\<string> | Issuer of the certificate that matches the private key.| | issuers | Array<string> | Issuer of the certificate that matches the private key.|
**Example** **Example**
```ts ```ts
...@@ -1730,8 +1697,8 @@ Invoked when a permission request is received. ...@@ -1730,8 +1697,8 @@ Invoked when a permission request is received.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ------- | ------------------------------------ | ---------------- | | ------- | ---------------------------------------- | -------------- |
| request | [PermissionRequest](#permissionrequest9) | The user's operation. | | request | [PermissionRequest](#permissionrequest9) | User operation.|
**Example** **Example**
...@@ -1774,19 +1741,19 @@ Invoked when a permission request is received. ...@@ -1774,19 +1741,19 @@ Invoked when a permission request is received.
onContextMenuShow(callback: (event?: { param: WebContextMenuParam, result: WebContextMenuResult }) => boolean) onContextMenuShow(callback: (event?: { param: WebContextMenuParam, result: WebContextMenuResult }) => boolean)
Invoked when a context menu is displayed upon a long press on a specific element (such as an image or link). Shows a context menu after the user long presses a specific element, such as an image or a link.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ------- | ------------------------------------ | ---------------- | | ------ | ---------------------------------------- | ----------- |
| param | [WebContextMenuParam](#webcontextmenuparam9) | Parameters related to the context menu.| | param | [WebContextMenuParam](#webcontextmenuparam9) | Parameters related to the context menu. |
| result | [WebContextMenuResult](#webcontextmenuresult9) | Result of the context menu.| | result | [WebContextMenuResult](#webcontextmenuresult9) | Result of the context menu.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------------------- | | ------- | ------------------------ |
| boolean | The value **true** means a custom menu, and **false** means the default menu.| | boolean | The value **true** means a custom menu, and **false** means the default menu.|
**Example** **Example**
...@@ -1819,7 +1786,7 @@ Invoked when the scrollbar of the page scrolls. ...@@ -1819,7 +1786,7 @@ Invoked when the scrollbar of the page scrolls.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ------- | ------------------------------------ | ---------------- | | ------- | ------ | ------------ |
| xOffset | number | Position of the scrollbar on the x-axis.| | xOffset | number | Position of the scrollbar on the x-axis.|
| yOffset | number | Position of the scrollbar on the y-axis.| | yOffset | number | Position of the scrollbar on the y-axis.|
...@@ -1852,9 +1819,9 @@ Registers a callback for receiving a request to obtain the geolocation informati ...@@ -1852,9 +1819,9 @@ Registers a callback for receiving a request to obtain the geolocation informati
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ----------- | ------------------------------- | ---------------- | | ----------- | ------------------------------- | -------------- |
| origin | string | Index of the origin. | | origin | string | Index of the origin. |
| geolocation | [JsGeolocation](#jsgeolocation) | The user's operation.| | geolocation | [JsGeolocation](#jsgeolocation) | User operation.|
**Example** **Example**
...@@ -1897,7 +1864,7 @@ Triggered to notify the user that the request for obtaining the geolocation info ...@@ -1897,7 +1864,7 @@ Triggered to notify the user that the request for obtaining the geolocation info
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ----------- | ------------------------------- | ---------------- | | -------- | ---------- | -------------------- |
| callback | () => void | Callback invoked when the request for obtaining geolocation information has been canceled. | | callback | () => void | Callback invoked when the request for obtaining geolocation information has been canceled. |
**Example** **Example**
...@@ -1929,7 +1896,7 @@ Registers a callback for the component's entering into full screen mode. ...@@ -1929,7 +1896,7 @@ Registers a callback for the component's entering into full screen mode.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ----------- | ------------------------------- | ---------------- | | ------- | ---------------------------------------- | -------------- |
| handler | [FullScreenExitHandler](#fullscreenexithandler9) | Function handle for exiting full screen mode.| | handler | [FullScreenExitHandler](#fullscreenexithandler9) | Function handle for exiting full screen mode.|
**Example** **Example**
...@@ -1962,7 +1929,7 @@ Registers a callback for the component's exiting full screen mode. ...@@ -1962,7 +1929,7 @@ Registers a callback for the component's exiting full screen mode.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ----------- | ------------------------------- | ---------------- | | -------- | ---------- | ------------- |
| callback | () => void | Callback invoked when the component exits full screen mode.| | callback | () => void | Callback invoked when the component exits full screen mode.|
**Example** **Example**
...@@ -1998,11 +1965,11 @@ Registers a callback for window creation. ...@@ -1998,11 +1965,11 @@ Registers a callback for window creation.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ----------- | ------------------------------- | ---------------- | | ------------- | ---------------------------------------- | -------------------------- |
| isAlert | boolean | Whether to open the target URL in a new window. The value **true** means to open the target URL in a new window, and **false** means to open the target URL in a new tab.| | isAlert | boolean | Whether to open the target URL in a new window. The value **true** means to open the target URL in a new window, and **false** means to open the target URL in a new tab.|
| isUserTrigger | boolean | Whether the creation is triggered by the user. The value **true** means that the creation is triggered by the user, and **false** means the opposite.| | isUserTrigger | boolean | Whether the creation is triggered by the user. The value **true** means that the creation is triggered by the user, and **false** means the opposite. |
| targetUrl | string | Target URL.| | targetUrl | string | Target URL. |
| handler | [ControllerHandler](#controllerhandler9) | **WebController** instance for setting the new window.| | handler | [ControllerHandler](#controllerhandler9) | **WebController** instance for setting the new window. |
**Example** **Example**
...@@ -2011,14 +1978,14 @@ Registers a callback for window creation. ...@@ -2011,14 +1978,14 @@ Registers a callback for window creation.
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller:WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src:'www.example.com', controller: this.controller }) Web({ src:'www.example.com', controller: this.controller })
.multiWindowAccess(true) .multiWindowAccess(true)
.onWindowNew((event) => { .onWindowNew((event) => {
console.log("onWindowNew...") console.log("onWindowNew...")
var popController: WebController = new WebController() var popController: web_webview.WebviewController = new web_webview.WebviewController()
event.handler.setWebController(popController) event.handler.setWebController(popController)
}) })
} }
...@@ -2035,7 +2002,7 @@ Registers a callback for window closure. ...@@ -2035,7 +2002,7 @@ Registers a callback for window closure.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ----------- | ------------------------------- | ---------------- | | -------- | ---------- | ------------ |
| callback | () => void | Callback invoked when the window closes.| | callback | () => void | Callback invoked when the window closes.|
**Example** **Example**
...@@ -2057,9 +2024,44 @@ Registers a callback for window closure. ...@@ -2057,9 +2024,44 @@ Registers a callback for window closure.
} }
``` ```
### onSearchResultReceive<sup>9+</sup>
onSearchResultReceive(callback: (event?: {activeMatchOrdinal: number, numberOfMatches: number, isDoneCounting: boolean}) => void): WebAttribute
Invoked to notify the caller of the search result on the web page.
**Parameters**
| Name | Type | Description |
| ------------------ | ------- | ---------------------------------------- |
| activeMatchOrdinal | number | Sequence number of the current match, which starts from 0. |
| numberOfMatches | number | Total number of matches. |
| isDoneCounting | boolean | Whether the search operation on the current page is complete. This API may be called multiple times until **isDoneCounting** is **true**.|
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.onSearchResultReceive(ret => {
console.log("on search result receive:" + "[cur]" + ret.activeMatchOrdinal +
"[total]" + ret.numberOfMatches + "[isDone]"+ ret.isDoneCounting)
})
}
}
}
```
## ConsoleMessage ## ConsoleMessage
Implements the **ConsoleMessage** object. For details about the sample code, see [onConsole](#onconsole). Implements the **ConsoleMessage** object. For the sample code, see [onConsole](#onconsole).
### getLineNumber ### getLineNumber
...@@ -2111,7 +2113,7 @@ Obtains the path and name of the web page source file. ...@@ -2111,7 +2113,7 @@ Obtains the path and name of the web page source file.
## JsResult ## JsResult
Implements the **JsResult** object, which indicates the result returned to the **\<Web>** component to indicate the user operation performed in the dialog box. For details about the sample code, see [onAlert Event](#onalert). Implements the **JsResult** object, which indicates the result returned to the **\<Web>** component to indicate the user operation performed in the dialog box. For the sample code, see [onAlert Event](#onalert).
### handleCancel ### handleCancel
...@@ -2139,7 +2141,7 @@ Notifies the **\<Web>** component of the user's confirm operation in the dialog ...@@ -2139,7 +2141,7 @@ Notifies the **\<Web>** component of the user's confirm operation in the dialog
## FullScreenExitHandler<sup>9+</sup> ## FullScreenExitHandler<sup>9+</sup>
Defines a **FullScreenExitHandler** for listening for exiting full screen mode. For the sample code, see [onFullScreenEnter](#onfullscreenenter9). Implements a **FullScreenExitHandler** object for listening for exiting full screen mode. For the sample code, see [onFullScreenEnter](#onfullscreenenter9).
### exitFullScreen<sup>9+</sup> ### exitFullScreen<sup>9+</sup>
...@@ -2149,23 +2151,23 @@ Exits full screen mode. ...@@ -2149,23 +2151,23 @@ Exits full screen mode.
## ControllerHandler<sup>9+</sup> ## ControllerHandler<sup>9+</sup>
Defines a **WebController** for new web components. For the sample code, see [onWindowNew](#onwindownew9). Implements a **WebviewController** object for new **\<Web>** components. For the sample code, see [onWindowNew](#onwindownew9).
### setWebController<sup>9+</sup> ### setWebController<sup>9+</sup>
setWebController(controller: WebController): void setWebController(controller: WebviewController): void
Sets a **WebController** object. Sets a **WebviewController** object.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ------ | ------ | ---- | ---- | ----------- | | ---------- | ------------- | ---- | ---- | ------------------------- |
| controller | WebController | Yes | - | **WebController** object to set.| | controller | [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | Yes | - | **WebviewController** object of the **\<Web>** component.|
## WebResourceError ## WebResourceError
Implements the **WebResourceError** object. For details about the sample code, see [onErrorReceive](#onerrorreceive). Implements the **WebResourceError** object. For the sample code, see [onErrorReceive](#onerrorreceive).
### getErrorCode ### getErrorCode
...@@ -2193,7 +2195,7 @@ Obtains error information about resource loading. ...@@ -2193,7 +2195,7 @@ Obtains error information about resource loading.
## WebResourceRequest ## WebResourceRequest
Implements the **WebResourceRequest** object. For details about the sample code, see [onErrorReceive](#onerrorreceive). Implements the **WebResourceRequest** object. For the sample code, see [onErrorReceive](#onerrorreceive).
### getRequestHeader ### getRequestHeader
...@@ -2267,7 +2269,7 @@ Describes the request/response header returned by the **\<Web>** component. ...@@ -2267,7 +2269,7 @@ Describes the request/response header returned by the **\<Web>** component.
## WebResourceResponse ## WebResourceResponse
Implements the **WebResourceResponse** object. For details about the sample code, see [onHttpErrorReceive](#onhttperrorreceive). Implements the **WebResourceResponse** object. For the sample code, see [onHttpErrorReceive](#onhttperrorreceive).
### getReasonMessage ### getReasonMessage
...@@ -2349,9 +2351,9 @@ Sets the data in the resource response. ...@@ -2349,9 +2351,9 @@ Sets the data in the resource response.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name| Type | Mandatory| Default Value| Description |
| ---- | ------ | ---- | ---- | ----------- | | ------ | ---------------- | ---- | ------ | ------------------------------------------------------------ |
| data | string | Yes | - | Resource response data to set.| | data | string | Yes | - | Resource response data to set. When set to a number, the value indicates a file handle.|
### setResponseEncoding<sup>9+</sup> ### setResponseEncoding<sup>9+</sup>
...@@ -2415,7 +2417,7 @@ Sets the status code of the resource response. ...@@ -2415,7 +2417,7 @@ Sets the status code of the resource response.
## FileSelectorResult<sup>9+</sup> ## FileSelectorResult<sup>9+</sup>
Notifies the **\<Web>** component of the file selection result. For details about the sample code, see [onShowFileSelector](#onshowfileselector9). Notifies the **\<Web>** component of the file selection result. For the sample code, see [onShowFileSelector](#onshowfileselector9).
### handleFileList<sup>9+</sup> ### handleFileList<sup>9+</sup>
...@@ -2431,7 +2433,7 @@ Instructs the **\<Web>** component to select a file. ...@@ -2431,7 +2433,7 @@ Instructs the **\<Web>** component to select a file.
## FileSelectorParam<sup>9+</sup> ## FileSelectorParam<sup>9+</sup>
Implements the **FileSelectorParam** object. For details about the sample code, see [onShowFileSelector](#onshowfileselector9). Implements the **FileSelectorParam** object. For the sample code, see [onShowFileSelector](#onshowfileselector9).
### getTitle<sup>9+</sup> ### getTitle<sup>9+</sup>
...@@ -2483,7 +2485,7 @@ Checks whether multimedia capabilities are invoked. ...@@ -2483,7 +2485,7 @@ Checks whether multimedia capabilities are invoked.
## HttpAuthHandler<sup>9+</sup> ## HttpAuthHandler<sup>9+</sup>
Implements the **HttpAuthHandler** object. For details about the sample code, see [onHttpAuthRequest](#onhttpauthrequest9). Implements the **HttpAuthHandler** object. For the sample code, see [onHttpAuthRequest](#onhttpauthrequest9).
### cancel<sup>9+</sup> ### cancel<sup>9+</sup>
...@@ -2524,7 +2526,7 @@ Uses the password cached on the server for authentication. ...@@ -2524,7 +2526,7 @@ Uses the password cached on the server for authentication.
## SslErrorHandler<sup>9+</sup> ## SslErrorHandler<sup>9+</sup>
Implements an **SslErrorHandler** object. For details about the sample code, see [onSslErrorEventReceive Event](#onsslerroreventreceive9). Implements an **SslErrorHandler** object. For the sample code, see [onSslErrorEventReceive Event](#onsslerroreventreceive9).
### handleCancel<sup>9+</sup> ### handleCancel<sup>9+</sup>
...@@ -2540,7 +2542,7 @@ Continues using the SSL certificate. ...@@ -2540,7 +2542,7 @@ Continues using the SSL certificate.
## ClientAuthenticationHandler<sup>9+</sup> ## ClientAuthenticationHandler<sup>9+</sup>
Defines a **ClientAuthenticationHandler** object returned by the **\<Web>** component. For details about the sample code, see [onClientAuthenticationRequest](#onclientauthenticationrequest9). Implements a **ClientAuthenticationHandler** object returned by the **\<Web>** component. For the sample code, see [onClientAuthenticationRequest](#onclientauthenticationrequest9).
### confirm<sup>9+</sup> ### confirm<sup>9+</sup>
...@@ -2550,9 +2552,9 @@ Uses the specified private key and client certificate chain. ...@@ -2550,9 +2552,9 @@ Uses the specified private key and client certificate chain.
**Parameters** **Parameters**
| Name | Type| Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ---------- | | ------------- | ------ | ---- | ------------------ |
| priKeyFile | string | Yes | File that stores the private key, which is a directory including the file name.| | priKeyFile | string | Yes | File that stores the private key, which is a directory including the file name. |
| certChainFile | string | Yes | File that stores the certificate chain, which is a directory including the file name.| | certChainFile | string | Yes | File that stores the certificate chain, which is a directory including the file name.|
### cancel<sup>9+</sup> ### cancel<sup>9+</sup>
...@@ -2569,7 +2571,7 @@ Ignores this request. ...@@ -2569,7 +2571,7 @@ Ignores this request.
## PermissionRequest<sup>9+</sup> ## PermissionRequest<sup>9+</sup>
Implements the **PermissionRequest** object. For details about the sample code, see [onPermissionRequest](#onpermissionrequest9). Implements the **PermissionRequest** object. For the sample code, see [onPermissionRequest](#onpermissionrequest9).
### deny<sup>9+</sup> ### deny<sup>9+</sup>
...@@ -2586,7 +2588,7 @@ Obtains the origin of this web page. ...@@ -2586,7 +2588,7 @@ Obtains the origin of this web page.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------------- | | ------ | ------------ |
| string | Origin of the web page that requests the permission.| | string | Origin of the web page that requests the permission.|
### getAccessibleResource<sup>9+</sup> ### getAccessibleResource<sup>9+</sup>
...@@ -2598,7 +2600,7 @@ Obtains the list of accessible resources requested for the web page. For details ...@@ -2598,7 +2600,7 @@ Obtains the list of accessible resources requested for the web page. For details
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------- | ----------------------- | | --------------- | ------------- |
| Array\<string\> | List of accessible resources requested by the web page.| | Array\<string\> | List of accessible resources requested by the web page.|
### grant<sup>9+</sup> ### grant<sup>9+</sup>
...@@ -2609,13 +2611,13 @@ Grants the permission for resources requested by the web page. ...@@ -2609,13 +2611,13 @@ Grants the permission for resources requested by the web page.
**Parameters** **Parameters**
| Name | Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| --------- | --------------- | ---- | ----- | ---------------------- | | --------- | --------------- | ---- | ---- | ------------- |
| resources | Array\<string\> | Yes | - | List of accessible resources requested by the web page.| | resources | Array\<string\> | Yes | - | List of resources that can be requested by the web page with the permission to grant.|
## WebContextMenuParam<sup>9+</sup> ## WebContextMenuParam<sup>9+</sup>
Provides the information about the context menu that is displayed when a page element is long pressed. For details about the sample code, see [onContextMenuShow](#oncontextmenushow9). Implements a context menu, which is displayed after the user long presses a specific element, such as an image or a link. For the sample code, see [onContextMenuShow](#oncontextmenushow9).
### x<sup>9+</sup> ### x<sup>9+</sup>
...@@ -2626,7 +2628,7 @@ Obtains the X coordinate of the context menu. ...@@ -2626,7 +2628,7 @@ Obtains the X coordinate of the context menu.
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------- | ----------------------- | | ------ | ------------------ |
| number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.| | number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.|
### y<sup>9+</sup> ### y<sup>9+</sup>
...@@ -2638,7 +2640,7 @@ Obtains the Y coordinate of the context menu. ...@@ -2638,7 +2640,7 @@ Obtains the Y coordinate of the context menu.
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------- | ----------------------- | | ------ | ------------------ |
| number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.| | number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.|
### getLinkUrl<sup>9+</sup> ### getLinkUrl<sup>9+</sup>
...@@ -2650,19 +2652,19 @@ Obtains the URL of the destination link. ...@@ -2650,19 +2652,19 @@ Obtains the URL of the destination link.
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------- | ----------------------- | | ------ | ------------------------- |
| string | If it is a link that is being long pressed, the URL that has passed the security check is returned.| | string | If it is a link that is being long pressed, the URL that has passed the security check is returned.|
### getUnfilterendLinkUrl<sup>9+</sup> ### getUnfilteredLinkUrl<sup>9+</sup>
getUnfilterendLinkUrl(): string getUnfilteredLinkUrl(): string
Obtains the URL of the destination link. Obtains the URL of the destination link.
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------- | ----------------------- | | ------ | --------------------- |
| string | If it is a link that is being long pressed, the original URL is returned.| | string | If it is a link that is being long pressed, the original URL is returned.|
### getSourceUrl<sup>9+</sup> ### getSourceUrl<sup>9+</sup>
...@@ -2674,7 +2676,7 @@ Obtain the source URL. ...@@ -2674,7 +2676,7 @@ Obtain the source URL.
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------- | ----------------------- | | ------ | ------------------------ |
| string | If the selected element has the **src** attribute, the URL in the **src** is returned.| | string | If the selected element has the **src** attribute, the URL in the **src** is returned.|
### existsImageContents<sup>9+</sup> ### existsImageContents<sup>9+</sup>
...@@ -2686,12 +2688,12 @@ Checks whether image content exists. ...@@ -2686,12 +2688,12 @@ Checks whether image content exists.
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------- | ----------------------- | | ------- | ------------------------- |
| boolean | The value **true** means that there is image content in the element being long pressed, and **false** means the opposite.| | boolean | The value **true** means that there is image content in the element being long pressed, and **false** means the opposite.|
## WebContextMenuResult<sup>9+</sup> ## WebContextMenuResult<sup>9+</sup>
Defines the response event executed when a context menu is displayed. For details about the sample code, see [onContextMenuShow](#oncontextmenushow9). Implements a **WebContextMenuResult** object. For the sample code, see [onContextMenuShow](#oncontextmenushow9).
### closeContextMenu<sup>9+</sup> ### closeContextMenu<sup>9+</sup>
...@@ -2707,7 +2709,7 @@ Copies the image specified in **WebContextMenuParam**. ...@@ -2707,7 +2709,7 @@ Copies the image specified in **WebContextMenuParam**.
## JsGeolocation ## JsGeolocation
Implements the **PermissionRequest** object. For details about the sample code, see [onGeolocationShow Event](#ongeolocationshow). Implements the **PermissionRequest** object. For the sample code, see [onGeolocationShow Event](#ongeolocationshow).
### invoke ### invoke
...@@ -2717,15 +2719,17 @@ Sets the geolocation permission status of a web page. ...@@ -2717,15 +2719,17 @@ Sets the geolocation permission status of a web page.
**Parameters** **Parameters**
| Name | Type| Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| --------- | ------- | ---- | ----- | ---------------------- | | ------ | ------- | ---- | ---- | ---------------------------------------- |
| origin | string | Yes | - | Index of the origin. | | origin | string | Yes | - | Index of the origin. |
| allow | boolean | Yes | - | Geolocation permission status.| | allow | boolean | Yes | - | Geolocation permission status. |
| retain | boolean | Yes | - | Whether the geolocation permission status can be saved to the system. The **[GeolocationPermissions](#geolocationpermissions9)** API can be used to manage the geolocation permission status saved to the system.| | retain | boolean | Yes | - | Whether the geolocation permission status can be saved to the system. You can manage the geolocation permissions saved to the system through [GeolocationPermissions<sup>9+</sup>](../apis/js-apis-webview.md#geolocationpermissions).|
## WebController ## WebController
Defines a **WebController** to control the behavior of the **\<Web>** component. A **WebController** can control only one **\<Web>** component, and the APIs in the **WebController** can be invoked only after it has been bound to the target **\<Web>** component. Implements a **WebController** to control the behavior of the **\<Web>** component. A **WebController** can control only one **\<Web>** component, and the APIs in the **WebController** can be invoked only after it has been bound to the target **\<Web>** component.
This API is deprecated since API version 9. You are advised to use [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller).
### Creating an Object ### Creating an Object
...@@ -2733,12 +2737,14 @@ Defines a **WebController** to control the behavior of the **\<Web>** component. ...@@ -2733,12 +2737,14 @@ Defines a **WebController** to control the behavior of the **\<Web>** component.
webController: WebController = new WebController() webController: WebController = new WebController()
``` ```
### requestFocus ### requestFocus<sup>(deprecated)</sup>
requestFocus() requestFocus()
Requests focus for this web page. Requests focus for this web page.
This API is deprecated since API version 9. You are advised to use [requestFocus<sup>9+</sup>](../apis/js-apis-webview.md#requestfocus).
**Example** **Example**
```ts ```ts
...@@ -2760,12 +2766,14 @@ Requests focus for this web page. ...@@ -2760,12 +2766,14 @@ Requests focus for this web page.
} }
``` ```
### accessBackward ### accessBackward<sup>(deprecated)</sup>
accessBackward(): boolean accessBackward(): boolean
Checks whether going to the previous page can be performed on the current page. Checks whether going to the previous page can be performed on the current page.
This API is deprecated since API version 9. You are advised to use [accessBackward<sup>9+</sup>](../apis/js-apis-webview.md#accessbackward).
**Return value** **Return value**
| Type | Description | | Type | Description |
...@@ -2794,12 +2802,14 @@ Checks whether going to the previous page can be performed on the current page. ...@@ -2794,12 +2802,14 @@ Checks whether going to the previous page can be performed on the current page.
} }
``` ```
### accessForward ### accessForward<sup>(deprecated)</sup>
accessForward(): boolean accessForward(): boolean
Checks whether going to the next page can be performed on the current page. Checks whether going to the next page can be performed on the current page.
This API is deprecated since API version 9. You are advised to use [accessForward<sup>9+</sup>](../apis/js-apis-webview.md#accessforward).
**Return value** **Return value**
| Type | Description | | Type | Description |
...@@ -2828,12 +2838,14 @@ Checks whether going to the next page can be performed on the current page. ...@@ -2828,12 +2838,14 @@ Checks whether going to the next page can be performed on the current page.
} }
``` ```
### accessStep ### accessStep<sup>(deprecated)</sup>
accessStep(step: number): boolean accessStep(step: number): boolean
Performs a specific number of steps forward or backward from the current page. Performs a specific number of steps forward or backward from the current page.
This API is deprecated since API version 9. You are advised to use [accessStep<sup>9+</sup>](../apis/js-apis-webview.md#accessstep).
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
...@@ -2869,12 +2881,14 @@ Performs a specific number of steps forward or backward from the current page. ...@@ -2869,12 +2881,14 @@ Performs a specific number of steps forward or backward from the current page.
} }
``` ```
### backward ### backward<sup>(deprecated)</sup>
backward(): void backward(): void
Goes to the previous page based on the history stack. This API is generally used together with **accessBackward**. Goes to the previous page based on the history stack. This API is generally used together with **accessBackward**.
This API is deprecated since API version 9. You are advised to use [backward<sup>9+</sup>](../apis/js-apis-webview.md#backward).
**Example** **Example**
```ts ```ts
...@@ -2896,12 +2910,14 @@ Goes to the previous page based on the history stack. This API is generally used ...@@ -2896,12 +2910,14 @@ Goes to the previous page based on the history stack. This API is generally used
} }
``` ```
### forward ### forward<sup>(deprecated)</sup>
forward(): void forward(): void
Goes to the next page based on the history stack. This API is generally used together with **accessForward**. Goes to the next page based on the history stack. This API is generally used together with **accessForward**.
This API is deprecated since API version 9. You are advised to use [forward<sup>9+</sup>](../apis/js-apis-webview.md#forward).
**Example** **Example**
```ts ```ts
...@@ -2957,12 +2973,14 @@ Performs a specific number of steps forward or backward on the current page base ...@@ -2957,12 +2973,14 @@ Performs a specific number of steps forward or backward on the current page base
} }
``` ```
### deleteJavaScriptRegister ### deleteJavaScriptRegister<sup>(deprecated)</sup>
deleteJavaScriptRegister(name: string) deleteJavaScriptRegister(name: string)
Deletes a specific application JavaScript object that is registered with the window through **registerJavaScriptProxy**. The deletion takes effect immediately, with no need for invoking the [refresh](#refresh) API. Deletes a specific application JavaScript object that is registered with the window through **registerJavaScriptProxy**. The deletion takes effect immediately, with no need for invoking the [refresh](#refresh) API.
This API is deprecated since API version 9. You are advised to use [deleteJavaScriptRegister<sup>9+</sup>](../apis/js-apis-webview.md#deletejavascriptregister).
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
...@@ -2991,12 +3009,14 @@ Deletes a specific application JavaScript object that is registered with the win ...@@ -2991,12 +3009,14 @@ Deletes a specific application JavaScript object that is registered with the win
} }
``` ```
### getHitTest ### getHitTest<sup>(deprecated)</sup>
getHitTest(): HitTestType getHitTest(): HitTestType
Obtains the element type of the area being clicked. Obtains the element type of the area being clicked.
This API is deprecated since API version 9. You are advised to use [getHitTest<sup>9+</sup>](../apis/js-apis-webview.md#gethittest).
**Return value** **Return value**
| Type | Description | | Type | Description |
...@@ -3191,7 +3211,7 @@ Obtains the default user agent of the current web page. ...@@ -3191,7 +3211,7 @@ Obtains the default user agent of the current web page.
} }
``` ```
### loadData ### loadData<sup>(deprecated)</sup>
loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string }) loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string })
...@@ -3201,6 +3221,8 @@ If **baseUrl** is set to a data URL, the encoded string will be loaded by the ** ...@@ -3201,6 +3221,8 @@ If **baseUrl** is set to a data URL, the encoded string will be loaded by the **
If **baseUrl** is set to an HTTP or HTTPS URL, the encoded string will be processed by the **\<Web>** component as a non-encoded string in a manner similar to **loadUrl**. If **baseUrl** is set to an HTTP or HTTPS URL, the encoded string will be processed by the **\<Web>** component as a non-encoded string in a manner similar to **loadUrl**.
This API is deprecated since API version 9. You are advised to use [loadData<sup>9+</sup>](../apis/js-apis-webview.md#loaddata).
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
...@@ -3236,7 +3258,7 @@ If **baseUrl** is set to an HTTP or HTTPS URL, the encoded string will be proces ...@@ -3236,7 +3258,7 @@ If **baseUrl** is set to an HTTP or HTTPS URL, the encoded string will be proces
} }
``` ```
### loadUrl ### loadUrl<sup>(deprecated)</sup>
loadUrl(options: { url: string | Resource, headers?: Array\<Header\> }) loadUrl(options: { url: string | Resource, headers?: Array\<Header\> })
...@@ -3246,6 +3268,8 @@ The object injected through **loadUrl** is valid only in the current document. I ...@@ -3246,6 +3268,8 @@ The object injected through **loadUrl** is valid only in the current document. I
The object injected through **registerJavaScriptProxy** is still valid on a new page redirected through **loadUrl**. The object injected through **registerJavaScriptProxy** is still valid on a new page redirected through **loadUrl**.
This API is deprecated since API version 9. You are advised to use [loadUrl<sup>9+</sup>](../apis/js-apis-webview.md#loadurl).
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
...@@ -3274,12 +3298,14 @@ The object injected through **registerJavaScriptProxy** is still valid on a new ...@@ -3274,12 +3298,14 @@ The object injected through **registerJavaScriptProxy** is still valid on a new
} }
``` ```
### onActive ### onActive<sup>(deprecated)</sup>
onActive(): void onActive(): void
Invoked when the **\<Web>** component enters the active state. Invoked when the **\<Web>** component enters the active state.
This API is deprecated since API version 9. You are advised to use [onActive<sup>9+</sup>](../apis/js-apis-webview.md#onactive).
**Example** **Example**
```ts ```ts
...@@ -3301,12 +3327,14 @@ Invoked when the **\<Web>** component enters the active state. ...@@ -3301,12 +3327,14 @@ Invoked when the **\<Web>** component enters the active state.
} }
``` ```
### onInactive ### onInactive<sup>(deprecated)</sup>
onInactive(): void onInactive(): void
Invoked when the **\<Web>** component enters the inactive state. Invoked when the **\<Web>** component enters the inactive state.
This API is deprecated since API version 9. You are advised to use [onInactive<sup>9+</sup>](../apis/js-apis-webview.md#oninactive).
**Example** **Example**
```ts ```ts
...@@ -3328,11 +3356,13 @@ Invoked when the **\<Web>** component enters the inactive state. ...@@ -3328,11 +3356,13 @@ Invoked when the **\<Web>** component enters the inactive state.
} }
``` ```
### zoom ### zoom<sup>(deprecated)</sup>
zoom(factor: number): void zoom(factor: number): void
Sets a zoom factor for the current web page. Sets a zoom factor for the current web page.
This API is deprecated since API version 9. You are advised to use [zoom<sup>9+</sup>](../apis/js-apis-webview.md#zoom).
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -3364,7 +3394,7 @@ Sets a zoom factor for the current web page. ...@@ -3364,7 +3394,7 @@ Sets a zoom factor for the current web page.
### zoomIn<sup>9+</sup> ### zoomIn<sup>9+</sup>
zoomIn(): boolean zoomIn(): boolean
Zooms in on the current web page by 20%. Zooms in on this web page by 20%.
**Return value** **Return value**
...@@ -3397,7 +3427,7 @@ Zooms in on the current web page by 20%. ...@@ -3397,7 +3427,7 @@ Zooms in on the current web page by 20%.
### zoomOut<sup>9+</sup> ### zoomOut<sup>9+</sup>
zoomOut(): boolean zoomOut(): boolean
Zooms out of the current web page by 20%. Zooms out of this web page by 20%.
**Return value** **Return value**
...@@ -3427,12 +3457,14 @@ Zooms out of the current web page by 20%. ...@@ -3427,12 +3457,14 @@ Zooms out of the current web page by 20%.
} }
``` ```
### refresh ### refresh<sup>(deprecated)</sup>
refresh() refresh()
Invoked when the **\<Web>** component refreshes the web page. Invoked when the **\<Web>** component refreshes the web page.
This API is deprecated since API version 9. You are advised to use [refresh<sup>9+</sup>](../apis/js-apis-webview.md#refresh).
**Example** **Example**
```ts ```ts
...@@ -3454,11 +3486,13 @@ Invoked when the **\<Web>** component refreshes the web page. ...@@ -3454,11 +3486,13 @@ Invoked when the **\<Web>** component refreshes the web page.
} }
``` ```
### registerJavaScriptProxy ### registerJavaScriptProxy<sup>(deprecated)</sup>
registerJavaScriptProxy(options: { object: object, name: string, methodList: Array\<string\> }) registerJavaScriptProxy(options: { object: object, name: string, methodList: Array\<string\> })
Registers a JavaScript object and invokes the methods of the object in the window. You must invoke the [refresh](#refresh) API for the registration to take effect. Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. You must invoke the [refresh](#refresh) API for the registration to take effect.
This API is deprecated since API version 9. You are advised to use [registerJavaScriptProxy<sup>9+</sup>](../apis/js-apis-webview.md#registerjavascriptproxy).
**Parameters** **Parameters**
...@@ -3520,11 +3554,13 @@ Registers a JavaScript object and invokes the methods of the object in the windo ...@@ -3520,11 +3554,13 @@ Registers a JavaScript object and invokes the methods of the object in the windo
``` ```
### runJavaScript ### runJavaScript<sup>(deprecated)</sup>
runJavaScript(options: { script: string, callback?: (result: string) => void }) runJavaScript(options: { script: string, callback?: (result: string) => void })
Asynchronously executes a JavaScript script. This API uses a callback to return the script execution result. **runJavaScript** can be invoked only after **loadUrl** is executed. For example, it can be executed in **onPageEnd**. Executes a JavaScript script. This API uses an asynchronous callback to return the script execution result. **runJavaScript** can be invoked only after **loadUrl** is executed. For example, it can be invoked in **onPageEnd**.
This API is deprecated since API version 9. You are advised to use [runJavaScript<sup>9+</sup>](../apis/js-apis-webview.md#runjavascript).
**Parameters** **Parameters**
...@@ -3579,12 +3615,14 @@ Asynchronously executes a JavaScript script. This API uses a callback to return ...@@ -3579,12 +3615,14 @@ Asynchronously executes a JavaScript script. This API uses a callback to return
``` ```
### stop ### stop<sup>(deprecated)</sup>
stop() stop()
Stops page loading. Stops page loading.
This API is deprecated since API version 9. You are advised to use [stop<sup>9+</sup>](../apis/js-apis-webview.md#stop).
**Example** **Example**
```ts ```ts
...@@ -3606,12 +3644,14 @@ Stops page loading. ...@@ -3606,12 +3644,14 @@ Stops page loading.
} }
``` ```
### clearHistory ### clearHistory<sup>(deprecated)</sup>
clearHistory(): void clearHistory(): void
Clears the browsing history. Clears the browsing history.
This API is deprecated since API version 9. You are advised to use [clearHistory<sup>9+</sup>](../apis/js-apis-webview.md#clearhistory).
**Example** **Example**
```ts ```ts
...@@ -3664,7 +3704,7 @@ Clears the user operation corresponding to the SSL certificate error event recor ...@@ -3664,7 +3704,7 @@ Clears the user operation corresponding to the SSL certificate error event recor
clearClientAuthenticationCache(): void clearClientAuthenticationCache(): void
Clears the user operation corresponding to the client certificate request event recorded by the \<Web> component. Clears the user operation corresponding to the client certificate request event recorded by the **\<Web>** component.
**Example** **Example**
...@@ -3730,7 +3770,7 @@ Creates web message ports. ...@@ -3730,7 +3770,7 @@ Creates web message ports.
| Type | Description | | Type | Description |
| ------------------------------- | ------------- | | ---------------------------------------- | ---------- |
| Array\<[WebMessagePort](#webmessageport9)\> | List of web message ports.| | Array\<[WebMessagePort](#webmessageport9)\> | List of web message ports.|
**Example** **Example**
...@@ -3764,9 +3804,9 @@ Sends a web message to an HTML5 window. ...@@ -3764,9 +3804,9 @@ Sends a web message to an HTML5 window.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ---------- | --------------- | ---- | ---- | ------------------------- | | ------- | ------------------------------------ | ---- | ---- | ----------------- |
| message | [WebMessageEvent](#webmessageevent9) | Yes | - |Message to send, including the data and message port.| | message | [WebMessageEvent](#webmessageevent9) | Yes | - | Message to send, including the data and message port.|
| uri | string | Yes | - | URI for receiving the message.| | uri | string | Yes | - | URI for receiving the message. |
**Example** **Example**
...@@ -3870,12 +3910,12 @@ Sends a web message to an HTML5 window. ...@@ -3870,12 +3910,12 @@ Sends a web message to an HTML5 window.
getUrl(): string getUrl(): string
Obtains the URL of the current page. Obtains the URL of this page.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------- | ------------- | | ------ | ----------- |
| string | URL of the current page.| | string | URL of the current page.|
**Example** **Example**
...@@ -3898,8 +3938,115 @@ Obtains the URL of the current page. ...@@ -3898,8 +3938,115 @@ Obtains the URL of the current page.
} }
``` ```
### searchAllAsync<sup>9+</sup>
searchAllAsync(searchString: string): void
Searches the web page for content that matches the keyword specified by **'searchString'** and highlights the matches on the page. This API returns the result asynchronously through [onSearchResultReceive](#onsearchresultreceive9).
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
| ------------ | ------ | ---- | ---- | ------- |
| searchString | string | Yes | - | Search keyword.|
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
@State searchString: string = "xxx"
build() {
Column() {
Button('searchString')
.onClick(() => {
this.controller.searchAllAsync(this.searchString)
})
Button('clearMatches')
.onClick(() => {
this.controller.clearMatches()
})
Button('searchNext')
.onClick(() => {
this.controller.searchNext(true)
})
Web({ src: 'www.example.com', controller: this.controller })
.onSearchResultReceive(ret => {
console.log("on search result receive:" + "[cur]" + ret.activeMatchOrdinal +
"[total]" + ret.numberOfMatches + "[isDone]"+ ret.isDoneCounting)
})
}
}
}
```
### clearMatches<sup>9+</sup>
clearMatches(): void
Clears the matches found through [searchAllAsync](#searchallasync9).
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('clearMatches')
.onClick(() => {
this.controller.clearMatches()
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### searchNext<sup>9+</sup>
searchNext(forward: boolean): void
Searches for and highlights the next match.
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
| ------- | ------- | ---- | ---- | ----------- |
| forward | boolean | Yes | - | Whether to search forward.|
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('searchNext')
.onClick(() => {
this.controller.searchNext(true)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
## HitTestValue<sup>9+</sup> ## HitTestValue<sup>9+</sup>
Implements the **HitTestValue** object. For details about the sample code, see [getHitTestValue](#gethittestvalue9). Implements the **HitTestValue** object. For the sample code, see [getHitTestValue](#gethittestvalue9).
### getType<sup>9+</sup> ### getType<sup>9+</sup>
getType(): HitTestType getType(): HitTestType
...@@ -3968,39 +4115,6 @@ Sets the cookie. This API returns the result synchronously. Returns **true** if ...@@ -3968,39 +4115,6 @@ Sets the cookie. This API returns the result synchronously. Returns **true** if
} }
``` ```
### saveCookieSync<sup>9+</sup>
saveCookieSync(): boolean
Saves the cookies in the memory to the drive. This API returns the result synchronously.
**Return value**
| Type | Description |
| ------- | -------------------- |
| boolean | Operation result.|
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('saveCookieSync')
.onClick(() => {
let result = this.controller.getCookieManager().saveCookieSync()
console.log("result: " + result)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### getCookie<sup>9+</sup> ### getCookie<sup>9+</sup>
getCookie(url: string): string getCookie(url: string): string
...@@ -4009,13 +4123,13 @@ Obtains the cookie value corresponding to the specified URL. ...@@ -4009,13 +4123,13 @@ Obtains the cookie value corresponding to the specified URL.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ----------------- | | ---- | ------ | ---- | ---- | ----------------- |
| url | string | Yes | - | URL of the cookie value to obtain.| | url | string | Yes | - | URL of the cookie value to obtain.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------------- | | ------ | ----------------- |
| string | Cookie value corresponding to the specified URL.| | string | Cookie value corresponding to the specified URL.|
**Example** **Example**
...@@ -4032,7 +4146,7 @@ Obtains the cookie value corresponding to the specified URL. ...@@ -4032,7 +4146,7 @@ Obtains the cookie value corresponding to the specified URL.
Column() { Column() {
Button('getCookie') Button('getCookie')
.onClick(() => { .onClick(() => {
let value = webview.WebCookieManager.getCookie('www.example.com') let value = web_webview.WebCookieManager.getCookie('www.example.com')
console.log("value: " + value) console.log("value: " + value)
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -4051,12 +4165,12 @@ Sets a cookie value for the specified URL. ...@@ -4051,12 +4165,12 @@ Sets a cookie value for the specified URL.
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ----------------- | | ----- | ------ | ---- | ---- | ----------------- |
| url | string | Yes | - | URL of the cookie to set.| | url | string | Yes | - | URL of the cookie to set.|
| value | string | Yes | - | Cookie value to set.| | value | string | Yes | - | Cookie value to set. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------------- | | ------- | ------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example** **Example**
...@@ -4119,12 +4233,12 @@ Saves the cookies in the memory to the drive. This API returns the result synchr ...@@ -4119,12 +4233,12 @@ Saves the cookies in the memory to the drive. This API returns the result synchr
### saveCookieAsync<sup>9+</sup> ### saveCookieAsync<sup>9+</sup>
saveCookieAsync(): Promise\<boolean> saveCookieAsync(): Promise\<boolean>
Saves cookies in the memory to the drive. This API uses a promise to return the value. Saves the cookies in the memory to the drive. This API uses a promise to return the value.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------------- | | ----------------- | --------------------------- |
| Promise\<boolean> | Promise used to return the result.| | Promise\<boolean> | Promise used to return the result.|
**Example** **Example**
...@@ -4158,12 +4272,12 @@ Saves cookies in the memory to the drive. This API uses a promise to return the ...@@ -4158,12 +4272,12 @@ Saves cookies in the memory to the drive. This API uses a promise to return the
### saveCookieAsync<sup>9+</sup> ### saveCookieAsync<sup>9+</sup>
saveCookieAsync(callback: AsyncCallback\<boolean>): void saveCookieAsync(callback: AsyncCallback\<boolean>): void
Saves cookies in the memory to the drive. This API uses an asynchronous callback to return the result. Saves the cookies in the memory to the drive. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ----------------- | | -------- | ----------------------- | ---- | ---- | ---------------------------- |
| callback | AsyncCallback\<boolean> | Yes | - | Callback used to return the operation result.| | callback | AsyncCallback\<boolean> | Yes | - | Callback used to return the operation result.|
**Example** **Example**
...@@ -4198,7 +4312,7 @@ Checks whether the **WebCookieManager** instance has the permission to send and ...@@ -4198,7 +4312,7 @@ Checks whether the **WebCookieManager** instance has the permission to send and
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------------- | | ------- | ------------------- |
| boolean | Whether the **WebCookieManager** instance has the permission to send and receive cookies.| | boolean | Whether the **WebCookieManager** instance has the permission to send and receive cookies.|
**Example** **Example**
...@@ -4232,7 +4346,7 @@ Sets whether the **WebCookieManager** instance has the permission to send and re ...@@ -4232,7 +4346,7 @@ Sets whether the **WebCookieManager** instance has the permission to send and re
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ----------------- | | ------ | ------- | ---- | ---- | --------------------- |
| accept | boolean | Yes | - | Whether the **WebCookieManager** instance has the permission to send and receive cookies.| | accept | boolean | Yes | - | Whether the **WebCookieManager** instance has the permission to send and receive cookies.|
**Example** **Example**
...@@ -4265,645 +4379,8 @@ Checks whether the **WebCookieManager** instance has the permission to send and ...@@ -4265,645 +4379,8 @@ Checks whether the **WebCookieManager** instance has the permission to send and
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------------- | | ------- | ---------------------- |
| boolean | Whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.| | boolean | Whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('isThirdPartyCookieAllowed')
.onClick(() => {
let result = web_webview.WebCookieManager.isThirdPartyCookieAllowed()
console.log("result: " + result)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### putAcceptThirdPartyCookieEnabled<sup>9+</sup>
putAcceptThirdPartyCookieEnabled(accept: boolean): void
Sets whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ----------------- |
| accept | boolean | Yes | - | Whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('putAcceptThirdPartyCookieEnabled')
.onClick(() => {
web_webview.WebCookieManager.putAcceptThirdPartyCookieEnabled(false)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### existCookie<sup>9+</sup>
existCookie(): boolean
Checks whether cookies exist.
**Return value**
| Type | Description |
| ------- | -------------------- |
| boolean | Whether cookies exist.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('existCookie')
.onClick(() => {
let result = web_webview.WebCookieManager.existCookie()
console.log("result: " + result)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### deleteEntireCookie<sup>9+</sup>
deleteEntireCookie(): void
Deletes all cookies.
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('deleteEntireCookie')
.onClick(() => {
web_webview.WebCookieManager.deleteEntireCookie()
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### deleteSessionCookie<sup>9+</sup>
deleteSessionCookie(): void
Deletes all session cookies.
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('deleteSessionCookie')
.onClick(() => {
webview.WebCookieManager.deleteSessionCookie()
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
## WebDataBase<sup>9+</sup>
Implements the **WebDataBase** object.
### existHttpAuthCredentials<sup>9+</sup>
static existHttpAuthCredentials(): boolean
Checks whether any saved HTTP authentication credentials exist. This API is synchronous.
**Return value**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Whether any saved HTTP authentication credentials exist. Returns **true** if any saved HTTP authentication credentials exist exists; returns **false** otherwise.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('existHttpAuthCredentials')
.onClick(() => {
let result = web_webview.WebDataBase.existHttpAuthCredentials()
console.log('result: ' + result)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### deleteHttpAuthCredentials<sup>9+</sup>
static deleteHttpAuthCredentials(): void
Deletes all HTTP authentication credentials saved in the cache. This API returns the result synchronously.
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('deleteHttpAuthCredentials')
.onClick(() => {
web_webview.WebDataBase.deleteHttpAuthCredentials()
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### getHttpAuthCredentials<sup>9+</sup>
static getHttpAuthCredentials(host: string, realm: string): Array\<string\>
Retrieves HTTP authentication credentials for a given host and domain. This API is synchronous.
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ---------------- |
| host | string | Yes | - | Host for which you want to obtain the HTTP authentication credentials.|
| realm | string | Yes | - | Realm for which you want to obtain the HTTP authentication credentials. |
**Return value**
| Type | Description |
| --------------- | ---------------------- |
| Array\<string\> | Returns the array of the matching user names and passwords if the operation is successful; returns an empty array otherwise.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
host: string = "www.spincast.org"
realm: string = "protected example"
username_password: string[]
build() {
Column() {
Button('getHttpAuthCredentials')
.onClick(() => {
this.username_password = web_webview.WebDataBase.getHttpAuthCredentials(this.host, this.realm)
console.log('num: ' + this.username_password.length)
ForEach(this.username_password, (item) => {
console.log('username_password: ' + item)
}, item => item)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### saveHttpAuthCredentials<sup>9+</sup>
static saveHttpAuthCredentials(host: string, realm: string, username: string, password: string): void
Saves HTTP authentication credentials for a given host and realm. This API returns the result synchronously.
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
| -------- | ------ | ---- | ---- | ---------------- |
| host | string | Yes | - | Host for which you want to obtain the HTTP authentication credentials.|
| realm | string | Yes | - | Realm to which HTTP authentication credentials apply. |
| username | string | Yes | - | User name. |
| password | string | Yes | - | Password. |
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
host: string = "www.spincast.org"
realm: string = "protected example"
build() {
Column() {
Button('saveHttpAuthCredentials')
.onClick(() => {
web_webview.WebDataBase.saveHttpAuthCredentials(this.host, this.realm, "Stromgol", "Laroche")
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
## GeolocationPermissions<sup>9+</sup>
Defines a **GeolocationPermissions** object.
### allowGeolocation<sup>9+</sup>
static allowGeolocation(origin: string): void
Allows the specified source to use the geolocation information.
**Parameters**
| Name | Type| Mandatory| Default Value| Description |
| -------- | -------- | ---- | ----- | ------------- |
| origin | string | Yes | - | Index of the origin.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
origin: string = "file:///"
build() {
Column() {
Button('allowGeolocation')
.onClick(() => {
web_webview.GeolocationPermissions.allowGeolocation(this.origin)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### deleteGeolocation<sup>9+</sup>
static deleteGeolocation(origin: string): void
Clears the geolocation permission status of a specified source.
**Parameters**
| Name | Type| Mandatory| Default Value| Description |
| -------- | -------- | ---- | ----- | ------------- |
| origin | string | Yes | - | Index of the origin.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
origin: string = "file:///"
build() {
Column() {
Button('deleteGeolocation')
.onClick(() => {
web_webview.GeolocationPermissions.deleteGeolocation(this.origin)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### deleteAllGeolocation<sup>9+</sup>
static deleteAllGeolocation(): void
Clears the geolocation permission status of all sources.
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('deleteAllGeolocation')
.onClick(() => {
web_webview.GeolocationPermissions.deleteAllGeolocation()
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### getAccessibleGeolocation<sup>9+</sup>
static getAccessibleGeolocation(origin: string, callback: AsyncCallback\<boolean\>): void
Obtains the geolocation permission status of the specified source. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type| Mandatory| Default Value| Description |
| -------- | -------- | ---- | ----- | ------------- |
| origin | string | Yes | - | Index of the origin.|
| callback | AsyncCallback\<boolean\> | Yes| - | Callback used to return the geolocation permission status of the specified source. If the operation is successful, the value **true** means that the geolocation permission is granted, and **false** means the opposite. If the operation fails, the geolocation permission status of the specified source is not found.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
origin: string = "file:///"
build() {
Column() {
Button('getAccessibleGeolocationAsync')
.onClick(() => {
web_webview.GeolocationPermissions.getAccessibleGeolocation(this.origin, (error, result) => {
if (error) {
console.log('getAccessibleGeolocationAsync error: ' + JSON.stringify(error))
return
}
console.log('getAccessibleGeolocationAsync result: ' + result)
})
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### getAccessibleGeolocation<sup>9+</sup>
static getAccessibleGeolocation(origin: string): Promise\<boolean\>
Obtains the geolocation permission status of the specified source. This API uses a promise to return the result.
**Parameters**
| Name | Type| Mandatory| Default Value| Description |
| -------- | -------- | ---- | ----- | ------------- |
| origin | string | Yes | - | Index of the origin.|
**Return value**
| Type | Description |
| ------------------ | ------------------------------------ |
| Promise\<boolean\> | Promise used to return the geolocation permission status of the specified source. If the operation is successful, the value **true** means that the geolocation permission is granted, and **false** means the opposite. If the operation fails, the geolocation permission status of the specified source is not found.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
origin: string = "file:///"
build() {
Column() {
Button('getAccessibleGeolocationPromise')
.onClick(() => {
web_webview.GeolocationPermissions.getAccessibleGeolocation(this.origin).then(result => {
console.log('getAccessibleGeolocationPromise result: ' + result)
}).catch(error => {
console.log('getAccessibleGeolocationPromise error: ' + JSON.stringify(error))
})
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### getStoredGeolocation<sup>9+</sup>
static getStoredGeolocation(callback: AsyncCallback\<Array\<string\>\>): void
Obtains the geolocation permission status of all sources. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type| Mandatory| Default Value| Description |
| -------- | -------- | ---- | ----- | ------------- |
| callback | AsyncCallback\<Array\<string\>\> | Yes| - | Callback used to return the geolocation permission status of all sources.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('getStoredGeolocationAsync')
.onClick(() => {
web_webview.GeolocationPermissions.getStoredGeolocation((error, origins) => {
if (error) {
console.log('getStoredGeolocationAsync error: ' + JSON.stringify(error))
return
}
let origins_str: string = origins.join()
console.log('getStoredGeolocationAsync origins: ' + origins_str)
})
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### getStoredGeolocation<sup>9+</sup>
static getStoredGeolocation(): Promise\<Array\<string\>\>
Obtains the geolocation permission status of all sources. This API uses a promise to return the result.
**Parameters**
| Name | Type| Mandatory| Default Value| Description |
| -------- | -------- | ---- | ----- | ------------- |
| callback | AsyncCallback\<Array\<string\>\> | Yes| - | Callback used to return the geolocation permission status of all sources.|
**Return value**
| Type | Description |
| -------------------------- | ------------------------------------ |
| Promise\<Array\<string\>\> | Promise used to return the geolocation permission status of all sources.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('getStoredGeolocationPromise')
.onClick(() => {
web_webview.GeolocationPermissions.getStoredGeolocation().then(origins => {
let origins_str: string = origins.join()
console.log('getStoredGeolocationPromise origins: ' + origins_str)
}).catch(error => {
console.log('getStoredGeolocationPromise error: ' + JSON.stringify(error))
})
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
## WebStorage<sup>9+</sup>
Implements the **WebStorage** object, which can be used to manage the Web SQL and the HTML5 Web Storage API. All **\<Web>** components in an application share one **WebStorage**.
### deleteAllData<sup>9+</sup>
static deleteAllData(): void
Deletes all data in the Web SQL database.
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('deleteAllData')
.onClick(() => {
web_webview.WebStorage.deleteAllData()
})
Web({ src: 'www.example.com', controller: this.controller })
.databaseAccess(true)
}
}
}
```
### deleteOrigin<sup>9+</sup>
static deleteOrigin(origin : string): void
Deletes all data in the specified origin.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ---------- |
| origin | string | Yes | Index of the origin.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
origin: string = "origin"
build() {
Column() {
Button('getHttpAuthCredentials')
.onClick(() => {
web_webview.WebStorage.deleteOrigin(this.origin)
})
Web({ src: 'www.example.com', controller: this.controller })
.databaseAccess(true)
}
}
}
```
### getOrigins<sup>9+</sup>
static getOrigins(callback: AsyncCallback\<Array\<WebStorageOrigin>>) : void
Obtains information about all origins that are currently using the Web SQL database. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
| callback | AsyncCallback<Array<[WebStorageOrigin](#webstorageorigin9)>> | Yes | Callback used to return the information about the origins. For details, see **WebStorageOrigin**.|
**Example** **Example**
...@@ -4914,85 +4391,30 @@ Obtains information about all origins that are currently using the Web SQL datab ...@@ -4914,85 +4391,30 @@ Obtains information about all origins that are currently using the Web SQL datab
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: WebController = new WebController()
origin: string = "origin"
build() {
Column() {
Button('getOrigins')
.onClick(() => {
web_webview.WebStorage.getOrigins((error, origins) => {
if (error) {
console.log('error: ' + error)
return
}
for (let i = 0; i < origins.length; i++) {
console.log('origin: ' + origins[i].origin)
console.log('usage: ' + origins[i].usage)
console.log('quota: ' + origins[i].quota)
}
})
})
Web({ src: 'www.example.com', controller: this.controller })
.databaseAccess(true)
}
}
}
```
### getOrigins<sup>9+</sup>
static getOrigins() : Promise\<Array\<WebStorageOrigin>>
Obtains information about all origins that are currently using the Web SQL database. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ---------------------------------------- | ---------------------------------------- |
| Promise<Array<[WebStorageOrigin](#webstorageorigin9)>> | Promise used to return the information about the origins. For details, see **WebStorageOrigin**.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
origin: string = "origin"
build() { build() {
Column() { Column() {
Button('getOrigins') Button('isThirdPartyCookieAllowed')
.onClick(() => { .onClick(() => {
web_webview.WebStorage.getOrigins() let result = web_webview.WebCookieManager.isThirdPartyCookieAllowed()
.then(origins => { console.log("result: " + result)
for (let i = 0; i < origins.length; i++) {
console.log('origin: ' + origins[i].origin)
console.log('usage: ' + origins[i].usage)
console.log('quota: ' + origins[i].quota)
}
})
.catch(error => {
console.log('error: ' + error)
})
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.databaseAccess(true)
} }
} }
} }
``` ```
### getOriginQuota<sup>9+</sup> ### putAcceptThirdPartyCookieEnabled<sup>9+</sup>
static getOriginQuota(origin : string, callback : AsyncCallback\<number>) : void putAcceptThirdPartyCookieEnabled(accept: boolean): void
Obtains the storage quota of an origin in the Web SQL database, in bytes. This API uses an asynchronous callback to return the result. Sets whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | ---------------------- | ---- | --------- | | ------ | ------- | ---- | ---- | ------------------------ |
| origin | string | Yes | Index of the origin.| | accept | boolean | Yes | - | Whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the storage quota of the origin.|
**Example** **Example**
...@@ -5003,129 +4425,29 @@ Obtains the storage quota of an origin in the Web SQL database, in bytes. This A ...@@ -5003,129 +4425,29 @@ Obtains the storage quota of an origin in the Web SQL database, in bytes. This A
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: WebController = new WebController()
origin: string = "origin"
build() {
Column() {
Button('getOriginQuota')
.onClick(() => {
web_webview.WebStorage.getOriginQuota(this.origin, (error, quota) => {
if (error) {
console.log('error: ' + error)
return
}
console.log('quota: ' + quota)
})
})
Web({ src: 'www.example.com', controller: this.controller })
.databaseAccess(true)
}
}
}
```
### getOriginQuota<sup>9+</sup>
static getOriginQuota(origin : string) : Promise\<number>
Obtains the storage quota of an origin in the Web SQL database, in bytes. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ---------- |
| origin | string | Yes | Index of the origin.|
**Return value**
| Type | Description |
| ---------------- | ----------------------- |
| Promise\<number> | Promise used to return the storage quota of the origin.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController();
origin: string = "origin"
build() {
Column() {
Button('getOriginQuota')
.onClick(() => {
web_webview.WebStorage.getOriginQuota(this.origin)
.then(quota => {
console.log('quota: ' + quota)
})
.catch(error => {
console.log('error: ' + error)
})
})
Web({ src: 'www.example.com', controller: this.controller })
.databaseAccess(true)
}
}
}
```
### getOriginUsage<sup>9+</sup>
static getOriginUsage(origin : string, callback : AsyncCallback\<number>) : void
Obtains the storage usage of an origin in the Web SQL database, in bytes. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ---------- |
| origin | string | Yes | Index of the origin.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the storage usage of the origin. |
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController();
origin: string = "origin"
build() { build() {
Column() { Column() {
Button('getOriginUsage') Button('putAcceptThirdPartyCookieEnabled')
.onClick(() => { .onClick(() => {
web_webview.WebStorage.getOriginUsage(this.origin, (error, usage) => { web_webview.WebCookieManager.putAcceptThirdPartyCookieEnabled(false)
if (error) {
console.log('error: ' + error)
return
}
console.log('usage: ' + usage)
})
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.databaseAccess(true)
} }
} }
} }
``` ```
### getOriginUsage<sup>9+</sup> ### existCookie<sup>9+</sup>
static getOriginUsage(origin : string) : Promise\<number> existCookie(): boolean
Obtains the storage usage of an origin in the Web SQL database, in bytes. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description | Checks whether cookies exist.
| ------ | ------ | ---- | ---------- |
| origin | string | Yes | Index of the origin.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ---------------------- | | ------- | ----------- |
| Promise\<number> | Promise used to return the storage usage of the origin.| | boolean | Whether cookies exist.|
**Example** **Example**
...@@ -5134,83 +4456,32 @@ Obtains the storage usage of an origin in the Web SQL database, in bytes. This A ...@@ -5134,83 +4456,32 @@ Obtains the storage usage of an origin in the Web SQL database, in bytes. This A
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent {
controller: WebController = new WebController();
origin: string = "origin"
build() {
Column() {
Button('getOriginQuota')
.onClick(() => {
web_webview.WebStorage.getOriginUsage(this.origin)
.then(usage => {
console.log('usage: ' + usage)
})
.catch(error => {
console.log('error: ' + error)
})
})
Web({ src: 'www.example.com', controller: this.controller })
.databaseAccess(true)
}
}
}
```
### searchAllAsync<sup>9+</sup>
searchAllAsync(searchString: string): void
Searches the web page for content that matches the keyword specified by **'searchString'** and highlights the matches on the page. This API returns the result asynchronously through [onSearchResultReceive](#onsearchresultreceive9).
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
| ---- | ------ | ---- | ---- | --------------------- |
| searchString | string | Yes | - | Search keyword.|
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: WebController = new WebController()
@State searchString: string = "xxx"
build() { build() {
Column() { Column() {
Button('searchString') Button('existCookie')
.onClick(() => {
this.controller.searchAllAsync(this.searchString)
})
Button('clearMatches')
.onClick(() => {
this.controller.clearMatches()
})
Button('searchNext')
.onClick(() => { .onClick(() => {
this.controller.searchNext(true) let result = web_webview.WebCookieManager.existCookie()
console.log("result: " + result)
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onSearchResultReceive(ret => {
console.log("on search result receive:" + "[cur]" + ret.activeMatchOrdinal +
"[total]" + ret.numberOfMatches + "[isDone]"+ ret.isDoneCounting)
})
} }
} }
} }
``` ```
### clearMatches<sup>9+</sup> ### deleteEntireCookie<sup>9+</sup>
deleteEntireCookie(): void
clearMatches(): void
Clears the matches found through [searchAllAsync](#searchallasync9). Deletes all cookies.
**Example** **Example**
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
...@@ -5218,9 +4489,9 @@ Clears the matches found through [searchAllAsync](#searchallasync9). ...@@ -5218,9 +4489,9 @@ Clears the matches found through [searchAllAsync](#searchallasync9).
build() { build() {
Column() { Column() {
Button('clearMatches') Button('deleteEntireCookie')
.onClick(() => { .onClick(() => {
this.controller.clearMatches() web_webview.WebCookieManager.deleteEntireCookie()
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
} }
...@@ -5228,23 +4499,16 @@ Clears the matches found through [searchAllAsync](#searchallasync9). ...@@ -5228,23 +4499,16 @@ Clears the matches found through [searchAllAsync](#searchallasync9).
} }
``` ```
### searchNext<sup>9+</sup> ### deleteSessionCookie<sup>9+</sup>
deleteSessionCookie(): void
searchNext(forward: boolean): void
Searches for and highlights the next match.
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
| ---- | ------ | ---- | ---- | --------------------- |
| forward | boolean | Yes | - | Whether to search forward.|
Deletes all session cookies.
**Example** **Example**
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
...@@ -5252,9 +4516,9 @@ Searches for and highlights the next match. ...@@ -5252,9 +4516,9 @@ Searches for and highlights the next match.
build() { build() {
Column() { Column() {
Button('searchNext') Button('deleteSessionCookie')
.onClick(() => { .onClick(() => {
this.controller.searchNext(true) web_webview.WebCookieManager.deleteSessionCookie()
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
} }
...@@ -5262,53 +4526,6 @@ Searches for and highlights the next match. ...@@ -5262,53 +4526,6 @@ Searches for and highlights the next match.
} }
``` ```
### onSearchResultReceive<sup>9+</sup>
onSearchResultReceive(callback: (event?: {activeMatchOrdinal: number, numberOfMatches: number, isDoneCounting: boolean}) => void): WebAttribute
Invoked to notify the caller of the search result on the web page.
**Parameters**
| Name | Type | Description |
| ------------------ | ------------- | ----------------------------------- |
| activeMatchOrdinal | number | Sequence number of the current match, which starts from 0.|
| numberOfMatches | number | Total number of matches.|
| isDoneCounting | boolean | Whether the search operation on the current page is complete. This API may be called multiple times until **isDoneCounting** is **true**.|
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.onSearchResultReceive(ret => {
console.log("on search result receive:" + "[cur]" + ret.activeMatchOrdinal +
"[total]" + ret.numberOfMatches + "[isDone]"+ ret.isDoneCounting)
})
}
}
}
```
## WebStorageOrigin<sup>9+</sup>
Provides usage information about the Web SQL database.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ---------- |
| origin | string | Yes | Index of the origin.|
| usage | number | Yes | Storage usage of the origin. |
| quota | number | Yes | Storage quota of the origin. |
## MessageLevel ## MessageLevel
| Name | Description | | Name | Description |
...@@ -5365,6 +4582,7 @@ Enumerates the reasons why the rendering process exits. ...@@ -5365,6 +4582,7 @@ Enumerates the reasons why the rendering process exits.
| HttpAnchorImg | Image with a hyperlink, where **src** is **http**.| | HttpAnchorImg | Image with a hyperlink, where **src** is **http**.|
| Img | HTML::img tag. | | Img | HTML::img tag. |
| Map | Geographical address. | | Map | Geographical address. |
| Phone | Phone number. |
| Unknown | Unknown content. | | Unknown | Unknown content. |
## SslError<sup>9+</sup> ## SslError<sup>9+</sup>
...@@ -5372,7 +4590,7 @@ Enumerates the reasons why the rendering process exits. ...@@ -5372,7 +4590,7 @@ Enumerates the reasons why the rendering process exits.
Enumerates the error codes returned by **onSslErrorEventReceive** API. Enumerates the error codes returned by **onSslErrorEventReceive** API.
| Name | Description | | Name | Description |
| -------------- | ----------------- | | ------------ | ----------- |
| Invalid | Minor error. | | Invalid | Minor error. |
| HostMismatch | The host name does not match. | | HostMismatch | The host name does not match. |
| DateInvalid | The certificate has an invalid date. | | DateInvalid | The certificate has an invalid date. |
...@@ -5381,7 +4599,7 @@ Enumerates the error codes returned by **onSslErrorEventReceive** API. ...@@ -5381,7 +4599,7 @@ Enumerates the error codes returned by **onSslErrorEventReceive** API.
## ProtectedResourceType<sup>9+</sup> ## ProtectedResourceType<sup>9+</sup>
| Name | Description | Remarks | | Name | Description | Remarks |
| --------- | -------------- | -------------- | | --------- | ------------- | -------------------------- |
| MidiSysex | MIDI SYSEX resource.| Currently, only permission events can be reported. MIDI devices are not yet supported.| | MidiSysex | MIDI SYSEX resource.| Currently, only permission events can be reported. MIDI devices are not yet supported.|
## WebAsyncController ## WebAsyncController
...@@ -5483,7 +4701,7 @@ Stores this web page. This API uses a promise to return the result. ...@@ -5483,7 +4701,7 @@ Stores this web page. This API uses a promise to return the result.
## WebMessagePort<sup>9+</sup> ## WebMessagePort<sup>9+</sup>
Defines a **WebMessagePort** instance, which can be used to send and receive messages. Implements a **WebMessagePort** instance, which can be used to send and receive messages.
### close<sup>9+</sup> ### close<sup>9+</sup>
close(): void close(): void
...@@ -5498,7 +4716,7 @@ Sends messages. For the complete sample code, see [postMessage](#postmessage9). ...@@ -5498,7 +4716,7 @@ Sends messages. For the complete sample code, see [postMessage](#postmessage9).
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ----------------- | | ------- | ------------------------------------ | ---- | ---- | ------- |
| message | [WebMessageEvent](#webmessageevent9) | Yes | - | Message to send.| | message | [WebMessageEvent](#webmessageevent9) | Yes | - | Message to send.|
**Example** **Example**
...@@ -5533,7 +4751,7 @@ Registers a callback to receive messages from an HTML5 page. For the complete sa ...@@ -5533,7 +4751,7 @@ Registers a callback to receive messages from an HTML5 page. For the complete sa
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ----------------- | | -------- | -------- | ---- | ---- | ---------- |
| callback | function | Yes | - | Callback for receiving messages.| | callback | function | Yes | - | Callback for receiving messages.|
**Example** **Example**
...@@ -5573,7 +4791,7 @@ Obtains the messages stored in this object. ...@@ -5573,7 +4791,7 @@ Obtains the messages stored in this object.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------- | ------------- | | ------ | -------------- |
| string | Message stored in the object of this type.| | string | Message stored in the object of this type.|
**Example** **Example**
...@@ -5605,7 +4823,7 @@ Sets the message in this object. For the complete sample code, see [postMessage] ...@@ -5605,7 +4823,7 @@ Sets the message in this object. For the complete sample code, see [postMessage]
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ----------------- | | ---- | ------ | ---- | ---- | ------- |
| data | string | Yes | - | Message to send.| | data | string | Yes | - | Message to send.|
**Example** **Example**
...@@ -5639,7 +4857,7 @@ Obtains the message port stored in this object. ...@@ -5639,7 +4857,7 @@ Obtains the message port stored in this object.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------- | ------------- | | ---------------------------------------- | ---------------- |
| Array\<[WebMessagePort](#webmessageport9)\> | Message port stored in the object of this type.| | Array\<[WebMessagePort](#webmessageport9)\> | Message port stored in the object of this type.|
**Example** **Example**
...@@ -5673,7 +4891,7 @@ Sets the message port in this object. For the complete sample code, see [postMes ...@@ -5673,7 +4891,7 @@ Sets the message port in this object. For the complete sample code, see [postMes
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ----------------- | | ----- | ---------------------------------------- | ---- | ---- | --------- |
| ports | Array\<[WebMessagePort](#webmessageport9)\> | Yes | - | Message port.| | ports | Array\<[WebMessagePort](#webmessageport9)\> | Yes | - | Message port.|
**Example** **Example**
......
...@@ -27,18 +27,18 @@ loadAnimation( ...@@ -27,18 +27,18 @@ loadAnimation(
path: string, container: object, render: string, loop: boolean, autoplay: boolean, name: string ): AnimationItem path: string, container: object, render: string, loop: boolean, autoplay: boolean, name: string ): AnimationItem
Loads an animation. Before calling this method, declare the **Animator('\__lottie\_ets')** object and check that the canvas layout is complete. This method can be used together with a lifecycle callback of the **Canvas** component, for example, **onAppear()** and **onPageShow()**. Loads an animation. Before calling this API, declare the **Animator('__lottie_ets')** object and make sure the canvas layout is complete. This API can be used together with the lifecycle callback **onReady()** of the **Canvas** component.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------------- | --------------------------- | ---- | ---------------------------------------- | | -------------- | --------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Path of the animation resource file in the HAP file. The resource file must be in JSON format. Example: **path: "common/lottie/data.json"**| | path | string | Yes | Path of the animation resource file in the HAP file. The resource file must be in JSON format. Example: **path: "common/lottie/data.json"**|
| container | object | Yes | Canvas drawing context. A **CanvasRenderingContext2D** object must be declared in advance.| | container | object | Yes | Canvas drawing context. A **CanvasRenderingContext2D** object must be declared in advance.|
| render | string | Yes | Rendering type. The value can only be **"canvas"**. | | render | string | Yes | Rendering type. The value can only be **"canvas"**. |
| loop | boolean \| number | No | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends; the default value is **true**. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays.| | loop | boolean \| number | No | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends; the default value is **true**. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays.|
| autoplay | boolean | No | Whether to automatically play the animation. The default value is **true**. | | autoplay | boolean | No | Whether to automatically play the animation.<br>Default value: **true** |
| name | string | No | Custom animation name. In later versions, the name can be used to reference and control the animation. The default value is null. | | name | string | No | Custom animation name. In later versions, the name can be used to reference and control the animation.<br/>Default value: null |
| initialSegment | [number, number] | No | Start frame and end frame of the animation, respectively. | | initialSegment | [number, number] | No | Start frame and end frame of the animation, respectively. |
...@@ -46,15 +46,16 @@ Loads an animation. Before calling this method, declare the **Animator('\__lotti ...@@ -46,15 +46,16 @@ Loads an animation. Before calling this method, declare the **Animator('\__lotti
destroy(name: string): void destroy(name: string): void
Destroys the animation. This method must be called when a page exits. This method can be used together with a lifecycle callback of the **Canvas** component, for example, **onDisappear()** and **onPageHide()**. Destroys the animation. This API must be called when a page exits. This API can be used together with a lifecycle callback of the **Canvas** component, for example, **onDisappear()** and **onPageHide()**.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the animation to destroy, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are destroyed.| | name | string | Yes | Name of the animation to destroy, which is the same as the **name** in the **loadAnimation** API. By default, all animations are destroyed. |
**Example** **Example**
```ts ```ts
// xxx.ets // xxx.ets
import lottie from '@ohos/lottieETS' import lottie from '@ohos/lottieETS'
...@@ -78,7 +79,7 @@ Destroys the animation. This method must be called when a page exits. This metho ...@@ -78,7 +79,7 @@ Destroys the animation. This method must be called when a page exits. This metho
.width('30%') .width('30%')
.height('20%') .height('20%')
.backgroundColor('#0D9FFB') .backgroundColor('#0D9FFB')
.onAppear(() => { .onReady(() => {
console.log('canvas onAppear'); console.log('canvas onAppear');
this.animateItem = lottie.loadAnimation({ this.animateItem = lottie.loadAnimation({
container: this.controller, container: this.controller,
...@@ -133,7 +134,7 @@ Plays a specified animation. ...@@ -133,7 +134,7 @@ Plays a specified animation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the animation to play, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are played.| | name | string | Yes | Name of the animation to play, which is the same as the **name** in the **loadAnimation** API. By default, all animations are played. |
**Example** **Example**
...@@ -152,7 +153,7 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani ...@@ -152,7 +153,7 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the animation to pause, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are paused.| | name | string | Yes | Name of the animation to pause, which is the same as the **name** in the **loadAnimation** API. By default, all animations are paused. |
**Example** **Example**
...@@ -165,13 +166,13 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani ...@@ -165,13 +166,13 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani
togglePause(name: string): void togglePause(name: string): void
Pauses or plays a specified animation. This method is equivalent to the switching between **lottie.play()** and **lottie.pause()**. Pauses or plays a specified animation. This API is equivalent to the switching between **lottie.play()** and **lottie.pause()**.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are paused.| | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are paused or played. |
**Example** **Example**
...@@ -190,7 +191,7 @@ Stops the specified animation. The next time **lottie.play()** is called, the an ...@@ -190,7 +191,7 @@ Stops the specified animation. The next time **lottie.play()** is called, the an
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are paused.| | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are stopped. |
**Example** **Example**
...@@ -209,8 +210,8 @@ Sets the playback speed of the specified animation. ...@@ -209,8 +210,8 @@ Sets the playback speed of the specified animation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ---------------------------------------- | | ----- | ------ | ---- | ---------------------------------------- |
| speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays in forward direction. If the value is less than 0, the animation plays in reversed direction. If the value is 0, the animation is paused. If the value is 1.0 or -1.0, the animation plays at the normal speed.| | speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays in forward direction. If the value is less than 0, the animation plays in reversed direction. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are stopped.| | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are set. |
**Example** **Example**
...@@ -230,7 +231,7 @@ Sets the direction in which the specified animation plays. ...@@ -230,7 +231,7 @@ Sets the direction in which the specified animation plays.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------------------ | ---- | ---------------------------------------- | | --------- | ------------------ | ---- | ---------------------------------------- |
| direction | AnimationDirection | Yes | Direction in which the animation plays. **1**: forwards; **-1**: backwards. When set to play backwards, the animation plays from the current playback progress to the first frame. When this setting is combined with **loop** being set to **true**, the animation plays backwards continuously. When the value of **speed** is less than 0, the animation also plays backwards.<br>AnimationDirection: 1 \| -1 | | direction | AnimationDirection | Yes | Direction in which the animation plays. **1**: forwards; **-1**: backwards. When set to play backwards, the animation plays from the current playback progress to the first frame. When this setting is combined with **loop** being set to **true**, the animation plays backwards continuously. When the value of **speed** is less than 0, the animation also plays backwards.<br>AnimationDirection: 1 \| -1 |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are set.| | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are set. |
**Example** **Example**
...@@ -241,7 +242,7 @@ Sets the direction in which the specified animation plays. ...@@ -241,7 +242,7 @@ Sets the direction in which the specified animation plays.
## AnimationItem ## AnimationItem
Defines an **AnimationItem** object, which is returned by the **loadAnimation** interface and has attributes and interfaces. The attributes are described as follows: Defines an **AnimationItem** object, which is returned by the **loadAnimation** API and has attributes and APIs. The attributes are described as follows:
| Name | Type | Description | | Name | Type | Description |
| ----------------- | ---------------------------------------- | ---------------------------------------- | | ----------------- | ---------------------------------------- | ---------------------------------------- |
...@@ -253,11 +254,11 @@ Defines an **AnimationItem** object, which is returned by the **loadAnimation** ...@@ -253,11 +254,11 @@ Defines an **AnimationItem** object, which is returned by the **loadAnimation**
| totalFrames | number | Total number of frames in the animation segment that is being played. | | totalFrames | number | Total number of frames in the animation segment that is being played. |
| frameRate | number | Frame rate (frame/s). | | frameRate | number | Frame rate (frame/s). |
| frameMult | number | Frame rate (frame/ms). | | frameMult | number | Frame rate (frame/ms). |
| playSpeed | number | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is 0, the animation is paused.|If the value is **1.0** or **-1.0**, the animation plays at the normal speed.| | playSpeed | number | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. |
| playDirection | number | Playback direction. The options are **1** (forward) and **-1** (backward). | | playDirection | number | Playback direction.<br>**1**: forward.<br/>**-1**: backward. |
| playCount | number | Number of times the animation plays. | | playCount | number | Number of times the animation plays. |
| isPaused | boolean | Whether the current animation is paused. The value **true** means that the animation is paused. | | isPaused | boolean | Whether the current animation is paused. The value **true** means that the animation is paused. |
| autoplay | boolean | Whether to automatically play the animation upon completion of the loading. The value **false** means that the **play()** interface needs to be called to start playing.| | autoplay | boolean | Whether to automatically play the animation upon completion of the loading. The value **false** means that the **play()** API needs to be called to start playing. |
| loop | boolean \| number | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays. | | loop | boolean \| number | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays. |
| renderer | any | Animation rendering object, which depends on the rendering type. | | renderer | any | Animation rendering object, which depends on the rendering type. |
| animationID | string | Animation ID. | | animationID | string | Animation ID. |
...@@ -309,7 +310,7 @@ Destroys an animation. ...@@ -309,7 +310,7 @@ Destroys an animation.
pause(name?: string): void pause(name?: string): void
Pauses an animation. When the **play** interface is called next time, the animation is played from the current frame. Pauses an animation. When the **play** API is called next time, the animation is played from the current frame.
**Parameters** **Parameters**
...@@ -328,7 +329,7 @@ Pauses an animation. When the **play** interface is called next time, the animat ...@@ -328,7 +329,7 @@ Pauses an animation. When the **play** interface is called next time, the animat
togglePause(name?: string): void togglePause(name?: string): void
Pauses or plays an animation. This method is equivalent to the switching between **play** and **pause**. Pauses or plays an animation. This API is equivalent to the switching between **play** and **pause**.
**Parameters** **Parameters**
...@@ -347,7 +348,7 @@ Pauses or plays an animation. This method is equivalent to the switching between ...@@ -347,7 +348,7 @@ Pauses or plays an animation. This method is equivalent to the switching between
stop(name?: string): void stop(name?: string): void
Stops an animation. When the **play** interface is called next time, the animation is played from the first frame. Stops an animation. When the **play** API is called next time, the animation is played from the first frame.
**Parameters** **Parameters**
...@@ -372,7 +373,7 @@ Sets the playback speed of an animation. ...@@ -372,7 +373,7 @@ Sets the playback speed of an animation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ---------------------------------------- | | ----- | ------ | ---- | ---------------------------------------- |
| speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is 0, the animation is paused.|If the value is **1.0** or **-1.0**, the animation plays at the normal speed.| | speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. |
**Example** **Example**
...@@ -411,7 +412,7 @@ Sets the animation to stop at the specified frame or time. ...@@ -411,7 +412,7 @@ Sets the animation to stop at the specified frame or time.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------- | ---- | ---------------------------------------- | | ------- | ------- | ---- | ---------------------------------------- |
| value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will stop. | | value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will stop. |
| isFrame | boolean | No | Whether to set the animation to stop at the specified frame. The value **true** means to set the animation to stop at the specified frame, and **false** means to set the animation to stop at the specified time progress. The default value is **false**.| | isFrame | boolean | No | Whether to set the animation to stop at the specified frame. The value **true** means to set the animation to stop at the specified frame, and **false** means to set the animation to stop at the specified time progress.<br/>Default value: **false** |
| name | string | No | Name of the target animation. By default, the value is null. | | name | string | No | Name of the target animation. By default, the value is null. |
**Example** **Example**
...@@ -435,8 +436,8 @@ Sets the animation to start from the specified frame or time progress. ...@@ -435,8 +436,8 @@ Sets the animation to start from the specified frame or time progress.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------- | ---- | ---------------------------------------- | | ------- | ------- | ---- | ---------------------------------------- |
| value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will start. | | value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will start. |
| isFrame | boolean | Yes | Whether to set the animation to start from the specified frame. The value **true** means to set the animation to start from the specified frame, and **false** means to set the animation to start from the specified time progress. The default value is **false**.| | isFrame | boolean | Yes | Whether to set the animation to start from the specified frame. The value **true** means to set the animation to start from the specified frame, and **false** means to set the animation to start from the specified time progress.<br/>Default value: **false** |
| name | string | No | Name of the target animation. By default, the value is null. | | name | string | No | Name of the target animation.<br/>Default value: null |
**Example** **Example**
...@@ -475,7 +476,7 @@ Sets the animation to play only the specified segment. ...@@ -475,7 +476,7 @@ Sets the animation to play only the specified segment.
resetSegments(forceFlag: boolean): void resetSegments(forceFlag: boolean): void
Resets the settings configured by the **playSegments** method to play all the frames. Resets the settings configured by the **playSegments** API to play all the frames.
**Parameters** **Parameters**
...@@ -526,13 +527,13 @@ Sets the precision of the **currentFrame** attribute to display floating-point n ...@@ -526,13 +527,13 @@ Sets the precision of the **currentFrame** attribute to display floating-point n
getDuration(inFrames?: boolean): void getDuration(inFrames?: boolean): void
Obtains the duration (irrelevant to the playback speed) or number of frames for playing an animation sequence. The settings are related to the input parameter **initialSegment** of the **Lottie.loadAnimation** interface. Obtains the duration (irrelevant to the playback speed) or number of frames for playing an animation sequence. The settings are related to the input parameter **initialSegment** of the **Lottie.loadAnimation** API.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------- | ---- | ---------------------------------------- | | -------- | ------- | ---- | ---------------------------------------- |
| inFrames | boolean | No | Whether to obtain the duration or number of frames.<br>**true**: number of frames.<br>**false**: duration, in ms.<br>Default value: **false**| | inFrames | boolean | No | Whether to obtain the duration or number of frames.<br>**true**: number of frames.<br>**false**: duration, in ms.<br/>Default value: **false** |
**Example** **Example**
...@@ -545,7 +546,7 @@ Obtains the duration (irrelevant to the playback speed) or number of frames for ...@@ -545,7 +546,7 @@ Obtains the duration (irrelevant to the playback speed) or number of frames for
addEventListener&lt;T = any&gt;(name: AnimationEventName, callback: AnimationEventCallback&lt;T&gt;): () =&gt; void addEventListener&lt;T = any&gt;(name: AnimationEventName, callback: AnimationEventCallback&lt;T&gt;): () =&gt; void
Adds an event listener. After the event is complete, the specified callback function is triggered. This method returns the function object that can delete the event listener. Adds an event listener. After the event is complete, the specified callback is triggered. This API returns the function object that can delete the event listener.
**Parameters** **Parameters**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册