diff --git a/en/application-dev/reference/apis/js-apis-data-storage.md b/en/application-dev/reference/apis/js-apis-data-storage.md index dbb9244fbe3f973baf0b307a80b7a0ed23482f71..faa2664335b3d738c3c6e5ef771d6ed92abf9c6e 100644 --- a/en/application-dev/reference/apis/js-apis-data-storage.md +++ b/en/application-dev/reference/apis/js-apis-data-storage.md @@ -8,8 +8,6 @@ The **DataStorage** module provides applications with data processing capability > - 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 APIs of this module are no longer maintained since API version 9. You are advised to use [@ohos.data.preferences](js-apis-data-preferences.md). -> -> - The APIs of this module can be used only in the FA model. ## Modules to Import @@ -188,7 +186,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------------------- | | path | string | Yes | Path of the target file.| -| callback | AsyncCallback<void> | Yes | Callback that returns no value. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** @@ -230,7 +228,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete | Type | Description | | ------------------- | ------------------------------- | -| Promise<void> | Promise that returns no value. | +| Promise<void> | Promise used to return the result.| **Example** @@ -295,7 +293,7 @@ Removes the singleton **Storage** instance of a file from the cache. The removed | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------------------- | | path | string | Yes | Path of the target file.| -| callback | AsyncCallback<void> | Yes | Callback that returns no value. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** @@ -337,7 +335,7 @@ Removes the singleton **Storage** instance of a file from the cache. The removed | Type | Description | | ------------------- | ------------------------------- | -| Promise<void> | Promise that returns no value. | +| Promise<void> | Promise used to return the result.| **Example** @@ -490,7 +488,7 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat | -------- | ------------------------- | ---- | ----------------------------------------- | | key | string | Yes | Key of the data. It cannot be empty. | | value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value.| -| callback | AsyncCallback<void> | Yes | Callback that returns no value. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** @@ -524,7 +522,7 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat | Type | Description | | ------------------- | --------------------------- | -| Promise<void> | Promise that returns no value. | +| Promise<void> | Promise used to return the result.| **Example** @@ -672,7 +670,7 @@ Deletes data with the specified key from this storage object. This API uses an a | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ------------------------------- | | key | string | Yes | Key of the data. It cannot be empty.| -| callback | AsyncCallback<void> | Yes | Callback that returns no value. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** @@ -705,7 +703,7 @@ Deletes data with the specified key from this storage object. This API uses a pr | Type | Description | | ------------------- | --------------------------- | -| Promise<void> | Promise that returns no value. | +| Promise<void> | Promise used to return the result.| **Example** @@ -746,7 +744,7 @@ Saves the modification of this object to the **Storage** instance and synchroniz | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | -| callback | AsyncCallback<void> | Yes | Callback that returns no value. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| **Example** @@ -773,7 +771,7 @@ Saves the modification of this object to the **Storage** instance and synchroniz | Type | Description | | ------------------- | --------------------------- | -| Promise<void> | Promise that returns no value. | +| Promise<void> | Promise used to return the result.| **Example** @@ -814,7 +812,7 @@ Clears this **Storage** object. This API uses an asynchronous callback to return | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | -| callback | AsyncCallback<void> | Yes | Callback that returns no value. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| **Example** @@ -840,7 +838,7 @@ Clears this **Storage** object. This API uses a promise to return the result. **Return value** | Type | Description | | ------------------- | --------------------------- | -| Promise<void> | Promise that returns no value. | +| Promise<void> | Promise used to return the result.| **Example** diff --git a/en/application-dev/reference/apis/js-apis-fileio.md b/en/application-dev/reference/apis/js-apis-fileio.md index 1723208acd9d746a72a360142ad3b890bccbddd8..3a1a597403b6c8ce5e89cb73047867e3478b5ddb 100644 --- a/en/application-dev/reference/apis/js-apis-fileio.md +++ b/en/application-dev/reference/apis/js-apis-fileio.md @@ -16,7 +16,7 @@ import fileio from '@ohos.fileio'; ## Guidelines -Before using the APIs provided by this module to perform operations on files or directories, obtain the path of the application sandbox as follows: +Before using the APIs provided by this module to perform operations on a file or directory, obtain the application sandbox path of the file or directory as follows: **Stage Model** @@ -44,7 +44,7 @@ export default class EntryAbility extends UIAbility { }) ``` - For details about how to obtain the FA model context, see [Contex](js-apis-inner-app-context.md#context). + For details about how to obtain the FA model context, see [Context](js-apis-inner-app-context.md#context). ## fileio.stat @@ -52,6 +52,10 @@ stat(path: string): Promise<Stat> Obtains file information. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#stat) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -62,8 +66,8 @@ Obtains file information. This API uses a promise to return the result. **Return value** -| Type | Description | -| ---------------------------- | ---------- | + | Type | Description | + | ---------------------------- | ---------- | | Promise<[Stat](#stat)> | Promise used to return the file information obtained.| **Example** @@ -84,6 +88,10 @@ stat(path: string, callback: AsyncCallback<Stat>): void Obtains file information. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#fsstat-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -108,6 +116,10 @@ statSync(path: string): Stat Synchronously obtains file information. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.statSync](js-apis-file-fs.md#fsstatsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -119,9 +131,9 @@ Synchronously obtains file information. **Return value** -| Type | Description | -| ------------- | ---------- | -| [Stat](#stat) | File information obtained.| + | Type | Description | + | ------------- | ---------- | + | [Stat](#stat) | File information obtained.| **Example** @@ -137,6 +149,10 @@ opendir(path: string): Promise<Dir> Opens a file directory. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -147,8 +163,8 @@ Opens a file directory. This API uses a promise to return the result. **Return value** -| Type | Description | -| -------------------------- | -------- | + | Type | Description | + | -------------------------- | -------- | | Promise<[Dir](#dir)> | Promise used to return the **Dir** object.| **Example** @@ -162,13 +178,17 @@ Opens a file directory. This API uses a promise to return the result. }); ``` - + ## fileio.opendir opendir(path: string, callback: AsyncCallback<Dir>): void Opens a file directory. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -194,8 +214,11 @@ opendirSync(path: string): Dir Synchronously opens a directory. -**System capability**: SystemCapability.FileManagement.File.FileIO +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.listFileSync](js-apis-file-fs.md#fslistfilesync) instead. +**System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -205,9 +228,9 @@ Synchronously opens a directory. **Return value** -| Type | Description | -| ----------- | -------- | -| [Dir](#dir) | A **Dir** instance corresponding to the directory.| + | Type | Description | + | ----------- | -------- | + | [Dir](#dir) | A **Dir** instance corresponding to the directory.| **Example** @@ -224,6 +247,10 @@ access(path: string, mode?: number): Promise<void> Checks whether the current process can access a file. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.access](js-apis-file-fs.md#fsaccess) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -235,9 +262,9 @@ Checks whether the current process can access a file. This API uses a promise to **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -257,6 +284,10 @@ access(path: string, mode?: number, callback: AsyncCallback<void>): void Checks whether the current process can access a file. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.access](js-apis-file-fs.md#fsaccess-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -283,6 +314,10 @@ accessSync(path: string, mode?: number): void Synchronously checks whether the current process can access the specified file. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.accessSync](js-apis-file-fs.md#fsaccesssync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -310,19 +345,23 @@ close(fd: number): Promise<void> Closes a file. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.close](js-apis-file-fs.md#fsclose) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ------------ | -| fd | number | Yes | File descriptor of the file to close.| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ------------ | + | fd | number | Yes | File descriptor of the file to close.| **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -343,14 +382,18 @@ close(fd: number, callback: AsyncCallback<void>): void Closes a file. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.close](js-apis-file-fs.md#fsclose-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | ------------ | -| fd | number | Yes | File descriptor of the file to close.| -| callback | AsyncCallback<void> | Yes | Callback invoked when the file is closed asynchronously.| + | Name | Type | Mandatory | Description | + | -------- | ------------------------- | ---- | ------------ | + | fd | number | Yes | File descriptor of the file to close.| + | callback | AsyncCallback<void> | Yes | Callback invoked immediately after the file is closed.| **Example** @@ -369,13 +412,17 @@ closeSync(fd: number): void Synchronously closes a file. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.closeSync](js-apis-file-fs.md#fsclosesync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ------------ | -| fd | number | Yes | File descriptor of the file to close.| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ------------ | + | fd | number | Yes | File descriptor of the file to close.| **Example** @@ -392,21 +439,25 @@ copyFile(src: string|number, dest: string|number, mode?: number): Promise<voi Copies a file. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.copyFile](js-apis-file-fs.md#fscopyfile) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | -------------------------- | ---- | ---------------------------------------- | -| src | string\|number | Yes | Path or file descriptor of the file to copy. | -| dest | string\|number | Yes | Path or file descriptor of the new file. | + | Name | Type | Mandatory | Description | + | ---- | -------------------------- | ---- | ---------------------------------------- | + | src | string\|number | Yes | Path or file descriptor of the file to copy. | + | dest | string\|number | Yes | Path or file descriptor of the new file. | | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten. | **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -427,16 +478,20 @@ copyFile(src: string|number, dest: string|number, mode: number, callback: AsyncC Copies a file. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.copyFile](js-apis-file-fs.md#fscopyfile-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | -------------------------- | ---- | ---------------------------------------- | -| src | string\|number | Yes | Path or file descriptor of the file to copy. | -| dest | string\|number | Yes | Path or file descriptor of the new file. | + | Name | Type | Mandatory | Description | + | -------- | -------------------------- | ---- | ---------------------------------------- | + | src | string\|number | Yes | Path or file descriptor of the file to copy. | + | dest | string\|number | Yes | Path or file descriptor of the new file. | | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| -| callback | AsyncCallback<void> | Yes | Callback invoked when the file is copied asynchronously. | + | callback | AsyncCallback<void> | Yes | Callback invoked immediately after the file is copied. | **Example** @@ -455,14 +510,18 @@ copyFileSync(src: string|number, dest: string|number, mode?: number): void Synchronously copies a file. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.copyFileSync](js-apis-file-fs.md#fscopyfilesync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | -------------------------- | ---- | ---------------------------------------- | -| src | string\|number | Yes | Path or file descriptor of the file to copy. | -| dest | string\|number | Yes | Path or file descriptor of the new file. | + | Name | Type | Mandatory | Description | + | ---- | -------------------------- | ---- | ---------------------------------------- | + | src | string\|number | Yes | Path or file descriptor of the file to copy. | + | dest | string\|number | Yes | Path or file descriptor of the new file. | | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| **Example** @@ -480,6 +539,10 @@ mkdir(path: string, mode?: number): Promise<void> Creates a directory. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.mkdir](js-apis-file-fs.md#fsmkdir) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -491,9 +554,9 @@ Creates a directory. This API uses a promise to return the result. **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -513,6 +576,10 @@ mkdir(path: string, mode: number, callback: AsyncCallback<void>): void Creates a directory. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.mkdir](js-apis-file-fs.md#fsmkdir-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -539,6 +606,10 @@ mkdirSync(path: string, mode?: number): void Synchronously creates a directory. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.mkdirSync](js-apis-file-fs.md#fsmkdirsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -562,6 +633,10 @@ open(path: string, flags?: number, mode?: number): Promise<number> Opens a file. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.open](js-apis-file-fs.md#fsopen) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -569,13 +644,13 @@ Opens a file. This API uses a promise to return the result. | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | | path | string | Yes | Application sandbox path of the file. | -| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create a file. The third parameter **mode** must also be specified.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (written to the end of the file).
- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.
- **0o200000**: If **path** does not point to a directory, throw an exception.
- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| +| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.
- **0o200000**: If **path** does not point to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o660**.
- **0o660**: The owner and user group have the read and write permissions.
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| **Return value** -| Type | Description | -| --------------------- | ----------- | + | Type | Description | + | --------------------- | ----------- | | Promise<number> | Promise used to return the file descriptor of the file opened.| **Example** @@ -596,6 +671,10 @@ open(path: string, flags: number, mode: number, callback: AsyncCallback<numbe Opens a file. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.open](js-apis-file-fs.md#fsopen-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -603,7 +682,7 @@ Opens a file. This API uses an asynchronous callback to return the result. | Name | Type | Mandatory| Description | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | path | string | Yes | Application sandbox path of the file. | -| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create a file. The third parameter **mode** must also be specified.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (written to the end of the file).
- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.
- **0o200000**: If **path** does not point to a directory, throw an exception.
- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| +| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.
- **0o200000**: If **path** does not point to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o660**.
- **0o660**: The owner and user group have the read and write permissions.
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| | callback | AsyncCallback<number> | Yes | Callback invoked when the file is open asynchronously. | @@ -623,6 +702,10 @@ openSync(path: string, flags?: number, mode?: number): number Synchronously opens a file. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.openSync](js-apis-file-fs.md#fsopensync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -630,14 +713,14 @@ Synchronously opens a file. | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | | path | string | Yes | Application sandbox path of the file. | -| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create a file. The third parameter **mode** must also be specified.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (written to the end of the file).
- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.
- **0o200000**: If **path** does not point to a directory, throw an exception.
- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| +| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.
- **0o200000**: If **path** does not point to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **0o4010000**: Open the file in synchronous I/O mode.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o660**.
- **0o660**: The owner and user group have the read and write permissions.
- **0o640**: The owner has the read and write permissions, and the user group has the read permission.
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.
The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.| **Return value** -| Type | Description | -| ------ | ----------- | -| number | File descriptor of the file opened.| + | Type | Description | + | ------ | ----------- | + | number | File descriptor of the file opened.| **Example** @@ -662,6 +745,10 @@ read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: numb Reads data from a file. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.read](js-apis-file-fs.md#fsread) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -674,9 +761,9 @@ Reads data from a file. This API uses a promise to return the result. **Return value** -| Type | Description | -| ---------------------------------- | ------ | -| Promise<[ReadOut](#readout)> | Promise used to return the data read.| + | Type | Description | + | ---------------------------------- | ------ | + | Promise<[ReadOut](#readout)> | Promise used to return the data read.| **Example** @@ -699,16 +786,20 @@ read(fd: number, buffer: ArrayBuffer, options: { offset?: number; length?: numbe Reads data from a file. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.read](js-apis-file-fs.md#fsread-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ---------------------------------------- | -| fd | number | Yes | File descriptor of the file to read. | -| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | -| options | Object | No | The options are as follows:
- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | -| callback | AsyncCallback<[ReadOut](#readout)> | Yes | Callback invoked when the data is read asynchronously. | + | Name | Type | Mandatory | Description | + | -------- | ---------------------------------------- | ---- | ---------------------------------------- | + | fd | number | Yes | File descriptor of the file to read. | + | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | + | options | Object | No | The options are as follows:
- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | + | callback | AsyncCallback<[ReadOut](#readout)> | Yes | Callback invoked when the data is read asynchronously. | **Example** @@ -731,21 +822,25 @@ readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: Synchronously reads data from a file. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.readSync](js-apis-file-fs.md#fsreadsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ----------- | ---- | ---------------------------------------- | -| fd | number | Yes | File descriptor of the file to read. | -| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | -| options | Object | No | The options are as follows:
- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | + | Name | Type | Mandatory | Description | + | ------- | ----------- | ---- | ---------------------------------------- | + | fd | number | Yes | File descriptor of the file to read. | + | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | + | options | Object | No | The options are as follows:
- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | **Return value** -| Type | Description | -| ------ | -------- | -| number | Length of the data read.| + | Type | Description | + | ------ | -------- | + | number | Length of the data read.| **Example** @@ -763,6 +858,10 @@ rmdir(path: string): Promise<void> Deletes a directory. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.rmdir](js-apis-file-fs.md#fsrmdir) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -773,9 +872,9 @@ Deletes a directory. This API uses a promise to return the result. **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -795,6 +894,10 @@ rmdir(path: string, callback: AsyncCallback<void>): void Deletes a directory. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.rmdir](js-apis-file-fs.md#fsrmdir-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -821,6 +924,10 @@ rmdirSync(path: string): void Synchronously deletes a directory. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.rmdirSync](js-apis-file-fs.md#fsrmdirsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -843,6 +950,10 @@ unlink(path: string): Promise<void> Deletes a file. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.unlink](js-apis-file-fs.md#fsunlink) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -853,9 +964,9 @@ Deletes a file. This API uses a promise to return the result. **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -875,6 +986,10 @@ unlink(path: string, callback: AsyncCallback<void>): void Deletes a file. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.unlink](js-apis-file-fs.md#fsunlink-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -882,7 +997,7 @@ Deletes a file. This API uses an asynchronous callback to return the result. | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------------------- | | path | string | Yes | Application sandbox path of the file.| -| callback | AsyncCallback<void> | Yes | Callback invoked when the file is deleted asynchronously. | +| callback | AsyncCallback<void> | Yes | Callback invoked immediately after the file is deleted. | **Example** @@ -900,6 +1015,10 @@ unlinkSync(path: string): void Synchronously deletes a file. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.unlinkSync](js-apis-file-fs.md#fsunlinksync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -922,21 +1041,25 @@ write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; lengt Writes data into a file. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.write](js-apis-file-fs.md#fswrite) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------------------------------- | ---- | ---------------------------------------- | -| fd | number | Yes | File descriptor of the file to write. | -| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | -| options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.
Constraints: offset + length <= Buffer size| + | Name | Type | Mandatory | Description | + | ------- | ------------------------------- | ---- | ---------------------------------------- | + | fd | number | Yes | File descriptor of the file to write. | + | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size| **Return value** -| Type | Description | -| --------------------- | -------- | -| Promise<number> | Promise used to return the length of the data written.| + | Type | Description | + | --------------------- | -------- | + | Promise<number> | Promise used to return the length of the data written.| **Example** @@ -957,16 +1080,20 @@ write(fd: number, buffer: ArrayBuffer|string, options: { offset?: number; length Writes data into a file. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.write](js-apis-file-fs.md#fswrite-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ---------------------------------------- | -| fd | number | Yes | File descriptor of the file to write. | -| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | -| options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.
Constraints: offset + length <= Buffer size| -| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | + | Name | Type | Mandatory | Description | + | -------- | ------------------------------- | ---- | ---------------------------------------- | + | fd | number | Yes | File descriptor of the file to write. | + | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size| + | callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | **Example** @@ -987,21 +1114,25 @@ writeSync(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; l Synchronously writes data into a file. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.writeSync](js-apis-file-fs.md#fswritesync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------------------------------- | ---- | ---------------------------------------- | -| fd | number | Yes | File descriptor of the file to write. | -| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | -| options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.
Constraints: offset + length <= Buffer size| + | Name | Type | Mandatory | Description | + | ------- | ------------------------------- | ---- | ---------------------------------------- | + | fd | number | Yes | File descriptor of the file to write. | + | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size| **Return value** -| Type | Description | -| ------ | -------- | -| number | Length of the data written in the file.| + | Type | Description | + | ------ | -------- | + | number | Length of the data written in the file.| **Example** @@ -1018,6 +1149,10 @@ hash(path: string, algorithm: string): Promise<string> Calculates the hash value of a file. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [hash.write](js-apis-file-hash.md#hashhash) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1029,8 +1164,8 @@ Calculates the hash value of a file. This API uses a promise to return the resul **Return value** -| Type | Description | -| --------------------- | -------------------------- | + | Type | Description | + | --------------------- | -------------------------- | | Promise<string> | Promise used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.| **Example** @@ -1051,6 +1186,10 @@ hash(path: string, algorithm: string, callback: AsyncCallback<string>): vo Calculates the hash value of a file. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [hash.write](js-apis-file-hash.md#hashhash-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1079,6 +1218,10 @@ chmod(path: string, mode: number): Promise<void> Changes file permissions. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1090,9 +1233,9 @@ Changes file permissions. This API uses a promise to return the result. **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -1112,6 +1255,10 @@ chmod(path: string, mode: number, callback: AsyncCallback<void>): void Changes file permissions. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1138,6 +1285,10 @@ chmodSync(path: string, mode: number): void Synchronously changes file permissions. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1161,18 +1312,22 @@ fstat(fd: number): Promise<Stat> Obtains file information based on the file descriptor. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#fsstat) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ------------ | -| fd | number | Yes | Descriptor of the target file.| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ------------ | + | fd | number | Yes | Descriptor of the target file.| **Return value** -| Type | Description | -| ---------------------------- | ---------- | + | Type | Description | + | ---------------------------- | ---------- | | Promise<[Stat](#stat)> | Promise used to return the file information obtained.| **Example** @@ -1194,14 +1349,18 @@ fstat(fd: number, callback: AsyncCallback<Stat>): void Obtains file information based on the file descriptor. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.stat](js-apis-file-fs.md#fsstat-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------- | ---- | ---------------- | + | Name | Type | Mandatory | Description | + | -------- | ---------------------------------- | ---- | ---------------- | | fd | number | Yes | File descriptor of the target file. | -| callback | AsyncCallback<[Stat](#stat)> | Yes | Callback invoked to return the file information obtained.| + | callback | AsyncCallback<[Stat](#stat)> | Yes | Callback invoked to return the file information obtained.| **Example** @@ -1220,18 +1379,22 @@ fstatSync(fd: number): Stat Synchronously obtains file information based on the file descriptor. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.statSync](js-apis-file-fs.md#fsstatsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ------------ | + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ------------ | | fd | number | Yes | File descriptor of the target file.| **Return value** -| Type | Description | -| ------------- | ---------- | + | Type | Description | + | ------------- | ---------- | | [Stat](#stat) | File information obtained.| **Example** @@ -1249,20 +1412,24 @@ ftruncate(fd: number, len?: number): Promise<void> Truncates a file based on the file descriptor. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ---------------- | -| fd | number | Yes | File descriptor of the file to truncate. | -| len | number | No | File length, in bytes, after truncation.| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ---------------- | + | fd | number | Yes | File descriptor of the file to truncate. | + | len | number | No | File length, in bytes, after truncation.| **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -1283,15 +1450,19 @@ ftruncate(fd: number, len?: number, callback: AsyncCallback<void>): void Truncates a file based on the file descriptor. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | ---------------- | -| fd | number | Yes | File descriptor of the file to truncate. | -| len | number | No | File length, in bytes, after truncation.| -| callback | AsyncCallback<void> | Yes | Callback that returns no value. | + | Name | Type | Mandatory | Description | + | -------- | ------------------------- | ---- | ---------------- | + | fd | number | Yes | File descriptor of the file to truncate. | + | len | number | No | File length, in bytes, after truncation.| + | callback | AsyncCallback<void> | Yes | Callback that returns no value. | **Example** @@ -1311,14 +1482,18 @@ ftruncateSync(fd: number, len?: number): void Synchronously truncates a file based on the file descriptor. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.truncateSync](js-apis-file-fs.md#fstruncatesync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ---------------- | -| fd | number | Yes | File descriptor of the file to truncate. | -| len | number | No | File length, in bytes, after truncation.| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ---------------- | + | fd | number | Yes | File descriptor of the file to truncate. | + | len | number | No | File length, in bytes, after truncation.| **Example** @@ -1336,6 +1511,10 @@ truncate(path: string, len?: number): Promise<void> Truncates a file based on the file path. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1347,9 +1526,9 @@ Truncates a file based on the file path. This API uses a promise to return the r **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -1370,6 +1549,10 @@ truncate(path: string, len?: number, callback: AsyncCallback<void>): void Truncates a file based on the file path. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.truncate](js-apis-file-fs.md#fstruncate-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1397,6 +1580,10 @@ truncateSync(path: string, len?: number): void Synchronously truncates a file based on the file path. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.truncateSync](js-apis-file-fs.md#fstruncatesync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1421,6 +1608,10 @@ readText(filePath: string, options?: { position?: number; length?: number; encod Reads the text content of a file. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.readText](js-apis-file-fs.md#fsreadtext) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1428,13 +1619,13 @@ Reads the text content of a file. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | | filePath | string | Yes | Application sandbox path of the file to read. | -| options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.| +| options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| **Return value** -| Type | Description | -| --------------------- | ---------- | -| Promise<string> | Promise used to return the content read.| + | Type | Description | + | --------------------- | ---------- | + | Promise<string> | Promise used to return the file content read.| **Example** @@ -1454,6 +1645,10 @@ readText(filePath: string, options: { position?: number; length?: number; encodi Reads the text content of a file. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.readText](js-apis-file-fs.md#fsreadtext-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1461,8 +1656,8 @@ Reads the text content of a file. This API uses an asynchronous callback to retu | Name | Type | Mandatory| Description | | -------- | --------------------------- | ---- | ------------------------------------------------------------ | | filePath | string | Yes | Application sandbox path of the file to read. | -| options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.| -| callback | AsyncCallback<string> | Yes | Callback used to return the content read. | +| options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| +| callback | AsyncCallback<string> | Yes | Callback invoked to return the content read. | **Example** @@ -1480,6 +1675,10 @@ readTextSync(filePath: string, options?: { position?: number; length?: number; e Synchronously reads the text of a file. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.readTextSync](js-apis-file-fs.md#fsreadtextsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1487,13 +1686,13 @@ Synchronously reads the text of a file. | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | | filePath | string | Yes | Application sandbox path of the file to read. | -| options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.| +| options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| **Return value** -| Type | Description | -| ------ | -------------------- | -| string | Promise used to return the content of the file read.| + | Type | Description | + | ------ | -------------------- | + | string | File content read.| **Example** @@ -1509,6 +1708,10 @@ lstat(path: string): Promise<Stat> Obtains link information. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.lstat](js-apis-file-fs.md#fslstat) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1519,9 +1722,9 @@ Obtains link information. This API uses a promise to return the result. **Return value** -| Type | Description | -| ---------------------------- | ---------- | -| Promise<[Stat](#stat)> | Promise used to return the link information obtained. For details, see [Stat](#stat).| + | Type | Description | + | ---------------------------- | ---------- | + | Promise<[Stat](#stat)> | Promise used to return the symbolic link information obtained. For details, see **stat**.| **Example** @@ -1541,6 +1744,10 @@ lstat(path: string, callback: AsyncCallback<Stat>): void Obtains link information. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.lstat](js-apis-file-fs.md#fslstat-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1548,7 +1755,7 @@ Obtains link information. This API uses an asynchronous callback to return the r | Name | Type | Mandatory| Description | | -------- | ---------------------------------- | ---- | -------------------------------------- | | path | string | Yes | Application sandbox path of the target file.| -| callback | AsyncCallback<[Stat](#stat)> | Yes | Callback used to return the link information obtained. | +| callback | AsyncCallback<[Stat](#stat)> | Yes | Callback invoked to return the symbolic link information obtained. | **Example** @@ -1566,6 +1773,10 @@ lstatSync(path: string): Stat Synchronously obtains the link information. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.lstatSync](js-apis-file-fs.md#fslstatsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1576,8 +1787,8 @@ Synchronously obtains the link information. **Return value** -| Type | Description | -| ------------- | ---------- | + | Type | Description | + | ------------- | ---------- | | [Stat](#stat) | Link information obtained.| **Example** @@ -1594,6 +1805,10 @@ rename(oldPath: string, newPath: string): Promise<void> Renames a file. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.rename](js-apis-file-fs.md#fsrename) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1605,9 +1820,9 @@ Renames a file. This API uses a promise to return the result. **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -1628,6 +1843,10 @@ rename(oldPath: string, newPath: string, callback: AsyncCallback<void>): v Renames a file. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.rename](js-apis-file-fs.md#fsrename-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1647,13 +1866,16 @@ Renames a file. This API uses an asynchronous callback to return the result. }); ``` - ## fileio.renameSync7+ renameSync(oldPath: string, newPath: string): void Synchronously renames a file. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.renameSync](js-apis-file-fs.md#fsrenamesync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1678,19 +1900,23 @@ fsync(fd: number): Promise<void> Flushes data of a file to disk. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.fsync](js-apis-file-fs.md#fsfsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ------------ | -| fd | number | Yes | File descriptor of the file to flush.| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ------------ | + | fd | number | Yes | File descriptor of the file to flush.| **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -1711,14 +1937,18 @@ fsync(fd: number, callback: AsyncCallback<void>): void Flushes data of a file to disk. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.fsync](js-apis-file-fs.md#fsfsync-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | --------------- | -| fd | number | Yes | File descriptor of the file to flush. | -| Callback | AsyncCallback<void> | Yes | Callback invoked when the file is synchronized in asynchronous mode.| + | Name | Type | Mandatory | Description | + | -------- | ------------------------- | ---- | --------------- | + | fd | number | Yes | File descriptor of the file to flush. | + | Callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| **Example** @@ -1735,15 +1965,19 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return fsyncSync(fd: number): void -Flushes data of a file to disk in synchronous mode. +Flushes data of a file to disk synchronously. + +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.fsyncSync](js-apis-file-fs.md#fsfsyncsync) instead. **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ------------ | -| fd | number | Yes | File descriptor of the file to flush.| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ------------ | + | fd | number | Yes | File descriptor of the file to flush.| **Example** @@ -1760,19 +1994,23 @@ fdatasync(fd: number): Promise<void> Flushes data of a file to disk. This API uses a promise to return the result. **fdatasync()** is similar to **fsync()**, but does not flush modified metadata unless that metadata is needed. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.fdatasync](js-apis-file-fs.md#fsfdatasync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ------------ | -| fd | number | Yes | File descriptor of the file to flush.| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ------------ | + | fd | number | Yes | File descriptor of the file to flush.| **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -1793,14 +2031,18 @@ fdatasync(fd: number, callback: AsyncCallback<void>): void Flushes data of a file to disk. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.fdatasync](js-apis-file-fs.md#fsfdatasync-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ----------------- | -| fd | number | Yes | File descriptor of the file to synchronize. | -| callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| + | Name | Type | Mandatory | Description | + | -------- | ------------------------------- | ---- | ----------------- | + | fd | number | Yes | File descriptor of the file to synchronize. | + | callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| **Example** @@ -1817,15 +2059,19 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return fdatasyncSync(fd: number): void -Synchronizes data in a file in synchronous mode. +Synchronizes data in a file synchronously. + +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.fdatasyncSync](js-apis-file-fs.md#fsfdatasyncsync) instead. **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ------------ | -| fd | number | Yes | File descriptor of the file to flush.| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ------------ | + | fd | number | Yes | File descriptor of the file to flush.| **Example** @@ -1842,6 +2088,10 @@ symlink(target: string, srcPath: string): Promise<void> Creates a symbolic link based on the file path. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.symlink](js-apis-file-fs.md#fssymlink) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1849,13 +2099,13 @@ Creates a symbolic link based on the file path. This API uses a promise to retur | Name | Type | Mandatory| Description | | ------- | ------ | ---- | ---------------------------- | | target | string | Yes | Application sandbox path of the target file. | -| srcPath | string | Yes | Application sandbox path of the symbolic link file.| +| srcPath | string | Yes | Application sandbox path of the symbolic link.| **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -1876,6 +2126,10 @@ symlink(target: string, srcPath: string, callback: AsyncCallback<void>): v Creates a symbolic link based on the file path. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.symlink](js-apis-file-fs.md#fssymlink-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1883,7 +2137,7 @@ Creates a symbolic link based on the file path. This API uses an asynchronous ca | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------------------------- | | target | string | Yes | Application sandbox path of the target file. | -| srcPath | string | Yes | Application sandbox path of the symbolic link file. | +| srcPath | string | Yes | Application sandbox path of the symbolic link. | | callback | AsyncCallback<void> | Yes | Callback invoked when the symbolic link is created asynchronously.| **Example** @@ -1903,6 +2157,10 @@ symlinkSync(target: string, srcPath: string): void Synchronously creates a symbolic link based on a specified path. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.symlinkSync](js-apis-file-fs.md#fssymlinksync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1910,7 +2168,7 @@ Synchronously creates a symbolic link based on a specified path. | Name | Type | Mandatory| Description | | ------- | ------ | ---- | ---------------------------- | | target | string | Yes | Application sandbox path of the target file. | -| srcPath | string | Yes | Application sandbox path of the symbolic link file.| +| srcPath | string | Yes | Application sandbox path of the symbolic link.| **Example** @@ -1927,6 +2185,10 @@ chown(path: string, uid: number, gid: number): Promise<void> Changes the file owner based on the file path. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1939,9 +2201,9 @@ Changes the file owner based on the file path. This API uses a promise to return **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -1962,6 +2224,10 @@ chown(path: string, uid: number, gid: number, callback: AsyncCallback<void> Changes the file owner based on the file path. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -1983,13 +2249,16 @@ Changes the file owner based on the file path. This API uses an asynchronous cal }); ``` - ## fileio.chownSync7+ chownSync(path: string, uid: number, gid: number): void Synchronously changes the file owner based on its path. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -2015,18 +2284,22 @@ mkdtemp(prefix: string): Promise<string> Creates a temporary directory. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.mkdtemp](js-apis-file-fs.md#fsmkdtemp) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ------ | ------ | ---- | --------------------------- | -| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| + | Name | Type | Mandatory | Description | + | ------ | ------ | ---- | --------------------------- | + | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| **Return value** -| Type | Description | -| --------------------- | ---------- | + | Type | Description | + | --------------------- | ---------- | | Promise<string> | Promise used to return the unique directory generated.| **Example** @@ -2046,14 +2319,18 @@ mkdtemp(prefix: string, callback: AsyncCallback<string>): void Creates a temporary directory. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.mkdtemp](js-apis-file-fs.md#fsmkdtemp-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | --------------------------- | -| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| -| callback | AsyncCallback<string> | Yes | Callback invoked when a temporary directory is created asynchronously. | + | Name | Type | Mandatory | Description | + | -------- | --------------------------- | ---- | --------------------------- | + | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| + | callback | AsyncCallback<string> | Yes | Callback invoked when a temporary directory is created asynchronously. | **Example** @@ -2070,19 +2347,23 @@ mkdtempSync(prefix: string): string Synchronously creates a temporary directory. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.mkdtempSync](js-apis-file-fs.md#fsmkdtempsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ------ | ------ | ---- | --------------------------- | -| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| + | Name | Type | Mandatory | Description | + | ------ | ------ | ---- | --------------------------- | + | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| **Return value** -| Type | Description | -| ------ | ---------- | -| string | Unique path generated.| + | Type | Description | + | ------ | ---------- | + | string | Unique path generated.| **Example** @@ -2097,20 +2378,24 @@ fchmod(fd: number, mode: number): Promise<void> Changes file permissions based on the file descriptor. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ---------------------------------------- | -| fd | number | Yes | File descriptor of the target file. | -| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ---------------------------------------- | + | fd | number | Yes | File descriptor of the target file. | + | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -2132,15 +2417,19 @@ fchmod(fd: number, mode: number, callback: AsyncCallback<void>): void Changes file permissions based on the file descriptor. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ---------------------------------------- | -| fd | number | Yes | File descriptor of the target file. | -| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| -| callback | AsyncCallback<void> | Yes | Callback invoked when the file permissions are changed asynchronously. | + | Name | Type | Mandatory | Description | + | -------- | ------------------------------- | ---- | ---------------------------------------- | + | fd | number | Yes | File descriptor of the target file. | + | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | callback | AsyncCallback<void> | Yes | Callback invoked when the file permissions are changed asynchronously. | **Example** @@ -2160,14 +2449,18 @@ fchmodSync(fd: number, mode: number): void Synchronously changes the file permissions based on the file descriptor. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ---------------------------------------- | -| fd | number | Yes | File descriptor of the target file. | -| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ---------------------------------------- | + | fd | number | Yes | File descriptor of the target file. | + | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
- **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| **Example** @@ -2183,7 +2476,11 @@ Synchronously changes the file permissions based on the file descriptor. createStream(path: string, mode: string): Promise<Stream> -Opens a file stream based on the file path. This API uses a promise to return the result. +Creates a stream based on the file path. This API uses a promise to return the result. + +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.createStream](js-apis-file-fs.md#fscreatestream) instead. **System capability**: SystemCapability.FileManagement.File.FileIO @@ -2196,9 +2493,9 @@ Opens a file stream based on the file path. This API uses a promise to return th **Return value** -| Type | Description | -| --------------------------------- | --------- | -| Promise<[Stream](#stream)> | Promise used to return the result.| + | Type | Description | + | --------------------------------- | --------- | + | Promise<[Stream](#stream)> | Promise used to return the stream opened.| **Example** @@ -2216,7 +2513,11 @@ Opens a file stream based on the file path. This API uses a promise to return th createStream(path: string, mode: string, callback: AsyncCallback<Stream>): void -Opens a file stream based on the file path. This API uses an asynchronous callback to return the result. +Creates a stream based on the file path. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.createStream](js-apis-file-fs.md#fscreatestream-1) instead. **System capability**: SystemCapability.FileManagement.File.FileIO @@ -2226,7 +2527,7 @@ Opens a file stream based on the file path. This API uses an asynchronous callba | -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | path | string | Yes | Application sandbox path of the file. | | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| -| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. | +| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is created asynchronously. | **Example** @@ -2242,7 +2543,11 @@ Opens a file stream based on the file path. This API uses an asynchronous callba createStreamSync(path: string, mode: string): Stream -Synchronously opens a stream based on the file path. +Synchronously creates a stream based on the file path. + +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.createStreamSync](js-apis-file-fs.md#fscreatestreamsync) instead. **System capability**: SystemCapability.FileManagement.File.FileIO @@ -2255,9 +2560,9 @@ Synchronously opens a stream based on the file path. **Return value** -| Type | Description | -| ------------------ | --------- | -| [Stream](#stream) | Stream opened.| + | Type | Description | + | ------------------ | --------- | +| [Stream](#stream) | Stream created.| **Example** @@ -2271,22 +2576,26 @@ Synchronously opens a stream based on the file path. fdopenStream(fd: number, mode: string): Promise<Stream> -Opens a file stream based on the file descriptor. This API uses a promise to return the result. +Opens a stream based on the file descriptor. This API uses a promise to return the result. + +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.fdopenStream](js-apis-file-fs.md#fsfdopenstream) instead. **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ---------------------------------------- | -| fd | number | Yes | File descriptor of the target file. | -| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ---------------------------------------- | + | fd | number | Yes | File descriptor of the target file. | + | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| **Return value** -| Type | Description | -| --------------------------------- | --------- | -| Promise<[Stream](#stream)> | Promise used to return the result.| + | Type | Description | + | --------------------------------- | --------- | + | Promise<[Stream](#stream)> | Promise used to return the stream opened.| **Example** @@ -2305,16 +2614,20 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret fdopenStream(fd: number, mode: string, callback: AsyncCallback<Stream>): void -Opens a file stream based on the file descriptor. This API uses an asynchronous callback to return the result. +Opens a stream based on the file descriptor. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.fdopenStream](js-apis-file-fs.md#fsfdopenstream-1) instead. **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ---------------------------------------- | -| fd | number | Yes | File descriptor of the target file. | -| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| + | Name | Type | Mandatory | Description | + | -------- | ---------------------------------------- | ---- | ---------------------------------------- | + | fd | number | Yes | File descriptor of the target file. | + | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. | **Example** @@ -2334,19 +2647,23 @@ fdopenStreamSync(fd: number, mode: string): Stream Synchronously opens a stream based on the file descriptor. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.fdopenStreamSync](js-apis-file-fs.md#fsfdopenstreamsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ---------------------------------------- | -| fd | number | Yes | File descriptor of the target file. | -| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ---------------------------------------- | + | fd | number | Yes | File descriptor of the target file. | + | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| **Return value** -| Type | Description | -| ------------------ | --------- | + | Type | Description | + | ------------------ | --------- | | [Stream](#stream) | Stream opened.| **Example** @@ -2364,21 +2681,25 @@ fchown(fd: number, uid: number, gid: number): Promise<void> Changes the file owner based on the file descriptor. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ------------ | -| fd | number | Yes | File descriptor of the target file.| -| uid | number | Yes | New UID. | -| gid | number | Yes | New GID. | + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ------------ | + | fd | number | Yes | File descriptor of the target file.| + | uid | number | Yes | New UID. | + | gid | number | Yes | New GID. | **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -2400,16 +2721,20 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback<void> Changes the file owner based on the file descriptor. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | --------------- | -| fd | number | Yes | File descriptor of the target file. | -| uid | number | Yes | New UID. | -| gid | number | Yes | New GID. | -| callback | AsyncCallback<void> | Yes | Callback invoked when the file owner is changed asynchronously.| + | Name | Type | Mandatory | Description | + | -------- | ------------------------- | ---- | --------------- | + | fd | number | Yes | File descriptor of the target file. | + | uid | number | Yes | New UID. | + | gid | number | Yes | New GID. | + | callback | AsyncCallback<void> | Yes | Callback invoked when the file owner is changed asynchronously.| **Example** @@ -2429,15 +2754,19 @@ fchownSync(fd: number, uid: number, gid: number): void Synchronously changes the file owner based on the file descriptor. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ------------ | -| fd | number | Yes | File descriptor of the target file.| -| uid | number | Yes | New UID. | -| gid | number | Yes | New GID. | + | Name | Type | Mandatory | Description | + | ---- | ------ | ---- | ------------ | + | fd | number | Yes | File descriptor of the target file.| + | uid | number | Yes | New UID. | + | gid | number | Yes | New GID. | **Example** @@ -2455,6 +2784,10 @@ lchown(path: string, uid: number, gid: number): Promise<void> Changes the file owner (owner of the symbolic link, not the file referred to by the symbolic link) based on the file path. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -2467,9 +2800,9 @@ Changes the file owner (owner of the symbolic link, not the file referred to by **Return value** -| Type | Description | -| ------------------- | ---------------------------- | -| Promise<void> | Promise that returns no value.| + | Type | Description | + | ------------------- | ---------------------------- | + | Promise<void> | Promise that returns no value.| **Example** @@ -2490,6 +2823,10 @@ lchown(path: string, uid: number, gid: number, callback: AsyncCallback<void&g Changes the file owner (owner of the symbolic link, not the file referred to by the symbolic link) based on the file path. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -2518,6 +2855,10 @@ lchownSync(path: string, uid: number, gid: number): void Synchronously changes the file owner based on the file path and changes the owner of the symbolic link (not the referenced file). +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** @@ -2550,13 +2891,13 @@ Listens for file or directory changes. This API uses an asynchronous callback to | Name | Type | Mandatory| Description | | -------- | --------------------------------- | ---- | ------------------------------------------------------------ | | filePath | string | Yes | Application sandbox path of the file. | -| events | number | Yes | -**1**: The file or directory is renamed.
- **2**: The file or directory is modified.
- **3**: The file or directory is modified and renamed.| +| events | number | Yes | - **1**: The file or directory is renamed.
- **2**: The file or directory is modified.
- **3**: The file or directory is modified and renamed.| | callback | AsyncCallback<number> | Yes | Called each time a change is detected. | **Return value** -| Type | Description | -| -------------------- | ---------- | + | Type | Description | + | -------------------- | ---------- | | [Watcher](#watcher7) | Promise used to return the **Watcher** instance.| **Example** @@ -2574,6 +2915,10 @@ Listens for file or directory changes. This API uses an asynchronous callback to Obtains the file read result. This class applies only to the **read()** method. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO | Name | Type | Readable | Writable | Description | @@ -2587,6 +2932,10 @@ Obtains the file read result. This class applies only to the **read()** method. Provides detailed file information. Before calling a method of the **Stat** class, use the [stat()](#fileiostat) method synchronously or asynchronously to create a **Stat** instance. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stat](js-apis-file-fs.md#stat) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO ### Attributes @@ -2595,7 +2944,7 @@ Provides detailed file information. Before calling a method of the **Stat** clas | ------ | ------ | ---- | ---- | ---------------------------------------- | | dev | number | Yes | No | Major device number. | | ino | number | Yes | No | File ID. Different files on the same device have different **ino**s. | -| mode | number | Yes | No | File type and permissions. The first four bits indicate the file type, and the last 12 bits indicate the permissions. The bit fields are described as follows:
- **0o170000**: mask used to obtain the file type.
- **0o140000**: The file is a socket.
- **0o120000**: The file is a symbolic link.
- **0o100000**: The file is a regular file.
- **0o060000**: The file is a block device.
- **0o040000**: The file is a directory.
- **0o020000**: The file is a character device.
- **0o010000**: The file is a named pipe, that is, FIFO.
- **0o0700**: mask used to obtain owner permissions.
- **0o0400**: The owner has the read permission on a regular file or a directory entry.
- **0o0200**: The owner has the permission to write a regular file or create and delete a directory entry.
- **0o0100**: The owner has the permission to execute a regular file or has the permission to search for the specified path in a directory.
- **0o0070**: mask used to obtain user group permissions.
- **0o0040**: The user group has the read permission on a regular file or a directory entry.
- **0o0020**: The user group has the permission to write a regular file or has the permission to create and delete a directory entry.
- **0o0010**: The user group has the permission to execute a regular file or has the permission to search for the specified path in a directory.
- **0o0007**: mask used to obtain permissions of other users.
- **0o0004**: Other user groups have the read permission on a regular file or a directory entry.
- **0o0002**: Other user groups have the permission to write a regular file or have the permission to create and delete a directory entry.
- **0o0001**: Other users have the permission to execute a regular file or search for the specified path in a directory.| +| mode | number | Yes | No | File type and permissions. The first four bits indicate the file type, and the last 12 bits indicate the permissions. The bit fields are described as follows:
- **0o170000**: mask used to obtain the file type.
- **0o140000**: The file is a socket.
- **0o120000**: The file is a symbolic link.
- **0o100000**: The file is a regular file.
- **0o060000**: The file is a block device.
- **0o040000**: The file is a directory.
- **0o020000**: The file is a character device.
- **0o010000**: The file is a named pipe (FIFO).
- **0o0700**: mask used to obtain the owner permissions.
- **0o0400**: The owner has the permission to read a regular file or a directory entry.
- **0o0200**: The owner has the permission to write a regular file or create and delete a directory entry.
- **0o0100**: The owner has the permission to execute a regular file or search for the specified path in a directory.
- **0o0070**: mask used to obtain the user group permissions.
- **0o0040**: The user group has the permission to read a regular file or a directory entry.
- **0o0020**: The user group has the permission to write a regular file or create and delete a directory entry.
- **0o0010**: The user group has the permission to execute a regular file or search for the specified path in a directory.
- **0o0007**: mask used to obtain the permissions of other users.
- **0o0004**: Other users have the permission to read a regular file or a directory entry.
- **0o0002**: Other users have the permission to write a regular file or create and delete a directory entry.
- **0o0001**: Other users have the permission to execute a regular file or search for the specified path in a directory.| | nlink | number | Yes | No | Number of hard links in the file. | | uid | number | Yes | No | User ID, that is ID of the file owner. | | gid | number | Yes | No | Group ID, that is, ID of the user group of the file. | @@ -2613,13 +2962,17 @@ isBlockDevice(): boolean Checks whether this file is a block special file. A block special file supports access by block only, and it is cached when accessed. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stat.isBlockDevice](js-apis-file-fs.md#isblockdevice) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | ---------------- | -| boolean | Whether the file is a block special file.| + | Type | Description | + | ------- | ---------------- | + | boolean | Whether the file is a block special file.| **Example** @@ -2635,13 +2988,17 @@ isCharacterDevice(): boolean Checks whether this file is a character special file. A character special file supports random access, and it is not cached when accessed. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stat.isCharacterDevice](js-apis-file-fs.md#ischaracterdevice) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | ----------------- | -| boolean | Whether the file is a character special file.| + | Type | Description | + | ------- | ----------------- | + | boolean | Whether the file is a character special file.| **Example** @@ -2657,13 +3014,17 @@ isDirectory(): boolean Checks whether this file is a directory. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stat.isDirectory](js-apis-file-fs.md#isdirectory) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | ------------- | -| boolean | Whether the file is a directory.| + | Type | Description | + | ------- | ------------- | + | boolean | Whether the file is a directory.| **Example** @@ -2679,13 +3040,17 @@ isFIFO(): boolean Checks whether this file is a named pipe (or FIFO). Named pipes are used for inter-process communication. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stat.isFIFO](js-apis-file-fs.md#isfifo) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | --------------------- | -| boolean | Whether the file is an FIFO.| + | Type | Description | + | ------- | --------------------- | + | boolean | Whether the file is an FIFO.| **Example** @@ -2701,13 +3066,17 @@ isFile(): boolean Checks whether this file is a regular file. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stat.isFile](js-apis-file-fs.md#isfile) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | --------------- | -| boolean | Whether the file is a regular file.| + | Type | Description | + | ------- | --------------- | + | boolean | Whether the file is a regular file.| **Example** @@ -2723,13 +3092,17 @@ isSocket(): boolean Checks whether this file is a socket. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stat.isSocket](js-apis-file-fs.md#issocket) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | -------------- | -| boolean | Whether the file is a socket.| + | Type | Description | + | ------- | -------------- | + | boolean | Whether the file is a socket.| **Example** @@ -2745,13 +3118,17 @@ isSymbolicLink(): boolean Checks whether this file is a symbolic link. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stat.isSymbolicLink](js-apis-file-fs.md#issymboliclink) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | --------------- | -| boolean | Whether the file is a symbolic link.| + | Type | Description | + | ------- | --------------- | + | boolean | Whether the file is a symbolic link.| **Example** @@ -2797,9 +3174,9 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | ---------------------- | -| callback | AsyncCallback<void> | Yes | Callback invoked when **watcher** is stopped asynchronously.| + | Name | Type | Mandatory | Description | + | -------- | ------------------------- | ---- | ---------------------- | + | callback | AsyncCallback<void> | Yes | Callback invoked when **watcher** is stopped asynchronously.| **Example** @@ -2816,8 +3193,11 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return ## Stream -Provides file stream management. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance. +Provides a stream for file operations. Before calling any API of the **Stream** class, use **createStream()** to create a **Stream** instance synchronously or asynchronously. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream](js-apis-file-fs.md#stream) instead. ### close7+ @@ -2825,12 +3205,16 @@ close(): Promise<void> Closes the stream. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.close](js-apis-file-fs.md#close) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------------------- | ------------- | + | Type | Description | + | ------------------- | ------------- | | Promise<void> | Promise used to return the stream close result.| **Example** @@ -2852,13 +3236,17 @@ close(callback: AsyncCallback<void>): void Closes the stream. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.close](js-apis-file-fs.md#close-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | ------------- | -| callback | AsyncCallback<void> | Yes | Callback invoked when the stream is closed asynchronously.| + | Name | Type | Mandatory | Description | + | -------- | ------------------------- | ---- | ------------- | + | callback | AsyncCallback<void> | Yes | Callback invoked immediately after the stream is closed.| **Example** @@ -2877,6 +3265,10 @@ closeSync(): void Synchronously closes the stream. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.closeSync](js-apis-file-fs.md#closesync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Example** @@ -2894,13 +3286,17 @@ flush(): Promise<void> Flushes the stream. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.flush](js-apis-file-fs.md#flush) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------------------- | ------------- | -| Promise<void> | Promise used to return the stream flushing result.| + | Type | Description | + | ------------------- | ------------- | + | Promise<void> | Promise used to return the result.| **Example** @@ -2921,13 +3317,17 @@ flush(callback: AsyncCallback<void>): void Flushes the stream. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.flush](js-apis-file-fs.md#flush-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | -------------- | -| callback | AsyncCallback<void> | Yes | Callback invoked when the stream is asynchronously flushed.| + | Name | Type | Mandatory | Description | + | -------- | ------------------------- | ---- | -------------- | + | callback | AsyncCallback<void> | Yes | Callback invoked when the stream is asynchronously flushed.| **Example** @@ -2946,6 +3346,10 @@ flushSync(): void Synchronously flushes the stream. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.flushSync](js-apis-file-fs.md#flushsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Example** @@ -2963,20 +3367,24 @@ write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; Writes data into the stream. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.write](js-apis-file-fs.md#write) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------------------------------- | ---- | ---------------------------------------- | -| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | -| options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.
Constraints: offset + length <= Buffer size | + | Name | Type | Mandatory | Description | + | ------- | ------------------------------- | ---- | ---------------------------------------- | + | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size | **Return value** -| Type | Description | -| --------------------- | -------- | -| Promise<number> | Promise used to return the length of the data written.| + | Type | Description | + | --------------------- | -------- | + | Promise<number> | Promise used to return the length of the data written.| **Example** @@ -2997,15 +3405,19 @@ write(buffer: ArrayBuffer|string, options: { offset?: number; length?: number; p Writes data into the stream. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.write](js-apis-file-fs.md#write-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | -| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | -| options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.
Constraints: offset + length <= Buffer size| -| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | + | Name | Type | Mandatory| Description | + | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | + | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size| + | callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | **Example** @@ -3027,20 +3439,24 @@ writeSync(buffer: ArrayBuffer|string, options?: { offset?: number; length?: numb Synchronously writes data into the stream. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.writeSync](js-apis-file-fs.md#writesync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ------------------------------- | ---- | ---------------------------------------- | -| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | -| options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.
Constraints: offset + length <= Buffer size | + | Name | Type | Mandatory | Description | + | ------- | ------------------------------- | ---- | ---------------------------------------- | + | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size | **Return value** -| Type | Description | -| ------ | -------- | -| number | Length of the data written in the file.| + | Type | Description | + | ------ | -------- | + | number | Length of the data written in the file.| **Example** @@ -3057,20 +3473,24 @@ read(buffer: ArrayBuffer, options?: { position?: number; offset?: number; length Reads data from the stream. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.read](js-apis-file-fs.md#read) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ----------- | ---- | ---------------------------------------- | -| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | -| options | Object | No | The options are as follows:
- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | + | Name | Type | Mandatory | Description | + | ------- | ----------- | ---- | ---------------------------------------- | + | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | + | options | Object | No | The options are as follows:
- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | **Return value** -| Type | Description | -| ---------------------------------- | ------ | -| Promise<[ReadOut](#readout)> | Promise used to return the data read.| + | Type | Description | + | ---------------------------------- | ------ | + | Promise<[ReadOut](#readout)> | Promise used to return the data read.| **Example** @@ -3092,15 +3512,19 @@ read(buffer: ArrayBuffer, options: { position?: number; offset?: number; length? Reads data from the stream. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.read](js-apis-file-fs.md#read-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ---------------------------------------- | -| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | -| options | Object | No | The options are as follows:
- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | -| callback | AsyncCallback<[ReadOut](#readout)> | Yes | Callback invoked when data is read asynchronously from the stream. | + | Name | Type | Mandatory | Description | + | -------- | ---------------------------------------- | ---- | ---------------------------------------- | + | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | + | options | Object | No | The options are as follows:
- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | + | callback | AsyncCallback<[ReadOut](#readout)> | Yes | Callback invoked when data is read asynchronously from the stream. | **Example** @@ -3122,20 +3546,24 @@ readSync(buffer: ArrayBuffer, options?: { position?: number; offset?: number; le Synchronously reads data from the stream. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.Stream.readSync](js-apis-file-fs.md#readsync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| ------- | ----------- | ---- | ---------------------------------------- | -| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | -| options | Object | No | The options are as follows:
- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | + | Name | Type | Mandatory | Description | + | ------- | ----------- | ---- | ---------------------------------------- | + | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | + | options | Object | No | The options are as follows:
- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | **Return value** -| Type | Description | -| ------ | -------- | -| number | Length of the data read.| + | Type | Description | + | ------ | -------- | + | number | Length of the data read.| **Example** @@ -3150,6 +3578,9 @@ Synchronously reads data from the stream. Manages directories. Before calling a method of the **Dir** class, use the **opendir()** method synchronously or asynchronously to create a **Dir** instance. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead. ### read @@ -3157,12 +3588,16 @@ read(): Promise<Dirent> Reads the next directory entry. This API uses a promise to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| -------------------------------- | ------------- | + | Type | Description | + | -------------------------------- | ------------- | | Promise<[Dirent](#dirent)> | Promise used to return the directory entry read.| **Example** @@ -3182,13 +3617,17 @@ read(callback: AsyncCallback<Dirent>): void Reads the next directory entry. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Parameters** -| Name | Type | Mandatory | Description | -| -------- | -------------------------------------- | ---- | ---------------- | -| callback | AsyncCallback<[Dirent](#dirent)> | Yes | Callback invoked when the next directory entry is asynchronously read.| + | Name | Type | Mandatory | Description | + | -------- | -------------------------------------- | ---- | ---------------- | + | callback | AsyncCallback<[Dirent](#dirent)> | Yes | Callback invoked when the next directory entry is asynchronously read.| **Example** @@ -3208,13 +3647,17 @@ readSync(): Dirent Synchronously reads the next directory entry. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.listFileSync](js-apis-file-fs.md#fslistfilesync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ----------------- | -------- | -| [Dirent](#dirent) | Directory entry read.| + | Type | Description | + | ----------------- | -------- | + | [Dirent](#dirent) | Directory entry read.| **Example** @@ -3229,6 +3672,10 @@ close(): Promise<void> Closes a directory. This API uses a promise to return the result. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Example** @@ -3240,12 +3687,16 @@ Closes a directory. This API uses a promise to return the result. After a direct ``` - ### close7+ +### close7+ close(callback: AsyncCallback<void>): void Closes a directory. This API uses an asynchronous callback to return the result. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile-1) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Example** @@ -3263,6 +3714,10 @@ closeSync(): void Closes a directory. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.listFileSync](js-apis-file-fs.md#fslistfilesync) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO **Example** @@ -3276,6 +3731,10 @@ Closes a directory. After a directory is closed, the file descriptor in Dir will Provides information about files and directories. Before calling a method of the **Dirent** class, use the [dir.read()](#read) method synchronously or asynchronously to create a **Dirent** instance. +> **NOTE** +> +> This API is deprecated since API version 9. Use [fs.listFile](js-apis-file-fs.md#fslistfile) instead. + **System capability**: SystemCapability.FileManagement.File.FileIO ### Attributes @@ -3291,13 +3750,17 @@ isBlockDevice(): boolean Checks whether this directory entry is a block special file. A block special file supports access by block only, and it is cached when accessed. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | ---------------- | -| boolean | Whether the directory entry is a block special file.| + | Type | Description | + | ------- | ---------------- | + | boolean | Whether the directory entry is a block special file.| **Example** @@ -3313,13 +3776,17 @@ isCharacterDevice(): boolean Checks whether a directory entry is a character special file. A character special file supports random access, and it is not cached when accessed. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | ----------------- | -| boolean | Whether the directory entry is a character special file.| + | Type | Description | + | ------- | ----------------- | + | boolean | Whether the directory entry is a character special file.| **Example** @@ -3335,13 +3802,17 @@ isDirectory(): boolean Checks whether a directory entry is a directory. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | ------------- | -| boolean | Whether the directory entry is a directory.| + | Type | Description | + | ------- | ------------- | + | boolean | Whether the directory entry is a directory.| **Example** @@ -3357,13 +3828,17 @@ isFIFO(): boolean Checks whether this directory entry is a named pipe (or FIFO). Named pipes are used for inter-process communication. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | --------------- | -| boolean | Whether the directory entry is a FIFO.| + | Type | Description | + | ------- | --------------- | + | boolean | Whether the directory entry is a FIFO.| **Example** @@ -3379,13 +3854,17 @@ isFile(): boolean Checks whether a directory entry is a regular file. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | --------------- | -| boolean | Whether the directory entry is a regular file.| + | Type | Description | + | ------- | --------------- | + | boolean | Whether the directory entry is a regular file.| **Example** @@ -3401,13 +3880,17 @@ isSocket(): boolean Checks whether a directory entry is a socket. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | -------------- | -| boolean | Whether the directory entry is a socket.| + | Type | Description | + | ------- | -------------- | + | boolean | Whether the directory entry is a socket.| **Example** @@ -3423,13 +3906,17 @@ isSymbolicLink(): boolean Checks whether a directory entry is a symbolic link. +> **NOTE** +> +> This API is deprecated since API version 9. + **System capability**: SystemCapability.FileManagement.File.FileIO **Return value** -| Type | Description | -| ------- | --------------- | -| boolean | Whether the directory entry is a symbolic link.| + | Type | Description | + | ------- | --------------- | + | boolean | Whether the directory entry is a symbolic link.| **Example** diff --git a/en/application-dev/reference/apis/js-apis-privacyManager.md b/en/application-dev/reference/apis/js-apis-privacyManager.md index 6728c9982acd69524098ceb82f1039535ffba3a1..00cb961b66ed837864db4c8376c06b316724a939 100644 --- a/en/application-dev/reference/apis/js-apis-privacyManager.md +++ b/en/application-dev/reference/apis/js-apis-privacyManager.md @@ -267,7 +267,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e | ID| Error Message| | -------- | -------- | -| 12100001 | The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. | +| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. | | 12100002 | The specified tokenID does not exist or refer to an application process. | | 12100003 | The specified permission does not exist or is not an user_grant permission. | | 12100004 | The interface is called repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. | @@ -315,7 +315,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e | ID| Error Message| | -------- | -------- | -| 12100001 | The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. | +| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. | | 12100002 | The specified tokenID does not exist or refer to an application process. | | 12100003 | The specified permission does not exist or is not an user_grant permission. | | 12100004 | The interface is called repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. | @@ -370,7 +370,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e | ID| Error Message| | -------- | -------- | -| 12100001 | The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. | +| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. | | 12100002 | The specified tokenID does not exist or refer to an application process. | | 12100003 | The specified permission does not exist or is not an user_grant permission. | | 12100004 | The interface is not used with | @@ -418,7 +418,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e | ID| Error Message| | -------- | -------- | -| 12100001 | The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. | +| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. | | 12100002 | The specified tokenID does not exist or refer to an application process. | | 12100003 | The specified permission does not exist or is not an user_grant permission. | | 12100004 | The interface is not used with | @@ -551,8 +551,8 @@ Represents the request for querying permission usage records. | Name | Type | Mandatory | Description | | -------- | -------------- | ---- | ---------------------------------------- | | tokenId | number | No | Token ID of the application (invoker).
By default, all applications are queried. | -| isRemote | boolean | No | Whether to query the permission usage records of the remote device.
The default value is **false**, which means the permission usage records of the local device are queried by default.| -| deviceId | string | No | ID of the device hosting the target application.
The default value is the local device ID. | +| isRemote | boolean | No | Whether to query the permission usage records of the remote device.
The default value is **false**, which means the permission usage records of the local device are queried by default.| +| deviceId | string | No | ID of the device hosting the target application.
The default value is the local device ID. | | bundleName | string | No | Bundle name of the target application.
By default, all applications are queried.| | permissionNames | Array<Permissions> | No | Permissions to query.
By default, the usage records of all permissions are queried. | | beginTime | number | No | Start time of the query, in ms.
The default value is **0**, which means the start time is not set.| diff --git a/en/application-dev/reference/apis/js-apis-rpc.md b/en/application-dev/reference/apis/js-apis-rpc.md index 4e2f4ed96e608f1f91cca03faea5188893be128f..22df13e5169b5c8589753aeb553689576e6f7c65 100644 --- a/en/application-dev/reference/apis/js-apis-rpc.md +++ b/en/application-dev/reference/apis/js-apis-rpc.md @@ -247,7 +247,7 @@ Obtains the data size of this **MessageSequence** object. | Type | Description | | ------ | ----------------------------------------------- | - | number | Size of the **MessageSequence** object obtained, in bytes.| + | number | Size of the **MessageSequence** instance obtained, in bytes.| **Example** @@ -293,6 +293,14 @@ Sets the size of the data contained in this **MessageSequence** object. | ------ | ------ | ---- | ------ | | size | number | Yes | Data size to set, in bytes.| +**Error codes** + +For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md). + + | ID| Error Message| + | -------- | -------- | + | 1900009 | write data to message sequence failed | + **Example** ```ts @@ -326,6 +334,7 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode | ID| Error Message| | -------- | -------- | + | 1900009 | write data to message sequence failed | | 1900011 | parcel memory alloc failed | **Example** @@ -452,6 +461,12 @@ Moves the read pointer to the specified position. | ------ | ------ | ---- | ------- | | pos | number | Yes | Position from which data is to read.| +**Error codes** + + | ID| Error Message| + | -------- | -------- | + | 1900010 | read data from message sequence failed | + **Example** ```ts @@ -484,6 +499,12 @@ Moves the write pointer to the specified position. | ------ | ------ | ---- | ----- | | pos | number | Yes | Position from which data is to write.| +**Error codes** + + | ID| Error Message| + | -------- | -------- | + | 1900009 | write data to message sequence failed | + **Example** ```ts @@ -2701,7 +2722,7 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode super(descriptor); this.modifyLocalInterface(this, descriptor); } - + asObject(): rpc.IRemoteObject { return this; } @@ -2718,7 +2739,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode } ``` - ### closeFileDescriptor9+ static closeFileDescriptor(fd: number): void @@ -2805,7 +2825,6 @@ Checks whether this **MessageSequence** object contains file descriptors. **Example** - ```ts import fs from '@ohos.file.fs'; let sequence = new rpc.MessageSequence(); @@ -2926,8 +2945,8 @@ Writes an anonymous shared object to this **MessageSequence** object. For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md). | ID| Error Message| - | -------- | ------- | - | 1900003 | write to ashmem failed | + | -------- | -------- | + | 1900009 | write data to message sequence failed | **Example** @@ -2948,7 +2967,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode } ``` - ### readAshmem readAshmem(): Ashmem @@ -2969,7 +2987,7 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode | ID| Error Message| | -------- | -------- | - | 1900004 | read from ashmem failed | + | 1900010 | read data from message sequence failed | **Example** @@ -3263,7 +3281,6 @@ Writes an interface token to this **MessageParcel** object. The remote object ca console.log("RpcServer: writeInterfaceToken is " + result); ``` - ### readInterfaceToken readInterfaceToken(): string @@ -3672,7 +3689,7 @@ Writes an Int value to this **MessageParcel** object. **Return value** | Type | Description | - | ------- | ----------------------------- | + | ------- | ----------------------------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| **Example** @@ -5825,7 +5842,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch | Name | Type | Mandatory| Description | | ------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. | | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -5836,7 +5853,6 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch | ------- | -------------------------------- | | boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.| - ### sendRequest8+(deprecated) >This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9). @@ -5851,7 +5867,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch | Name | Type | Mandatory| Description | | ------- | ---------------------------------------- | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. | | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -5862,7 +5878,6 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch | -------------------------------- | --------------------------------------------- | | Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.| - ### sendMessageRequest9+ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise<RequestResult> @@ -5875,7 +5890,7 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn | Name | Type | Mandatory| Description | | ------- | ------------------------------------ | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. | | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -5886,7 +5901,6 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn | ---------------------------- | ----------------------------------------- | | Promise<RequestResult> | Promise used to return the **requestResult** object.| - ### sendMessageRequest9+ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback<RequestResult>): void @@ -5899,7 +5913,7 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn | Name | Type | Mandatory| Description | | -------- | ------------------------------------ | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. | | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -5919,7 +5933,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch | Name | Type | Mandatory| Description | | -------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. | | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -5946,7 +5960,7 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode | ID| Error Message| | -------- | -------- | - | 1900008 | proxy or remote object is invalid | + | 1900005 | only proxy object permitted | ### addDeathrecipient(deprecated) @@ -5971,7 +5985,6 @@ Adds a callback for receiving death notifications of the remote object. This met | ------- | ---------------------------------------- | | boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.| - ### unregisterDeathRecipient9+ unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void @@ -5993,7 +6006,7 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode | ID| Error Message| | -------- | -------- | - | 1900008 | proxy or remote object is invalid | + | 1900005 | only proxy object permitted | ### removeDeathRecipient(deprecated) @@ -6040,7 +6053,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode | -------- | -------- | | 1900008 | proxy or remote object is invalid | - ### getInterfaceDescriptor(deprecated) >This API is no longer maintained since API version 9. You are advised to use [getDescriptor](#getdescriptor9). @@ -6057,7 +6069,6 @@ Obtains the interface descriptor (which is a string) of this object. | ------ | ---------------- | | string | Interface descriptor obtained.| - ### isObjectDead isObjectDead(): boolean @@ -6072,7 +6083,6 @@ Checks whether this object is dead. | ------- | ---------------------------------- | | boolean | Returns **true** if the object is dead; returns **false** otherwise.| - ## RemoteProxy Provides APIs to implement **IRemoteObject**. @@ -6101,7 +6111,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch | Name | Type | Mandatory| Description | | ------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. | | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -6177,7 +6187,7 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn | Name | Type | Mandatory| Description | | ------- | ------------------------------------ | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. | | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -6261,7 +6271,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch | Name | Type | Mandatory| Description | | ------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. | | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -6343,7 +6353,7 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn | Name | Type | Mandatory| Description | | -------- | ------------------------------------ | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. | | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -6424,7 +6434,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch | Name | Type | Mandatory| Description | | -------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. | | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -7079,13 +7089,12 @@ Provides common message options (flag and wait time). Use the specified flag to **System capability**: SystemCapability.Communication.IPC.Core - | Name | Value | Description | - | ------------- | ---- | ----------------------------------------------------------- | - | TF_SYNC | 0 | Synchronous call. | - | TF_ASYNC | 1 | Asynchronous call. | - | TF_ACCEPT_FDS | 0x10 | Indication to **sendMessageRequest9+** for returning the file descriptor.| - | TF_WAIT_TIME | 8 | Default waiting time, in seconds. | - + | Name | Value | Description | + | ------------- | --------- | ----------------------------------------------------------- | + | TF_SYNC | 0 (0x00) | Synchronous call. | + | TF_ASYNC | 1 (0x01) | Asynchronous call. | + | TF_ACCEPT_FDS | 16 (0x10) | Indication to **sendMessageRequest9+** for returning the file descriptor.| + | TF_WAIT_TIME | 4 (0x4) | Default waiting time, in seconds. | ### constructor9+ @@ -7101,7 +7110,6 @@ A constructor used to create a **MessageOption** object. | ------ | ------- | ---- | -------------------------------------- | | async | boolean | No | Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.| - **Example** ```ts @@ -7391,7 +7399,6 @@ Obtains the caller's token ID, which is used to verify the caller identity. } ``` - ### getCallingDeviceID static getCallingDeviceID(): string @@ -7484,7 +7491,6 @@ Flushes all suspended commands from the specified **RemoteProxy** to the corresp | ------ | ------------------------------- | ---- | ------------------- | | object | [IRemoteObject](#iremoteobject) | Yes | **RemoteProxy** specified. | - **Example** ```ts @@ -7577,7 +7583,6 @@ Changes the UID and PID of the remote user to the UID and PID of the local user. } ``` - ### restoreCallingIdentity9+ static restoreCallingIdentity(identity: string): void @@ -7667,7 +7672,6 @@ A constructor used to create a **RemoteObject** object. | ---------- | ------ | ---- | ------------ | | descriptor | string | Yes | Interface descriptor.| - ### sendRequest(deprecated) >This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9). @@ -7682,7 +7686,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch | Name | Type | Mandatory| Description | | ------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. | | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -7748,7 +7752,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch | Name | Type | Mandatory| Description | | ------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. | | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -7818,7 +7822,7 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn | Name | Type | Mandatory| Description | | ------- | ------------------------------------ | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. | | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -7874,7 +7878,7 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn | Name | Type | Mandatory| Description | | ------------- | ------------------------------------ | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. | | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -7924,7 +7928,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch | Name | Type | Mandatory| Description | | ------------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- | - | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| + | code | number | Yes | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. | | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. | | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. | @@ -8239,7 +8243,6 @@ Obtains the interface descriptor. | ------------- | --------------------------------------------- | | IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.| - **Example** ```ts @@ -8612,7 +8615,6 @@ Creates an **Ashmem** object by copying the file descriptor of an existing **Ash | ------ | ---------------------- | | Ashmem | **Ashmem** object created.| - **Example** ```ts diff --git a/en/application-dev/reference/apis/js-apis-wifi.md b/en/application-dev/reference/apis/js-apis-wifi.md index 76f27aa775302ff5d313d17f664401b6364e25b9..e9f2fbb84b4b39521a484f2c5ffc60680223d2ac 100644 --- a/en/application-dev/reference/apis/js-apis-wifi.md +++ b/en/application-dev/reference/apis/js-apis-wifi.md @@ -244,23 +244,6 @@ Enumerates the WLAN security types. | WIFI_SEC_TYPE_SAE | 4 | Simultaneous Authentication of Equals (SAE).| -## wifi.getScanInfosSync9+ - -getScanInfosSync():  Array<[WifiScanInfo](#wifiscaninfo)> - -Obtains the scan result. This API returns the result synchronously. - -**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_PEERS_MAC (or ohos.permission.LOCATION) - -**System capability**: SystemCapability.Communication.WiFi.STA - -**Return value** - - | **Type**| **Description**| - | -------- | -------- | - |  Array<[WifiScanInfo](#wifiscaninfo)> | Scan result obtained.| - - ## wifi.addDeviceConfig addDeviceConfig(config: WifiDeviceConfig): Promise<number> @@ -585,8 +568,8 @@ Connects to the specified network. **System API**: This is a system API. -**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permissio.MANAGE_WIFI_CONNECTION (available only to system applications) - +**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) + **System capability**: SystemCapability.Communication.WiFi.STA @@ -680,7 +663,7 @@ try { let rssi = 0; let band = 0; let level = wifi.getSignalLevel(rssi,band); - console.info("lelvel:" + JSON.stringify(lelvel)); + console.info("level:" + JSON.stringify(level)); }catch(error){ console.error("failed:" + JSON.stringify(error)); } @@ -1278,10 +1261,10 @@ Disables this hotspot. **Example** ```js -import wifi from '@ohos.wifiManager'; +import wifi from '@ohos.wifi'; try { - wifiManager.disableHotspot(); + wifi.disableHotspot(); }catch(error){ console.error("failed:" + JSON.stringify(error)); } @@ -1644,7 +1627,7 @@ Obtains the peer device list in the P2P connection. This API uses an asynchronou **Example** ```js -import wifi from '@ohos.wifiManager'; +import wifi from '@ohos.wifi'; wifi.getP2pPeerDevices((err, data) => { if (err) { @@ -2043,7 +2026,7 @@ import wifi from '@ohos.wifi'; try { let name = "****"; - wifi.setDeviceName(netId); + wifi.setDeviceName(name); }catch(error){ console.error("failed:" + JSON.stringify(error)); } diff --git a/en/application-dev/reference/apis/js-apis-wifiManager.md b/en/application-dev/reference/apis/js-apis-wifiManager.md index 6d560d345805826369d8b83cfdcbee53a47b00f5..32a9a545a4785e4de3ab0a600c74cc23bc1f8e6d 100644 --- a/en/application-dev/reference/apis/js-apis-wifiManager.md +++ b/en/application-dev/reference/apis/js-apis-wifiManager.md @@ -2,7 +2,6 @@ The **WLAN** module provides basic wireless local area network (WLAN) functions, peer-to-peer (P2P) functions, and WLAN message notification services. It allows applications to communicate with other devices over WLAN. > **NOTE** -> > 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. @@ -26,22 +25,22 @@ Enables WLAN. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| + | **Type**| **Description**| + | -------- | -------- | + | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.enableWifi(); @@ -64,22 +63,22 @@ Disables WLAN. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| + | **Type**| **Description**| + | -------- | -------- | + | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.disableWifi(); @@ -100,22 +99,22 @@ Checks whether WLAN is enabled. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.| + | **Type**| **Description**| + | -------- | -------- | + | boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let isActivate = wifiManager.isActivate(); @@ -137,22 +136,22 @@ Starts a scan for WLAN. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| + | **Type**| **Description**| + | -------- | -------- | + | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.scan(); @@ -173,27 +172,27 @@ Obtains the scan result. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| Array<[WifiScanInfo](#wifiscaninfo)> | Returns the hotspots detected.| + | **Type**| **Description**| + | -------- | -------- | + | Array<[WifiScanInfo](#wifiscaninfo)> | Returns the hotspots detected.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let scanInfoList = wifiManager.getScanInfoList(); console.info("scanInfoList:" + JSON.stringify(scanInfoList)); - let len = Object.keys(result).length; + let len = Object.keys(scanInfoList).length; console.log("wifi received scan info: " + len); if(len > 0){ for (var i = 0; i < len; ++i) { @@ -332,14 +331,14 @@ Adds network configuration. This API uses a promise to return the result. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| **Return value** -| **Type**| **Description**| -| -------- | -------- | + | **Type**| **Description**| + | -------- | -------- | | Promise<number> | Promise used to return the ID of the added network configuration. If **-1** is returned, the network configuration fails to be added.| **Error codes** @@ -347,13 +346,13 @@ Adds network configuration. This API uses a promise to return the result. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let config = { @@ -508,23 +507,23 @@ Adds network configuration. This API uses an asynchronous callback to return the **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| -| callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| + | callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let config = { @@ -552,27 +551,27 @@ Adds the configuration of a candidate network. This API uses a promise to return **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| **Return value** -| **Type**| **Description**| -| -------- | -------- | -| Promise<number> | Promise used to return the network configuration ID.| + | **Type**| **Description**| + | -------- | -------- | + | Promise<number> | Promise used to return the network configuration ID.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -````` - import wifi from '@ohos.wifiManager'; +`````js + import wifiManager from '@ohos.wifiManager'; try { let config = { @@ -600,22 +599,22 @@ Adds the configuration of a candidate network. This API uses an asynchronous cal **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| -| callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| + | callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -````` - import wifi from '@ohos.wifiManager'; +`````js + import wifiManager from '@ohos.wifiManager'; try { let config = { @@ -643,28 +642,28 @@ Removes the configuration of a candidate network. This API uses a promise to ret **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| networkId | number | Yes| ID of the network configuration to remove.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | networkId | number | Yes| ID of the network configuration to remove.| **Return value** -| **Type**| **Description**| -| -------- | -------- | -| Promise<void> | Promise used to return the result.| + | **Type**| **Description**| + | -------- | -------- | + | Promise<void> | Promise used to return the result.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let networkId = 0; @@ -688,9 +687,9 @@ Removes the configuration of a candidate network. This API uses an asynchronous **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| networkId | number | Yes| ID of the network configuration to remove.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | networkId | number | Yes| ID of the network configuration to remove.| | callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the operation is successful, the value of **err** is **0**. If **err** is not **0**, an error has occurred.| **Error codes** @@ -698,12 +697,12 @@ Removes the configuration of a candidate network. This API uses an asynchronous For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let networkId = 0; @@ -727,22 +726,22 @@ Obtains candidate network configuration. **Return value** -| **Type**| **Description**| -| -------- | -------- | -|  Array<[WifiDeviceConfig](#wifideviceconfig)> | Candidate network configuration obtained.| + | **Type**| **Description**| + | -------- | -------- | + |  Array<[WifiDeviceConfig](#wifideviceconfig)> | Candidate network configuration obtained.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | -| 2501000 | Operation failed.| + | -------- | -------- | +| 2501000 | Operation failed.| **Example** -````` - import wifi from '@ohos.wifiManager'; +`````js + import wifiManager from '@ohos.wifiManager'; try { let configs = wifiManager.getCandidateConfigs(); @@ -773,22 +772,22 @@ Connects to a candidate network added by the application. If the device is alrea **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| networkId | number | Yes| ID of the candidate network configuration.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | networkId | number | Yes| ID of the candidate network configuration.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| | 2501001 | Wifi is closed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let networkId = 0; @@ -814,23 +813,23 @@ Connects to the specified network. If the device is already connected to a hotsp **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| networkId | number | Yes| Network configuration ID.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | networkId | number | Yes| Network configuration ID.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| | 2501001 | Wifi is closed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let networkId = 0; @@ -848,15 +847,15 @@ Connects to the specified network. If the device is already connected to a hotsp **System API**: This is a system API. -**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permissio.MANAGE_WIFI_CONNECTION (available only to system applications) +**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.STA **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| Configuration of the WLAN to connect. | **Error codes** @@ -864,13 +863,13 @@ Connects to the specified network. If the device is already connected to a hotsp For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| | 2501001 | Wifi is closed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let config = { @@ -903,12 +902,12 @@ Disconnects the network. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.disconnect(); @@ -929,34 +928,34 @@ Obtains the WLAN signal level. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| rssi | number | Yes| RSSI of the hotspot, in dBm.| -| band | number | Yes| Frequency band of the WLAN AP.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | rssi | number | Yes| RSSI of the hotspot, in dBm.| + | band | number | Yes| Frequency band of the WLAN AP.| **Return value** -| **Type**| **Description**| -| -------- | -------- | -| number | Signal level obtained. The value range is [0, 4].| + | **Type**| **Description**| + | -------- | -------- | + | number | Signal level obtained. The value range is [0, 4].| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let rssi = 0; let band = 0; let level = wifiManager.getSignalLevel(rssi,band); - console.info("lelvel:" + JSON.stringify(lelvel)); + console.info("level:" + JSON.stringify(level)); }catch(error){ console.error("failed:" + JSON.stringify(error)); } @@ -975,8 +974,8 @@ Obtains WLAN connection information. This API uses a promise to return the resul **Return value** -| Type| Description| -| -------- | -------- | + | Type| Description| + | -------- | -------- | | Promise<[WifiLinkedInfo](#wifilinkedinfo)> | Promise used to return the WLAN connection information obtained.| **Error codes** @@ -984,7 +983,7 @@ Obtains WLAN connection information. This API uses a promise to return the resul For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| | 2501001 | Wifi is closed.| @@ -1000,24 +999,24 @@ Obtains WLAN connection information. This API uses an asynchronous callback to r **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<[WifiLinkedInfo](#wifilinkedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the WLAN connection information obtained. If **err** is not **0**, an error has occurred.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[WifiLinkedInfo](#wifilinkedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the WLAN connection information obtained. If **err** is not **0**, an error has occurred.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| | 2501001 | Wifi is closed.| **Example** - ```js - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; - wifi.getLinkedInfo((err, data) => { + wifiManager.getLinkedInfo((err, data) => { if (err) { console.error("get linked info error"); return; @@ -1025,12 +1024,12 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco console.info("get wifi linked info: " + JSON.stringify(data)); }); - wifi.getLinkedInfo().then(data => { + wifiManager.getLinkedInfo().then(data => { console.info("get wifi linked info: " + JSON.stringify(data)); }).catch(error => { console.info("get linked info error"); }); - ``` +``` ## WifiLinkedInfo9+ @@ -1104,24 +1103,6 @@ Enumerates the supplicant states. | UNINITIALIZED | 10 | The supplicant failed to set up the connection.| | INVALID | 11 | Invalid value.| -## SuppState10+ - -Enumerates the Wi-Fi standards. - -**System capability**: SystemCapability.Communication.WiFi.STA - -| Name| Value| Description| -| -------- | -------- | -------- | -| WIFI_STANDARD_UNDEFINED | 0 | Undefined| -| WIFI_STANDARD_11A | 1 | 802.11a| -| WIFI_STANDARD_11B | 2 | 802.11b| -| WIFI_STANDARD_11G | 3 | 802.11g| -| WIFI_STANDARD_11N | 4 | 802.11n| -| WIFI_STANDARD_11AC | 5 | 802.11ac| -| WIFI_STANDARD_11AX | 6 | 802.11ax| -| WIFI_STANDARD_11AD | 7 | 802.11ad| - - ## wifi.isConnected9+ isConnected(): boolean @@ -1134,21 +1115,21 @@ Checks whether the WLAN is connected. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.| + | **Type**| **Description**| + | -------- | -------- | + | boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let ret = wifiManager.isConnected(); @@ -1173,9 +1154,9 @@ Obtains the features supported by this device. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| number | Feature value. | + | **Type**| **Description**| + | -------- | -------- | + | number | Feature value. | **Feature IDs** @@ -1197,12 +1178,12 @@ Obtains the features supported by this device. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2401000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let ret = wifiManager.getSupportedFeatures(); @@ -1226,27 +1207,27 @@ Checks whether the device supports the specified WLAN feature. **Parameters** -| **Name**| **Type**| Mandatory| **Description**| -| -------- | -------- | -------- | -------- | -| featureId | number | Yes| Feature ID.| + | **Name**| **Type**| Mandatory| **Description**| + | -------- | -------- | -------- | -------- | + | featureId | number | Yes| Feature ID.| **Return value** -| **Type**| **Description**| -| -------- | -------- | -| boolean | Returns **true** if the feature is supported; returns **false** otherwise.| + | **Type**| **Description**| + | -------- | -------- | + | boolean | Returns **true** if the feature is supported; returns **false** otherwise.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2401000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let featureId = 0; @@ -1272,21 +1253,21 @@ Obtains the device MAC address. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| string[] | MAC address obtained.| + | **Type**| **Description**| + | -------- | -------- | + | string[] | MAC address obtained.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let ret = wifiManager.getDeviceMacAddress(); @@ -1309,21 +1290,21 @@ Obtains IP information. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| [IpInfo](#ipinfo9) | IP information obtained.| + | **Type**| **Description**| + | -------- | -------- | + | [IpInfo](#ipinfo9) | IP information obtained.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let info = wifiManager.getIpInfo(); @@ -1362,21 +1343,21 @@ Obtains the country code. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| string | Country code obtained.| + | **Type**| **Description**| + | -------- | -------- | + | string | Country code obtained.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2401000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let code = wifiManager.getCountryCode(); @@ -1403,13 +1384,13 @@ Re-associates with the network. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| | 2501001 | Wifi is closed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.reassociate(); @@ -1435,13 +1416,13 @@ Reconnects to the network. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| | 2501001 | Wifi is closed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.reconnect(); @@ -1464,21 +1445,21 @@ Obtains network configuration. **Return value** -| **Type**| **Description**| -| -------- | -------- | -|  Array<[WifiDeviceConfig](#wifideviceconfig)> | Array of network configuration obtained.| + | **Type**| **Description**| + | -------- | -------- | + |  Array<[WifiDeviceConfig](#wifideviceconfig)> | Array of network configuration obtained.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let configs = wifiManager.getDeviceConfigs(); @@ -1502,27 +1483,27 @@ Updates network configuration. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| New WLAN configuration.| **Return value** -| **Type**| **Description**| -| -------- | -------- | -| number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.| + | **Type**| **Description**| + | -------- | -------- | + | number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let config = { @@ -1551,8 +1532,8 @@ Disables network configuration. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | | netId | number | Yes| ID of the network configuration to disable.| **Error codes** @@ -1560,12 +1541,12 @@ Disables network configuration. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let netId = 0; @@ -1592,12 +1573,12 @@ Removes the configuration of all networks. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.removeAllDeviceConfigs(); @@ -1620,21 +1601,21 @@ Removes the specified network configuration. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| networkId | number | Yes| ID of the network configuration to remove.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | networkId | number | Yes| ID of the network configuration to remove.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let id = 0; @@ -1656,51 +1637,67 @@ Checks whether the current frequency band is supported. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| bandType | WifiBandType | Yes| Wi-Fi band type.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | bandType | WifiBandType | Yes| Wi-Fi band type.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let type = 0; - boolean isBandTypeSupported = wifiManager.isBandTypeSupported(type); + let isBandTypeSupported = wifiManager.isBandTypeSupported(type); console.info("isBandTypeSupported:" + isBandTypeSupported); }catch(error){ console.error("failed:" + JSON.stringify(error)); } ``` -## WifiBandType 10+ +## wifi.get5GChannelList10+ -Enumerates the Wi-Fi band types. +get5GChannelList(): Array<number> + +Obtains the list of 5 GHz channels supported by this device. + +**System API**: This is a system API. + +**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG **System capability**: SystemCapability.Communication.WiFi.STA -| Name| Value| Description| -| -------- | -------- | -------- | -| WIFI_BAND_NONE | 0 | Undefined| -| WIFI_BAND_2G | 1 | 2 GHz| -| WIFI_BAND_5G | 2 | 5 GHz| -| WIFI_BAND_6G | 3 | 6 GHz| -| WIFI_BAND_60G | 4 | 60 GHz| +**Error codes** +For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). -## wifi.get5GChannelList10+ +| **ID**| **Error Message**| + | -------- | -------- | +| 2501000 | Operation failed.| -get5GChannelList(): Array<number> +**Example** +```js + import wifiManager from '@ohos.wifiManager'; -Obtains the list of 5 GHz channels supported by this device. + try { + let channelList = wifiManager.get5GChannelList(); + console.info("channelList:" + JSON.stringify(channelList)); + }catch(error){ + console.error("failed:" + JSON.stringify(error)); + } +``` +## wifi.getDisconnectedReason10+ + +getDisconnectedReason(): DisconnectedReason + +Obtains the reason of the latest disconnection. **System API**: This is a system API. @@ -1713,21 +1710,41 @@ Obtains the list of 5 GHz channels supported by this device. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| + | -------- | -------- | +| 2601000 | Operation failed.| + +**Return value** + +| **Type**| **Description**| | -------- | -------- | -| 2501000 | Operation failed.| +| DisconnectedReason | Returns the reason of the latest disconnection obtained.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { - let channelList = wifiManager.get5GChannelList(); - console.info("channelList:" + JSON.stringify(channelList)); + let disconnectedReason = wifiManager.getDisconnectedReason(); + console.info("disconnectedReason:" + disconnectedReason); }catch(error){ console.error("failed:" + JSON.stringify(error)); } ``` +## DisconnectedReason 10+ + +Enumerates the Wi-Fi disconnection reasons. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Communication.WiFi.STA + +| Name| Value| Description| +| -------- | -------- | -------- | +| DISC_REASON_DEFAULT | 0 | Default reason.| +| DISC_REASON_WRONG_PWD | 1 | Incorrect password.| +| DISC_REASON_CONNECTION_FULL | 2 | The number of connections to the router has reached the limit.| + ## wifi.enableHotspot9+ enableHotspot(): void @@ -1745,12 +1762,12 @@ Enables this hotspot. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2601000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.enableHotspot(); @@ -1776,12 +1793,12 @@ Disables this hotspot. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2601000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.disableHotspot(); @@ -1804,21 +1821,21 @@ Checks whether the hotspot supports dual band. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| boolean | Returns **true** if the hotspot supports dual band; returns **false** otherwise.| + | **Type**| **Description**| + | -------- | -------- | + | boolean | Returns **true** if the hotspot supports dual band; returns **false** otherwise.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2601000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let ret = wifiManager.isHotspotDualBandSupported(); @@ -1842,21 +1859,21 @@ Checks whether this hotspot is active. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| boolean | Returns **true** if the hotspot is active; returns **false** otherwise.| + | **Type**| **Description**| + | -------- | -------- | + | boolean | Returns **true** if the hotspot is active; returns **false** otherwise.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2601000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let ret = wifiManager.isHotspotActive(); @@ -1880,21 +1897,21 @@ Sets hotspot configuration. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| config | [HotspotConfig](#hotspotconfig9) | Yes| Hotspot configuration to set.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | config | [HotspotConfig](#hotspotconfig9) | Yes| Hotspot configuration to set.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2601000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let config = { @@ -1943,21 +1960,21 @@ Obtains hotspot configuration. **Return value** -| **Type**| **Description**| -| -------- | -------- | -| [HotspotConfig](#hotspotconfig9) | Hotspot configuration obtained.| + | **Type**| **Description**| + | -------- | -------- | + | [HotspotConfig](#hotspotconfig9) | Hotspot configuration obtained.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2601000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let config = wifiManager.getHotspotConfig(); @@ -1975,27 +1992,27 @@ Obtains information about the connected stations. **System API**: This is a system API. -**Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) +**Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) **System capability**: SystemCapability.Communication.WiFi.AP.Core **Return value** -| **Type**| **Description**| -| -------- | -------- | -|  Array<[StationInfo](#stationinfo9)> | Connected stations obtained.| + | **Type**| **Description**| + | -------- | -------- | + |  Array<[StationInfo](#stationinfo9)> | Connected stations obtained.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2601000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let stations = wifiManager.getHotspotStations(); @@ -2032,8 +2049,8 @@ Obtains P2P link information. This API uses a promise to return the result. **Return value** -| Type| Description| -| -------- | -------- | + | Type| Description| + | -------- | -------- | | Promise<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Promise used to return the P2P link information obtained.| **Error codes** @@ -2041,14 +2058,14 @@ Obtains P2P link information. This API uses a promise to return the result. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; - wifi.getP2pLinkedInfo((err, data) => { + wifiManager.getP2pLinkedInfo((err, data) => { if (err) { console.error("get p2p linked info error"); return; @@ -2056,7 +2073,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco console.info("get wifi p2p linked info: " + JSON.stringify(data)); }); - wifi.getP2pLinkedInfo().then(data => { + wifiManager.getP2pLinkedInfo().then(data => { console.info("get wifi p2p linked info: " + JSON.stringify(data)); }); ``` @@ -2099,9 +2116,9 @@ Obtains P2P link information. This API uses an asynchronous callback to return t **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the P2P link information. If **err** is not **0**, an error has occurred.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the P2P link information. If **err** is not **0**, an error has occurred.| ## wifi.getCurrentP2pGroup9+ @@ -2116,8 +2133,8 @@ Obtains the current P2P group information. This API uses a promise to return the **Return value** -| Type| Description| -| -------- | -------- | + | Type| Description| + | -------- | -------- | | Promise<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | Promise used to return the P2P group information obtained.| **Error codes** @@ -2125,7 +2142,7 @@ Obtains the current P2P group information. This API uses a promise to return the For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| ## wifi.getCurrentP2pGroup9+ @@ -2140,23 +2157,23 @@ Obtains the current P2P group information. This API uses an asynchronous callbac **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; - wifi.getCurrentP2pGroup((err, data) => { + wifiManager.getCurrentP2pGroup((err, data) => { if (err) { console.error("get current P2P group error"); return; @@ -2164,7 +2181,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco console.info("get current P2P group: " + JSON.stringify(data)); }); - wifi.getCurrentP2pGroup().then(data => { + wifiManager.getCurrentP2pGroup().then(data => { console.info("get current P2P group: " + JSON.stringify(data)); }); ``` @@ -2181,16 +2198,16 @@ Obtains the peer device list in the P2P connection. This API uses a promise to r **Return value** -| Type| Description| -| -------- | -------- | -| Promise<[WifiP2pDevice[]](#wifip2pdevice9)> | Promise used to return the peer device list.| + | Type| Description| + | -------- | -------- | + | Promise<[WifiP2pDevice[]](#wifip2pdevice9)> | Promise used to return the peer device list.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| ## wifi.getP2pPeerDevices9+ @@ -2205,23 +2222,23 @@ Obtains the peer device list in the P2P connection. This API uses an asynchronou **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<[WifiP2pDevice[]](#wifip2pdevice9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the peer device list obtained. If **err** is not **0**, an error has occurred.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[WifiP2pDevice[]](#wifip2pdevice9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the peer device list obtained. If **err** is not **0**, an error has occurred.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; - wifi.getP2pPeerDevices((err, data) => { + wifiManager.getP2pPeerDevices((err, data) => { if (err) { console.error("get P2P peer devices error"); return; @@ -2229,7 +2246,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco console.info("get P2P peer devices: " + JSON.stringify(data)); }); - wifi.getP2pPeerDevices().then(data => { + wifiManager.getP2pPeerDevices().then(data => { console.info("get P2P peer devices: " + JSON.stringify(data)); }); ``` @@ -2276,16 +2293,16 @@ Obtains the local device information in the P2P connection. This API uses a prom **Return value** -| Type| Description| -| -------- | -------- | -| Promise<[WifiP2pDevice](#wifip2pdevice9)> | Promise used to return the local device information obtained.| + | Type| Description| + | -------- | -------- | + | Promise<[WifiP2pDevice](#wifip2pdevice9)> | Promise used to return the local device information obtained.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| ## wifi.getP2pLocalDevice9+ @@ -2300,17 +2317,19 @@ Obtains the local device information in the P2P connection. This API uses an asy **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<[WifiP2pDevice](#wifip2pdevice9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the local device information obtained. If **err** is not **0**, an error has occurred.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[WifiP2pDevice](#wifip2pdevice9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the local device information obtained. If **err** is not **0**, an error has occurred.| + +**Error codes** | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; wifiManager.getP2pLocalDevice((err, data) => { if (err) { @@ -2320,7 +2339,7 @@ Obtains the local device information in the P2P connection. This API uses an asy console.info("get P2P local device: " + JSON.stringify(data)); }); - wifi.getP2pLocalDevice().then(data => { + wifiManager.getP2pLocalDevice().then(data => { console.info("get P2P local device: " + JSON.stringify(data)); }); ``` @@ -2337,21 +2356,21 @@ Creates a P2P group. **Parameters** -| **Name**| **Type**| Mandatory| **Description**| -| -------- | -------- | -------- | -------- | -| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| Group configuration.| + | **Name**| **Type**| Mandatory| **Description**| + | -------- | -------- | -------- | -------- | + | config | [WifiP2PConfig](#wifip2pconfig9) | Yes| Group configuration.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let config = { @@ -2411,12 +2430,12 @@ Removes this P2P group. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.removeP2pGroup(); @@ -2437,25 +2456,25 @@ Sets up a P2P connection. **Parameters** -| **Name**| **Type**| Mandatory| **Description**| -| -------- | -------- | -------- | -------- | -| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| P2P group configuration.| + | **Name**| **Type**| Mandatory| **Description**| + | -------- | -------- | -------- | -------- | + | config | [WifiP2PConfig](#wifip2pconfig9) | Yes| P2P group configuration.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifi'; +```js + import wifiManager from '@ohos.wifiManager'; var recvP2pConnectionChangeFunc = result => { console.info("p2p connection change receive event: " + JSON.stringify(result)); - wifi.getP2pLinkedInfo((err, data) => { + wifiManager.getP2pLinkedInfo((err, data) => { if (err) { console.error('failed to get getP2pLinkedInfo: ' + JSON.stringify(err)); return; @@ -2463,16 +2482,16 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco console.info("get getP2pLinkedInfo: " + JSON.stringify(data)); }); } - wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc); + wifiManager.on("p2pConnectionChange", recvP2pConnectionChangeFunc); var recvP2pDeviceChangeFunc = result => { console.info("p2p device change receive event: " + JSON.stringify(result)); } - wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc); + wifiManager.on("p2pDeviceChange", recvP2pDeviceChangeFunc); var recvP2pPeerDeviceChangeFunc = result => { console.info("p2p peer device change receive event: " + JSON.stringify(result)); - wifi.getP2pPeerDevices((err, data) => { + wifiManager.getP2pPeerDevices((err, data) => { if (err) { console.error('failed to get peer devices: ' + JSON.stringify(err)); return; @@ -2489,17 +2508,17 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco "groupName":"", "goBand":0, } - wifi.p2pConnect(config); + wifiManager.p2pConnect(config); } } }); } - wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); + wifiManager.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); var recvP2pPersistentGroupChangeFunc = () => { console.info("p2p persistent group change receive event"); - wifi.getCurrentGroup((err, data) => { + wifiManager.getCurrentP2pGroup((err, data) => { if (err) { console.error('failed to get current group: ' + JSON.stringify(err)); return; @@ -2507,14 +2526,14 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco console.info("get current group: " + JSON.stringify(data)); }); } - wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); + wifiManager.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); - setTimeout(function() {wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000); - setTimeout(function() {wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000); - setTimeout(function() {wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000); - setTimeout(function() {wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000); - console.info("start discover devices -> " + wifi.startP2pDiscoverDevices()); - ``` + setTimeout(function() {wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000); + setTimeout(function() {wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000); + setTimeout(function() {wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000); + setTimeout(function() {wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000); + console.info("start discover devices -> " + wifiManager.startDiscoverP2pDevices()); +``` ## wifi.p2pCancelConnect9+ @@ -2531,12 +2550,12 @@ Cancels this P2P connection. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.p2pCancelConnect(); @@ -2560,12 +2579,12 @@ Starts to discover devices. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.startDiscoverP2pDevices(); @@ -2589,12 +2608,12 @@ Stops discovering devices. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { wifiManager.stopDiscoverP2pDevices(); @@ -2618,21 +2637,21 @@ Deletes a persistent group. **Parameters** -| **Name**| **Type**| Mandatory| **Description**| -| -------- | -------- | -------- | -------- | -| netId | number | Yes| ID of the group to delete.| + | **Name**| **Type**| Mandatory| **Description**| + | -------- | -------- | -------- | -------- | + | netId | number | Yes| ID of the group to delete.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let netId = 0; @@ -2656,21 +2675,21 @@ Obtains information about all P2P groups. This API uses a promise to return the **Return value** -| Type| Description| -| -------- | -------- | -| Promise< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> > | Promise used to return the group information obtained.| + | Type| Description| + | -------- | -------- | + | Promise< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> > | Promise used to return the group information obtained.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; wifiManager.getP2pGroups((err, data) => { if (err) { @@ -2680,7 +2699,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco console.info("get P2P groups: " + JSON.stringify(data)); }); - wifi.getP2pGroups().then(data => { + wifiManager.getP2pGroups().then(data => { console.info("get P2P groups: " + JSON.stringify(data)); }); @@ -2719,16 +2738,16 @@ Obtains information about all P2P groups. This API uses an asynchronous callback **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo9)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo9)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| ## wifi.setP2pDeviceName9+ @@ -2745,25 +2764,25 @@ Sets the device name. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| devName | string | Yes| Device name to set.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | devName | string | Yes| Device name to set.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** -``` - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; try { let name = "****"; - wifiManager.setP2pDeviceName(netId); + wifiManager.setP2pDeviceName(name); }catch(error){ console.error("failed:" + JSON.stringify(error)); } @@ -2781,17 +2800,17 @@ Registers the WLAN state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **wifiStateChange**.| -| callback | Callback<number> | Yes| Callback invoked to return the WLAN state.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **wifiStateChange**.| + | callback | Callback<number> | Yes| Callback invoked to return the WLAN state.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **WLAN states** @@ -2816,9 +2835,9 @@ Unregisters the WLAN state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **wifiStateChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **wifiStateChange**.| | callback | Callback<number> | No| Callback for the WLAN state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| **Error codes** @@ -2826,23 +2845,23 @@ Unregisters the WLAN state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifi'; +```js + import wifiManager from '@ohos.wifiManager'; var recvPowerNotifyFunc = result => { console.info("Receive power state change event: " + result); } // Register an event. - wifi.on("wifiStateChange", recvPowerNotifyFunc); + wifiManager.on("wifiStateChange", recvPowerNotifyFunc); // Unregister an event. - wifi.off("wifiStateChange", recvPowerNotifyFunc); - ``` + wifiManager.off("wifiStateChange", recvPowerNotifyFunc); +``` ## wifi.on('wifiConnectionChange')9+ @@ -2857,10 +2876,10 @@ Registers the WLAN connection state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **wifiConnectionChange**.| -| callback | Callback<number> | Yes| Callback invoked to return the WLAN connection state.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **wifiConnectionChange**.| + | callback | Callback<number> | Yes| Callback invoked to return the WLAN connection state.| **WLAN connection states** @@ -2874,7 +2893,7 @@ Registers the WLAN connection state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| ## wifi.off('wifiConnectionChange')9+ @@ -2889,9 +2908,9 @@ Unregisters the WLAN connection state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **wifiConnectionChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **wifiConnectionChange**.| | callback | Callback<number> | No| Callback for the WLAN connection state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| **Error codes** @@ -2899,23 +2918,23 @@ Unregisters the WLAN connection state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifi'; +```js + import wifiManager from '@ohos.wifiManager'; var recvWifiConnectionChangeFunc = result => { console.info("Receive wifi connection change event: " + result); } // Register an event. - wifi.on("wifiConnectionChange", recvWifiConnectionChangeFunc); + wifiManager.on("wifiConnectionChange", recvWifiConnectionChangeFunc); // Unregister an event. - wifi.off("wifiConnectionChange", recvWifiConnectionChangeFunc); - ``` + wifiManager.off("wifiConnectionChange", recvWifiConnectionChangeFunc); +``` ## wifi.on('wifiScanStateChange')9+ @@ -2929,10 +2948,10 @@ Registers the WLAN scan state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **wifiScanStateChange**.| -| callback | Callback<number> | Yes| Callback invoked to return the WLAN scan state.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **wifiScanStateChange**.| + | callback | Callback<number> | Yes| Callback invoked to return the WLAN scan state.| **WLAN scan states** @@ -2946,7 +2965,7 @@ Registers the WLAN scan state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| ## wifi.off('wifiScanStateChange')9+ @@ -2971,23 +2990,23 @@ Unregisters the WLAN scan state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifi'; +```js + import wifiManager from '@ohos.wifiManager'; var recvWifiScanStateChangeFunc = result => { console.info("Receive Wifi scan state change event: " + result); } // Register an event. - wifi.on("wifiScanStateChange", recvWifiScanStateChangeFunc); + wifiManager.on("wifiScanStateChange", recvWifiScanStateChangeFunc); // Unregister an event. - wifi.off("wifiScanStateChange", recvWifiScanStateChangeFunc); - ``` + wifiManager.off("wifiScanStateChange", recvWifiScanStateChangeFunc); +``` ## wifi.on('wifiRssiChange')9+ @@ -3001,17 +3020,17 @@ Registers the RSSI change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **wifiRssiChange**.| -| callback | Callback<number> | Yes| Callback invoked to return the RSSI, in dBm.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **wifiRssiChange**.| + | callback | Callback<number> | Yes| Callback invoked to return the RSSI, in dBm.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| ## wifi.off('wifiRssiChange')9+ @@ -3026,9 +3045,9 @@ Unregisters the RSSI change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **wifiRssiChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **wifiRssiChange**.| | callback | Callback<number> | No| Callback for the RSSI change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| **Error codes** @@ -3036,12 +3055,12 @@ Unregisters the RSSI change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2501000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; var recvWifiRssiChangeFunc = result => { console.info("Receive wifi rssi change event: " + result); @@ -3052,7 +3071,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco // Unregister an event. wifiManager.off("wifiRssiChange", recvWifiRssiChangeFunc); - ``` +``` ## wifi.on('hotspotStateChange')9+ @@ -3066,10 +3085,10 @@ Registers the hotspot state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **hotspotStateChange**.| -| callback | Callback<number> | Yes| Callback invoked to return the hotspot state.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **hotspotStateChange**.| + | callback | Callback<number> | Yes| Callback invoked to return the hotspot state.| **Hotspot states** @@ -3085,7 +3104,7 @@ Registers the hotspot state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2601000 | Operation failed.| ## wifi.off('hotspotStateChange')9+ @@ -3100,9 +3119,9 @@ Unregisters the hotspot state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **hotspotStateChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **hotspotStateChange**.| | callback | Callback<number> | No| Callback for the hotspot state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| **Error codes** @@ -3110,12 +3129,12 @@ Unregisters the hotspot state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2601000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; var recvHotspotStateChangeFunc = result => { console.info("Receive hotspot state change event: " + result); @@ -3126,7 +3145,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco // Unregister an event. wifiManager.off("hotspotStateChange", recvHotspotStateChangeFunc); - ``` +``` ## wifi.on('p2pStateChange')9+ @@ -3140,10 +3159,10 @@ Registers the P2P state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pStateChange**.| -| callback | Callback<number> | Yes| Callback invoked to return the P2P state.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pStateChange**.| + | callback | Callback<number> | Yes| Callback invoked to return the P2P state.| **P2P states** @@ -3160,7 +3179,7 @@ Registers the P2P state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| ## wifi.off('p2pStateChange')9+ @@ -3175,9 +3194,9 @@ Unregisters the P2P state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pStateChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pStateChange**.| | callback | Callback<number> | No| Callback for the P2P state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| **Error codes** @@ -3185,12 +3204,12 @@ Unregisters the P2P state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; var recvP2pStateChangeFunc = result => { console.info("Receive p2p state change event: " + result); @@ -3201,9 +3220,9 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco // Unregister an event. wifiManager.off("p2pStateChange", recvP2pStateChangeFunc); - ``` +``` - ## wifi.on('p2pConnectionChange')9+ +## wifi.on('p2pConnectionChange')9+ on(type: "p2pConnectionChange", callback: Callback<WifiP2pLinkedInfo>): void @@ -3215,9 +3234,9 @@ Registers the P2P connection state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pConnectionChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pConnectionChange**.| | callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Yes| Callback invoked to return the P2P connection state.| **Error codes** @@ -3225,7 +3244,7 @@ Registers the P2P connection state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| ## wifi.off('p2pConnectionChange')9+ @@ -3240,9 +3259,9 @@ Unregisters the P2P connection state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pConnectionChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pConnectionChange**.| | callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | No| Callback for the P2P connection state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| **Error codes** @@ -3250,12 +3269,12 @@ Unregisters the P2P connection state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; var recvP2pConnectionChangeFunc = result => { console.info("Receive p2p connection change event: " + result); @@ -3266,7 +3285,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco // Unregister an event. wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc); - ``` +``` ## wifi.on('p2pDeviceChange')9+ @@ -3280,9 +3299,9 @@ Registers the P2P device state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pDeviceChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pDeviceChange**.| | callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | Yes| Callback invoked to return the P2P device state.| **Error codes** @@ -3290,7 +3309,7 @@ Registers the P2P device state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| ## wifi.off('p2pDeviceChange')9+ @@ -3305,9 +3324,9 @@ Unregisters the P2P device state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pDeviceChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pDeviceChange**.| | callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | No| Callback for the P2P device state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| **Error codes** @@ -3315,12 +3334,12 @@ Unregisters the P2P device state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; var recvP2pDeviceChangeFunc = result => { console.info("Receive recv p2p device change event: " + result); @@ -3331,7 +3350,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco // Unregister an event. wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc); - ``` +``` ## wifi.on('p2pPeerDeviceChange')9+ @@ -3345,9 +3364,9 @@ Registers the P2P peer device state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.| | callback | Callback<[WifiP2pDevice[]](#wifip2pdevice9)> | Yes| Callback invoked to return the P2P peer device state.| **Error codes** @@ -3355,7 +3374,7 @@ Registers the P2P peer device state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| ## wifi.off('p2pPeerDeviceChange')9+ @@ -3370,9 +3389,9 @@ Unregisters the P2P peer device state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.| | callback | Callback<[WifiP2pDevice[]](#wifip2pdevice9)> | No| Callback for the P2P peer device state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| **Error codes** @@ -3380,12 +3399,12 @@ Unregisters the P2P peer device state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; var recvP2pPeerDeviceChangeFunc = result => { console.info("Receive recv p2p peer device change event: " + result); @@ -3396,7 +3415,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco // Unregister an event. wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); - ``` +``` ## wifi.on('p2pPersistentGroupChange')9+ @@ -3410,9 +3429,9 @@ Registers the P2P persistent group state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.| | callback | Callback<void> | Yes| Callback invoked to return the P2P persistent group state.| **Error codes** @@ -3420,7 +3439,7 @@ Registers the P2P persistent group state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| ## wifi.off('p2pPersistentGroupChange')9+ @@ -3435,9 +3454,9 @@ Unregisters the P2P persistent group state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.| | callback | Callback<void> | No| Callback for the P2P persistent group state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| **Error codes** @@ -3445,12 +3464,12 @@ Unregisters the P2P persistent group state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; var recvP2pPersistentGroupChangeFunc = result => { console.info("Receive recv p2p persistent group change event: " + result); @@ -3461,7 +3480,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco // Unregister an event. wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); - ``` +``` ## wifi.on('p2pDiscoveryChange')9+ @@ -3475,10 +3494,10 @@ Registers the P2P device discovery state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pDiscoveryChange**.| -| callback | Callback<number> | Yes| Callback invoked to return the P2P device discovery state.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.| + | callback | Callback<number> | Yes| Callback invoked to return the P2P device discovery state.| **P2P discovered device states** @@ -3492,7 +3511,7 @@ Registers the P2P device discovery state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| ## wifi.off('p2pDiscoveryChange')9+ @@ -3507,9 +3526,9 @@ Unregisters the P2P device discovery state change events. **Parameters** -| **Name**| **Type**| **Mandatory**| **Description**| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type. The value is **p2pDiscoveryChange**.| + | **Name**| **Type**| **Mandatory**| **Description**| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.| | callback | Callback<number> | No| Callback for the P2P device discovery state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| **Error codes** @@ -3517,12 +3536,12 @@ Unregisters the P2P device discovery state change events. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). | **ID**| **Error Message**| -| -------- | -------- | + | -------- | -------- | | 2801000 | Operation failed.| **Example** - ```js - import wifi from '@ohos.wifiManager'; +```js + import wifiManager from '@ohos.wifiManager'; var recvP2pDiscoveryChangeFunc = result => { console.info("Receive recv p2p discovery change event: " + result); @@ -3533,4 +3552,4 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco // Unregister an event. wifiManager.off("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc); - ``` +``` diff --git a/en/application-dev/reference/apis/js-apis-wifiManagerExt.md b/en/application-dev/reference/apis/js-apis-wifiManagerExt.md index 4d9f1c83dd5fb5739f63520ce52c132c514d0fa7..5dc2721915e3c220beea50f52c00991834dba27e 100644 --- a/en/application-dev/reference/apis/js-apis-wifiManagerExt.md +++ b/en/application-dev/reference/apis/js-apis-wifiManagerExt.md @@ -1,4 +1,4 @@ -# @ohos.wifiManagerExt (WLAN Extension Interface) +# @ohos.wifiManagerExt (WLAN Extension) This **wifiext** module provides WLAN extension interfaces for non-universal products. > **NOTE** @@ -27,8 +27,8 @@ Enables the WLAN hotspot. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). -| **Type**| **Description**| -| -------- | -------- | +| **ID**| **Error Message**| + | -------- | -------- | | 2701000 | Operation failed.| ## wifiext.disableHotspot9+ @@ -45,8 +45,8 @@ Disables the WLAN hotspot. For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). -| **Type**| **Description**| -| -------- | -------- | +| **ID**| **Error Message**| + | -------- | -------- | | 2701000 | Operation failed.| ## wifiext.getSupportedPowerMode9+ @@ -61,19 +61,19 @@ Obtains the supported power modes. This API uses a promise to return the result. **Return value** -| Type| Description| -| -------- | -------- | -| Promise<Array<[PowerMode](#powermode)>> | Promise used to return the power modes obtained.| + | Type| Description| + | -------- | -------- | + | Promise<Array<[PowerMode](#powermode)>> | Promise used to return the power modes obtained.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). -| **Type**| **Description**| -| -------- | -------- | +| **ID**| **Error Message**| + | -------- | -------- | | 2701000 | Operation failed.| -## PowerMode +## PowerMode9+ Enumerates the power modes. @@ -98,16 +98,16 @@ Obtains the supported power modes. This API uses an asynchronous callback to ret **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<Array<[PowerMode](#powermode)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power modes obtained. If **err** is not **0**, an error has occurred.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<Array<[PowerMode](#powermode)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power modes obtained. If **err** is not **0**, an error has occurred.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). -| **Type**| **Description**| -| -------- | -------- | +| **ID**| **Error Message**| + | -------- | -------- | | 2701000 | Operation failed.| ## wifiext.getPowerMode9+ @@ -122,16 +122,16 @@ Obtains the power mode. This API uses a promise to return the result. **Return value** -| Type| Description| -| -------- | -------- | -| Promise<[PowerMode](#powermode)> | Promise used to return the power modes obtained.| + | Type| Description| + | -------- | -------- | + | Promise<[PowerMode](#powermode)> | Promise used to return the power modes obtained.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). -| **Type**| **Description**| -| -------- | -------- | +| **ID**| **Error Message**| + | -------- | -------- | | 2701000 | Operation failed.| ## wifiext.getPowerMode9+ @@ -146,21 +146,21 @@ Obtains the power mode. This API uses an asynchronous callback to return the res **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<[PowerMode](#powermode)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power mode obtained. If **err** is not **0**, an error has occurred.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[PowerMode](#powermode)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power mode obtained. If **err** is not **0**, an error has occurred.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). -| **Type**| **Description**| -| -------- | -------- | +| **ID**| **Error Message**| + | -------- | -------- | | 2701000 | Operation failed.| ## wifiext.setPowerMode9+ -setPowerMode(model: PowerMode) : boolean; +setPowerMode(mode: PowerMode) : void; Sets the power mode. @@ -170,14 +170,14 @@ setPowerMode(model: PowerMode) : boolean; **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| model | [PowerMode](#powermode) | Yes| Power mode to set.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | model | [PowerMode](#powermode) | Yes| Power mode to set.| **Error codes** For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). -| **Type**| **Description**| -| -------- | -------- | +| **ID**| **Error Message**| + | -------- | -------- | | 2701000 | Operation failed.|