>  **NOTE**<br>The initial APIs of this module are supported since API version 6. 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 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
## Modules to Import
## Modules to Import
...
@@ -40,16 +40,18 @@ Obtains an [InputMethodController](#InputMethodController) instance.
...
@@ -40,16 +40,18 @@ Obtains an [InputMethodController](#InputMethodController) instance.
>  **NOTE**<br>The initial APIs of this module are supported since API version 8. 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 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
## Modules to Import
## Modules to Import
...
@@ -52,17 +52,17 @@ Obtains an **InputMethodEngine** instance.
...
@@ -52,17 +52,17 @@ Obtains an **InputMethodEngine** instance.
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** means to listen for displaying of the input method.<br>- The value **'keyboardHide'** means to listen for hiding of the input method.|
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** means to listen for displaying of the input method.<br>- The value **'keyboardHide'** means to listen for hiding of the input method.|
| callback | void | No | Callback used to return the result. |
| callback | void | No | Callback used to return the result. |
- Example
**Example**
```
```js
InputMethodEngine.on('keyboardShow', (err) => {
InputMethodEngine.on('keyboardShow',(err)=>{
console.info('keyboardShow');
console.info('keyboardShow');
});
});
```
```
### off('keyboardShow'|'keyboardHide')
### off('keyboardShow'|'keyboardHide')
...
@@ -166,19 +164,18 @@ Cancels listening for an input method event.
...
@@ -166,19 +164,18 @@ Cancels listening for an input method event.
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** means to listen for displaying of the input method.<br>- The value **'keyboardHide'** means to listen for hiding of the input method.|
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** means to listen for displaying of the input method.<br>- The value **'keyboardHide'** means to listen for hiding of the input method.|
| callback | void | No | Callback used to return the result. |
| callback | void | No | Callback used to return the result. |
| type | string | Yes | Listening type.<br>- The value **'keyDown'** means to listen for pressing of a key.<br>- The value **'keyUp'** means to listen for releasing of a key.|
| callback | [KeyEvent](#KeyEvent) | Yes| Callback used to return the key information.|
| type | string | Yes | Listening type.<br>- The value **'keyDown'** means to listen for pressing of a key.<br>- The value **'keyUp'** means to listen for releasing of a key.|
| callback | [KeyEvent](#KeyEvent) | Yes| Callback used to return the key information.|
- Example
**Example**
```
```js
KeyboardDelegate.on('keyDown', (event) => {
KeyboardDelegate.on('keyDown',(event)=>{
console.info('keyDown');
console.info('keyDown');
});
});
```
```
### off('keyDown'|'keyUp')
### off('keyDown'|'keyUp')
...
@@ -217,18 +212,18 @@ Cancels listening for a hard keyboard even.
...
@@ -217,18 +212,18 @@ Cancels listening for a hard keyboard even.
| type | string | Yes | Listening type.<br>- The value **'keyDown'** means to listen for pressing of a key.<br>- The value **'keyUp'** means to listen for releasing of a key.|
| type | string | Yes | Listening type.<br>- The value **'keyDown'** means to listen for pressing of a key.<br>- The value **'keyUp'** means to listen for releasing of a key.|
| callback | [KeyEvent](#KeyEvent) | No | Callback used to return the key information. |
| callback | [KeyEvent](#KeyEvent) | No | Callback used to return the key information. |
>  **NOTE**<br>The initial APIs of this module are supported since API version 6. 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 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
## Modules to Import
## Modules to Import
...
@@ -19,11 +19,11 @@ import pasteboard from '@ohos.pasteboard';
...
@@ -19,11 +19,11 @@ import pasteboard from '@ohos.pasteboard';
| Name | Type | Readable | Writable | Description |
| Name | Type | Readable | Writable | Description |
| localOnly | boolean | Yes | Yes | Whether local access only is set for the pasteboard.<br/>- The default value is **true**.<br/>- **true**: The **PasteData** is set for local access only.<br/>- **false**: The **PasteData** can be shared between devices. |
## PasteDataRecord<sup>7+</sup>
## PasteDataRecord<sup>7+</sup>
...
@@ -262,63 +278,65 @@ A data record is an abstract definition of the content on the pasteboard. The pa
...
@@ -262,63 +278,65 @@ A data record is an abstract definition of the content on the pasteboard. The pa
| Name | Type | Readable | Writable | Description |
| Name | Type | Readable | Writable | Description |
| Promise<void> | Promise used to return the result. If the operation is successful, the plain text content after conversion is returned. Otherwise, error information is returned. |
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
record.convertToText().then((data) => {
**Example**
console.info('convertToText success data : ' + JSON.stringify(data));
}).catch((error) => {
```js
console.error('convertToText failed because ' + JSON.stringify(error));
| callback | AsyncCallback<string> | Yes | Callback used to return the result. If this callback is successful, the plain text content after conversion is returned. Otherwise, error information is returned. |
- Example
**Example**
```
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
Before calling any **SystemPasteboard** method, you must obtain a **SystemPasteboard** object using [getSystemPasteboard](#pasteboardgetsystempasteboard).
Before calling any **SystemPasteboard** method, you must obtain a **SystemPasteboard** object using [getSystemPasteboard](#pasteboardgetsystempasteboard).
```
```
var systemPasteboard = pasteboard.getSystemPasteboard();
var systemPasteboard = pasteboard.getSystemPasteboard();
...
@@ -793,112 +830,117 @@ var systemPasteboard = pasteboard.getSystemPasteboard();
...
@@ -793,112 +830,117 @@ var systemPasteboard = pasteboard.getSystemPasteboard();
>  **NOTE**<br>The initial APIs of this module are supported since API version 6. 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 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
## Modules to Import
## Modules to Import
...
@@ -37,56 +37,58 @@ import request from '@ohos.request';
...
@@ -37,56 +37,58 @@ import request from '@ohos.request';
| Name | Type | Readable | Writable | Description |
| Name | Type | Readable | Writable | Description |
| NETWORK_MOBILE | number | Yes | No | Whether download is allowed when the cellular network is used. |
| NETWORK_MOBILE | number | Yes | No | Whether download is allowed when the cellular network is used. |
| NETWORK_WIFI | number | Yes | No | Whether download is allowed when the WLAN is used. |
| NETWORK_WIFI | number | Yes | No | Whether download is allowed when the WLAN is used. |
| ERROR_CANNOT_RESUME<sup>7+</sup> | number | Yes | No | Failure to resume the download due to an error. |
| ERROR_CANNOT_RESUME<sup>7+</sup> | number | Yes | No | Failure to resume the download due to an error. |
| ERROR_DEVICE_NOT_FOUND<sup>7+</sup> | number | Yes | No | Failure to find a storage device such as an SD card. |
| ERROR_DEVICE_NOT_FOUND<sup>7+</sup> | number | Yes | No | Failure to find a storage device such as an SD card. |
| ERROR_FILE_ALREADY_EXISTS<sup>7+</sup> | number | Yes | No | Failure to download the file because it already exists. |
| ERROR_FILE_ALREADY_EXISTS<sup>7+</sup> | number | Yes | No | Failure to download the file because it already exists. |
| ERROR_FILE_ERROR<sup>7+</sup> | number | Yes | No | File operation failure. |
| ERROR_FILE_ERROR<sup>7+</sup> | number | Yes | No | File operation failure. |
| ERROR_HTTP_DATA_ERROR<sup>7+</sup> | number | Yes | No | HTTP transmission failure. |
| ERROR_HTTP_DATA_ERROR<sup>7+</sup> | number | Yes | No | HTTP transmission failure. |
| ERROR_INSUFFICIENT_SPACE<sup>7+</sup> | number | Yes | No | Insufficient storage space. |
| ERROR_INSUFFICIENT_SPACE<sup>7+</sup> | number | Yes | No | Insufficient storage space. |
| ERROR_TOO_MANY_REDIRECTS<sup>7+</sup> | number | Yes | No | Error caused by too many network redirections. |
| ERROR_TOO_MANY_REDIRECTS<sup>7+</sup> | number | Yes | No | Error caused by too many network redirections. |
| ERROR_UNHANDLED_HTTP_CODE<sup>7+</sup> | number | Yes | No | Unidentified HTTP code. |
| ERROR_UNHANDLED_HTTP_CODE<sup>7+</sup> | number | Yes | No | Unidentified HTTP code. |
| ERROR_UNKNOWN<sup>7+</sup> | number | Yes | No | Unknown error. |
| ERROR_UNKNOWN<sup>7+</sup> | number | Yes | No | Unknownerror. |
| PAUSED_QUEUED_FOR_WIFI<sup>7+</sup> | number | Yes | No | Download paused and queuing for WLAN connection, because the file size exceeds the maximum value allowed by a cellular network session. |
| PAUSED_QUEUED_FOR_WIFI<sup>7+</sup> | number | Yes | No | Download paused and queuing for WLAN connection, because the file size exceeds the maximum value allowed by a cellular network session. |
| PAUSED_UNKNOWN<sup>7+</sup> | number | Yes | No | Download paused due to unknown reasons. |
| PAUSED_UNKNOWN<sup>7+</sup> | number | Yes | No | Download paused due to unknown reasons. |
| PAUSED_WAITING_FOR_NETWORK<sup>7+</sup> | number | Yes | No | Download paused due to a network connection problem, for example, network disconnection. |
| PAUSED_WAITING_FOR_NETWORK<sup>7+</sup> | number | Yes | No | Download paused due to a network connection problem, for example, network disconnection. |
| PAUSED_WAITING_TO_RETRY<sup>7+</sup> | number | Yes | No | Download paused and then retried. |
| PAUSED_WAITING_TO_RETRY<sup>7+</sup> | number | Yes | No | Download paused and then retried. |
| SESSION_FAILED<sup>7+</sup> | number | Yes | No | Download failure without retry. |
| SESSION_FAILED<sup>7+</sup> | number | Yes | No | Download failure without retry. |
| SESSION_PAUSED<sup>7+</sup> | number | Yes | No | Download paused. |
| SESSION_PAUSED<sup>7+</sup> | number | Yes | No | Downloadpaused. |
| SESSION_PENDING<sup>7+</sup> | number | Yes | No | Download pending. |
| SESSION_PENDING<sup>7+</sup> | number | Yes | No | Downloadpending. |
| SESSION_RUNNING<sup>7+</sup> | number | Yes | No | Download in progress. |
| SESSION_RUNNING<sup>7+</sup> | number | Yes | No | Download in progress. |
| SESSION_SUCCESSFUL<sup>7+</sup> | number | Yes | No | Successful download. |
| SESSION_SUCCESSFUL<sup>7+</sup> | number | Yes | No | Successfuldownload. |
Subscribes to the **headerReceive** event, which is triggered when an HTTP response header is received. This method uses an asynchronous callback to return the result.
Subscribes to the **headerReceive** event, which is triggered when an HTTP response header is received. This API uses an asynchronous callback to return the result.
| Promise<boolean> | Promise used to return the task removal result. If **true** is returned, the task is removed. If **false** is returned, the task fails to be removed. |
| files | Array<[File](#file)> | Yes | List of files to upload, which is submitted through **multipart/form-data**. |
| data | Array<[RequestData](#requestdata)> | No | Form data in the request body. |
| data | Array<[RequestData](#requestdata)> | No | Form data in the request body. |
## File
## File
...
@@ -335,10 +344,10 @@ Removes this upload task. This method uses an asynchronous callback to return th
...
@@ -335,10 +344,10 @@ Removes this upload task. This method uses an asynchronous callback to return th
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| filename | string | No | File name in the header when **multipart** is used. |
| filename | string | No | File name in the header when **multipart** is used. |
| name | string | No | Name of a form item when **multipart** is used. The default value is **file**. |
| name | string | No | Name of a form item when **multipart** is used. The default value is **file**. |
| uri | string | Yes | Local path for storing files.<br/>The **dataability** and **internal** protocol types are supported. However, the **internal** protocol type supports only temporary directories. The following is an example:<br/>dataability:///com.domainname.dataability.persondata/person/10/file.txt<br/>internal://cache/path/to/file.txt |
| uri | string | Yes | Local path for storing files.<br/>The **dataability** and **internal** protocol types are supported. However, the **internal** protocol type supports only temporary directories. The following is an example:<br/>dataability:///com.domainname.dataability.persondata/person/10/file.txt<br/>internal://cache/path/to/file.txt |
| type | string | No | Type of the file content. By default, the type is obtained based on the extension of the file name or URI. |
| type | string | No | Type of the file content. By default, the type is obtained based on the extension of the file name or URI. |
## RequestData
## RequestData
...
@@ -347,68 +356,71 @@ Removes this upload task. This method uses an asynchronous callback to return th
...
@@ -347,68 +356,71 @@ Removes this upload task. This method uses an asynchronous callback to return th
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| name | string | Yes | Name of a form element. |
| name | string | Yes | Name of a form element. |
| value | string | Yes | Value of a form element. |
| value | string | Yes | Value of a form element. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
downloadTask.resume((err, result)=>{
if (err) {
**Example**
console.error('Failed to resume the download task. Cause:' + err);
return;
```js
}
downloadTask.resume((err,result)=>{
if (result) {
if(err){
console.info('Download task resumed.');
console.error('Failed to resume the download task. Cause:'+err);
} else {
return;
console.error('Failed to resume the download task.');
}
}
if(result){
});
console.info('Download task resumed.');
}else{
console.error('Failed to resume the download task.');
}
});
```
```
...
@@ -942,14 +970,14 @@ Resumes this download task. This method uses an asynchronous callback to return
...
@@ -942,14 +970,14 @@ Resumes this download task. This method uses an asynchronous callback to return
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| url | string | Yes | Resource URL. |
| url | string | Yes | ResourceURL. |
| header | object | No | HTTP or HTTPS header added to a download request. |
| header | object | No | HTTP or HTTPS header added to a download request. |
| enableMetered | boolean | No | Download allowed in metered connections. |
| enableMetered | boolean | No | Download allowed in metered connections. |
| enableRoaming | boolean | No | Download allowed on a roaming network. |
| enableRoaming | boolean | No | Download allowed on a roaming network. |
| description | string | No | Description of the download session. |
| description | string | No | Description of the download session. |
| filePath<sup>7+</sup> | string | No | Download path. (The default path is [ERROR:Invalid link:en-us_topic_0000001135742582.xml#xref8132147102215,link:en-us_topic_0000001127125012.xml#section1856519365229](en-us_topic_0000001127125012.xml#section1856519365229)).<br/>- filePath:'workspace/test.txt': The **workspace** directory is created in the default path to store files.<br/>- filePath:'test.txt': Files are stored in the default path.<br/>- filePath:'workspace/': The **workspace** directory is created in the default path to store files. |
| filePath<sup>7+</sup> | string | No | Download path. (The default path is [ERROR:Invalid link:en-us_topic_0000001135742582.xml#xref8132147102215,link:en-us_topic_0000001127125012.xml#section1856519365229](en-us_topic_0000001127125012.xml#section1856519365229)).<br/>- filePath:'workspace/test.txt': The **workspace** directory is created in the default path to store files.<br/>- filePath:'test.txt': Files are stored in the default path.<br/>- filePath:'workspace/': The **workspace** directory is created in the default path to store files. |
| networkType | number | No | Network type allowed for download. |
| networkType | number | No | Network type allowed for download. |
| title | string | No | Title of the download session. |
| title | string | No | Title of the download session. |
## DownloadInfo<sup>7+</sup>
## DownloadInfo<sup>7+</sup>
...
@@ -958,14 +986,14 @@ Resumes this download task. This method uses an asynchronous callback to return
...
@@ -958,14 +986,14 @@ Resumes this download task. This method uses an asynchronous callback to return
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| downloadId | number | Yes | ID of the downloaded file. |
| downloadId | number | Yes | ID of the downloaded file. |
| failedReason | number | No | Download failure cause, which can be any constant of [ERROR_*](#constants). |
| failedReason | number | No | Download failure cause, which can be any constant of [ERROR_*](#constants). |
| filePath | string | Yes | URI of the saved file. |
| pausedReason | number | No | Reason for session pause, which can be any constant of [PAUSED_*](#constants). |
| pausedReason | number | No | Reason for session pause, which can be any constant of [PAUSED_*](#constants). |
| status | number | Yes | Download status code, which can be any constant of [SESSION_*](#constants). |
| status | number | Yes | Download status code, which can be any constant of [SESSION_*](#constants). |
>  **NOTE**<br>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.
>
## Modules to Import
## Modules to Import
```
```
import systemTime from '@ohos.systemTime';
import systemTime from '@ohos.systemTime';
```
```
...
@@ -22,16 +22,17 @@ Sets the system time. This API uses an asynchronous callback to return the resul
...
@@ -22,16 +22,17 @@ Sets the system time. This API uses an asynchronous callback to return the resul
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
| callback | AsyncCallback<number> | Yes| Callback used to return the time.|
- Example
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
```
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
| callback | AsyncCallback<number> | Yes| Callback used to return the time.|
**Example**
```js
systemTime.getCurrentTime(true,(error,data)=>{
systemTime.getCurrentTime(true,(error,data)=>{
if(error){
if(error){
console.error(`failed to systemTime.getCurrentTime because `+JSON.stringify(error));
console.error(`failed to systemTime.getCurrentTime because `+JSON.stringify(error));
...
@@ -111,19 +115,21 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return
...
@@ -111,19 +115,21 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
- Return value
| Name| Type| Mandatory| Description|
| Type| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- |
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
| Promise<number> | Promise used to return the time.|
- Example
**Return value**
```
| Type| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the time.|
**Example**
```js
systemTime.getCurrentTime().then((data)=>{
systemTime.getCurrentTime().then((data)=>{
console.log(`systemTime.getCurrentTime success data : `+JSON.stringify(data));
console.log(`systemTime.getCurrentTime success data : `+JSON.stringify(data));
}).catch((error)=>{
}).catch((error)=>{
...
@@ -140,15 +146,16 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This
...
@@ -140,15 +146,16 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
| callback | AsyncCallback<number> | Yes| Callback used to return the time.|
- Example
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
```
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
| callback | AsyncCallback<number> | Yes| Callback used to return the time.|
**Example**
```js
systemTime.getRealActiveTime(true,(error,data)=>{
systemTime.getRealActiveTime(true,(error,data)=>{
if(error){
if(error){
console.error(`failed to systemTime.getRealActiveTimebecause `+JSON.stringify(error));
console.error(`failed to systemTime.getRealActiveTimebecause `+JSON.stringify(error));
...
@@ -167,19 +174,21 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This
...
@@ -167,19 +174,21 @@ Obtains the time elapsed since system start, excluding the deep sleep time. This
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
- Return value
| Name| Type| Mandatory| Description|
| Type| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- |
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
| Promise<number> | Promise used to return the time.|
- Example
**Return value**
```
| Type| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the time.|
**Example**
```js
systemTime.getCurrentTime().then((data)=>{
systemTime.getCurrentTime().then((data)=>{
console.log(`systemTime.getRealActiveTime success data : `+JSON.stringify(data));
console.log(`systemTime.getRealActiveTime success data : `+JSON.stringify(data));
}).catch((error)=>{
}).catch((error)=>{
...
@@ -196,15 +205,16 @@ Obtains the time elapsed since system start, including the deep sleep time. This
...
@@ -196,15 +205,16 @@ Obtains the time elapsed since system start, including the deep sleep time. This
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
| callback | AsyncCallback<number> | Yes| Callback used to return the time.|
- Example
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
```
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
| callback | AsyncCallback<number> | Yes| Callback used to return the time.|
**Example**
```js
systemTime.getRealTime(true,(error,data)=>{
systemTime.getRealTime(true,(error,data)=>{
if(error){
if(error){
console.error(`failed to systemTime.getRealTime because `+JSON.stringify(error));
console.error(`failed to systemTime.getRealTime because `+JSON.stringify(error));
...
@@ -223,19 +233,21 @@ Obtains the time elapsed since system start, including the deep sleep time. This
...
@@ -223,19 +233,21 @@ Obtains the time elapsed since system start, including the deep sleep time. This
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
- Return value
| Name| Type| Mandatory| Description|
| Type| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- |
| isNano | boolean | No| Whether nanoseconds or milliseconds will be returned. If the value is **true**, nanoseconds will be returned. Otherwise, milliseconds will be returned.|
| Promise<number> | Promise used to return the time.|
- Example
**Return value**
```
| Type| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the time.|
>  **NOTE**<br>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.
| callback | AsyncCallback<number> | Yes | Callback used to return the wallpaper ID. If the wallpaper of the specified type is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to 2^31-1. |
if (error) {
console.error(`failed to getId because: ` + JSON.stringify(error));
**Example**
return;
}
```js
console.log(`success to getId: ` + JSON.stringify(data));
| Promise<number> | Promise used to return the wallpaper ID. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to 2^31-1. |
| callback | AsyncCallback<number> | Yes | Callback used to return the minimum wallpaper height, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default height should be used instead. |
wallpaper.getMinHeight((error, data) => {
if (error) {
**Example**
console.error(`failed to getMinHeight because: ` + JSON.stringify(error));
return;
```js
}
wallpaper.getMinHeight((error,data)=>{
console.log(`success to getMinHeight: ` + JSON.stringify(data));
if(error){
});
console.error(`failed to getMinHeight because: `+JSON.stringify(error));
```
return;
}
console.log(`success to getMinHeight: `+JSON.stringify(data));
});
```
## wallpaper.getMinHeight
## wallpaper.getMinHeight
...
@@ -172,21 +177,21 @@ Obtains the minimum height of the wallpaper.
...
@@ -172,21 +177,21 @@ Obtains the minimum height of the wallpaper.
| Promise<number> | Promise used to return the minimum wallpaper height, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default height should be used instead. |
| callback | AsyncCallback<number> | Yes | Callback used to return the minimum wallpaper width, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default width should be used instead. |
| Promise<number> | Promised used to return the minimum wallpaper width, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default width should be used instead. |
wallpaper.getMinWidth().then((data) => {
console.log(`success to getMinWidth: ` + JSON.stringify(data));
**Example**
}).catch((error) => {
console.error(`failed to getMinWidth because: ` + JSON.stringify(error));
```js
});
wallpaper.getMinWidth().then((data)=>{
```
console.log(`success to getMinWidth: `+JSON.stringify(data));
}).catch((error)=>{
console.error(`failed to getMinWidth because: `+JSON.stringify(error));
});
```
## wallpaper.isChangePermitted
## wallpaper.isChangePermitted
...
@@ -248,22 +254,23 @@ Checks whether to allow the application to change the wallpaper for the current
...
@@ -248,22 +254,23 @@ Checks whether to allow the application to change the wallpaper for the current
| callback | AsyncCallback<boolean> | Yes | Callback used to return the queried result. Returns **true** if it is allowed; returns **false** otherwise. |
wallpaper.isChangePermitted((error, data) => {
if (error) {
**Example**
console.error(`failed to isChangePermitted because: ` + JSON.stringify(error));
return;
```js
}
wallpaper.isChangePermitted((error,data)=>{
console.log(`success to isChangePermitted: ` + JSON.stringify(data));
if(error){
});
console.error(`failed to isChangePermitted because: `+JSON.stringify(error));
```
return;
}
console.log(`success to isChangePermitted: `+JSON.stringify(data));
});
```
## wallpaper.isChangePermitted
## wallpaper.isChangePermitted
...
@@ -274,20 +281,21 @@ Checks whether to allow the application to change the wallpaper for the current
...
@@ -274,20 +281,21 @@ Checks whether to allow the application to change the wallpaper for the current
| Promise<boolean> | Promise used to return whether to allow the application to change the wallpaper for the current user. Returns **true** if it is allowed; returns **false** otherwise. |
wallpaper.isChangePermitted().then((data) => {
console.log(`success to isChangePermitted: ` + JSON.stringify(data));
**Example**
}).catch((error) => {
console.error(`failed to isChangePermitted because: ` + JSON.stringify(error));
```js
});
wallpaper.isChangePermitted().then((data)=>{
```
console.log(`success to isChangePermitted: `+JSON.stringify(data));
}).catch((error)=>{
console.error(`failed to isChangePermitted because: `+JSON.stringify(error));
});
```
## wallpaper.isOperationAllowed
## wallpaper.isOperationAllowed
...
@@ -298,22 +306,23 @@ Checks whether the user is allowed to set wallpapers.
...
@@ -298,22 +306,23 @@ Checks whether the user is allowed to set wallpapers.
| callback | AsyncCallback<boolean> | Yes | Callback used to return whether the user is allowed to set wallpapers. Returns **true** if it is allowed; returns **false** otherwise. |
wallpaper.isOperationAllowed((error, data) => {
if (error) {
**Example**
console.error(`failed to isOperationAllowed because: ` + JSON.stringify(error));
return;
```js
}
wallpaper.isOperationAllowed((error,data)=>{
console.log(`success to isOperationAllowed: ` + JSON.stringify(data));
if(error){
});
console.error(`failed to isOperationAllowed because: `+JSON.stringify(error));
```
return;
}
console.log(`success to isOperationAllowed: `+JSON.stringify(data));
});
```
## wallpaper.isOperationAllowed
## wallpaper.isOperationAllowed
...
@@ -324,20 +333,21 @@ Checks whether the user is allowed to set wallpapers.
...
@@ -324,20 +333,21 @@ Checks whether the user is allowed to set wallpapers.
| Promise<boolean> | Promise used to return whether the user is allowed to set wallpapers. Returns **true** if it is allowed; returns **false** otherwise. |
wallpaper.isOperationAllowed().then((data) => {
console.log(`success to isOperationAllowed: ` + JSON.stringify(data));
**Example**
}).catch((error) => {
console.error(`failed to isOperationAllowed because: ` + JSON.stringify(error));
```js
});
wallpaper.isOperationAllowed().then((data)=>{
```
console.log(`success to isOperationAllowed: `+JSON.stringify(data));
}).catch((error)=>{
console.error(`failed to isOperationAllowed because: `+JSON.stringify(error));
});
```
## wallpaper.reset
## wallpaper.reset
...
@@ -350,23 +360,24 @@ Removes a wallpaper of the specified type and restores the default one.
...
@@ -350,23 +360,24 @@ Removes a wallpaper of the specified type and restores the default one.
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the result of removal is returned. Otherwise, error information is returned. |
if (error) {
console.error(`failed to reset because: ` + JSON.stringify(error));
| Promise<void> | Promise used to return the result. If the operation is successful, the result of removal is returned. Otherwise, error information is returned. |
}).catch((error) => {
console.error(`failed to reset because: ` + JSON.stringify(error));
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the setting result is returned. Otherwise, error information is returned. |
- Example
**Example**
```
//The source type is string.
```js
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
| Promise<void> | Promise used to return the result. If the operation is successful, the setting result is returned. Otherwise, error information is returned. |
| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, the file descriptor ID to the wallpaper is returned. Otherwise, error information is returned. |
if (error) {
console.error(`failed to getFile because: ` + JSON.stringify(error));
**Example**
return;
}
```js
console.log(`success to getFile: ` + JSON.stringify(data));
console.log(`success to getFile: ` + JSON.stringify(data));
| Promise<number> | Promise used to return the result. If the operation is successful, the file descriptor ID to the wallpaper is returned. Otherwise, error information is returned. |
}).catch((error) => {
console.error(`failed to getFile because: ` + JSON.stringify(error));
| type | string | Yes | Type of the event to subscribe to. The value **colorChange** indicates subscribing to the wallpaper color change event. |
| callback | function | Yes | Callback triggered when the wallpaper color changes. The wallpaper type and main colors are returned.<br/>- colors<br/> Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolor).<br/>- wallpaperType<br/> Wallpaper type. |
- Example
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
```
| type | string | Yes | Type of the event to subscribe to. The value **colorChange** indicates subscribing to the wallpaper color change event. |
let listener = (colors, wallpaperType) => {
| callback | function | Yes | Callback triggered when the wallpaper color changes. The wallpaper type and main colors are returned.<br/>- colors<br/> Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolor).<br/>- wallpaperType<br/> Wallpaper type. |
console.log(`wallpaper color changed.`);
};
**Example**
wallpaper.on('colorChange', listener);
```
```js
letlistener=(colors,wallpaperType)=>{
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange',listener);
```
## wallpaper.off('colorChange')
## wallpaper.off('colorChange')
...
@@ -596,24 +616,25 @@ Unsubscribes from the wallpaper color change event.
...
@@ -596,24 +616,25 @@ Unsubscribes from the wallpaper color change event.
| type | string | Yes | Type of the event to unsubscribe from. The value **colorChange** indicates unsubscribing from the wallpaper color change event. |
| callback | function | No | Callback for the wallpaper color change event. If this parameter is not specified, all callbacks corresponding to the wallpaper color change event are invoked.<br/>- colors<br/> Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolor).<br/>- wallpaperType<br/> Wallpaper type. |
- Example
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
```
| type | string | Yes | Type of the event to unsubscribe from. The value **colorChange** indicates unsubscribing from the wallpaper color change event. |
let listener = (colors, wallpaperType) => {
| callback | function | No | Callback for the wallpaper color change event. If this parameter is not specified, all callbacks corresponding to the wallpaper color change event are invoked.<br/>- colors<br/> Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolor).<br/>- wallpaperType<br/> Wallpaper type. |
console.log(`wallpaper color changed.`);
};
**Example**
wallpaper.on('colorChange', listener);
// Unsubscribe from the listener.
```js
wallpaper.off('colorChange', listener);
letlistener=(colors,wallpaperType)=>{
//Unsubscribe from all subscriptions of the colorChange type.
console.log(`wallpaper color changed.`);
wallpaper.off('colorChange');
};
```
wallpaper.on('colorChange',listener);
// Unsubscribe from the listener.
wallpaper.off('colorChange',listener);
//Unsubscribe from all subscriptions of the colorChange type.
wallpaper.off('colorChange');
```
## RgbaColor
## RgbaColor
...
@@ -622,7 +643,7 @@ Unsubscribes from the wallpaper color change event.
...
@@ -622,7 +643,7 @@ Unsubscribes from the wallpaper color change event.
| Name | Type | Readable | Writable | Description |
| Name | Type | Readable | Writable | Description |