提交 f251f0d0 编写于 作者: E ester.zhou

Update docs (9604)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 b169e240
...@@ -202,7 +202,7 @@ struct DialogTest { ...@@ -202,7 +202,7 @@ struct DialogTest {
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9 Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
The **\<List>** component is a scrollable container. By default, it taks up the entire screen height. When any component with a fixed height takes up part of the screen height, you need to explicitly specify **layoutWeight(1)** for the parent container of the **\<List>** component to take up the remaining height instead of the entire screen height. The **\<List>** component is a scrollable container. By default, it takes up the entire screen height. When any component with a fixed height takes up part of the screen height, you need to explicitly specify **layoutWeight(1)** for the parent container of the **\<List>** component to take up the remaining height instead of the entire screen height.
## How do I center child components in a grid container? ## How do I center child components in a grid container?
......
...@@ -30,7 +30,7 @@ let options = {trim : false, declarationKey:"_declaration", ...@@ -30,7 +30,7 @@ let options = {trim : false, declarationKey:"_declaration",
nameKey : "_name", elementsKey : "_elements"} nameKey : "_name", elementsKey : "_elements"}
let result:any = conv.convert(xml, options) // Convert fields in the XML file into JavaScript objects. let result:any = conv.convert(xml, options) // Convert fields in the XML file into JavaScript objects.
console.log('Test: ' + JSON.stringify(result)) console.log('Test: ' + JSON.stringify(result))
console.log('Test: ' + result._declaration._attributes.version) // vesion field in XML file console.log('Test: ' + result._declaration._attributes.version) // version field in XML file
console.log('Test: ' + result._elements[0]._elements[0]._elements[0]._text) // title field in XML file console.log('Test: ' + result._elements[0]._elements[0]._elements[0]._text) // title field in XML file
``` ```
......
...@@ -13,14 +13,14 @@ Each application can subscribe to common events as required. After your applicat ...@@ -13,14 +13,14 @@ Each application can subscribe to common events as required. After your applicat
## Common Event Subscription Development ## Common Event Subscription Development
### When to Use ### When to Use
You can create a subscriber object to subscribe to a common event to obtain the parameters passed in the event. Certain system common events require specific permissions to subscribe to. For details, see [Required Permissions](../reference/apis/js-apis-commonEvent.md). You can create a subscriber object to subscribe to a common event to obtain the parameters passed in the event. Certain system common events require specific permissions to subscribe to. For details, see [Required Permissions](../reference/apis/js-apis-commonEvent.md#required-permissions).
### Available APIs ### Available APIs
| API | Description| | API | Description|
| ---------------------------------------------------------------------------------------------- | ----------- | | ---------------------------------------------------------------------------------------------- | ----------- |
| commonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback) | Creates a subscriber. This API uses a callback to return the result.| | createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback) | Creates a subscriber. This API uses a callback to return the result.|
| commonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo) | Creates a subscriber. This API uses a promise to return the result. | | createSubscriber(subscribeInfo: CommonEventSubscribeInfo) | Creates a subscriber. This API uses a promise to return the result. |
| commonEvent.subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback) | Subscribes to common events.| | subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback) | Subscribes to common events.|
### How to Develop ### How to Develop
1. Import the **commonEvent** module. 1. Import the **commonEvent** module.
...@@ -82,8 +82,8 @@ You can use the **publish** APIs to publish a custom common event, which can car ...@@ -82,8 +82,8 @@ You can use the **publish** APIs to publish a custom common event, which can car
### Available APIs ### Available APIs
| API | Description| | API | Description|
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| commonEvent.publish(event: string, callback: AsyncCallback) | Publishes a common event.| | publish(event: string, callback: AsyncCallback) | Publishes a common event.|
| commonEvent.publish(event: string, options: CommonEventPublishData, callback: AsyncCallback) | Publishes a common event with given attributes.| | publish(event: string, options: CommonEventPublishData, callback: AsyncCallback) | Publishes a common event with given attributes.|
### How to Develop ### How to Develop
#### Development for Publishing a Common Event #### Development for Publishing a Common Event
...@@ -119,7 +119,7 @@ import commonEvent from '@ohos.commonEvent' ...@@ -119,7 +119,7 @@ import commonEvent from '@ohos.commonEvent'
// Attributes of a common event. // Attributes of a common event.
var options = { var options = {
code: 1, // Result code of the common event code: 1, // Result code of the common event
data: "initial data",// Result data of the common event data: "initial data";// Result data of the common event
} }
``` ```
...@@ -144,7 +144,7 @@ You can use the **unsubscribe** API to unsubscribe from a common event. ...@@ -144,7 +144,7 @@ You can use the **unsubscribe** API to unsubscribe from a common event.
### Available APIs ### Available APIs
| API | Description| | API | Description|
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| commonEvent.unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback) | Unsubscribes from a common event.| | unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback) | Unsubscribes from a common event.|
### How to Develop ### How to Develop
1. Import the **commonEvent** module. 1. Import the **commonEvent** module.
......
...@@ -7,16 +7,13 @@ Common Event Service (CES) enables applications to publish, subscribe to, and un ...@@ -7,16 +7,13 @@ Common Event Service (CES) enables applications to publish, subscribe to, and un
![ces](figures/ces.png) ![ces](figures/ces.png)
- System common event: sent by the system based on system policies to the applications that have subscribed to the event. This type of event includes the screen-on/off events that the users are aware of and the system events published by key system services, such as USB device attachment or detachment, network connection, and system update events. - System common event: sent by the system based on system policies to the applications that have subscribed to the event. This type of event includes the screen-on/off events that the users are aware of and the system events published by key system services, such as USB device attachment or detachment, network connection, and system update events.
- Custom common event: customized by applications to be received by specific subscribers. This type of event is usually related to the service logic of the sender applications. - Custom common event: customized by applications to be received by specific subscribers. This type of event is usually related to the service logic of the sender applications.
The Advanced Notification Service (ANS) enables applications to publish notifications. Below are some typical use cases for publishing notifications: The Advanced Notification Service (ANS) enables applications to publish notifications. Below are some typical use cases for publishing notifications:
- Display received SMS messages and instant messages. - Display received SMS messages and instant messages.
- Display push messages of applications, such as advertisements, version updates, and news notifications.
- Display push messages of applications, such as advertisements, version updates, and news notifications. - Display ongoing events, such as music playback, navigation information, and download progress.
- Display ongoing events, such as music playback, navigation information, and download progress.
Notifications are displayed in the notification panel. Uses can delete a notification or click the notification to trigger predefined actions. Notifications are displayed in the notification panel. Uses can delete a notification or click the notification to trigger predefined actions.
......
...@@ -16,19 +16,6 @@ import emitter from '@ohos.events.emitter' ...@@ -16,19 +16,6 @@ import emitter from '@ohos.events.emitter'
None None
## EventPriority
Enumerates the event emit priority levels.
**System capability**: SystemCapability.Notification.Emitter
| Name | Value | Description |
| --------- | ---- | ------------------------------------------------- |
| IMMEDIATE | 0 | The event will be emitted immediately. |
| HIGH | 1 | The event will be emitted before low-priority events. |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority. |
| IDLE | 3 | The event will be emitted after all the other events. |
## emitter.on ## emitter.on
on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void
...@@ -47,13 +34,13 @@ Subscribes to an event in persistent manner. This API uses a callback to return ...@@ -47,13 +34,13 @@ Subscribes to an event in persistent manner. This API uses a callback to return
**Example** **Example**
```javascript ```javascript
var innerEvent = { let innerEvent = {
eventId: 1 eventId: 1
}; };
var callback = (eventData) => { function EmitterCallback(eventData) {
console.info('callback'); console.info('callback');
}; }
emitter.on(innerEvent, callback); emitter.on(innerEvent, EmitterCallback);
``` ```
## emitter.once ## emitter.once
...@@ -74,13 +61,13 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve ...@@ -74,13 +61,13 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve
**Example** **Example**
```javascript ```javascript
var innerEvent = { let innerEvent = {
eventId: 1 eventId: 1
}; };
var callback = (eventData) => { function EmitterCallback(eventData) {
console.info('once callback'); console.info('once callback');
}; };
emitter.once(innerEvent, callback); emitter.once(innerEvent, EmitterCallback);
``` ```
## emitter.off ## emitter.off
...@@ -121,18 +108,31 @@ Emits an event to the event queue. ...@@ -121,18 +108,31 @@ Emits an event to the event queue.
**Example** **Example**
```javascript ```javascript
var eventData = { let eventData = {
data: { data: {
"content": "c", "content": "c",
"id": 1, "id": 1,
}}; }};
var innerEvent = { let innerEvent = {
eventId: 1, eventId: 1,
priority: emitter.EventPriority.HIGH priority: emitter.EventPriority.HIGH
}; };
emitter.emit(innerEvent, eventData); emitter.emit(innerEvent, eventData);
``` ```
## EventPriority
Enumerates the event emit priority levels.
**System capability**: SystemCapability.Notification.Emitter
| Name | Value | Description |
| --------- | ---- | --------------------------------------------------- |
| IMMEDIATE | 0 | The event will be emitted immediately. |
| HIGH | 1 | The event will be emitted before low-priority events. |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority.|
| IDLE | 3 | The event will be emitted after all the other events. |
## InnerEvent ## InnerEvent
Describes an in-process event. Describes an in-process event.
...@@ -141,7 +141,7 @@ Describes an in-process event. ...@@ -141,7 +141,7 @@ Describes an in-process event.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| -------- | ------------------------------- | ---- | ---- | ---------------------------------- | | -------- | ------------------------------- | ---- | ---- | ---------------------------------- |
| eventId | number | Yes | Yes | Event ID, which is used to identify an event.| | eventId | number | Yes | Yes | Event ID. |
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event. | | priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event. |
## EventData ## EventData
......
...@@ -233,61 +233,46 @@ Locks the screen. This API uses a promise to return the result. ...@@ -233,61 +233,46 @@ Locks the screen. This API uses a promise to return the result.
}); });
``` ```
## EventType
## screenlock.on<sup>9+</sup> Defines the system event type.
on(type: 'beginWakeUp' | 'endWakeUp' | 'beginScreenOn' | 'endScreenOn' | 'beginScreenOff' | 'endScreenOff' | 'unlockScreen' | 'beginExitAnimation', callback: Callback\<void\>): void
Subscribes to screen lock status changes.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API and cannot be called by third-party applications. | Name| Description|
| -------- | -------- |
**Parameters** | beginWakeUp | Wakeup starts when the event starts.|
| endWakeUp | Wakeup ends when the event ends.|
| Name| Type| Mandatory| Description| | beginScreenOn | Screen turn-on starts when the event starts.|
| -------- | -------- | -------- | -------- | | endScreenOn | Screen turn-on ends when the event ends.|
| type | string | Yes| Event type.<br>- **"beginWakeUp"**: Wakeup starts.<br>- **"endWakeUp"**: Wakeup ends.<br>- **"beginScreenOn"**: Screen turn-on starts.<br>- **"endScreenOn"**: Screen turn-on ends.<br>- **"beginScreenOff"**: Screen turn-off starts.<br>- **"endScreenOff"**: Screen turn-off ends.<br>- **"unlockScreen"**: The screen is unlocked.<br>- **"beginExitAnimation"**: Animation starts to exit.| | beginScreenOff | Screen turn-off starts when the event starts.|
| callback | Callback\<void\> | Yes| Callback used to return the result.| | endScreenOff | Screen turn-off ends when the event ends.|
| unlockScreen | The screen is unlocked.|
**Example** | lockScreen | The screen is locked.|
| beginExitAnimation | Animation starts to exit.|
```js | beginSleep | The screen enters sleep mode.|
screenlock.on('beginWakeUp', () => { | endSleep | The screen exits sleep mode.|
console.log('beginWakeUp triggered'); | changeUser | The user is switched.|
}); | screenlockEnabled | Screen lock is enabled.|
``` | serviceRestart | The screen lock service is restarted.|
## screenlock.on<sup>9+</sup>
## SystemEvent
on(type: 'beginSleep' | 'endSleep' | 'changeUser', callback: Callback\<number\>): void
Defines the structure of the system event callback.
Subscribes to screen lock status changes.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API and cannot be called by third-party applications. | Name| Description|
| -------- | -------- |
**Parameters** | eventType | System event type.|
| params | System event parameters.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type.<br>- **"beginSleep"**: The screen enters sleep mode.<br>- **"endSleep"**: The screen exits sleep mode.<br>- **"changeUser"**: The user is switched.|
| callback | Callback\<number\> | Yes| Callback used to return the result. |
**Example**
```js ## screenlock.onSystemEvent<sup>9+</sup>
screenlock.on('beginSleep', (why) => {
console.log('beginSleep triggered:' + why);
});
```
## screenlock.on<sup>9+</sup>
on(type: 'screenlockEnabled', callback: Callback\<boolean\>): void onSystemEvent(callback: Callback\<SystemEvent\>): boolean
Subscribes to screen lock status changes. Registers a callback for system events related to screen locking.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
...@@ -297,41 +282,26 @@ Subscribes to screen lock status changes. ...@@ -297,41 +282,26 @@ Subscribes to screen lock status changes.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type.<br>- **"screenlockEnabled"**: Screen lock is enabled.| | callback | Callback\<SystemEvent\> | Yes| Callback for system events related to screen locking|
| callback | Callback\<boolean\> | Yes| Callback used to return the result. |
**Example**
```js
screenlock.on('screenlockEnabled', (isEnabled) => {
console.log('screenlockEnabled triggered, result:' + isEnabled);
});
```
## screenlock.off<sup>9+</sup>
off(type: 'beginWakeUp' | 'endWakeUp' | 'beginScreenOn' | 'endScreenOn' | 'beginScreenOff' | 'endScreenOff' **Return value**
| 'unlockScreen' | 'beginExitAnimation' | 'screenlockEnabled' | 'beginSleep' | 'endSleep' | 'changeUser', callback: Callback\<void\>): void
Unsubscribes from screen lock status changes.
**System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description| | Type | Description |
| -------- | -------- | -------- | -------- | | ------- | -------------------------------------------- |
| type | string | Yes| Event type.<br>- **"beginWakeUp"**: Wakeup starts.<br>- **"endWakeUp"**: Wakeup ends.<br>- **"beginScreenOn"**: Screen turn-on starts.<br>- **"endScreenOn"**: Screen turn-on ends.<br>- **"beginScreenOff"**: Screen turn-off starts.<br>- **"endScreenOff"**: Screen turn-off ends.<br>- **"unlockScreen"**: The screen is unlocked.<br>- **"beginExitAnimation"**: Animation starts to exit.<br>- **"screenlockEnabled"**: Screen lock is enabled.<br>- **"beginSleep"**: The screen enters sleep mode.<br>- **"endSleep"**: The screen exits sleep mode.<br>- **"changeUser"**: The user is switched.| | boolean | The value **true** means that the callback is registered successfully, and **false** means the opposite.|
| callback | Callback\<void\> | Yes| Callback used to return the result.|
**Example** **Example**
```js ```js
screenlock.off('beginWakeUp', () => { let isSuccess = screenlock.onSystemEvent((err, event)=>{
console.log("callback"); console.log(`onSystemEvent:callback:${event.eventType}`)
}); if (err) {
console.log(`onSystemEvent callback error -> ${JSON.stringify(err)}`);
}
});
if (!isSuccess) {
console.log(`onSystemEvent result is false`)
}
``` ```
## screenlock.sendScreenLockEvent<sup>9+</sup> ## screenlock.sendScreenLockEvent<sup>9+</sup>
...@@ -375,7 +345,7 @@ Sends an event to the screen lock service. This API uses a promise to return the ...@@ -375,7 +345,7 @@ Sends an event to the screen lock service. This API uses a promise to return the
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | String | Yes| Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"screenDrawDone"**: Screen drawing is complete.| | event | String | Yes| Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"screenDrawDone"**: Screen drawing is complete.|
| parameter | number | Yes| Screen unlock status.<br>- **0**: The unlock is successful.<br>- **1**: The unlock failed.<br>- **2**: The unlock was canceled.| | parameter | number | Yes| Screen unlock status.<br>- **0**: The unlock is successful.<br>- **1**: The unlock fails.<br>- **2**: The unlock is canceled.|
**Return value** **Return value**
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
The **systemTime** module provides system time and time zone features. You can use the APIs of this module to set and obtain the system time and time zone. The **systemTime** module provides system time and time zone features. You can use the APIs of this module to set and obtain the system time and time zone.
> **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 of this module are system APIs and cannot be called by third-party applications. > - 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
...@@ -60,7 +60,7 @@ Sets the system time. This API uses a promise to return the result. ...@@ -60,7 +60,7 @@ Sets the system time. This API uses a promise to return the result.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ | | ------ | ------ | ---- | ------------------ |
| time | number | Yes | Timestamp to set, in milliseconds. | | time | number | Yes | Timestamp to set, in milliseconds.|
**Return value** **Return value**
...@@ -83,7 +83,7 @@ Sets the system time. This API uses a promise to return the result. ...@@ -83,7 +83,7 @@ Sets the system time. This API uses a promise to return the result.
## systemTime.getCurrentTime<sup>8+</sup> ## systemTime.getCurrentTime<sup>8+</sup>
getCurrentTime(isNano?: boolean, callback: AsyncCallback&lt;number&gt;): void getCurrentTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since the Unix epoch. This API uses an asynchronous callback to return the result. Obtains the time elapsed since the Unix epoch. This API uses an asynchronous callback to return the result.
...@@ -93,7 +93,7 @@ Obtains the time elapsed since the Unix epoch. This API uses an asynchronous cal ...@@ -93,7 +93,7 @@ Obtains the time elapsed since the Unix epoch. This API uses an asynchronous cal
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds. | | isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. |
**Example** **Example**
...@@ -109,6 +109,33 @@ Obtains the time elapsed since the Unix epoch. This API uses an asynchronous cal ...@@ -109,6 +109,33 @@ Obtains the time elapsed since the Unix epoch. This API uses an asynchronous cal
``` ```
## systemTime.getCurrentTime<sup>8+</sup>
getCurrentTime(callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since the Unix epoch. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. |
**Example**
```js
systemTime.getCurrentTime((error, data) => {
if (error) {
console.error(`failed to systemTime.getCurrentTime because ` + JSON.stringify(error));
return;
}
console.log(`systemTime.getCurrentTime success data : ` + JSON.stringify(data));
});
```
## systemTime.getCurrentTime<sup>8+</sup> ## systemTime.getCurrentTime<sup>8+</sup>
getCurrentTime(isNano?: boolean): Promise&lt;number&gt; getCurrentTime(isNano?: boolean): Promise&lt;number&gt;
...@@ -121,7 +148,7 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return ...@@ -121,7 +148,7 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------------------------------------------ | | ------ | ------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds. | | isNano | boolean | No | Whether the time to return is in nanoseconds.<br/>- **true**: in nanoseconds.<br>- **false**: in milliseconds. |
**Return value** **Return value**
...@@ -142,7 +169,7 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return ...@@ -142,7 +169,7 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return
## systemTime.getRealActiveTime<sup>8+</sup> ## systemTime.getRealActiveTime<sup>8+</sup>
getRealActiveTime(isNano?: boolean, callback: AsyncCallback&lt;number&gt;): void getRealActiveTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since system start, excluding the deep sleep time. This API uses an asynchronous callback to return the result. Obtains the time elapsed since system start, excluding the deep sleep time. This API uses an asynchronous callback to return the result.
...@@ -152,7 +179,7 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This ...@@ -152,7 +179,7 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds. | | isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br/>- **true**: in nanoseconds.<br>- **false**: in milliseconds. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time.| | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time.|
**Example** **Example**
...@@ -168,6 +195,33 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This ...@@ -168,6 +195,33 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This
``` ```
## systemTime.getRealActiveTime<sup>8+</sup>
getRealActiveTime(callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since system start, excluding the deep sleep time. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time.|
**Example**
```js
systemTime.getRealActiveTime((error, data) => {
if (error) {
console.error(`failed to systemTime.getRealActiveTimebecause ` + JSON.stringify(error));
return;
}
console.log(`systemTime.getRealActiveTime success data : ` + JSON.stringify(data));
});
```
## systemTime.getRealActiveTime<sup>8+</sup> ## systemTime.getRealActiveTime<sup>8+</sup>
getRealActiveTime(isNano?: boolean): Promise&lt;number&gt; getRealActiveTime(isNano?: boolean): Promise&lt;number&gt;
...@@ -180,7 +234,7 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This ...@@ -180,7 +234,7 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------------------------------------------ | | ------ | ------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds. | | isNano | boolean | No | Whether the time to return is in nanoseconds.<br/>- **true**: in nanoseconds.<br>- **false**: in milliseconds. |
**Return value** **Return value**
...@@ -201,7 +255,7 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This ...@@ -201,7 +255,7 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This
## systemTime.getRealTime<sup>8+</sup> ## systemTime.getRealTime<sup>8+</sup>
getRealTime(isNano?: boolean, callback: AsyncCallback&lt;number&gt;): void getRealTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since system start, including the deep sleep time. This API uses an asynchronous callback to return the result. Obtains the time elapsed since system start, including the deep sleep time. This API uses an asynchronous callback to return the result.
...@@ -211,7 +265,7 @@ Obtains the time elapsed since system start, including the deep sleep time. This ...@@ -211,7 +265,7 @@ Obtains the time elapsed since system start, including the deep sleep time. This
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds. | | isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br/>- **true**: in nanoseconds.<br>- **false**: in milliseconds. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. |
**Example** **Example**
...@@ -229,6 +283,32 @@ Obtains the time elapsed since system start, including the deep sleep time. This ...@@ -229,6 +283,32 @@ Obtains the time elapsed since system start, including the deep sleep time. This
## systemTime.getRealTime<sup>8+</sup> ## systemTime.getRealTime<sup>8+</sup>
getRealTime(callback: AsyncCallback&lt;number&gt;): void
Obtains the time elapsed since system start, including the deep sleep time. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. |
**Example**
```js
systemTime.getRealTime((error, data) => {
if (error) {
console.error(`failed to systemTime.getRealTime because ` + JSON.stringify(error));
return;
}
console.log(`systemTime.getRealTime success data: ` + JSON.stringify(data));
});
```
## systemTime.getRealTime<sup>8+</sup>
getRealTime(isNano?: boolean): Promise&lt;number&gt; getRealTime(isNano?: boolean): Promise&lt;number&gt;
Obtains the time elapsed since system start, including the deep sleep time. This API uses a promise to return the result. Obtains the time elapsed since system start, including the deep sleep time. This API uses a promise to return the result.
...@@ -239,7 +319,7 @@ Obtains the time elapsed since system start, including the deep sleep time. This ...@@ -239,7 +319,7 @@ Obtains the time elapsed since system start, including the deep sleep time. This
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------------------------------------------ | | ------ | ------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds. | | isNano | boolean | No | Whether the time to return is in nanoseconds.<br/>- **true**: in nanoseconds.<br>- **false**: in milliseconds. |
**Return value** **Return value**
...@@ -278,7 +358,7 @@ Sets the system date. This API uses an asynchronous callback to return the resul ...@@ -278,7 +358,7 @@ Sets the system date. This API uses an asynchronous callback to return the resul
**Example** **Example**
```js ```js
var data = new Date("October 13, 2020 11:13:00"); var data = new Date();
systemTime.setDate(data,(error, data) => { systemTime.setDate(data,(error, data) => {
if (error) { if (error) {
console.error('failed to systemTime.setDate because ' + JSON.stringify(error)); console.error('failed to systemTime.setDate because ' + JSON.stringify(error));
...@@ -314,7 +394,7 @@ Sets the system date. This API uses a promise to return the result. ...@@ -314,7 +394,7 @@ Sets the system date. This API uses a promise to return the result.
**Example** **Example**
```js ```js
var data = new Date("October 13, 2020 11:13:00"); var data = new Date();
systemTime.setDate(data).then((value) => { systemTime.setDate(data).then((value) => {
console.log(`systemTime.setDate success data : ` + JSON.stringify(value)); console.log(`systemTime.setDate success data : ` + JSON.stringify(value));
}).catch((error) => { }).catch((error) => {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
The **systemTimer** module provides system timer features. You can use the APIs of this module to implement the alarm clock and other timer services. The **systemTimer** module provides system timer features. You can use the APIs of this module to implement the alarm clock and other timer services.
> **NOTE**<br/> > **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 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 of this module are system APIs and cannot be called by third-party applications. >- The APIs of this module are system APIs and cannot be called by third-party applications.
...@@ -24,12 +24,9 @@ Creates a timer. This API uses an asynchronous callback to return the result. ...@@ -24,12 +24,9 @@ Creates a timer. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------ | ---- | --------------------------------------------------------------------------------------- | | ------- | ---------------------------------| ---- | --------------------------------------------------------------------------- |
| options | TimerOptions | Yes | Timer options.<br>**TIMER_TYPE_REALTIME**: sets the timer to the real-time type. If it is not specified, the timer is of the non-real-time type.<br>**TIMER_TYPE_WAKEUP**: sets the timer to the wakeup type. If it is not specified, the timer is of the non-wakeup type.<br>**TIMER_TYPE_EXACT**: sets the timer to the exact type. If it is not specified, the timer is of the non-exact type.<br>**TIMER_TYPE_IDLE: number**: sets the timer to the idle type. If it is not specified, the timer is of the non-idle type (not yet supported).| | options | [TimerOptions](#timeroptions) | Yes | Timer options. |
| repeat | boolean | Yes | Whether the timer is a repeating timer. The value **true** means that the timer is a repeating timer, and **false** means that the timer is a one-shot timer. |
| interval | number | No | Repeat interval. For a repeating timer, the value must be greater than 5000 ms. For a one-shot timer, the value is **0**. |
| wantAgent| wantAgent | No | **wantAgent** object of the notification to be sent when the timer expires. (An OpenHarmony application MainAbility can be started, but not an SA service.) |
**Return value** **Return value**
...@@ -68,12 +65,9 @@ Creates a timer. This API uses a promise to return the result. ...@@ -68,12 +65,9 @@ Creates a timer. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------ | ---- | --------------------------------------------------------------------------------------- | | ------- | ---------------------------------| ---- | --------------------------------------------------------------------------- |
| options | TimerOptions | Yes | Timer options.<br>**TIMER_TYPE_REALTIME**: sets the timer to the real-time type. If it is not specified, the timer is of the non-real-time type.<br>**TIMER_TYPE_WAKEUP**: sets the timer to the wakeup type. If it is not specified, the timer is of the non-wakeup type.<br>**TIMER_TYPE_EXACT**: sets the timer to the exact type. If it is not specified, the timer is of the non-exact type.<br>**TIMER_TYPE_IDLE: number**: sets the timer to the idle type. If it is not specified, the timer is of the non-idle type (not yet supported).| | options | [TimerOptions](#timeroptions) | Yes | Timer options. |
| repeat | boolean | Yes | Whether the timer is a repeating timer. The value **true** means that the timer is a repeating timer, and **false** means that the timer is a one-shot timer. |
| interval | number | No | Repeat interval. For a repeating timer, the value must be greater than 5000 ms. For a one-shot timer, the value is **0**. |
| wantAgent| wantAgent | No | **wantAgent** object of the notification to be sent when the timer expires. (An OpenHarmony application MainAbility can be started, but not an SA service.) |
**Return value** **Return value**
...@@ -112,7 +106,7 @@ Starts a timer. This API uses an asynchronous callback to return the result. ...@@ -112,7 +106,7 @@ Starts a timer. This API uses an asynchronous callback to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ------------------------------------------------------------ | | ----------- | --------------------------- | ---- | ------------------------------------------------------------ |
| timer | number | Yes | ID of the timer. | | timer | number | Yes | ID of the timer. |
| triggerTime | number | Yes | Time when the timer is triggered, in milliseconds. | | triggerTime | number | Yes | Time when the timer is triggered, in milliseconds. |
...@@ -125,8 +119,10 @@ export default { ...@@ -125,8 +119,10 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.createTimer(options)
systemTimer.startTimer(timerId, 10000, (error, data) => { let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime, (error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.startTimer ` + JSON.stringify(error)); console.error(`failed to systemTime.startTimer ` + JSON.stringify(error));
return; return;
...@@ -136,7 +132,7 @@ export default { ...@@ -136,7 +132,7 @@ export default {
} }
} }
``` ```
## systemTime.startTimer ## systemTime.startTimer
startTimer(timer: number, triggerTime: number): Promise&lt;void&gt; startTimer(timer: number, triggerTime: number): Promise&lt;void&gt;
...@@ -149,9 +145,7 @@ Starts a timer. This API uses a promise to return the result. ...@@ -149,9 +145,7 @@ Starts a timer. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ------------------------------------------------------------ | | ----------- | --------------------------- | ---- | ------------------------------------------------------------ |
| timer | number | Yes | ID of the timer. | | timer | number | Yes | ID of the timer. | | triggerTime | number | Yes | Time when the timer is triggered, in milliseconds. |
| triggerTime | number | Yes | Time when the timer is triggered, in milliseconds. |
**Example** **Example**
...@@ -162,8 +156,10 @@ export default { ...@@ -162,8 +156,10 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.createTimer(options)
systemTimer.startTimer(timerId, 10000).then((data) => { let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime).then((data) => {
console.log(`systemTime.startTimer success data : ` + JSON.stringify(data)); console.log(`systemTime.startTimer success data : ` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.startTimer because ` + JSON.stringify(error)); console.error(`failed to systemTime.startTimer because ` + JSON.stringify(error));
...@@ -196,9 +192,11 @@ export default { ...@@ -196,9 +192,11 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.createTimer(options)
systemTimer.startTimer(timerId, 100000) let triggerTime = new Date().getTime()
systemTimer.stoptTimer(timerId, 10000, (error, data) => { triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
systemTimer.stoptTimer(timerId, (error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.startTimer ` + JSON.stringify(error)); console.error(`failed to systemTime.startTimer ` + JSON.stringify(error));
return; return;
...@@ -222,7 +220,7 @@ Stops a timer. This API uses a promise to return the result. ...@@ -222,7 +220,7 @@ Stops a timer. This API uses a promise to return the result.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------------------------------------------ | | ------ | ------- | ---- | ------------------------------------------------------------ |
| timer | number | Yes | ID of the timer. | | timer | number | Yes | ID of the timer. |
**Example** **Example**
...@@ -233,9 +231,11 @@ export default { ...@@ -233,9 +231,11 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.createTimer(options)
systemTimer.startTimer(timerId, 100000) let triggerTime = new Date().getTime()
systemTimer.stoptTimer(timerId, 10000).then((data) => { triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
systemTimer.stoptTimer(timerId).then((data) => {
console.log(`systemTime.startTimer success data : ` + JSON.stringify(data)); console.log(`systemTime.startTimer success data : ` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.startTimer because ` + JSON.stringify(error)); console.error(`failed to systemTime.startTimer because ` + JSON.stringify(error));
...@@ -268,8 +268,10 @@ export default { ...@@ -268,8 +268,10 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.createTimer(options)
systemTimer.startTimer(timerId, 100000) let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
systemTimer.stopTimer(timerId) systemTimer.stopTimer(timerId)
systemTimer.destroyTimer(timerId, (error, data) => { systemTimer.destroyTimer(timerId, (error, data) => {
if (error) { if (error) {
...@@ -306,10 +308,12 @@ export default { ...@@ -306,10 +308,12 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.createTimer(options)
systemTimer.startTimer(timerId, 100000) let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
systemTimer.stopTimer(timerId) systemTimer.stopTimer(timerId)
systemTimer.destroytTimer(timerId, 10000).then((data) => { systemTimer.destroyTimer(timerId, 10000).then((data) => {
console.log(`systemTime.startTimer success data : ` + JSON.stringify(data)); console.log(`systemTime.startTimer success data : ` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.startTimer because ` + JSON.stringify(error)); console.error(`failed to systemTime.startTimer because ` + JSON.stringify(error));
...@@ -317,3 +321,17 @@ export default { ...@@ -317,3 +321,17 @@ export default {
} }
} }
``` ```
## TimerOptions
Defines the initialization options for **createTimer**.
**System capability**: SystemCapability.MiscServices.Time
| Name | Type | Mandatory| Description |
| -------- | ------------------| ---- | ------------------------------------------------------------------------------------------------------------------------- |
| type | number | Yes | **const TIMER_TYPE_REALTIME**: sets the timer to the CPU time type. If it is not specified, the timer is of the wall-time type.<br>**const TIMER_TYPE_WAKEUP**: sets the timer to the wakeup type. If it is not specified, the timer is of the non-wakeup type.<br>**const TIMER_TYPE_EXACT**: sets the timer to the exact type. If it is not specified, the timer is of the non-exact type.<br>**const TIMER_TYPE_IDLE: number**: sets the timer to the idle type. If it is not specified, the timer is of the non-idle type (not yet supported). |
| repeat | boolean | Yes | Whether the timer is a repeating timer. The value **true** means that the timer is a repeating timer, and **false** means that the timer is a one-shot timer. |
| interval | number | No | Repeat interval. For a repeating timer, the value must be greater than 5000 ms. For a one-shot timer, the value is **0**. |
| wantAgent| wantAgent | No | **wantAgent** object of the notification to be sent when the timer expires. (An application MainAbility can be started, but not a Service ability.) |
| callback | number | Yes | Callback used to return the timer ID. |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册