| write(string eventName, EventType type, object keyValues, AsyncCallback\<void> callback): void | Logs application events in asynchronous mode. This API uses an asynchronous callback to return the result. |
| write(string eventName, EventType type, object keyValues): Promise\<void> | Logs application events in asynchronous mode. This API uses a promise to return the result. |
| write(AppEventInfo info, AsyncCallback\<void> callback): void | Logs application events by domain in asynchronous mode. This API uses an asynchronous callback to return the result.|
| write(AppEventInfo info): Promise\<void> | Logs application events by domain in asynchronous mode. This API uses a promise to return the result.|
| write(AppEventInfo info, AsyncCallback\<void> callback): void | Logs application events in asynchronous mode. This API uses an asynchronous callback to return the result.|
| write(AppEventInfo info): Promise\<void> | Logs application events in asynchronous mode. This API uses a promise to return the result. |
When an asynchronous callback is used, the return value can be processed directly in the callback.
...
...
@@ -49,12 +47,12 @@ For details about the result codes, see [Event Verification Result Codes](#event
| Result Code| Cause | Verification Rules | Handling Method |
| 0 | N/A | Event verification is successful. | Event logging is normal. No action is required. |
| -1 | Invalid event name | The name is not empty and contains a maximum of 48 characters.<br>The name consists of only the following characters: digits (0 to 9), letters (a to z), and underscore \(_).<br>The name does not start with a digit or underscore \(_).| Ignore this event and do not perform logging. |
| -1 | Invalid event name | The name is not empty and contains a maximum of 48 characters.<br>The name consists of only the following characters: digits (0 to 9), letters (a to z), and underscore (\_).<br>The name does not start with a digit or underscore (\_).| Ignore this event and do not perform logging. |
| -2 | Invalid event parameter type | The event name must be a string.<br>The event type must be a number.<br>The event parameter must be an object.| Ignore this event and do not perform logging. |
| -4 | Invalid event domain name | The name is not empty and contains a maximum of 32 characters.<br>The name consists of only the following characters: digits (0 to 9), letters (a to z), and underscore \(_).<br>The name does not start with a digit or underscore \(_).| Ignore this event and do not perform logging. |
| -4 | Invalid event domain name | The name is not empty and contains a maximum of 32 characters.<br>The name consists of only the following characters: digits (0 to 9), letters (a to z), and underscore (\_).<br>The name does not start with a digit or underscore (\_).| Ignore this event and do not perform logging. |
| -99 | Application event logging disabled | Application event logging is disabled. | Ignore this event and do not perform logging. |
| -100 | Unknown error | None. | Ignore this event and do not perform logging. |
| 1 | Invalid key name | The name is not empty and contains a maximum of 16 characters.<br>The name consists of only the following characters: digits (0 to 9), letters (a to z), and underscore \(_).<br>The name does not start with a digit or underscore \(_).<br>The name does not end with an underscore \(_).| Ignore the key-value pair and continue to perform logging. |
| 1 | Invalid key name | The name is not empty and contains a maximum of 16 characters.<br>The name consists of only the following characters: digits (0 to 9), letters (a to z), and underscore (\_).<br>The name does not start with a digit or underscore (\_).<br>The name does not end with an underscore (\_).| Ignore the key-value pair and continue to perform logging. |
| 2 | Invalid key type | The key must be a string. | Ignore the key-value pair and continue to perform logging. |
| 3 | Invalid value type | The supported value types vary depending on the programming language:<br>boolean, number, string, or Array [basic element]| Ignore the key-value pair and continue to perform logging. |
| 4 | Invalid length for values of the string type| For a value of the string type, the maximum length is 8*1024 characters. | Truncate the value with the first 8*1024 characters retained, and continue to perform logging.|
...
...
@@ -84,6 +82,7 @@ The following uses a one-time event watcher as an example to illustrate the deve
.fontWeight(FontWeight.Bold)
Button("1 writeTest").onClick(()=>{
// Perform event logging based on the input event parameters.
hiAppEvent.write({
domain:"test_domain",
name:"test_event",
...
...
@@ -100,6 +99,7 @@ The following uses a one-time event watcher as an example to illustrate the deve
})
Button("2 addWatcherTest").onClick(()=>{
// Add an event watcher based on the input subscription parameters.
hiAppEvent.addWatcher({
name:"watcher1",
appEventFilters:[{domain:"test_domain"}],
...
...
@@ -109,17 +109,23 @@ The following uses a one-time event watcher as an example to illustrate the deve
timeOut:2
},
onTrigger:function(curRow,curSize,holder){
// If the holder object is null, return an error after recording it in the log.
if(holder==null){
console.error("HiAppEvent holder is null");
return;
}
// Set the size threshold to 1,000 bytes for obtaining an event package.
holder.setSize(1000);
leteventPkg=null;
// Obtain the event package based on the configured size threshold. If returned event package is null, all event data has been obtained.
@@ -127,6 +133,7 @@ The following uses a one-time event watcher as an example to illustrate the deve
})
Button("3 removeWatcherTest").onClick(()=>{
// Remove the specified event watcher.
hiAppEvent.removeWatcher({
name:"watcher1"
})
...
...
@@ -157,9 +164,3 @@ The following uses a one-time event watcher as an example to illustrate the deve
```
5. On the application UI, touch button 3 to remove the event watcher. Then, touch button 1 for multiple times to perform application event logging. In such a case, there will be no log information about the callback invoked by the event watcher.
## Samples
The following sample is provided to help you better understand how to develop the application event logging feature:
@@ -7,7 +7,7 @@ There are two types of updates: SD card update and over the air (OTA) update.
- The SD card update depends on the update packages and SD cards.
- The OTA update depends on the server deployed by the device manufacturer for managing update packages. The OTA server IP address is passed by the caller. The request interface is fixed and developed by the device manufacturer.
> **Note:**
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
...
...
@@ -43,13 +43,13 @@ Obtains an **OnlineUpdater** object.
```ts
try{
varupgradeInfo={
constupgradeInfo={
upgradeApp:"com.ohos.ota.updateclient",
businessType:{
vendor:update.BusinessVendor.PUBLIC,
subType:update.BusinessSubType.FIRMWARE
}
}
};
letupdater=update.getOnlineUpdater(upgradeInfo);
}catch(error){
console.error(`Fail to get updater error: ${error}`);
...
...
@@ -226,22 +226,22 @@ Obtains the description file of the new version. This API uses an asynchronous c
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
**Example**
```ts
// Version digest information
varversionDigestInfo={
constversionDigestInfo={
versionDigest:"versionDigest"// Version digest information in the check result
}
};
// Download options
vardownloadOptions={
constdownloadOptions={
allowNetwork:update.NetType.CELLULAR,// Whether to allow download over data network
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
**Example**
```ts
// Version digest information
varversionDigestInfo={
constversionDigestInfo={
versionDigest:"versionDigest"// Version digest information in the check result
}
};
// Options for resuming download
varresumeDownloadOptions={
constresumeDownloadOptions={
allowNetwork:update.NetType.CELLULAR,// Whether to allow download over data network
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
**Example**
```ts
// Version digest information
varversionDigestInfo={
constversionDigestInfo={
versionDigest:"versionDigest"// Version digest information in the check result
}
};
// Options for pausing download
varpauseDownloadOptions={
constpauseDownloadOptions={
isAllowAutoResume:true// Whether to allow automatic resuming of download
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
**Example**
```ts
// Version digest information
varversionDigestInfo={
constversionDigestInfo={
versionDigest:"versionDigest"// Version digest information in the check result
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
**Example**
```ts
// Version digest information
varversionDigestInfo={
constversionDigestInfo={
versionDigest:"versionDigest"// Version digest information in the check result
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
**Example**
...
...
@@ -1041,10 +1041,10 @@ Enables listening for update events. This API uses an asynchronous callback to r
**Example**
```ts
vareventClassifyInfo={
consteventClassifyInfo={
eventClassify:update.EventClassify.TASK,// Listening for update events
extraInfo:""
}
};
updater.on(eventClassifyInfo,(eventInfo)=>{
console.log("updater on "+JSON.stringify(eventInfo));
...
...
@@ -1068,10 +1068,10 @@ Disables listening for update events. This API uses an asynchronous callback to
**Example**
```ts
vareventClassifyInfo={
consteventClassifyInfo={
eventClassify:update.EventClassify.TASK,// Listening for update events
extraInfo:""
}
};
updater.off(eventClassifyInfo,(eventInfo)=>{
console.log("updater off "+JSON.stringify(eventInfo));
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.|
**Example**
```ts
varupgradeFiles=[{
constupgradeFiles=[{
fileType:update.ComponentType.OTA,// OTA package
filePath:"path"// Path of the local update package