HiAppEvent
- Modules to Import
- Required Permissions
- Functions
- write(string, EventType, any..., AsyncCallback<number>)
- write(string, EventType, any...)
- writeJson(string, EventType, object, AsyncCallback<number>)
- writeJson(string, EventType, object)
- Enums
- EventType
Modules to Import
import hiappevent from '@ohos.hiappevent';
Required Permissions
None.
Functions
write(string, EventType, any..., AsyncCallback<number>)
Writes event information to the event file of the current day. This function supports variable parameters and uses an asynchronous callback to return the result.
Parameters
Example
hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strData", "strValue", (err, value) => {
if (err) {
// Event writing failed: The event contains invalid parameters or the event parameter verification fails.
console.error(`failed to write event because ${err}`);
return;
}
// Event writing succeeded.
console.log(`success to write event: ${value}`);
});
write(string, EventType, any...)
Writes event information to the event file of the current day. This function supports variable parameters and uses an asynchronous promise to return the result.
Parameters
Return Values
Example
hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strData", "strValue")
.then((value) => {
// Event writing succeeded.
console.log(`success to write event: ${value}`);
}).catch((err) => {
// Event writing failed: The event contains invalid parameters or the event parameter verification fails.
console.error(`failed to write event because ${err}`);
});
writeJson(string, EventType, object, AsyncCallback<number>)
Writes event information to the event file of the current day. This function supports JSON parameters and uses an asynchronous callback to return the result.
Parameters
Example
hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "strData":"strValue"}, (err, value) => {
if (err) {
// Event writing failed: The event contains invalid parameters or the event parameter verification fails.
console.error(`failed to write event because ${err}`);
return;
}
// Event writing succeeded.
console.log(`success to write event: ${value}`);
});
writeJson(string, EventType, object)
Writes event information to the event file of the current day. This function supports JSON parameters and uses an asynchronous promise to return the result.
Parameters
Indicates an array of JSON parameters of the app event. A key must be a string, and a value must be a string, number, boolean, or Array (which can only be a string, number, or boolean). |
Return Values
Example
hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "strData":"strValue"})
.then((value) => {
// Event writing succeeded.
console.log(`success to write event: ${value}`);
}).catch((err) => {
// Event writing failed: The event contains invalid parameters or the event parameter verification fails.
console.error(`failed to write event because ${err}`);
});
Enums
EventType
Enumerates event types.