1# HiAppEvent<a name="EN-US_TOPIC_0000001162414647"></a> 2 3- [Modules to Import](#en-us_topic_0000001150092213_s56d19203690d4782bfc74069abb6bd71) 4- [Required Permissions](#en-us_topic_0000001150092213_section11257113618419) 5- [Functions](#en-us_topic_0000001150092213_section125675489541) 6- [write\(string, EventType, any..., AsyncCallback<number\>\)](#en-us_topic_0000001150092213_section192192415554) 7- [write\(string, EventType, any...\)](#en-us_topic_0000001150092213_section1696563334210) 8- [writeJson\(string, EventType, object, AsyncCallback<number\>\)](#en-us_topic_0000001150092213_section570630172512) 9- [writeJson\(string, EventType, object\)](#en-us_topic_0000001150092213_section0857164934517) 10- [Enums](#en-us_topic_0000001150092213_section1978842154715) 11- [EventType](#en-us_topic_0000001150092213_section099619567453) 12 13## Modules to Import<a name="en-us_topic_0000001150092213_s56d19203690d4782bfc74069abb6bd71"></a> 14 15``` 16import hiappevent from '@ohos.hiappevent'; 17``` 18 19## Required Permissions<a name="en-us_topic_0000001150092213_section11257113618419"></a> 20 21None. 22 23## Functions<a name="en-us_topic_0000001150092213_section125675489541"></a> 24 25## write\(string, EventType, any..., AsyncCallback<number\>\)<a name="en-us_topic_0000001150092213_section192192415554"></a> 26 27Writes event information to the event file of the current day. This function supports variable parameters and uses an asynchronous callback to return the result. 28 29**Parameters** 30 31<a name="en-us_topic_0000001150092213_table1051173843112"></a> 32<table><thead align="left"><tr id="en-us_topic_0000001150092213_row551638113119"><th class="cellrowborder" valign="top" width="13.969999999999999%" id="mcps1.1.5.1.1"><p id="en-us_topic_0000001150092213_p2512384316"><a name="en-us_topic_0000001150092213_p2512384316"></a><a name="en-us_topic_0000001150092213_p2512384316"></a>Name</p> 33</th> 34<th class="cellrowborder" valign="top" width="13.389999999999999%" id="mcps1.1.5.1.2"><p id="en-us_topic_0000001150092213_p1551113810318"><a name="en-us_topic_0000001150092213_p1551113810318"></a><a name="en-us_topic_0000001150092213_p1551113810318"></a>Type</p> 35</th> 36<th class="cellrowborder" valign="top" width="8.23%" id="mcps1.1.5.1.3"><p id="en-us_topic_0000001150092213_p3519387317"><a name="en-us_topic_0000001150092213_p3519387317"></a><a name="en-us_topic_0000001150092213_p3519387317"></a>Mandatory</p> 37</th> 38<th class="cellrowborder" valign="top" width="64.41%" id="mcps1.1.5.1.4"><p id="en-us_topic_0000001150092213_p1351123815315"><a name="en-us_topic_0000001150092213_p1351123815315"></a><a name="en-us_topic_0000001150092213_p1351123815315"></a>Description</p> 39</th> 40</tr> 41</thead> 42<tbody><tr id="en-us_topic_0000001150092213_row13511538183119"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p1551838113117"><a name="en-us_topic_0000001150092213_p1551838113117"></a><a name="en-us_topic_0000001150092213_p1551838113117"></a>eventName</p> 43</td> 44<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p1051133893111"><a name="en-us_topic_0000001150092213_p1051133893111"></a><a name="en-us_topic_0000001150092213_p1051133893111"></a>string</p> 45</td> 46<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p155183816314"><a name="en-us_topic_0000001150092213_p155183816314"></a><a name="en-us_topic_0000001150092213_p155183816314"></a>Yes</p> 47</td> 48<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p1551173863113"><a name="en-us_topic_0000001150092213_p1551173863113"></a><a name="en-us_topic_0000001150092213_p1551173863113"></a>Indicates the app event name.</p> 49</td> 50</tr> 51<tr id="en-us_topic_0000001150092213_row18516388310"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p3511938103117"><a name="en-us_topic_0000001150092213_p3511938103117"></a><a name="en-us_topic_0000001150092213_p3511938103117"></a>eventType</p> 52</td> 53<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p55183820313"><a name="en-us_topic_0000001150092213_p55183820313"></a><a name="en-us_topic_0000001150092213_p55183820313"></a>EventType</p> 54</td> 55<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p13511138123117"><a name="en-us_topic_0000001150092213_p13511138123117"></a><a name="en-us_topic_0000001150092213_p13511138123117"></a>Yes</p> 56</td> 57<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p75213386311"><a name="en-us_topic_0000001150092213_p75213386311"></a><a name="en-us_topic_0000001150092213_p75213386311"></a>Indicates the app event type.</p> 58</td> 59</tr> 60<tr id="en-us_topic_0000001150092213_row05293803113"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p1452193814313"><a name="en-us_topic_0000001150092213_p1452193814313"></a><a name="en-us_topic_0000001150092213_p1452193814313"></a>params</p> 61</td> 62<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p185283815313"><a name="en-us_topic_0000001150092213_p185283815313"></a><a name="en-us_topic_0000001150092213_p185283815313"></a>any...</p> 63</td> 64<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p25283811312"><a name="en-us_topic_0000001150092213_p25283811312"></a><a name="en-us_topic_0000001150092213_p25283811312"></a>No</p> 65</td> 66<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p552193863115"><a name="en-us_topic_0000001150092213_p552193863115"></a><a name="en-us_topic_0000001150092213_p552193863115"></a>Indicates an array of parameters of the app event. Enter the name and value of each parameter in sequence. A parameter name must be a string, and a parameter value must be a string, number, boolean, or Array (which can only be a string, number, or boolean).</p> 67</td> 68</tr> 69<tr id="en-us_topic_0000001150092213_row13838183316719"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p28393335711"><a name="en-us_topic_0000001150092213_p28393335711"></a><a name="en-us_topic_0000001150092213_p28393335711"></a>callback</p> 70</td> 71<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p48396339719"><a name="en-us_topic_0000001150092213_p48396339719"></a><a name="en-us_topic_0000001150092213_p48396339719"></a>AsyncCallback<number></p> 72</td> 73<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p1783913331671"><a name="en-us_topic_0000001150092213_p1783913331671"></a><a name="en-us_topic_0000001150092213_p1783913331671"></a>No</p> 74</td> 75<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p9749191318299"><a name="en-us_topic_0000001150092213_p9749191318299"></a><a name="en-us_topic_0000001150092213_p9749191318299"></a>Indicates the callback function, which can be used to process the received return value.</p> 76<a name="en-us_topic_0000001150092213_ul988644310291"></a><a name="en-us_topic_0000001150092213_ul988644310291"></a><ul id="en-us_topic_0000001150092213_ul988644310291"><li>Value <strong id="en-us_topic_0000001150092213_b293623314256"><a name="en-us_topic_0000001150092213_b293623314256"></a><a name="en-us_topic_0000001150092213_b293623314256"></a>0</strong> indicates that the event parameter verification is successful, and the event will be written to the event file asynchronously. </li><li>A value greater than 0 indicates that invalid parameters are present in the event, and the event will be written to the event file asynchronously after the invalid parameters are ignored. </li><li>A value less than 0 indicates that the event parameter verification fails, and the event will not be written to the event file asynchronously.</li></ul> 77</td> 78</tr> 79</tbody> 80</table> 81 82**Example** 83 84``` 85hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strData", "strValue", (err, value) => { 86 if (err) { 87 // Event writing failed: The event contains invalid parameters or the event parameter verification fails. 88 console.error(`failed to write event because ${err}`); 89 return; 90 } 91 92 // Event writing succeeded. 93 console.log(`success to write event: ${value}`); 94}); 95``` 96 97## write\(string, EventType, any...\)<a name="en-us_topic_0000001150092213_section1696563334210"></a> 98 99Writes event information to the event file of the current day. This function supports variable parameters and uses an asynchronous promise to return the result. 100 101**Parameters** 102 103<a name="en-us_topic_0000001150092213_table1096583374216"></a> 104<table><thead align="left"><tr id="en-us_topic_0000001150092213_row1296612339427"><th class="cellrowborder" valign="top" width="13.969999999999999%" id="mcps1.1.5.1.1"><p id="en-us_topic_0000001150092213_p696663354219"><a name="en-us_topic_0000001150092213_p696663354219"></a><a name="en-us_topic_0000001150092213_p696663354219"></a>Name</p> 105</th> 106<th class="cellrowborder" valign="top" width="13.389999999999999%" id="mcps1.1.5.1.2"><p id="en-us_topic_0000001150092213_p179660332421"><a name="en-us_topic_0000001150092213_p179660332421"></a><a name="en-us_topic_0000001150092213_p179660332421"></a>Type</p> 107</th> 108<th class="cellrowborder" valign="top" width="8.23%" id="mcps1.1.5.1.3"><p id="en-us_topic_0000001150092213_p11966143312427"><a name="en-us_topic_0000001150092213_p11966143312427"></a><a name="en-us_topic_0000001150092213_p11966143312427"></a>Mandatory</p> 109</th> 110<th class="cellrowborder" valign="top" width="64.41%" id="mcps1.1.5.1.4"><p id="en-us_topic_0000001150092213_p596610331427"><a name="en-us_topic_0000001150092213_p596610331427"></a><a name="en-us_topic_0000001150092213_p596610331427"></a>Description</p> 111</th> 112</tr> 113</thead> 114<tbody><tr id="en-us_topic_0000001150092213_row6966113310425"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p796623344217"><a name="en-us_topic_0000001150092213_p796623344217"></a><a name="en-us_topic_0000001150092213_p796623344217"></a>eventName</p> 115</td> 116<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p596683319422"><a name="en-us_topic_0000001150092213_p596683319422"></a><a name="en-us_topic_0000001150092213_p596683319422"></a>string</p> 117</td> 118<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p17966193374218"><a name="en-us_topic_0000001150092213_p17966193374218"></a><a name="en-us_topic_0000001150092213_p17966193374218"></a>Yes</p> 119</td> 120<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p19661533194218"><a name="en-us_topic_0000001150092213_p19661533194218"></a><a name="en-us_topic_0000001150092213_p19661533194218"></a>Indicates the app event name.</p> 121</td> 122</tr> 123<tr id="en-us_topic_0000001150092213_row896623314429"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p17966153316425"><a name="en-us_topic_0000001150092213_p17966153316425"></a><a name="en-us_topic_0000001150092213_p17966153316425"></a>eventType</p> 124</td> 125<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p496613364212"><a name="en-us_topic_0000001150092213_p496613364212"></a><a name="en-us_topic_0000001150092213_p496613364212"></a>EventType</p> 126</td> 127<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p10966233134216"><a name="en-us_topic_0000001150092213_p10966233134216"></a><a name="en-us_topic_0000001150092213_p10966233134216"></a>Yes</p> 128</td> 129<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p1796643344218"><a name="en-us_topic_0000001150092213_p1796643344218"></a><a name="en-us_topic_0000001150092213_p1796643344218"></a>Indicates the app event type.</p> 130</td> 131</tr> 132<tr id="en-us_topic_0000001150092213_row1696653315423"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p109660332428"><a name="en-us_topic_0000001150092213_p109660332428"></a><a name="en-us_topic_0000001150092213_p109660332428"></a>params</p> 133</td> 134<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p1396663313428"><a name="en-us_topic_0000001150092213_p1396663313428"></a><a name="en-us_topic_0000001150092213_p1396663313428"></a>any...</p> 135</td> 136<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p1196673354215"><a name="en-us_topic_0000001150092213_p1196673354215"></a><a name="en-us_topic_0000001150092213_p1196673354215"></a>No</p> 137</td> 138<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p199671338422"><a name="en-us_topic_0000001150092213_p199671338422"></a><a name="en-us_topic_0000001150092213_p199671338422"></a>Indicates an array of parameters of the app event. Enter the name and value of each parameter in sequence. A parameter name must be a string, and a parameter value must be a string, number, boolean, or Array (which can only be a string, number, or boolean).</p> 139</td> 140</tr> 141</tbody> 142</table> 143 144**Return Values** 145 146<a name="en-us_topic_0000001150092213_table106721328171713"></a> 147<table><thead align="left"><tr id="en-us_topic_0000001150092213_row9672122817176"><th class="cellrowborder" valign="top" width="26.06%" id="mcps1.1.3.1.1"><p id="en-us_topic_0000001150092213_p106728288171"><a name="en-us_topic_0000001150092213_p106728288171"></a><a name="en-us_topic_0000001150092213_p106728288171"></a>Type</p> 148</th> 149<th class="cellrowborder" valign="top" width="73.94%" id="mcps1.1.3.1.2"><p id="en-us_topic_0000001150092213_p5672112817178"><a name="en-us_topic_0000001150092213_p5672112817178"></a><a name="en-us_topic_0000001150092213_p5672112817178"></a>Description</p> 150</th> 151</tr> 152</thead> 153<tbody><tr id="en-us_topic_0000001150092213_row06721528191711"><td class="cellrowborder" valign="top" width="26.06%" headers="mcps1.1.3.1.1 "><p id="en-us_topic_0000001150092213_p107821612171919"><a name="en-us_topic_0000001150092213_p107821612171919"></a><a name="en-us_topic_0000001150092213_p107821612171919"></a>Promise<void></p> 154</td> 155<td class="cellrowborder" valign="top" width="73.94%" headers="mcps1.1.3.1.2 "><p id="en-us_topic_0000001150092213_p4672828141718"><a name="en-us_topic_0000001150092213_p4672828141718"></a><a name="en-us_topic_0000001150092213_p4672828141718"></a>Indicates the promise used to return the execution result.</p> 156</td> 157</tr> 158</tbody> 159</table> 160 161**Example** 162 163``` 164hiappevent.write("testEvent", hiappevent.EventType.FAULT, "intData", 100, "strData", "strValue") 165 .then((value) => { 166 // Event writing succeeded. 167 console.log(`success to write event: ${value}`); 168 }).catch((err) => { 169 // Event writing failed: The event contains invalid parameters or the event parameter verification fails. 170 console.error(`failed to write event because ${err}`); 171 }); 172``` 173 174## writeJson\(string, EventType, object, AsyncCallback<number\>\)<a name="en-us_topic_0000001150092213_section570630172512"></a> 175 176Writes event information to the event file of the current day. This function supports JSON parameters and uses an asynchronous callback to return the result. 177 178**Parameters** 179 180<a name="en-us_topic_0000001150092213_table1054125415456"></a> 181<table><thead align="left"><tr id="en-us_topic_0000001150092213_row354155454518"><th class="cellrowborder" valign="top" width="13.969999999999999%" id="mcps1.1.5.1.1"><p id="en-us_topic_0000001150092213_p17541135415455"><a name="en-us_topic_0000001150092213_p17541135415455"></a><a name="en-us_topic_0000001150092213_p17541135415455"></a>Name</p> 182</th> 183<th class="cellrowborder" valign="top" width="13.389999999999999%" id="mcps1.1.5.1.2"><p id="en-us_topic_0000001150092213_p454195484516"><a name="en-us_topic_0000001150092213_p454195484516"></a><a name="en-us_topic_0000001150092213_p454195484516"></a>Type</p> 184</th> 185<th class="cellrowborder" valign="top" width="8.23%" id="mcps1.1.5.1.3"><p id="en-us_topic_0000001150092213_p115414549454"><a name="en-us_topic_0000001150092213_p115414549454"></a><a name="en-us_topic_0000001150092213_p115414549454"></a>Mandatory</p> 186</th> 187<th class="cellrowborder" valign="top" width="64.41%" id="mcps1.1.5.1.4"><p id="en-us_topic_0000001150092213_p155411354104516"><a name="en-us_topic_0000001150092213_p155411354104516"></a><a name="en-us_topic_0000001150092213_p155411354104516"></a>Description</p> 188</th> 189</tr> 190</thead> 191<tbody><tr id="en-us_topic_0000001150092213_row6541155413451"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p125411454184516"><a name="en-us_topic_0000001150092213_p125411454184516"></a><a name="en-us_topic_0000001150092213_p125411454184516"></a>eventName</p> 192</td> 193<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p5541195416452"><a name="en-us_topic_0000001150092213_p5541195416452"></a><a name="en-us_topic_0000001150092213_p5541195416452"></a>string</p> 194</td> 195<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p754115424514"><a name="en-us_topic_0000001150092213_p754115424514"></a><a name="en-us_topic_0000001150092213_p754115424514"></a>Yes</p> 196</td> 197<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p185421054144516"><a name="en-us_topic_0000001150092213_p185421054144516"></a><a name="en-us_topic_0000001150092213_p185421054144516"></a>Indicates the app event name.</p> 198</td> 199</tr> 200<tr id="en-us_topic_0000001150092213_row2542145416459"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p19542185415455"><a name="en-us_topic_0000001150092213_p19542185415455"></a><a name="en-us_topic_0000001150092213_p19542185415455"></a>eventType</p> 201</td> 202<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p20542205474519"><a name="en-us_topic_0000001150092213_p20542205474519"></a><a name="en-us_topic_0000001150092213_p20542205474519"></a>EventType</p> 203</td> 204<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p1354295494510"><a name="en-us_topic_0000001150092213_p1354295494510"></a><a name="en-us_topic_0000001150092213_p1354295494510"></a>Yes</p> 205</td> 206<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p754216544454"><a name="en-us_topic_0000001150092213_p754216544454"></a><a name="en-us_topic_0000001150092213_p754216544454"></a>Indicates the app event type.</p> 207</td> 208</tr> 209<tr id="en-us_topic_0000001150092213_row354265418456"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p1354215547452"><a name="en-us_topic_0000001150092213_p1354215547452"></a><a name="en-us_topic_0000001150092213_p1354215547452"></a>jsonParam</p> 210</td> 211<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p754225416456"><a name="en-us_topic_0000001150092213_p754225416456"></a><a name="en-us_topic_0000001150092213_p754225416456"></a>object</p> 212</td> 213<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p55421654124517"><a name="en-us_topic_0000001150092213_p55421654124517"></a><a name="en-us_topic_0000001150092213_p55421654124517"></a>Yes</p> 214</td> 215<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p55431154164513"><a name="en-us_topic_0000001150092213_p55431154164513"></a><a name="en-us_topic_0000001150092213_p55431154164513"></a>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).</p> 216</td> 217</tr> 218<tr id="en-us_topic_0000001150092213_row87751758579"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p777595810712"><a name="en-us_topic_0000001150092213_p777595810712"></a><a name="en-us_topic_0000001150092213_p777595810712"></a>callback</p> 219</td> 220<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p1577513581719"><a name="en-us_topic_0000001150092213_p1577513581719"></a><a name="en-us_topic_0000001150092213_p1577513581719"></a>AsyncCallback<number></p> 221</td> 222<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p157753585718"><a name="en-us_topic_0000001150092213_p157753585718"></a><a name="en-us_topic_0000001150092213_p157753585718"></a>No</p> 223</td> 224<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p1065434111303"><a name="en-us_topic_0000001150092213_p1065434111303"></a><a name="en-us_topic_0000001150092213_p1065434111303"></a>Indicates the callback function, which can be used to process the received return value.</p> 225<a name="en-us_topic_0000001150092213_ul182248492307"></a><a name="en-us_topic_0000001150092213_ul182248492307"></a><ul id="en-us_topic_0000001150092213_ul182248492307"><li>Value <strong id="en-us_topic_0000001150092213_b27171235133215"><a name="en-us_topic_0000001150092213_b27171235133215"></a><a name="en-us_topic_0000001150092213_b27171235133215"></a>0</strong> indicates that the event parameter verification is successful, and the event will be written to the event file asynchronously. </li><li>A value greater than 0 indicates that invalid parameters are present in the event, and the event will be written to the event file asynchronously after the invalid parameters are ignored. </li><li>A value less than 0 indicates that the event parameter verification fails, and the event will not be written to the event file asynchronously.</li></ul> 226</td> 227</tr> 228</tbody> 229</table> 230 231**Example** 232 233``` 234hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "strData":"strValue"}, (err, value) => { 235 if (err) { 236 // Event writing failed: The event contains invalid parameters or the event parameter verification fails. 237 console.error(`failed to write event because ${err}`); 238 return; 239 } 240 241 // Event writing succeeded. 242 console.log(`success to write event: ${value}`); 243}); 244``` 245 246## writeJson\(string, EventType, object\)<a name="en-us_topic_0000001150092213_section0857164934517"></a> 247 248Writes event information to the event file of the current day. This function supports JSON parameters and uses an asynchronous promise to return the result. 249 250**Parameters** 251 252<a name="en-us_topic_0000001150092213_table11857249104514"></a> 253<table><thead align="left"><tr id="en-us_topic_0000001150092213_row198584493457"><th class="cellrowborder" valign="top" width="13.969999999999999%" id="mcps1.1.5.1.1"><p id="en-us_topic_0000001150092213_p128580494453"><a name="en-us_topic_0000001150092213_p128580494453"></a><a name="en-us_topic_0000001150092213_p128580494453"></a>Name</p> 254</th> 255<th class="cellrowborder" valign="top" width="13.389999999999999%" id="mcps1.1.5.1.2"><p id="en-us_topic_0000001150092213_p2085813494456"><a name="en-us_topic_0000001150092213_p2085813494456"></a><a name="en-us_topic_0000001150092213_p2085813494456"></a>Type</p> 256</th> 257<th class="cellrowborder" valign="top" width="8.23%" id="mcps1.1.5.1.3"><p id="en-us_topic_0000001150092213_p1285894934516"><a name="en-us_topic_0000001150092213_p1285894934516"></a><a name="en-us_topic_0000001150092213_p1285894934516"></a>Mandatory</p> 258</th> 259<th class="cellrowborder" valign="top" width="64.41%" id="mcps1.1.5.1.4"><p id="en-us_topic_0000001150092213_p48581849104511"><a name="en-us_topic_0000001150092213_p48581849104511"></a><a name="en-us_topic_0000001150092213_p48581849104511"></a>Description</p> 260</th> 261</tr> 262</thead> 263<tbody><tr id="en-us_topic_0000001150092213_row98581498450"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p1185884919459"><a name="en-us_topic_0000001150092213_p1185884919459"></a><a name="en-us_topic_0000001150092213_p1185884919459"></a>eventName</p> 264</td> 265<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p28586495454"><a name="en-us_topic_0000001150092213_p28586495454"></a><a name="en-us_topic_0000001150092213_p28586495454"></a>string</p> 266</td> 267<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p2858144912459"><a name="en-us_topic_0000001150092213_p2858144912459"></a><a name="en-us_topic_0000001150092213_p2858144912459"></a>Yes</p> 268</td> 269<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p8858164984518"><a name="en-us_topic_0000001150092213_p8858164984518"></a><a name="en-us_topic_0000001150092213_p8858164984518"></a>Indicates the app event name.</p> 270</td> 271</tr> 272<tr id="en-us_topic_0000001150092213_row198584495457"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p128583494450"><a name="en-us_topic_0000001150092213_p128583494450"></a><a name="en-us_topic_0000001150092213_p128583494450"></a>eventType</p> 273</td> 274<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p13858449194517"><a name="en-us_topic_0000001150092213_p13858449194517"></a><a name="en-us_topic_0000001150092213_p13858449194517"></a>EventType</p> 275</td> 276<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p1785894934513"><a name="en-us_topic_0000001150092213_p1785894934513"></a><a name="en-us_topic_0000001150092213_p1785894934513"></a>Yes</p> 277</td> 278<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p198581349194515"><a name="en-us_topic_0000001150092213_p198581349194515"></a><a name="en-us_topic_0000001150092213_p198581349194515"></a>Indicates the app event type.</p> 279</td> 280</tr> 281<tr id="en-us_topic_0000001150092213_row78580497453"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="en-us_topic_0000001150092213_p2085819494459"><a name="en-us_topic_0000001150092213_p2085819494459"></a><a name="en-us_topic_0000001150092213_p2085819494459"></a>jsonParam</p> 282</td> 283<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="en-us_topic_0000001150092213_p8859749154519"><a name="en-us_topic_0000001150092213_p8859749154519"></a><a name="en-us_topic_0000001150092213_p8859749154519"></a>object</p> 284</td> 285<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="en-us_topic_0000001150092213_p1385984964515"><a name="en-us_topic_0000001150092213_p1385984964515"></a><a name="en-us_topic_0000001150092213_p1385984964515"></a>Yes</p> 286</td> 287<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="en-us_topic_0000001150092213_p1859114984515"><a name="en-us_topic_0000001150092213_p1859114984515"></a><a name="en-us_topic_0000001150092213_p1859114984515"></a>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).</p> 288</td> 289</tr> 290</tbody> 291</table> 292 293**Return Values** 294 295<a name="en-us_topic_0000001150092213_table10811610134713"></a> 296<table><thead align="left"><tr id="en-us_topic_0000001150092213_row7811410124716"><th class="cellrowborder" valign="top" width="26.06%" id="mcps1.1.3.1.1"><p id="en-us_topic_0000001150092213_p118116107479"><a name="en-us_topic_0000001150092213_p118116107479"></a><a name="en-us_topic_0000001150092213_p118116107479"></a>Type</p> 297</th> 298<th class="cellrowborder" valign="top" width="73.94%" id="mcps1.1.3.1.2"><p id="en-us_topic_0000001150092213_p8811910124715"><a name="en-us_topic_0000001150092213_p8811910124715"></a><a name="en-us_topic_0000001150092213_p8811910124715"></a>Description</p> 299</th> 300</tr> 301</thead> 302<tbody><tr id="en-us_topic_0000001150092213_row1181161019479"><td class="cellrowborder" valign="top" width="26.06%" headers="mcps1.1.3.1.1 "><p id="en-us_topic_0000001150092213_p15811181004712"><a name="en-us_topic_0000001150092213_p15811181004712"></a><a name="en-us_topic_0000001150092213_p15811181004712"></a>Promise<void></p> 303</td> 304<td class="cellrowborder" valign="top" width="73.94%" headers="mcps1.1.3.1.2 "><p id="en-us_topic_0000001150092213_p14811710164718"><a name="en-us_topic_0000001150092213_p14811710164718"></a><a name="en-us_topic_0000001150092213_p14811710164718"></a>Indicates the promise used to return the execution result.</p> 305</td> 306</tr> 307</tbody> 308</table> 309 310**Example** 311 312``` 313hiappevent.writeJson("testEvent", hiappevent.EventType.FAULT, {"intData":100, "strData":"strValue"}) 314 .then((value) => { 315 // Event writing succeeded. 316 console.log(`success to write event: ${value}`); 317 }).catch((err) => { 318 // Event writing failed: The event contains invalid parameters or the event parameter verification fails. 319 console.error(`failed to write event because ${err}`); 320 }); 321``` 322 323## Enums<a name="en-us_topic_0000001150092213_section1978842154715"></a> 324 325## EventType<a name="en-us_topic_0000001150092213_section099619567453"></a> 326 327Enumerates event types. 328 329<a name="en-us_topic_0000001150092213_table20633101642315"></a> 330<table><thead align="left"><tr id="en-us_topic_0000001150092213_row663331618238"><th class="cellrowborder" valign="top" width="27.900000000000002%" id="mcps1.1.4.1.1"><p id="en-us_topic_0000001150092213_a3d0fc780cc904c1cbab7991251622f65"><a name="en-us_topic_0000001150092213_a3d0fc780cc904c1cbab7991251622f65"></a><a name="en-us_topic_0000001150092213_a3d0fc780cc904c1cbab7991251622f65"></a>Name</p> 331</th> 332<th class="cellrowborder" valign="top" width="12.43%" id="mcps1.1.4.1.2"><p id="en-us_topic_0000001150092213_aace9cae4ba0d4939bfa048460f61c3c7"><a name="en-us_topic_0000001150092213_aace9cae4ba0d4939bfa048460f61c3c7"></a><a name="en-us_topic_0000001150092213_aace9cae4ba0d4939bfa048460f61c3c7"></a>Default Value</p> 333</th> 334<th class="cellrowborder" valign="top" width="59.67%" id="mcps1.1.4.1.3"><p id="en-us_topic_0000001150092213_afec895de33f94e3c87ee7acc20190a17"><a name="en-us_topic_0000001150092213_afec895de33f94e3c87ee7acc20190a17"></a><a name="en-us_topic_0000001150092213_afec895de33f94e3c87ee7acc20190a17"></a>Description</p> 335</th> 336</tr> 337</thead> 338<tbody><tr id="en-us_topic_0000001150092213_row188481425182510"><td class="cellrowborder" valign="top" width="27.900000000000002%" headers="mcps1.1.4.1.1 "><p id="en-us_topic_0000001150092213_p13876443113318"><a name="en-us_topic_0000001150092213_p13876443113318"></a><a name="en-us_topic_0000001150092213_p13876443113318"></a>FAULT</p> 339</td> 340<td class="cellrowborder" valign="top" width="12.43%" headers="mcps1.1.4.1.2 "><p id="en-us_topic_0000001150092213_p2282152962115"><a name="en-us_topic_0000001150092213_p2282152962115"></a><a name="en-us_topic_0000001150092213_p2282152962115"></a>1</p> 341</td> 342<td class="cellrowborder" valign="top" width="59.67%" headers="mcps1.1.4.1.3 "><p id="en-us_topic_0000001150092213_p28751543103312"><a name="en-us_topic_0000001150092213_p28751543103312"></a><a name="en-us_topic_0000001150092213_p28751543103312"></a>Fault event</p> 343</td> 344</tr> 345<tr id="en-us_topic_0000001150092213_row0461622112513"><td class="cellrowborder" valign="top" width="27.900000000000002%" headers="mcps1.1.4.1.1 "><p id="en-us_topic_0000001150092213_p68697436338"><a name="en-us_topic_0000001150092213_p68697436338"></a><a name="en-us_topic_0000001150092213_p68697436338"></a>STATISTIC</p> 346</td> 347<td class="cellrowborder" valign="top" width="12.43%" headers="mcps1.1.4.1.2 "><p id="en-us_topic_0000001150092213_p1310553911218"><a name="en-us_topic_0000001150092213_p1310553911218"></a><a name="en-us_topic_0000001150092213_p1310553911218"></a>2</p> 348</td> 349<td class="cellrowborder" valign="top" width="59.67%" headers="mcps1.1.4.1.3 "><p id="en-us_topic_0000001150092213_p14868114312331"><a name="en-us_topic_0000001150092213_p14868114312331"></a><a name="en-us_topic_0000001150092213_p14868114312331"></a>Statistical event</p> 350</td> 351</tr> 352<tr id="en-us_topic_0000001150092213_row91702048195619"><td class="cellrowborder" valign="top" width="27.900000000000002%" headers="mcps1.1.4.1.1 "><p id="en-us_topic_0000001150092213_p123991673342"><a name="en-us_topic_0000001150092213_p123991673342"></a><a name="en-us_topic_0000001150092213_p123991673342"></a>SECURITY</p> 353</td> 354<td class="cellrowborder" valign="top" width="12.43%" headers="mcps1.1.4.1.2 "><p id="en-us_topic_0000001150092213_p14170114811561"><a name="en-us_topic_0000001150092213_p14170114811561"></a><a name="en-us_topic_0000001150092213_p14170114811561"></a>3</p> 355</td> 356<td class="cellrowborder" valign="top" width="59.67%" headers="mcps1.1.4.1.3 "><p id="en-us_topic_0000001150092213_p1539912793411"><a name="en-us_topic_0000001150092213_p1539912793411"></a><a name="en-us_topic_0000001150092213_p1539912793411"></a>Security event</p> 357</td> 358</tr> 359<tr id="en-us_topic_0000001150092213_row717094895612"><td class="cellrowborder" valign="top" width="27.900000000000002%" headers="mcps1.1.4.1.1 "><p id="en-us_topic_0000001150092213_p10231410193416"><a name="en-us_topic_0000001150092213_p10231410193416"></a><a name="en-us_topic_0000001150092213_p10231410193416"></a>BEHAVIOR</p> 360</td> 361<td class="cellrowborder" valign="top" width="12.43%" headers="mcps1.1.4.1.2 "><p id="en-us_topic_0000001150092213_p1817134815569"><a name="en-us_topic_0000001150092213_p1817134815569"></a><a name="en-us_topic_0000001150092213_p1817134815569"></a>4</p> 362</td> 363<td class="cellrowborder" valign="top" width="59.67%" headers="mcps1.1.4.1.3 "><p id="en-us_topic_0000001150092213_p523171020343"><a name="en-us_topic_0000001150092213_p523171020343"></a><a name="en-us_topic_0000001150092213_p523171020343"></a>System behavior event</p> 364</td> 365</tr> 366</tbody> 367</table> 368 369