提交 7c791789 编写于 作者: 王江颖 提交者: Gitee

Merge branch 'OpenHarmony-3.2-Beta2' of gitee.com:openharmony/docs into OpenHarmony-3.2-Beta2

Signed-off-by: N王江颖 <wangjiangying@huawei.com>
...@@ -7,7 +7,7 @@ A relational database (RDB) store allows you to operate local data with or witho ...@@ -7,7 +7,7 @@ A relational database (RDB) store allows you to operate local data with or witho
## Available APIs ## Available APIs
For details about RDB APIs, see [Relational Database](../reference/apis/js-apis-data-rdb.md). Most of the RDB store APIs are asynchronous interfaces, which can use a callback or promise to return the result. This document uses the promise-based APIs as an example. For details about the APIs, see [Relational Database](../reference/apis/js-apis-data-rdb.md).
### Creating or Deleting an RDB Store ### Creating or Deleting an RDB Store
...@@ -17,10 +17,8 @@ The following table describes the APIs available for creating and deleting an RD ...@@ -17,10 +17,8 @@ The following table describes the APIs available for creating and deleting an RD
| API| Description| | API| Description|
| -------- | -------- | | -------- | -------- |
|getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback&lt;RdbStore&gt;): void| Obtains an RDB store. This API uses a callback to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>- **context**: context of the application or function.<br>- **config**: configuration of the RDB store.<br>- **version**: RDB version.<br>- **callback**: callback invoked to return the RDB store obtained.| |getRdbStore(context: Context, config: StoreConfig, version: number): Promise&lt;RdbStore&gt; | Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.<br>- **context**: context of the application or function.<br>- **config**: configuration of the RDB store.<br>- **version**: version of the RDB store.|
|getRdbStore(context: Context, config: StoreConfig, version: number): Promise&lt;RdbStore&gt; | Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>- **context**: context of the application or function.<br>- **config**: configuration of the RDB store.<br>- **version**: RDB version.| | deleteRdbStore(context: Context, name: string): Promise&lt;void&gt; | Deletes an RDB store. This API uses a promise to return the result.<br>- **context**: context of the application or function.<br>- **name**: name of the RDB store to delete.|
|deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt; ): void | Deletes an RDB store. This API uses a callback to return the result. <br>- **context**: context of the application or function.<br>- **name**: RDB store to delete.<br>- **callback**: callback invoked to return the result.|
| deleteRdbStore(context: Context, name: string): Promise&lt;void&gt; | Deletes an RDB store. This API uses a promise to return the result.<br>- **context**: context of the application or function.<br>- **name**: RDB store to delete.|
### Managing Data in an RDB Store ### Managing Data in an RDB Store
...@@ -30,34 +28,31 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th ...@@ -30,34 +28,31 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
The RDB provides APIs for inserting data through a **ValuesBucket** in a data table. If the data is inserted, the row ID of the data inserted will be returned; otherwise, **-1** will be returned. The RDB provides APIs for inserting data through a **ValuesBucket** in a data table. If the data is inserted, the row ID of the data inserted will be returned; otherwise, **-1** will be returned.
**Table 2** APIs for inserting data **Table 2** API for inserting data
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | insert(table: string, values: ValuesBucket, callback: AsyncCallback&lt;number&gt;):void | Inserts a row of data into a table. This API uses a callback to return the result.<br>- **table**: name of the target table.<br>- **values**: data to be inserted into the table.<br>- **callback**: callback invoked to return the result. If the operation is successful, the row ID will be returned; otherwise, **-1** will be returned.| | RdbStore | insert(table:string,values:ValuesBucket):Promise&lt;number&gt; | Inserts a row of data into a table. This API uses a promise to return the result.<br>If the operation is successful, the row ID will be returned; otherwise, **-1** will be returned.<br>- **table**: name of the target table.<br>- **values**: data to be inserted into the table.|
| RdbStore | insert(table: string, values: ValuesBucket): Promise&lt;number&gt; | Inserts a row of data into a table. This API uses a promise to return the result.<br>- **table**: name of the target table.<br>- **values**: data to be inserted into the table.|
- **Updating data** - **Updating data**
Call the **update()** method to pass new data and specify the update conditions by using **RdbPredicates**. If the data is updated, the number of rows of the updated data will be returned; otherwise, **0** will be returned. Call the **update()** method to pass new data and specify the update conditions by using **RdbPredicates**. If the data is updated, the number of rows of the updated data will be returned; otherwise, **0** will be returned.
**Table 3** APIs for updating data **Table 3** API for updating data
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void | Updates data in the RDB store based on the specified **RdbPredicates** object. This API uses a callback to return the result.<br>- **values**: data to update, which is stored in a **ValuesBucket**.<br>- **predicates**: conditions for updating data.<br>- **callback**: callback invoked to return the number of rows updated.| | RdbStore | update(values:ValuesBucket,predicates:RdbPredicates):Promise&lt;number&gt; | Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the result.<br>Return value: number of rows updated.<br>- **values**: data to update, which is stored in **ValuesBucket**.<br>- **predicates**: conditions for updating data. |
| RdbStore | update(values: ValuesBucket, predicates: RdbPredicates): Promise&lt;number&gt; | Updates data in the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result.<br>- **values**: data to update, which is stored in a **ValuesBucket**.<br>- **predicates**: conditions for updating data.|
- **Deleting data** - **Deleting data**
Call the **delete()** method to delete data meeting the conditions specified by **RdbPredicates**. If the data is deleted, the number of rows of the deleted data will be returned; otherwise, **0** will be returned. Call the **delete()** method to delete data meeting the conditions specified by **RdbPredicates**. If the data is deleted, the number of rows of the deleted data will be returned; otherwise, **0** will be returned.
**Table 4** APIs for deleting data **Table 4** API for deleting data
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | delete(predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void | Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.<br>- **predicates**: conditions for deleting data.<br>- **callback**: callback invoked to return the number of rows updated.| | RdbStore | delete(predicates:RdbPredicates):Promise&lt;number&gt; | Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result.<br>Return value: number of rows updated.<br>- **predicates**: conditions for deleting data. |
| RdbStore | delete(predicates: RdbPredicates): Promise&lt;number&gt; | Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result.<br>- **predicates**: conditions for deleting data.|
- **Querying data** - **Querying data**
...@@ -70,53 +65,31 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th ...@@ -70,53 +65,31 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | query(predicates: RdbPredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;): void | Queries data in the RDB store based on the specified **RdbPredicates** object. This API uses a callback to return the result.<br>- **predicates**: conditions for querying data.<br>- **columns**: columns to query. If this parameter is not specified, the query applies to all columns.<br>- **callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | RdbStore | query(predicates:RdbPredicates,columns?:Array&lt;string&gt;):Promise&lt;ResultSet&gt; | Queries data from the RDB store based on specified conditions. This API uses a promise to return the result.<br>- **predicates**: conditions for querying data.<br>- **columns**: columns to query. If this parameter is not specified, the query applies to all columns.|
| RdbStore | query(predicates: RdbPredicates, columns?: Array&lt;string&gt;): Promise&lt;ResultSet&gt; | Queries data in the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result.<br>- **predicates**: conditions for querying data.<br>- **columns**: columns to query. If this parameter is not specified, the query applies to all columns.| | RdbStore | querySql(sql:string,bindArgs?:Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt; | Queries data using the specified SQL statement. This API uses a promise to return the result.<br>- **sql**: SQL statement.<br>- **bindArgs**: arguments in the SQL statement.|
| RdbStore | querySql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void | Queries data in the RDB store using the specified SQL statement. This API uses a callback to return the result.<br>- **sql**: SQL statement.<br>- **bindArgs**: arguments in the SQL statement.<br>- **callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| RdbStore | querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt; | Queries data in the RDB store using the specified SQL statement. This API uses a promise to return the result.<br>- **sql**: SQL statement.<br>- **bindArgs**: arguments in the SQL statement.|
### Using Predicates ### Using Predicates
The RDB provides **RdbPredicates** for you to set database operation conditions. The RDB provides **RdbPredicates** for you to set database operation conditions.
The following lists common predicates. For more information about predicates, see [**RdbPredicates**](../reference/apis/js-apis-data-rdb.md#rdbpredicates).
**Table 6** APIs for using RDB store predicates **Table 6** APIs for using RDB store predicates
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbPredicates |inDevices(devices: Array\<string>): RdbPredicates | Specifies remote devices on the network with RDB stores to be synchronized.<br>- **devices**: IDs of the remote devices on the network.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | equalTo(field:string,value:ValueType):RdbPredicates | Sets an **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value to match the **RdbPredicates**.<br>- **RdbPredicates**: **RdbPredicates** object that matches the specified field.|
| RdbPredicates |inAllDevices(): RdbPredicates | Connects to all remote devices on the network with RDB stores to be synchronized.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | notEqualTo(field:string,value:ValueType):RdbPredicates | Sets an **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value to match the **RdbPredicates**.<br>- **RdbPredicates**: **RdbPredicates** object that matches the specified field.|
| RdbPredicates | equalTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | or():RdbPredicates | Adds the OR condition to the **RdbPredicates**.<br>- **RdbPredicates**: **RdbPredicates** with the OR condition.|
| RdbPredicates | notEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | and():RdbPredicates | Adds the AND condition to the **RdbPredicates**.<br>- **RdbPredicates**: **RdbPredicates** with the AND condition.|
| RdbPredicates | beginWrap(): RdbPredicates | Adds a left parenthesis to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with a left parenthesis.| | RdbPredicates | contains(field:string,value:string):RdbPredicates | Sets an **RdbPredicates** to match a string containing the specified value.<br>- **field**: column name in the database table.<br>- **value**: value to match the **RdbPredicates**.<br>- **RdbPredicates**: **RdbPredicates** object that matches the specified field.|
| RdbPredicates | endWrap(): RdbPredicates | Adds a right parenthesis to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with a right parenthesis.|
| RdbPredicates | or(): RdbPredicates | Adds the OR condition to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with the OR condition.|
| RdbPredicates | and(): RdbPredicates | Adds the AND condition to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with the AND condition.|
| RdbPredicates | contains(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string containing the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string.|
| RdbPredicates | beginsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that starts with the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | endsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that ends with the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | isNull(field: string): RdbPredicates | Sets the **RdbPredicates** to match the field whose value is null.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | isNotNull(field: string): RdbPredicates | Sets the **RdbPredicates** to match the field whose value is not null.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | like(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that is similar to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | glob(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match the specified string.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | between(field: string, low: ValueType, high: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value within the specified range.<br>- **field**: column name in the database table.<br>- **low**: minimum value that matches the **RdbPredicates**.<br>- **high**: maximum value that matches the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range.<br>- **field**: column name in the database table.<br>- **low**: minimum value that matches the **RdbPredicates**.<br>- **high**: maximum value that matches the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | greaterThan(field: string, value: ValueType): RdbPredicatesgr | Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | lessThan(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | orderByAsc(field: string): RdbPredicates | Sets the **RdbPredicates** to match the column with values sorted in ascending order.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | orderByDesc(field: string): RdbPredicates | Sets the **RdbPredicates** to match the column with values sorted in descending order.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | distinct(): RdbPredicates | Sets the **RdbPredicates** to filter out duplicate records.<br>- **RdbPredicates**: returns a **RdbPredicates** object that can filter out duplicate records.|
| RdbPredicates | limitAs(value: number): RdbPredicates | Sets the **RdbPredicates** to specify the maximum number of records.<br>- **value**: maximum number of records.<br>- **RdbPredicates**: returns a **RdbPredicates** object that can be used to set the maximum number of records.|
| RdbPredicates | offsetAs(rowOffset: number): RdbPredicates | Sets the **RdbPredicates** to specify the start position of the returned result.<br>- **rowOffset**: start position of the returned result. The value is a positive integer.<br>- **RdbPredicates**: returns a **RdbPredicates** object that specifies the start position of the returned result.|
| RdbPredicates | groupBy(fields: Array&lt;string&gt;): RdbPredicates | Sets the **RdbPredicates** to group rows that have the same value into summary rows.<br>- **fields**: names of the columns grouped for querying data.<br>- **RdbPredicates**: returns a **RdbPredicates** object that groups rows with the same value.|
| RdbPredicates | indexedBy(indexName: string): RdbPredicates | Sets the **RdbPredicates** to specify the index column.<br>- **indexName**: name of the index column.<br>- **RdbPredicates**: returns a **RdbPredicates** object that specifies the index column.|
| RdbPredicates | in(field: string, value: Array&lt;ValueType&gt;): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.<br>- **field**: column name in the database table.<br>- **value**: array of **ValueType** to match.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.<br>- **field**: column name in the database table.<br>- **value**: array of **ValueType** to match.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
### Using the Result Set ### Using the Result Set
A result set can be regarded as a row of data in the queried results. It allows you to traverse and access the data you have queried. The following table describes the external APIs of **ResultSet**. A result set can be regarded as a row of data in the queried results. It allows you to traverse and access the data you have queried.
For details about how to use result set APIs, see [Result Set](../reference/apis/js-apis-data-resultset.md).
> **NOTICE**<br> > **NOTICE**<br>
> After a result set is used, you must call the **close()** method to close it explicitly. > After a result set is used, you must call the **close()** method to close it explicitly.
...@@ -125,19 +98,12 @@ A result set can be regarded as a row of data in the queried results. It allows ...@@ -125,19 +98,12 @@ A result set can be regarded as a row of data in the queried results. It allows
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ResultSet | goTo(offset:number): boolean | Moves the result set forwards or backwards by the specified offset relative to its current position.| | ResultSet | goToFirstRow():boolean | Moves to the first row of the result set.|
| ResultSet | goToRow(position: number): boolean | Moves the result set to the specified row.| | ResultSet | getString(columnIndex:number):string | Obtains the value in the form of a string based on the specified column and current row.|
| ResultSet | goToNextRow(): boolean | Moves the result set to the next row.| | ResultSet | getBlob(columnIndex:number):Uint8Array | Obtains the value in the form of a byte array based on the specified column and the current row.|
| ResultSet | goToPreviousRow(): boolean | Moves the result set to the previous row.| | ResultSet | getDouble(columnIndex:number):number | Obtains the value in the form of double based on the specified column and current row.|
| ResultSet | getColumnIndex(columnName: string): number | Obtains the column index based on the specified column name.| | ResultSet | getLong(columnIndex:number):number | Obtains the value in the form of a long integer based on the specified column and current row.|
| ResultSet | getColumnName(columnIndex: number): string | Obtains the column name based on the specified column index.| | ResultSet | close():void | Closes the result set.|
| ResultSet | goToFirstRow(): boolean | Moves to the first row of the result set.|
| ResultSet | goToLastRow(): boolean | Moves to the last row of the result set.|
| ResultSet | getString(columnIndex: number): string | Obtains the value in the specified column of the current row, in a string.|
| ResultSet | getBlob(columnIndex: number): Uint8Array | Obtains the values in the specified column of the current row, in a byte array.|
| ResultSet | getDouble(columnIndex: number): number | Obtains the values in the specified column of the current row, in double.|
| ResultSet | isColumnNull(columnIndex: number): boolean | Checks whether the value in the specified column of the current row is null.|
| ResultSet | close(): void | Closes the result set.|
...@@ -147,32 +113,29 @@ A result set can be regarded as a row of data in the queried results. It allows ...@@ -147,32 +113,29 @@ A result set can be regarded as a row of data in the queried results. It allows
**Setting Distributed Tables** **Setting Distributed Tables**
**Table 8** APIs for setting distributed tables **Table 8** API for setting distributed tables
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | setDistributedTables(tables: Array\<string>, callback: AsyncCallback\<void>): void | Sets a list of distributed tables. This API uses a callback to return the result.<br>- **tables**: names of the distributed tables to set.<br>- **callback**: callback invoked to return the result.| | RdbStore | setDistributedTables(tables: Array\<string>): Promise\<void> | Sets distributed tables. This API uses a promise to return the result.<br>- **tables**: names of the distributed tables to set.|
| RdbStore | setDistributedTables(tables: Array\<string>): Promise\<void> | Sets a list of distributed tables. This API uses a promise to return the result.<br>- **tables**: names of the distributed tables to set.|
**Obtaining the Distributed Table Name for a Remote Device** **Obtaining the Distributed Table Name for a Remote Device**
You can obtain the distributed table name for a remote device based on the local table name. The distributed table name can be used to query the RDB store of the remote device. You can obtain the distributed table name for a remote device based on the local table name. The distributed table name can be used to query the RDB store of the remote device.
**Table 9** APIs for obtaining the distributed table name of a remote device **Table 9** API for obtaining the distributed table name of a remote device
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | obtainDistributedTableName(device: string, table: string, callback: AsyncCallback\<string>): void | Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the database of a remote device is queried. This API uses an asynchronous callback to return the result.<br>- **device**: remote device.<br>- **table**: local table name.<br>- **callback**: callback used to return the result. If the operation is successful, the distributed table name of the remote device will be returned. | | RdbStore | obtainDistributedTableName(device: string, table: string): Promise\<string> | Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the RDB store of a remote device is queried. This API uses a promise to return the result.<br>- **device**: remote device.<br>- **table**: local table name.|
| RdbStore | obtainDistributedTableName(device: string, table: string): Promise\<string> | Obtains the distributed table name for a remote device based on the local table name. The distributed table name is used to query the RDB store of the remote device. This API uses a promise to return the result.<br>- **device**: remote device.<br>- **table**: local table name.|
**Synchronizing Data Between Devices** **Synchronizing Data Between Devices**
**Table 10** APIs for synchronizing data between devices **Table 10** API for synchronizing data between devices
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback\<Array\<[string, number]>>): void | Synchronizes data between devices. This API uses a callback to return the result.<br>- **mode**: data synchronization mode. **SYNC_MODE_PUSH** means to push data from the local device to a remote device. **SYNC_MODE_PULL** means to pull data from a remote device to the local device.<br>- **predicates**: data and devices to be synchronized.<br>- **callback**: callback invoked to return the result. In the result, **string** indicates the device ID, and **number** indicates the synchronization status of each device. The value **0** indicates a success, and other values indicate a failure.| | RdbStore | sync(mode: SyncMode, predicates: RdbPredicates): Promise\<Array\<[string, number]>> | Synchronizes data between devices. This API uses a promise to return the result.<br>- **mode**: synchronization mode. **SYNC_MODE_PUSH** means to push data from the local device to a remote device. **SYNC_MODE_PULL** means to pull data from a remote device to the local device.<br>- **predicates**: specifies the data and devices to synchronize.<br>- **string**: device ID. <br>- **number**: synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
| RdbStore | sync(mode: SyncMode, predicates: RdbPredicates): Promise\<Array\<[string, number]>> | Synchronizes data between devices. This API uses a promise to return the result.<br>- **mode**: data synchronization mode. **SYNC_MODE_PUSH** means to push data from the local device to a remote device. **SYNC_MODE_PULL** means to pull data from a remote device to the local device.<br>- **predicates**: data and devices to be synchronized. |
**Registering an RDB Store Observer** **Registering an RDB Store Observer**
...@@ -188,27 +151,25 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -188,27 +151,25 @@ You can obtain the distributed table name for a remote device based on the local
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore |off(event:'dataChange', type: SubscribeType, observer: Callback\<Array\<string>>): void;| Unregisters the observer of the specified type for the RDB store. This API uses a callback to return the result.<br>- **type**: subscription type. **SUBSCRIBE_TYPE_REMOTE** means to subscribe to remote data changes.<br>- **observer**: observer to unregister.| | RdbStore |off(event:'dataChange', type: SubscribeType, observer: Callback\<Array\<string>>): void;| Unregisters the observer of the specified type for the RDB store. This method uses a callback to return the result.<br>- **type**: subscription type. **SUBSCRIBE_TYPE_REMOTE** means to subscribe to remote data changes.<br>- **observer**: observer to unregister.|
### Backing Up and Restoring an RDB Store ### Backing Up and Restoring an RDB Store
**Backing Up an RDB Store** **Backing Up an RDB Store**
**Table 13** APIs for backing up an RDB store **Table 13** API for backing up an RDB store
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore |backup(destName:string, callback: AsyncCallback&lt;void&gt;):void| Backs up an RDB store. This API uses an asynchronous callback to return the result.<br>- **destName**: name of the RDB backup file.<br>- **callback**: callback invoked to return the result.|
| RdbStore |backup(destName:string): Promise&lt;void&gt;| Backs up an RDB store. This API uses a promise to return the result.<br>- **destName**: name of the RDB backup file.| | RdbStore |backup(destName:string): Promise&lt;void&gt;| Backs up an RDB store. This API uses a promise to return the result.<br>- **destName**: name of the RDB backup file.|
**Restoring an RDB Store** **Restoring an RDB Store**
**Table 14** APIs for restoring an RDB store **Table 14** API for restoring an RDB store
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore |restore(srcName:string, callback: AsyncCallback&lt;void&gt;):void| Restores an RDB store using a backup file. This API uses an asynchronous callback to return the result.<br>- **srcName**: name of the RDB backup file.<br>- **callback**: callback invoked to return the result.| | RdbStore |restore(srcName:string): Promise&lt;void&gt;| Restores an RDB store from a backup file. This API uses a promise to return the result.<br>- **srcName**: name of the backup file used to restore the RDB store.|
| RdbStore |restore(srcName:string): Promise&lt;void&gt;| Restores an RDB store using a backup file. This API uses a promise to return the result.<br>- **srcName**: name of the RDB backup file.|
**Transaction** **Transaction**
...@@ -236,7 +197,7 @@ Table 15 Transaction APIs ...@@ -236,7 +197,7 @@ Table 15 Transaction APIs
import data_rdb from '@ohos.data.rdb' import data_rdb from '@ohos.data.rdb'
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = {name: "rdbstore.db",} const STORE_CONFIG = {name: "rdbstore.db"}
data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) { data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) {
rdbStore.executeSql(CREATE_TABLE_TEST) rdbStore.executeSql(CREATE_TABLE_TEST)
console.info('create table done.') console.info('create table done.')
...@@ -253,7 +214,7 @@ Table 15 Transaction APIs ...@@ -253,7 +214,7 @@ Table 15 Transaction APIs
```js ```js
var u8 = new Uint8Array([1, 2, 3]) var u8 = new Uint8Array([1, 2, 3])
const valueBucket = {"name": "Tom", "age": 18, "salary": 100.5, "blobType": u8,} const valueBucket = {"name": "Tom", "age": 18, "salary": 100.5, "blobType": u8}
let insertPromise = rdbStore.insert("test", valueBucket) let insertPromise = rdbStore.insert("test", valueBucket)
``` ```
...@@ -396,4 +357,3 @@ Table 15 Transaction APIs ...@@ -396,4 +357,3 @@ Table 15 Transaction APIs
console.info('Restore failed, err: ' + err) console.info('Restore failed, err: ' + err)
}) })
``` ```
# Standard NFC Card Emulation # Standard NFC Card Emulation
The cardEmulation module implements Near-Field Communication (NFC) card emulation. The **cardEmulation** module implements Near-Field Communication (NFC) card emulation.
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -19,7 +19,7 @@ isSupported(feature: number): boolean ...@@ -19,7 +19,7 @@ isSupported(feature: number): boolean
Checks whether a certain type of card emulation is supported. Checks whether a certain type of card emulation is supported.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -27,11 +27,11 @@ Checks whether a certain type of card emulation is supported. ...@@ -27,11 +27,11 @@ Checks whether a certain type of card emulation is supported.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the card emulation is supported; returns **false** otherwise.| | boolean | Returns **true** if the card emulation is supported; returns **false** otherwise.|
## HceService ## HceService<sup>8+</sup>
Implements Host-based Card Emulation (HCE). Before calling any API in **HceService**, you must use **new cardEmulation.HceService()** to create an **HceService** instance. Implements Host-based Card Emulation (HCE). Before calling any API in **HceService**, you must use **new cardEmulation.HceService()** to create an **HceService** instance.
### startHCE ### startHCE<sup>8+</sup>
startHCE(aidList: string[]): boolean startHCE(aidList: string[]): boolean
...@@ -39,7 +39,7 @@ Starts HCE. ...@@ -39,7 +39,7 @@ Starts HCE.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameters** **Parameters**
...@@ -47,7 +47,7 @@ Starts HCE. ...@@ -47,7 +47,7 @@ Starts HCE.
| ------- | -------- | ---- | ----------------------- | | ------- | -------- | ---- | ----------------------- |
| aidList | string[] | Yes | Application ID (AID) list to be registered for card emulation.| | aidList | string[] | Yes | Application ID (AID) list to be registered for card emulation.|
### stopHCE ### stopHCE<sup>8+</sup>
stopHCE(): boolean stopHCE(): boolean
...@@ -55,9 +55,9 @@ Stops HCE. ...@@ -55,9 +55,9 @@ Stops HCE.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
### on ### on<sup>8+</sup>
on(type: "hceCmd", callback: AsyncCallback<number[]>): void; on(type: "hceCmd", callback: AsyncCallback<number[]>): void;
...@@ -65,7 +65,7 @@ Subscribes to messages from the peer device after **startHCE()**. ...@@ -65,7 +65,7 @@ Subscribes to messages from the peer device after **startHCE()**.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameters** **Parameters**
...@@ -74,7 +74,7 @@ Subscribes to messages from the peer device after **startHCE()**. ...@@ -74,7 +74,7 @@ Subscribes to messages from the peer device after **startHCE()**.
| type | string | Yes | Event type to subscribe to. The value is **hceCmd**. | | type | string | Yes | Event type to subscribe to. The value is **hceCmd**. |
| callback | AsyncCallback<number[]> | Yes | Callback invoked to return the subscribed event. The input parameter is a data array that complies with the Application Protocol Data Unit (APDU).| | callback | AsyncCallback<number[]> | Yes | Callback invoked to return the subscribed event. The input parameter is a data array that complies with the Application Protocol Data Unit (APDU).|
### sendResponse ### sendResponse<sup>8+</sup>
sendResponse(responseApdu: number[]): void; sendResponse(responseApdu: number[]): void;
...@@ -82,7 +82,7 @@ Sends a response to the peer device. ...@@ -82,7 +82,7 @@ Sends a response to the peer device.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameters** **Parameters**
......
# CommonEvent # CommonEvent
> **NOTE** The **CommonEvent** module provides common event capabilities, including the capabilities to publish, subscribe to, and unsubscribe from common events, as well obtaining and setting the common event result code and result data.
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Required Permissions > **NOTE**<br>
>
| Common Event Macro | Common Event Name | Subscriber Permissions | > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
| ------------ | ------------------ | ---------------------- |
| COMMON_EVENT_BOOT_COMPLETED | usual.event.BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED |
| COMMON_EVENT_LOCKED_BOOT_COMPLETED | usual.event.LOCKED_BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED |
| COMMON_EVENT_SHUTDOWN | usual.event.SHUTDOWN | - |
| COMMON_EVENT_BATTERY_CHANGED | usual.event.BATTERY_CHANGED | - |
| COMMON_EVENT_BATTERY_LOW | usual.event.BATTERY_LOW | - |
| COMMON_EVENT_BATTERY_OKAY | usual.event.BATTERY_OKAY | - |
| COMMON_EVENT_POWER_CONNECTED | usual.event.POWER_CONNECTED | - |
| COMMON_EVENT_POWER_DISCONNECTED | usual.event.POWER_DISCONNECTED | - |
| COMMON_EVENT_SCREEN_OFF | usual.event.SCREEN_OFF | - |
| COMMON_EVENT_SCREEN_ON | usual.event.SCREEN_ON | - |
| COMMON_EVENT_THERMAL_LEVEL_CHANGED | usual.event.THERMAL_LEVEL_CHANGED | - |
| COMMON_EVENT_USER_PRESENT | usual.event.USER_PRESENT | - |
| COMMON_EVENT_TIME_TICK | usual.event.TIME_TICK | - |
| COMMON_EVENT_TIME_CHANGED | usual.event.TIME_CHANGED | - |
| COMMON_EVENT_DATE_CHANGED | usual.event.DATE_CHANGED | - |
| COMMON_EVENT_TIMEZONE_CHANGED | usual.event.TIMEZONE_CHANGED | - |
| COMMON_EVENT_CLOSE_SYSTEM_DIALOGS | usual.event.CLOSE_SYSTEM_DIALOGS | - |
| COMMON_EVENT_PACKAGE_ADDED | usual.event.PACKAGE_ADDED | - |
| COMMON_EVENT_PACKAGE_REPLACED | usual.event.PACKAGE_REPLACED | - |
| COMMON_EVENT_MY_PACKAGE_REPLACED | usual.event.MY_PACKAGE_REPLACED | - |
| COMMON_EVENT_PACKAGE_REMOVED | usual.event.PACKAGE_REMOVED | - |
| COMMON_EVENT_BUNDLE_REMOVED | usual.event.BUNDLE_REMOVED | - |
| COMMON_EVENT_PACKAGE_FULLY_REMOVED | usual.event.PACKAGE_FULLY_REMOVED | - |
| COMMON_EVENT_PACKAGE_CHANGED | usual.event.PACKAGE_CHANGED | - |
| COMMON_EVENT_PACKAGE_RESTARTED | usual.event.PACKAGE_RESTARTED | - |
| COMMON_EVENT_PACKAGE_DATA_CLEARED | usual.event.PACKAGE_DATA_CLEARED | - |
| COMMON_EVENT_PACKAGES_SUSPENDED | usual.event.PACKAGES_SUSPENDED | - |
| COMMON_EVENT_PACKAGES_UNSUSPENDED | usual.event.PACKAGES_UNSUSPENDED | - |
| COMMON_EVENT_MY_PACKAGE_SUSPENDED | usual.event.MY_PACKAGE_SUSPENDED | - |
| COMMON_EVENT_MY_PACKAGE_UNSUSPENDED | usual.event.MY_PACKAGE_UNSUSPENDED | - |
| COMMON_EVENT_UID_REMOVED | usual.event.UID_REMOVED | - |
| COMMON_EVENT_PACKAGE_FIRST_LAUNCH | usual.event.PACKAGE_FIRST_LAUNCH | - |
| COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION | usual.event.PACKAGE_NEEDS_VERIFICATION | - |
| COMMON_EVENT_PACKAGE_VERIFIED | usual.event.PACKAGE_VERIFIED | - |
| COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE | usual.event.EXTERNAL_APPLICATIONS_AVAILABLE | - |
| COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE | usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE | - |
| COMMON_EVENT_CONFIGURATION_CHANGED | usual.event.CONFIGURATION_CHANGED | - |
| COMMON_EVENT_LOCALE_CHANGED | usual.event.LOCALE_CHANGED | - |
| COMMON_EVENT_MANAGE_PACKAGE_STORAGE | usual.event.MANAGE_PACKAGE_STORAGE | - |
| COMMON_EVENT_DRIVE_MODE | common.event.DRIVE_MODE | - |
| COMMON_EVENT_HOME_MODE | common.event.HOME_MODE | - |
| COMMON_EVENT_OFFICE_MODE | common.event.OFFICE_MODE | - |
| COMMON_EVENT_USER_STARTED | usual.event.USER_STARTED | - |
| COMMON_EVENT_USER_BACKGROUND | usual.event.USER_BACKGROUND | - |
| COMMON_EVENT_USER_FOREGROUND | usual.event.USER_FOREGROUND | - |
| COMMON_EVENT_USER_SWITCHED | usual.event.USER_SWITCHED | ohos.permission.MANAGE_USERS |
| COMMON_EVENT_USER_STARTING | usual.event.USER_STARTING | ohos.permission.INTERACT_ACROSS_USERS |
| COMMON_EVENT_USER_UNLOCKED | usual.event.USER_UNLOCKED | - |
| COMMON_EVENT_USER_STOPPING | usual.event.USER_STOPPING | ohos.permission.INTERACT_ACROSS_USERS |
| COMMON_EVENT_USER_STOPPED | usual.event.USER_STOPPED | - |
| COMMON_EVENT_HWID_LOGIN | common.event.HWID_LOGIN | - |
| COMMON_EVENT_HWID_LOGOUT | common.event.HWID_LOGOUT | - |
| COMMON_EVENT_HWID_TOKEN_INVALID | common.event.HWID_TOKEN_INVALID | - |
| COMMON_EVENT_HWID_LOGOFF | common.event.HWID_LOGOFF | - |
| COMMON_EVENT_WIFI_POWER_STATE | usual.event.wifi.POWER_STATE | - |
| COMMON_EVENT_WIFI_SCAN_FINISHED | usual.event.wifi.SCAN_FINISHED | ohos.permission.LOCATION |
| COMMON_EVENT_WIFI_RSSI_VALUE | usual.event.wifi.RSSI_VALUE | ohos.permission.GET_WIFI_INFO |
| COMMON_EVENT_WIFI_CONN_STATE | usual.event.wifi.CONN_STATE | - |
| COMMON_EVENT_WIFI_HOTSPOT_STATE | usual.event.wifi.HOTSPOT_STATE | - |
| COMMON_EVENT_WIFI_AP_STA_JOIN | usual.event.wifi.WIFI_HS_STA_JOIN | ohos.permission.GET_WIFI_INFO |
| COMMON_EVENT_WIFI_AP_STA_LEAVE | usual.event.wifi.WIFI_HS_STA_LEAVE | ohos.permission.GET_WIFI_INFO |
| COMMON_EVENT_WIFI_MPLINK_STATE_CHANGE | usual.event.wifi.mplink.STATE_CHANGE | ohos.permission.MPLINK_CHANGE_STATE |
| COMMON_EVENT_WIFI_P2P_CONN_STATE | usual.event.wifi.p2p.CONN_STATE_CHANGE | ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION |
| COMMON_EVENT_WIFI_P2P_STATE_CHANGED | usual.event.wifi.p2p.STATE_CHANGE | ohos.permission.GET_WIFI_INFO |
| COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED | usual.event.wifi.p2p.DEVICES_CHANGE | ohos.permission.GET_WIFI_INFO |
| COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED | usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE | ohos.permission.GET_WIFI_INFO |
| COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED | usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE | ohos.permission.GET_WIFI_INFO |
| COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED | usual.event.wifi.p2p.GROUP_STATE_CHANGED | ohos.permission.GET_WIFI_INFO |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfree.ag.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CURRENT_DEVICE_UPDATE | usual.event.bluetooth.handsfree.ag.CURRENT_DEVICE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfree.ag.AUDIO_STATE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CURRENT_DEVICE_UPDATE | usual.event.bluetooth.a2dpsource.CURRENT_DEVICE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_PLAYING_STATE_UPDATE | usual.event.bluetooth.a2dpsource.PLAYING_STATE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE | usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED | usual.event.bluetooth.remotedevice.DISCOVERED | ohos.permission.LOCATION and ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CLASS_VALUE_UPDATE | usual.event.bluetooth.remotedevice.CLASS_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_CONNECTED | usual.event.bluetooth.remotedevice.ACL_CONNECTED | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED | usual.event.bluetooth.remotedevice.ACL_DISCONNECTED | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE | usual.event.bluetooth.remotedevice.NAME_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE | usual.event.bluetooth.remotedevice.PAIR_STATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_BATTERY_VALUE_UPDATE | usual.event.bluetooth.remotedevice.BATTERY_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT | usual.event.bluetooth.remotedevice.SDP_RESULT | - |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_UUID_VALUE | usual.event.bluetooth.remotedevice.UUID_VALUE | ohos.permission.DISCOVER_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_REQ | usual.event.bluetooth.remotedevice.PAIRING_REQ | ohos.permission.DISCOVER_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL | usual.event.bluetooth.remotedevice.PAIRING_CANCEL | - |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ | usual.event.bluetooth.remotedevice.CONNECT_REQ | - |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY | usual.event.bluetooth.remotedevice.CONNECT_REPLY | - |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL | usual.event.bluetooth.remotedevice.CONNECT_CANCEL | - |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE | - |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE | - |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT | usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT | - |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE | - |
| COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE | usual.event.bluetooth.host.STATE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE | usual.event.bluetooth.host.REQ_DISCOVERABLE | - |
| COMMON_EVENT_BLUETOOTH_HOST_REQ_ENABLE | usual.event.bluetooth.host.REQ_ENABLE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISABLE | usual.event.bluetooth.host.REQ_DISABLE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_HOST_SCAN_MODE_UPDATE | usual.event.bluetooth.host.SCAN_MODE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_STARTED | usual.event.bluetooth.host.DISCOVERY_STARTED | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_FINISHED | usual.event.bluetooth.host.DISCOVERY_FINISHED | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_HOST_NAME_UPDATE | usual.event.bluetooth.host.NAME_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsink.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_PLAYING_STATE_UPDATE | usual.event.bluetooth.a2dpsink.PLAYING_STATE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_AUDIO_STATE_UPDATE | usual.event.bluetooth.a2dpsink.AUDIO_STATE_UPDATE | ohos.permission.USE_BLUETOOTH |
| COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED | usual.event.nfc.action.ADAPTER_STATE_CHANGED | - |
| COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED | usual.event.nfc.action.RF_FIELD_ON_DETECTED | ohos.permission.MANAGE_SECURE_SETTINGS |
| COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED | usual.event.nfc.action.RF_FIELD_OFF_DETECTED | ohos.permission.MANAGE_SECURE_SETTINGS |
| COMMON_EVENT_DISCHARGING | usual.event.DISCHARGING | - |
| COMMON_EVENT_CHARGING | usual.event.CHARGING | - |
| COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED | usual.event.DEVICE_IDLE_MODE_CHANGED | - |
| COMMON_EVENT_POWER_SAVE_MODE_CHANGED | usual.event.POWER_SAVE_MODE_CHANGED | - |
| COMMON_EVENT_USER_ADDED | usual.event.USER_ADDED | ohos.permission.MANAGE_USERS |
| COMMON_EVENT_USER_REMOVED | usual.event.USER_REMOVED | ohos.permission.MANAGE_USERS |
| COMMON_EVENT_ABILITY_ADDED | usual.event.ABILITY_ADDED | ohos.permission.LISTEN_BUNDLE_CHANGE |
| COMMON_EVENT_ABILITY_REMOVED | usual.event.ABILITY_REMOVED | ohos.permission.LISTEN_BUNDLE_CHANGE |
| COMMON_EVENT_ABILITY_UPDATED | usual.event.ABILITY_UPDATED | ohos.permission.LISTEN_BUNDLE_CHANGE |
| COMMON_EVENT_LOCATION_MODE_STATE_CHANGED | usual.event.location.MODE_STATE_CHANGED | - |
| COMMON_EVENT_IVI_SLEEP | common.event.IVI_SLEEP | - |
| COMMON_EVENT_IVI_PAUSE | common.event.IVI_PAUSE | - |
| COMMON_EVENT_IVI_STANDBY | common.event.IVI_STANDBY | - |
| COMMON_EVENT_IVI_LASTMODE_SAVE | common.event.IVI_LASTMODE_SAVE | - |
| COMMON_EVENT_IVI_VOLTAGE_ABNORMAL | common.event.IVI_VOLTAGE_ABNORMAL | - |
| COMMON_EVENT_IVI_HIGH_TEMPERATURE | common.event.IVI_HIGH_TEMPERATURE | - |
| COMMON_EVENT_IVI_EXTREME_TEMPERATURE | common.event.IVI_EXTREME_TEMPERATURE | - |
| COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL | common.event.IVI_TEMPERATURE_ABNORMAL | - |
| COMMON_EVENT_IVI_VOLTAGE_RECOVERY | common.event.IVI_VOLTAGE_RECOVERY | - |
| COMMON_EVENT_IVI_TEMPERATURE_RECOVERY | common.event.IVI_TEMPERATURE_RECOVERY | - |
| COMMON_EVENT_IVI_ACTIVE | common.event.IVI_ACTIVE | - |
| COMMON_EVENT_USB_DEVICE_ATTACHED | usual.event.hardware.usb.action.USB_DEVICE_ATTACHED | - |
| COMMON_EVENT_USB_DEVICE_DETACHED | usual.event.hardware.usb.action.USB_DEVICE_DETACHED | - |
| COMMON_EVENT_USB_ACCESSORY_ATTACHED | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED | - |
| COMMON_EVENT_USB_ACCESSORY_DETACHED | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED | - |
| COMMON_EVENT_DISK_REMOVED | usual.event.data.DISK_REMOVED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_DISK_UNMOUNTED | usual.event.data.DISK_UNMOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_DISK_MOUNTED | usual.event.data.DISK_MOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_DISK_BAD_REMOVAL | usual.event.data.DISK_BAD_REMOVAL | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_DISK_UNMOUNTABLE | usual.event.data.DISK_UNMOUNTABLE | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_DISK_EJECT | usual.event.data.DISK_EJECT | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_VOLUME_REMOVED | usual.event.data.VOLUME_REMOVED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_VOLUME_UNMOUNTED | usual.event.data.VOLUME_UNMOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_VOLUME_MOUNTED | usual.event.data.VOLUME_MOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_VOLUME_BAD_REMOVAL | usual.event.data.VOLUME_BAD_REMOVAL | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_VOLUME_EJECT | usual.event.data.VOLUME_EJECT | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED | usual.event.data.VISIBLE_ACCOUNTS_UPDATED | ohos.permission.GET_APP_ACCOUNTS |
| COMMON_EVENT_ACCOUNT_DELETED | usual.event.data.ACCOUNT_DELETED | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS |
| COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED |
| COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | - |
| COMMON_EVENT_SPLIT_SCREEN | usual.event.SPLIT_SCREEN | ohos.permission.RECEIVER_SPLIT_SCREEN |
## Modules to Import ## Modules to Import
...@@ -163,6 +12,168 @@ ...@@ -163,6 +12,168 @@
import CommonEvent from '@ohos.commonEvent'; import CommonEvent from '@ohos.commonEvent';
``` ```
## Support
Provides the event types supported by the **CommonEvent** module. The name and value indicate the macro and name of a common event, respectively.
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Value | Subscriber Permissions | Description |
| ------------ | ------------------ | ---------------------- | -------------------- |
| COMMON_EVENT_BOOT_COMPLETED | usual.event.BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the user has finished booting and the system has been loaded. |
| COMMON_EVENT_LOCKED_BOOT_COMPLETED | usual.event.LOCKED_BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the user has finished booting and the system has been loaded but the screen is still locked. |
| COMMON_EVENT_SHUTDOWN | usual.event.SHUTDOWN | - | Indicates the common event that the device is being shut down and the final shutdown will proceed. |
| COMMON_EVENT_BATTERY_CHANGED | usual.event.BATTERY_CHANGED | - | Indicates the common event that the charging state, level, and other information about the battery have changed. |
| COMMON_EVENT_BATTERY_LOW | usual.event.BATTERY_LOW | - | Indicates the common event that the battery level is low. |
| COMMON_EVENT_BATTERY_OKAY | usual.event.BATTERY_OKAY | - | Indicates the common event that the battery exits the low state. |
| COMMON_EVENT_POWER_CONNECTED | usual.event.POWER_CONNECTED | - | Indicates the common event that the device is connected to an external power supply. |
| COMMON_EVENT_POWER_DISCONNECTED | usual.event.POWER_DISCONNECTED | - | Indicates the common event that the device is disconnected from the external power supply. |
| COMMON_EVENT_SCREEN_OFF | usual.event.SCREEN_OFF | - | Indicates the common event that the device screen is off and the device is sleeping. |
| COMMON_EVENT_SCREEN_ON | usual.event.SCREEN_ON | - | Indicates the common event that the device screen is on and the device is in interactive state. |
| COMMON_EVENT_THERMAL_LEVEL_CHANGED<sup>8+<sup> | usual.event.THERMAL_LEVEL_CHANGED | - | Indicates the common event that the device's thermal level has changed. |
| COMMON_EVENT_USER_PRESENT | usual.event.USER_PRESENT | - | Indicates the common event that the user unlocks the device. |
| COMMON_EVENT_TIME_TICK | usual.event.TIME_TICK | - | Indicates the common event that the system time has changed. |
| COMMON_EVENT_TIME_CHANGED | usual.event.TIME_CHANGED | - | Indicates the common event that the system time is set. |
| COMMON_EVENT_DATE_CHANGED | usual.event.DATE_CHANGED | - | Indicates the common event that the system time has changed. |
| COMMON_EVENT_TIMEZONE_CHANGED | usual.event.TIMEZONE_CHANGED | - | Indicates the common event that the system time zone has changed. |
| COMMON_EVENT_CLOSE_SYSTEM_DIALOGS | usual.event.CLOSE_SYSTEM_DIALOGS | - | Indicates the common event that a user closes a temporary system dialog box. |
| COMMON_EVENT_PACKAGE_ADDED | usual.event.PACKAGE_ADDED | - | Indicates the common event that a new application package has been installed on the device. |
| COMMON_EVENT_PACKAGE_REPLACED | usual.event.PACKAGE_REPLACED | - | Indicates the common event that a later version of an installed application package has replaced the previous one on the device. |
| COMMON_EVENT_MY_PACKAGE_REPLACED | usual.event.MY_PACKAGE_REPLACED | - | Indicates the common event that a later version of your application package has replaced the previous one. |
| COMMON_EVENT_PACKAGE_REMOVED | usual.event.PACKAGE_REMOVED | - | Indicates the common event that an installed application has been uninstalled from the device with the application data retained. |
| COMMON_EVENT_BUNDLE_REMOVED | usual.event.BUNDLE_REMOVED | - | Indicates the common event that an installed bundle has been uninstalled from the device with the application data retained. |
| COMMON_EVENT_PACKAGE_FULLY_REMOVED | usual.event.PACKAGE_FULLY_REMOVED | - | Indicates the common event that an installed application, including both the application data and code, has been completely uninstalled from the device. |
| COMMON_EVENT_PACKAGE_CHANGED | usual.event.PACKAGE_CHANGED | - | Indicates the common event that an application package has been changed (for example, a component in the package has been enabled or disabled). |
| COMMON_EVENT_PACKAGE_RESTARTED | usual.event.PACKAGE_RESTARTED | - | Indicates the common event that the user has restarted the application package and killed all its processes. |
| COMMON_EVENT_PACKAGE_DATA_CLEARED | usual.event.PACKAGE_DATA_CLEARED | - | Indicates the common event that the user has cleared the application package data. |
| COMMON_EVENT_PACKAGE_CACHE_CLEARED<sup>9+</sup> | usual.event.PACKAGE_CACHE_CLEARED | - | Indicates the common event that the user clears the application package cache. |
| COMMON_EVENT_PACKAGES_SUSPENDED | usual.event.PACKAGES_SUSPENDED | - | Indicates the common event that application packages have been suspended. |
| COMMON_EVENT_PACKAGES_UNSUSPENDED | usual.event.PACKAGES_UNSUSPENDED | - | Indicates the common event that application packages have not been suspended. |
| COMMON_EVENT_MY_PACKAGE_SUSPENDED | usual.event.MY_PACKAGE_SUSPENDED | - | Indicates the common event that an application package has been suspended. |
| COMMON_EVENT_MY_PACKAGE_UNSUSPENDED | usual.event.MY_PACKAGE_UNSUSPENDED | - | Indicates the common event that application package has not been suspended. |
| COMMON_EVENT_UID_REMOVED | usual.event.UID_REMOVED | - | Indicates the common event that a user ID has been removed from the system. |
| COMMON_EVENT_PACKAGE_FIRST_LAUNCH | usual.event.PACKAGE_FIRST_LAUNCH | - | Indicates the common event that an installed application is started for the first time. |
| COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION | usual.event.PACKAGE_NEEDS_VERIFICATION | - | Indicates the common event that an application requires system verification. |
| COMMON_EVENT_PACKAGE_VERIFIED | usual.event.PACKAGE_VERIFIED | - | Indicates the common event that an application has been verified by the system. |
| COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE | usual.event.EXTERNAL_APPLICATIONS_AVAILABLE | - | Indicates the common event that applications installed on the external storage become available for the system. |
| COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE | usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE | - | Indicates the common event that applications installed on the external storage become unavailable for the system. |
| COMMON_EVENT_CONFIGURATION_CHANGED | usual.event.CONFIGURATION_CHANGED | - | Indicates the common event that the device state (for example, orientation and locale) has changed. |
| COMMON_EVENT_LOCALE_CHANGED | usual.event.LOCALE_CHANGED | - | Indicates the common event that the device locale has changed. |
| COMMON_EVENT_MANAGE_PACKAGE_STORAGE | usual.event.MANAGE_PACKAGE_STORAGE | - | Indicates the common event that the device storage is insufficient. |
| COMMON_EVENT_DRIVE_MODE | common.event.DRIVE_MODE | - | Indicates the common event that the system is in driving mode. |
| COMMON_EVENT_HOME_MODE | common.event.HOME_MODE | - | Indicates the common event that the system is in home mode. |
| COMMON_EVENT_OFFICE_MODE | common.event.OFFICE_MODE | - | Indicates the common event that the system is in office mode. |
| COMMON_EVENT_USER_STARTED | usual.event.USER_STARTED | - | Indicates the common event that the user has been started. |
| COMMON_EVENT_USER_BACKGROUND | usual.event.USER_BACKGROUND | - | Indicates the common event that the user has been brought to the background. |
| COMMON_EVENT_USER_FOREGROUND | usual.event.USER_FOREGROUND | - | Indicates the common event that the user has been brought to the foreground. |
| COMMON_EVENT_USER_SWITCHED | usual.event.USER_SWITCHED | ohos.permission.MANAGE_USERS | Indicates the common event that user switching is happening. |
| COMMON_EVENT_USER_STARTING | usual.event.USER_STARTING | ohos.permission.INTERACT_ACROSS_USERS | Indicates the common event that the user is going to be started. |
| COMMON_EVENT_USER_UNLOCKED | usual.event.USER_UNLOCKED | - | Indicates the common event that the credential-encrypted storage has been unlocked for the current user when the device is unlocked after being restarted. |
| COMMON_EVENT_USER_STOPPING | usual.event.USER_STOPPING | ohos.permission.INTERACT_ACROSS_USERS | Indicates the common event that the user is going to be stopped. |
| COMMON_EVENT_USER_STOPPED | usual.event.USER_STOPPED | - | Indicates the common event that the user has been stopped. |
| COMMON_EVENT_HWID_LOGIN | common.event.HWID_LOGIN | - | Indicates the common event about a HUAWEI ID login. |
| COMMON_EVENT_HWID_LOGOUT | common.event.HWID_LOGOUT | - | Indicates the common event about a HUAWEI ID logout. |
| COMMON_EVENT_HWID_TOKEN_INVALID | common.event.HWID_TOKEN_INVALID | - | Indicates the common event that the HUAWEI ID is invalid. |
| COMMON_EVENT_HWID_LOGOFF | common.event.HWID_LOGOFF | - | Indicates the common event about a HUAWEI ID logoff. |
| COMMON_EVENT_WIFI_POWER_STATE | usual.event.wifi.POWER_STATE | - | Indicates the common event about the Wi-Fi network state, such as enabled and disabled. |
| COMMON_EVENT_WIFI_SCAN_FINISHED | usual.event.wifi.SCAN_FINISHED | ohos.permission.LOCATION | Indicates the common event that the Wi-Fi access point has been scanned and proven to be available. |
| COMMON_EVENT_WIFI_RSSI_VALUE | usual.event.wifi.RSSI_VALUE | ohos.permission.GET_WIFI_INFO | Indicates the common event that the Wi-Fi signal strength (RSSI) has changed. |
| COMMON_EVENT_WIFI_CONN_STATE | usual.event.wifi.CONN_STATE | - | Indicates the common event that the Wi-Fi connection state has changed. |
| COMMON_EVENT_WIFI_HOTSPOT_STATE | usual.event.wifi.HOTSPOT_STATE | - | Indicates the common event about the Wi-Fi hotspot state, such as enabled or disabled. |
| COMMON_EVENT_WIFI_AP_STA_JOIN | usual.event.wifi.WIFI_HS_STA_JOIN | ohos.permission.GET_WIFI_INFO | Indicates the common event that a client has joined the Wi-Fi hotspot of the current device. |
| COMMON_EVENT_WIFI_AP_STA_LEAVE | usual.event.wifi.WIFI_HS_STA_LEAVE | ohos.permission.GET_WIFI_INFO |Indicates the common event that a client has disconnected from the Wi-Fi hotspot of the current device. |
| COMMON_EVENT_WIFI_MPLINK_STATE_CHANGE | usual.event.wifi.mplink.STATE_CHANGE | ohos.permission.MPLINK_CHANGE_STATE | Indicates the common event that the state of MPLINK (an enhanced Wi-Fi feature) has changed. |
| COMMON_EVENT_WIFI_P2P_CONN_STATE | usual.event.wifi.p2p.CONN_STATE_CHANGE | ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION | Indicates the common event that the Wi-Fi P2P connection state has changed. |
| COMMON_EVENT_WIFI_P2P_STATE_CHANGED | usual.event.wifi.p2p.STATE_CHANGE | ohos.permission.GET_WIFI_INFO | Indicates the common event about the Wi-Fi P2P state, such as enabled and disabled. |
| COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED | usual.event.wifi.p2p.DEVICES_CHANGE | ohos.permission.GET_WIFI_INFO | Indicates the common event about the status change of Wi-Fi P2P peer devices. |
| COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED | usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE | ohos.permission.GET_WIFI_INFO | Indicates the common event about the Wi-Fi P2P discovery status change. |
| COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED | usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE | ohos.permission.GET_WIFI_INFO | Indicates the common event about the status change of the Wi-Fi P2P local device. |
| COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED | usual.event.wifi.p2p.GROUP_STATE_CHANGED | ohos.permission.GET_WIFI_INFO | Indicates the common event that the Wi-Fi P2P group information has changed. |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfree.ag.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event about the connection state of Bluetooth handsfree communication. |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CURRENT_DEVICE_UPDATE | usual.event.bluetooth.handsfree.ag.CURRENT_DEVICE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the device connected to the Bluetooth handsfree is active. |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfree.ag.AUDIO_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the connection state of Bluetooth A2DP has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event about the connection state of Bluetooth A2DP. |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CURRENT_DEVICE_UPDATE | usual.event.bluetooth.a2dpsource.CURRENT_DEVICE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the device connected using Bluetooth A2DP is active. |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_PLAYING_STATE_UPDATE | usual.event.bluetooth.a2dpsource.PLAYING_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the playing state of Bluetooth A2DP has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the AVRCP connection state of Bluetooth A2DP has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE | usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the audio codec state of Bluetooth A2DP has changed. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED | usual.event.bluetooth.remotedevice.DISCOVERED | ohos.permission.LOCATION and ohos.permission.USE_BLUETOOTH | Indicates the common event that a remote Bluetooth device is discovered. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CLASS_VALUE_UPDATE | usual.event.bluetooth.remotedevice.CLASS_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the Bluetooth class of a remote Bluetooth device has changed. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_CONNECTED | usual.event.bluetooth.remotedevice.ACL_CONNECTED | ohos.permission.USE_BLUETOOTH | Indicates the common event that a low-ACL connection has been established with a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED | usual.event.bluetooth.remotedevice.ACL_DISCONNECTED | ohos.permission.USE_BLUETOOTH | Indicates the common event that a low-ACL connection has been disconnected from a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE | usual.event.bluetooth.remotedevice.NAME_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the friendly name of a remote Bluetooth device is retrieved for the first time or is changed since the last retrieval. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE | usual.event.bluetooth.remotedevice.PAIR_STATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the connection state of a remote Bluetooth device has changed. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_BATTERY_VALUE_UPDATE | usual.event.bluetooth.remotedevice.BATTERY_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the battery level of a remote Bluetooth device is retrieved for the first time or is changed since the last retrieval. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT | usual.event.bluetooth.remotedevice.SDP_RESULT | - | Indicates the common event about the SDP state of a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_UUID_VALUE | usual.event.bluetooth.remotedevice.UUID_VALUE | ohos.permission.DISCOVER_BLUETOOTH | Indicates the common event about the UUID connection state of a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_REQ | usual.event.bluetooth.remotedevice.PAIRING_REQ | ohos.permission.DISCOVER_BLUETOOTH | Indicates the common event about the pairing request from a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL | usual.event.bluetooth.remotedevice.PAIRING_CANCEL | - | Indicates the common event that Bluetooth pairing is canceled. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ | usual.event.bluetooth.remotedevice.CONNECT_REQ | - | Indicates the common event about the connection request from a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY | usual.event.bluetooth.remotedevice.CONNECT_REPLY | - | Indicates the common event about the response to the connection request from a remote Bluetooth device. |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL | usual.event.bluetooth.remotedevice.CONNECT_CANCEL | - | Indicates the common event that the connection to a remote Bluetooth device has been canceled. |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE | - | Indicates the common event that the connection state of a Bluetooth handsfree has changed. |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE | - | Indicates the common event that the audio state of a Bluetooth handsfree has changed. |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT | usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT | - | Indicates the common event that the audio gateway state of a Bluetooth handsfree has changed. |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE | - | Indicates the common event that the calling state of a Bluetooth handsfree has changed. |
| COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE | usual.event.bluetooth.host.STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the state of a Bluetooth adapter has been changed, for example, Bluetooth has been enabled or disabled. |
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE | usual.event.bluetooth.host.REQ_DISCOVERABLE | - | Indicates the common event about the request for the user to allow Bluetooth device scanning. |
| COMMON_EVENT_BLUETOOTH_HOST_REQ_ENABLE | usual.event.bluetooth.host.REQ_ENABLE | ohos.permission.USE_BLUETOOTH | Indicates the common event about the request for the user to enable Bluetooth. |
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISABLE | usual.event.bluetooth.host.REQ_DISABLE | ohos.permission.USE_BLUETOOTH | Indicates the common event about the request for the user to disable Bluetooth. |
| COMMON_EVENT_BLUETOOTH_HOST_SCAN_MODE_UPDATE | usual.event.bluetooth.host.SCAN_MODE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the Bluetooth scanning mode of a device has changed. |
| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_STARTED | usual.event.bluetooth.host.DISCOVERY_STARTED | ohos.permission.USE_BLUETOOTH | Indicates the common event that the Bluetooth scanning has been started on the device. |
| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_FINISHED | usual.event.bluetooth.host.DISCOVERY_FINISHED | ohos.permission.USE_BLUETOOTH | Indicates the common event that the Bluetooth scanning is finished on the device. |
| COMMON_EVENT_BLUETOOTH_HOST_NAME_UPDATE | usual.event.bluetooth.host.NAME_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the Bluetooth adapter name of the device has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsink.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the connection state of Bluetooth A2DP Sink has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_PLAYING_STATE_UPDATE | usual.event.bluetooth.a2dpsink.PLAYING_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the playing state of Bluetooth A2DP Sink has changed. |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_AUDIO_STATE_UPDATE | usual.event.bluetooth.a2dpsink.AUDIO_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | Indicates the common event that the audio state of Bluetooth A2DP Sink has changed. |
| COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED | usual.event.nfc.action.ADAPTER_STATE_CHANGED | - | Indicates the common event that the state of the device's NFC adapter has changed. |
| COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED | usual.event.nfc.action.RF_FIELD_ON_DETECTED | ohos.permission.MANAGE_SECURE_SETTINGS | Indicates the common event that the NFC RF field is detected to be in the enabled state. |
| COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED | usual.event.nfc.action.RF_FIELD_OFF_DETECTED | ohos.permission.MANAGE_SECURE_SETTINGS | Indicates the common event that the NFC RF field is detected to be in the disabled state. |
| COMMON_EVENT_DISCHARGING | usual.event.DISCHARGING | - | Indicates the common event that the system stops charging the battery. |
| COMMON_EVENT_CHARGING | usual.event.CHARGING | - | Indicates the common event that the system starts charging the battery. |
| COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED | usual.event.DEVICE_IDLE_MODE_CHANGED | - | Indicates the common event that the system idle mode has changed. |
| COMMON_EVENT_POWER_SAVE_MODE_CHANGED | usual.event.POWER_SAVE_MODE_CHANGED | - | Indicates the common event that the power saving mode of the system has changed. |
| COMMON_EVENT_USER_ADDED | usual.event.USER_ADDED | ohos.permission.MANAGE_USERS | Indicates the common event that a user has been added to the system. |
| COMMON_EVENT_USER_REMOVED | usual.event.USER_REMOVED | ohos.permission.MANAGE_USERS | Indicates the common event that a user has been removed from the system. |
| COMMON_EVENT_ABILITY_ADDED | usual.event.ABILITY_ADDED | ohos.permission.LISTEN_BUNDLE_CHANGE | Indicates the common event that an ability has been added. |
| COMMON_EVENT_ABILITY_REMOVED | usual.event.ABILITY_REMOVED | ohos.permission.LISTEN_BUNDLE_CHANGE | Indicates the common event that an ability has been removed. |
| COMMON_EVENT_ABILITY_UPDATED | usual.event.ABILITY_UPDATED | ohos.permission.LISTEN_BUNDLE_CHANGE | Indicates the common event that an ability has been updated. |
| COMMON_EVENT_LOCATION_MODE_STATE_CHANGED | usual.event.location.MODE_STATE_CHANGED | - | Indicates the common event that the location mode of the system has changed. |
| COMMON_EVENT_IVI_SLEEP | common.event.IVI_SLEEP | - | Indicates the common event that the in-vehicle infotainment (IVI) system of a vehicle is sleeping. |
| COMMON_EVENT_IVI_PAUSE | common.event.IVI_PAUSE | - | Indicates the common event that the IVI system of a vehicle has entered sleep mode and the playing application is instructed to stop playback. |
| COMMON_EVENT_IVI_STANDBY | common.event.IVI_STANDBY | - | Indicates the common event that a third-party application is instructed to pause the current work. |
| COMMON_EVENT_IVI_LASTMODE_SAVE | common.event.IVI_LASTMODE_SAVE | - | Indicates the common event that a third-party application is instructed to save its last mode. |
| COMMON_EVENT_IVI_VOLTAGE_ABNORMAL | common.event.IVI_VOLTAGE_ABNORMAL | - | Indicates the common event that the voltage of the vehicle's power system is abnormal. |
| COMMON_EVENT_IVI_HIGH_TEMPERATURE | common.event.IVI_HIGH_TEMPERATURE | - | Indicates the common event that the temperature of the IVI system is high. |
| COMMON_EVENT_IVI_EXTREME_TEMPERATURE | common.event.IVI_EXTREME_TEMPERATURE | - | Indicates the common event that the temperature of the IVI system is extremely high. |
| COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL | common.event.IVI_TEMPERATURE_ABNORMAL | - | Indicates the common event that the IVI system has an extreme temperature. |
| COMMON_EVENT_IVI_VOLTAGE_RECOVERY | common.event.IVI_VOLTAGE_RECOVERY | - | Indicates the common event that the voltage of the vehicle's power system is restored to normal. |
| COMMON_EVENT_IVI_TEMPERATURE_RECOVERY | common.event.IVI_TEMPERATURE_RECOVERY | - | Indicates the common event that the temperature of the IVI system is restored to normal. |
| COMMON_EVENT_IVI_ACTIVE | common.event.IVI_ACTIVE | - | Indicates the common event that the battery service is active. |
| COMMON_EVENT_USB_DEVICE_ATTACHED | usual.event.hardware.usb.action.USB_DEVICE_ATTACHED | - | Indicates the common event that a USB device has been attached when the user device functions as a USB host. |
| COMMON_EVENT_USB_DEVICE_DETACHED | usual.event.hardware.usb.action.USB_DEVICE_DETACHED | - | Indicates the common event that a USB device has been detached when the user device functions as a USB host. |
| COMMON_EVENT_USB_ACCESSORY_ATTACHED | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED | - | Indicates the common event that a USB accessory was attached. |
| COMMON_EVENT_USB_ACCESSORY_DETACHED | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED | - | Indicates the common event that a USB accessory was detached. |
| COMMON_EVENT_DISK_REMOVED | usual.event.data.DISK_REMOVED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed. |
| COMMON_EVENT_DISK_UNMOUNTED | usual.event.data.DISK_UNMOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was unmounted. |
| COMMON_EVENT_DISK_MOUNTED | usual.event.data.DISK_MOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was mounted. |
| COMMON_EVENT_DISK_BAD_REMOVAL | usual.event.data.DISK_BAD_REMOVAL | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed without being unmounted. |
| COMMON_EVENT_DISK_UNMOUNTABLE | usual.event.data.DISK_UNMOUNTABLE | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device becomes unmountable. |
| COMMON_EVENT_DISK_EJECT | usual.event.data.DISK_EJECT | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was ejected. |
| COMMON_EVENT_VOLUME_REMOVED<sup>9+<sup> | usual.event.data.VOLUME_REMOVED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed. |
| COMMON_EVENT_VOLUME_UNMOUNTED<sup>9+<sup> | usual.event.data.VOLUME_UNMOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was unmounted. |
| COMMON_EVENT_VOLUME_MOUNTED<sup>9+<sup> | usual.event.data.VOLUME_MOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was mounted. |
| COMMON_EVENT_VOLUME_BAD_REMOVAL<sup>9+<sup> | usual.event.data.VOLUME_BAD_REMOVAL | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed without being unmounted. |
| COMMON_EVENT_VOLUME_EJECT<sup>9+<sup> | usual.event.data.VOLUME_EJECT | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was ejected. |
| COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED | usual.event.data.VISIBLE_ACCOUNTS_UPDATED | ohos.permission.GET_APP_ACCOUNTS | Indicates the common event that the account visibility changed. |
| COMMON_EVENT_ACCOUNT_DELETED | usual.event.data.ACCOUNT_DELETED | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | Indicates the common event that the account was deleted. |
| COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the foundation is ready. |
| COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | - | Indicates the common event that the airplane mode of the device has changed. |
| COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | ohos.permission.RECEIVER_SPLIT_SCREEN | Indicates the common event of screen splitting. |
| COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has changed. |
| COMMON_EVENT_SPN_INFO_CHANGED<sup>9+<sup> | usual.event.SPN_INFO_CHANGED | - | Indicates the common event that the SPN displayed has been updated. |
## CommonEvent.publish ## CommonEvent.publish
publish(event: string, callback: AsyncCallback\<void>): void publish(event: string, callback: AsyncCallback\<void>): void
...@@ -181,7 +192,7 @@ Publishes a common event. This API uses a callback to return the result. ...@@ -181,7 +192,7 @@ Publishes a common event. This API uses a callback to return the result.
**Example** **Example**
```js ```js
// Callback for common event publication. // Callback for common event publication
function PublishCallBack(err) { function PublishCallBack(err) {
if (err.code) { if (err.code) {
console.error("publish failed " + JSON.stringify(err)); console.error("publish failed " + JSON.stringify(err));
...@@ -218,8 +229,8 @@ Publishes a common event with given attributes. This API uses a callback to retu ...@@ -218,8 +229,8 @@ Publishes a common event with given attributes. This API uses a callback to retu
```js ```js
// Attributes of a common event. // Attributes of a common event.
var options = { var options = {
code: 0, // Result code of the common event code: 0, // Result code of the common event.
data: "initial data",// Result data of the common event data: "initial data";// Result data of the common event.
isOrdered: true // The common event is an ordered one. isOrdered: true // The common event is an ordered one.
} }
...@@ -246,6 +257,8 @@ Publishes a common event to a specific user. This API uses a callback to return ...@@ -246,6 +257,8 @@ Publishes a common event to a specific user. This API uses a callback to return
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Readable/Writable| Type | Mandatory| Description | | Name | Readable/Writable| Type | Mandatory| Description |
...@@ -257,7 +270,7 @@ Publishes a common event to a specific user. This API uses a callback to return ...@@ -257,7 +270,7 @@ Publishes a common event to a specific user. This API uses a callback to return
**Example** **Example**
```js ```js
// Callback for common event publication. // Callback for common event publication
function PublishAsUserCallBack(err) { function PublishAsUserCallBack(err) {
if (err.code) { if (err.code) {
console.error("publishAsUser failed " + JSON.stringify(err)); console.error("publishAsUser failed " + JSON.stringify(err));
...@@ -283,6 +296,8 @@ Publishes a common event with given attributes to a specific user. This API uses ...@@ -283,6 +296,8 @@ Publishes a common event with given attributes to a specific user. This API uses
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Readable/Writable| Type | Mandatory| Description | | Name | Readable/Writable| Type | Mandatory| Description |
...@@ -298,8 +313,8 @@ Publishes a common event with given attributes to a specific user. This API uses ...@@ -298,8 +313,8 @@ Publishes a common event with given attributes to a specific user. This API uses
```js ```js
// Attributes of a common event. // Attributes of a common event.
var options = { var options = {
code: 0, // Result code of the common event code: 0, // Result code of the common event.
data: "initial data",// Result data of the common event data: "initial data";// Result data of the common event
} }
// Callback for common event publication // Callback for common event publication
...@@ -560,7 +575,7 @@ Obtains the result code of this common event. This API uses a promise to return ...@@ -560,7 +575,7 @@ Obtains the result code of this common event. This API uses a promise to return
| Type | Description | | Type | Description |
| ---------------- | -------------------- | | ---------------- | -------------------- |
| Promise\<number> | Promise used to return the result code.| | Promise\<number> | Promise used to return the result.|
**Example** **Example**
...@@ -623,7 +638,7 @@ Sets the result code for this common event. This API uses a promise to return th ...@@ -623,7 +638,7 @@ Sets the result code for this common event. This API uses a promise to return th
| Type | Description | | Type | Description |
| ---------------- | -------------------- | | ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result code.| | Promise\<void> | Promise used to return the result.|
**Example** **Example**
...@@ -742,7 +757,7 @@ Sets the result data for this common event. This API uses a promise to return th ...@@ -742,7 +757,7 @@ Sets the result data for this common event. This API uses a promise to return th
| Type | Description | | Type | Description |
| ---------------- | -------------------- | | ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result data.| | Promise\<void> | Promise used to return the result.|
**Example** **Example**
......
# Active Tag # Active Tag
The **connectedTag** module provides methods for using active tags. You can use the APIs provided by this module to initialize the active tag chip and read and write active tags.
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -22,9 +24,9 @@ Initializes the active tag chip. ...@@ -22,9 +24,9 @@ Initializes the active tag chip.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the initialization is successful; returns **false** otherwise. | | boolean | Returns **true** if the initialization is successful; returns **false** otherwise.|
## connectedTag.uninit ## connectedTag.uninit
...@@ -38,9 +40,9 @@ Uninitializes the active tag resources. ...@@ -38,9 +40,9 @@ Uninitializes the active tag resources.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise. | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## connectedTag.readNdefTag ## connectedTag.readNdefTag
...@@ -54,9 +56,9 @@ Reads the content of this active tag. This method uses a promise to return the r ...@@ -54,9 +56,9 @@ Reads the content of this active tag. This method uses a promise to return the r
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| Promise&lt;string&gt; | Promise used to return the content of the active tag. | | Promise&lt;string&gt; | Promise used to return the content of the active tag.|
- Example - Example
``` ```
...@@ -78,9 +80,9 @@ Reads the content of this active tag. This method uses an asynchronous callback ...@@ -78,9 +80,9 @@ Reads the content of this active tag. This method uses an asynchronous callback
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the active tag content obtained. | | callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the active tag content obtained.|
- Example - Example
``` ```
...@@ -102,14 +104,14 @@ Writes data to this active tag. This method uses a promise to return the result. ...@@ -102,14 +104,14 @@ Writes data to this active tag. This method uses a promise to return the result.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| data | string | Yes | Data to write. The maximum length is 1024 bytes. | | data | string | Yes| Data to write. The maximum length is 1024 bytes.|
- Return value - Return value
| **Type** | **Description** | | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. This method returns no value. | | Promise&lt;void&gt; | Promise used to return the result. This method returns no value.|
- Example - Example
``` ```
...@@ -127,7 +129,7 @@ Writes data to this active tag. This method uses a promise to return the result. ...@@ -127,7 +129,7 @@ Writes data to this active tag. This method uses a promise to return the result.
## connectedTag.writeNdefTag ## connectedTag.writeNdefTag
writeNdefTag(data: string, callback: AsyncCallback&lt;string&gt;): void writeNdefTag(data: string, callback: AsyncCallback&lt;void&gt;): void
Writes data to this active tag. This method uses an asynchronous callback to return the result. Writes data to this active tag. This method uses an asynchronous callback to return the result.
...@@ -136,10 +138,10 @@ Writes data to this active tag. This method uses an asynchronous callback to ret ...@@ -136,10 +138,10 @@ Writes data to this active tag. This method uses an asynchronous callback to ret
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| data | string | Yes | Data to write. The maximum length is 1024 bytes. | | data | string | Yes| Data to write. The maximum length is 1024 bytes.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the operation result. | | callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the active tag content obtained.|
- Example - Example
``` ```
...@@ -168,16 +170,16 @@ Registers the NFC field strength state events. ...@@ -168,16 +170,16 @@ Registers the NFC field strength state events.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Event type. The value is **notify**. | | type | string | Yes| Event type. The value is **notify**.|
| callback | Callback&lt;number&gt; | Yes | Callback invoked to return the field strength state. | | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the field strength state.|
- Enumerates the field strength states. - Enumerates the field strength states.
| **Value** | **Description** | | **Value**| **Description**|
| -------- | -------- | | -------- | -------- |
| 0 | Field off. | | 0 | Field off.|
| 1 | Field on. | | 1 | Field on.|
## connectedTag.off('notify') ## connectedTag.off('notify')
...@@ -191,10 +193,10 @@ Unregisters the NFC field strength state events. ...@@ -191,10 +193,10 @@ Unregisters the NFC field strength state events.
**System capability**: SystemCapability.Communication.ConnectedTag **System capability**: SystemCapability.Communication.ConnectedTag
- Parameters - Parameters
| **Name** | **Type** | **Mandatory** | **Description** | | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Event type. The value is **notify**. | | type | string | Yes| Event type. The value is **notify**.|
| callback | Callback&lt;number&gt; | No | Callback used to return the field strength state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered. | | callback | Callback&lt;number&gt; | No| Callback used to return the field strength state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
- Example - Example
``` ```
...@@ -206,10 +208,10 @@ Unregisters the NFC field strength state events. ...@@ -206,10 +208,10 @@ Unregisters the NFC field strength state events.
console.info("nfc rf receive state: " + result); console.info("nfc rf receive state: " + result);
} }
// Register event notification // Register event notification.
connectedTag.on(NFC_RF_NOTIFY, recvNfcRfNotifyFunc); connectedTag.on(NFC_RF_NOTIFY, recvNfcRfNotifyFunc);
// Unregister event notification // Unregister event notification.
connectedTag.off(NFC_RF_NOTIFY, recvNfcRfNotifyFunc); connectedTag.off(NFC_RF_NOTIFY, recvNfcRfNotifyFunc);
``` ```
...@@ -217,7 +219,9 @@ Unregisters the NFC field strength state events. ...@@ -217,7 +219,9 @@ Unregisters the NFC field strength state events.
Enumerates the NFC states. Enumerates the NFC states.
| Name | Default Value | Description | **System capability**: SystemCapability.Communication.ConnectedTag
| -------- | -------- | -------- |
| NFC_RF_LEAVE | 0 | Field off. | | Name| Default Value| Description|
| NFC_RF_ENTER | 1 | Field on. | | -------- | -------- | -------- |
| NFC_RF_LEAVE | 0 | Field on.|
| NFC_RF_ENTER | 1 | Field on.|
...@@ -4,7 +4,7 @@ The relational database (RDB) manages data based on relational models. With the ...@@ -4,7 +4,7 @@ The relational database (RDB) manages data based on relational models. With the
This module provides the following RDB-related functions: This module provides the following RDB-related functions:
- [RdbPredicates](#rdbpredicates): predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store. - [RdbPredicates](#rdbpredicates): provides predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store.
- [RdbStore](#rdbstore): provides APIs for managing an RDB store. - [RdbStore](#rdbstore): provides APIs for managing an RDB store.
> **NOTE**<br/> > **NOTE**<br/>
...@@ -51,7 +51,7 @@ data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) { ...@@ -51,7 +51,7 @@ data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) {
getRdbStore(context: Context, config: StoreConfig, version: number): Promise&lt;RdbStore&gt; getRdbStore(context: Context, config: StoreConfig, version: number): Promise&lt;RdbStore&gt;
Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -166,14 +166,14 @@ let predicates = new data_rdb.RdbPredicates("EMPLOYEE") ...@@ -166,14 +166,14 @@ let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
inDevices(devices: Array&lt;string&gt;): RdbPredicates inDevices(devices: Array&lt;string&gt;): RdbPredicates
Specifies a remote device on the network during distributed database synchronization. Connects to the specified remote devices on the network during distributed database synchronization.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| devices | Array&lt;string&gt; | Yes| ID of the remote device to specify.| | devices | Array&lt;string&gt; | Yes| IDs of the remote devices in the same network.|
**Return value** **Return value**
| Type| Description| | Type| Description|
...@@ -211,7 +211,7 @@ predicates.inAllDevices() ...@@ -211,7 +211,7 @@ predicates.inAllDevices()
equalTo(field: string, value: ValueType): RdbPredicates equalTo(field: string, value: ValueType): RdbPredicates
Sets the **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value. Sets an **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -238,7 +238,7 @@ predicates.equalTo("NAME", "lisi") ...@@ -238,7 +238,7 @@ predicates.equalTo("NAME", "lisi")
notEqualTo(field: string, value: ValueType): RdbPredicates notEqualTo(field: string, value: ValueType): RdbPredicates
Sets the **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value. Sets an **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -362,7 +362,7 @@ predicates.equalTo("NAME", "Lisa") ...@@ -362,7 +362,7 @@ predicates.equalTo("NAME", "Lisa")
contains(field: string, value: string): RdbPredicates contains(field: string, value: string): RdbPredicates
Sets the **RdbPredicates** to match a string containing the specified value. Sets an **RdbPredicates** to match a string containing the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -389,7 +389,7 @@ predicates.contains("NAME", "os") ...@@ -389,7 +389,7 @@ predicates.contains("NAME", "os")
beginsWith(field: string, value: string): RdbPredicates beginsWith(field: string, value: string): RdbPredicates
Sets the **RdbPredicates** to match a string that starts with the specified value. Sets an **RdbPredicates** to match a string that starts with the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -416,7 +416,7 @@ predicates.beginsWith("NAME", "os") ...@@ -416,7 +416,7 @@ predicates.beginsWith("NAME", "os")
endsWith(field: string, value: string): RdbPredicates endsWith(field: string, value: string): RdbPredicates
Sets the **RdbPredicates** to match a string that ends with the specified value. Sets an **RdbPredicates** to match a string that ends with the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -443,7 +443,7 @@ predicates.endsWith("NAME", "se") ...@@ -443,7 +443,7 @@ predicates.endsWith("NAME", "se")
isNull(field: string): RdbPredicates isNull(field: string): RdbPredicates
Sets the **RdbPredicates** to match the field whose value is null. Sets an **RdbPredicates** to match the field whose value is null.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -469,7 +469,7 @@ predicates.isNull("NAME") ...@@ -469,7 +469,7 @@ predicates.isNull("NAME")
isNotNull(field: string): RdbPredicates isNotNull(field: string): RdbPredicates
Sets the **RdbPredicates** to match the field whose value is not null. Sets an **RdbPredicates** to match the field whose value is not null.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -495,7 +495,7 @@ predicates.isNotNull("NAME") ...@@ -495,7 +495,7 @@ predicates.isNotNull("NAME")
like(field: string, value: string): RdbPredicates like(field: string, value: string): RdbPredicates
Sets the **RdbPredicates** to match a string that is similar to the specified value. Sets an **RdbPredicates** to match a string that is similar to the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -522,7 +522,7 @@ predicates.like("NAME", "%os%") ...@@ -522,7 +522,7 @@ predicates.like("NAME", "%os%")
glob(field: string, value: string): RdbPredicates glob(field: string, value: string): RdbPredicates
Sets the **RdbPredicates** to match the specified string. Sets an **RdbPredicates** to match the specified string.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -549,7 +549,7 @@ predicates.glob("NAME", "?h*g") ...@@ -549,7 +549,7 @@ predicates.glob("NAME", "?h*g")
between(field: string, low: ValueType, high: ValueType): RdbPredicates between(field: string, low: ValueType, high: ValueType): RdbPredicates
Sets the **RdbPredicates** to match the field with data type **ValueType** and value within the specified range. Sets an **RdbPredicates** to match the field with data type **ValueType** and value within the specified range.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -577,7 +577,7 @@ predicates.between("AGE", 10, 50) ...@@ -577,7 +577,7 @@ predicates.between("AGE", 10, 50)
notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates
Sets the **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range. Sets an **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -604,7 +604,7 @@ predicates.notBetween("AGE", 10, 50) ...@@ -604,7 +604,7 @@ predicates.notBetween("AGE", 10, 50)
greaterThan(field: string, value: ValueType): RdbPredicates greaterThan(field: string, value: ValueType): RdbPredicates
Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value. Sets an **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -631,7 +631,7 @@ predicates.greaterThan("AGE", 18) ...@@ -631,7 +631,7 @@ predicates.greaterThan("AGE", 18)
lessThan(field: string, value: ValueType): RdbPredicates lessThan(field: string, value: ValueType): RdbPredicates
Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value. Sets an **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -659,7 +659,7 @@ predicates.lessThan("AGE", 20) ...@@ -659,7 +659,7 @@ predicates.lessThan("AGE", 20)
greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates
Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value. Sets an **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -687,7 +687,7 @@ predicates.greaterThanOrEqualTo("AGE", 18) ...@@ -687,7 +687,7 @@ predicates.greaterThanOrEqualTo("AGE", 18)
lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates
Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value. Sets an **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -715,7 +715,7 @@ predicates.lessThanOrEqualTo("AGE", 20) ...@@ -715,7 +715,7 @@ predicates.lessThanOrEqualTo("AGE", 20)
orderByAsc(field: string): RdbPredicates orderByAsc(field: string): RdbPredicates
Sets the **RdbPredicates** to match the column with values sorted in ascending order. Sets an **RdbPredicates** to match the column with values sorted in ascending order.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -742,7 +742,7 @@ predicates.orderByAsc("NAME") ...@@ -742,7 +742,7 @@ predicates.orderByAsc("NAME")
orderByDesc(field: string): RdbPredicates orderByDesc(field: string): RdbPredicates
Sets the **RdbPredicates** to match the column with values sorted in descending order. Sets an **RdbPredicates** to match the column with values sorted in descending order.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -768,7 +768,7 @@ predicates.orderByDesc("AGE") ...@@ -768,7 +768,7 @@ predicates.orderByDesc("AGE")
distinct(): RdbPredicates distinct(): RdbPredicates
Sets the **RdbPredicates** to filter out duplicate records. Sets an **RdbPredicates** to filter out duplicate records.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -789,7 +789,7 @@ predicates.equalTo("NAME", "Rose").distinct("NAME") ...@@ -789,7 +789,7 @@ predicates.equalTo("NAME", "Rose").distinct("NAME")
limitAs(value: number): RdbPredicates limitAs(value: number): RdbPredicates
Sets the **RdbPredicates** to specify the maximum number of records. Sets an **RdbPredicates** to specify the maximum number of records.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -815,7 +815,7 @@ predicates.equalTo("NAME", "Rose").limitAs(3) ...@@ -815,7 +815,7 @@ predicates.equalTo("NAME", "Rose").limitAs(3)
offsetAs(rowOffset: number): RdbPredicates offsetAs(rowOffset: number): RdbPredicates
Sets the **RdbPredicates** to specify the start position of the returned result. Sets an **RdbPredicates** to specify the start position of the returned result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -841,7 +841,7 @@ predicates.equalTo("NAME", "Rose").offsetAs(3) ...@@ -841,7 +841,7 @@ predicates.equalTo("NAME", "Rose").offsetAs(3)
groupBy(fields: Array&lt;string&gt;): RdbPredicates groupBy(fields: Array&lt;string&gt;): RdbPredicates
Sets the **RdbPredicates** to group rows that have the same value into summary rows. Sets an **RdbPredicates** to group rows that have the same value into summary rows.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -866,7 +866,7 @@ predicates.groupBy(["AGE", "NAME"]) ...@@ -866,7 +866,7 @@ predicates.groupBy(["AGE", "NAME"])
indexedBy(field: string): RdbPredicates indexedBy(field: string): RdbPredicates
Sets the **RdbPredicates** object to specify the index column. Sets an **RdbPredicates** object to specify the index column.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -893,7 +893,7 @@ predicates.indexedBy("SALARY_INDEX") ...@@ -893,7 +893,7 @@ predicates.indexedBy("SALARY_INDEX")
in(field: string, value: Array&lt;ValueType&gt;): RdbPredicates in(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range. Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -921,7 +921,7 @@ predicates.in("AGE", [18, 20]) ...@@ -921,7 +921,7 @@ predicates.in("AGE", [18, 20])
notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicates notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range. Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -948,6 +948,8 @@ predicates.notIn("NAME", ["Lisa", "Rose"]) ...@@ -948,6 +948,8 @@ predicates.notIn("NAME", ["Lisa", "Rose"])
Provides methods to manage an RDB store. Provides methods to manage an RDB store.
Before using the following APIs, use [executeSql](#executesql) to initialize the database table structure and related data. For details, see [RDB Development](../../database/database-relational-guidelines.md).
### insert ### insert
...@@ -1029,7 +1031,7 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T ...@@ -1029,7 +1031,7 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.| | values | [ValuesBucket](#valuesbucket) | Yes| Data to update. The value specifies the row of data to be updated in the database. The key-value pair is associated with the column name in the target table.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.| | predicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
...@@ -1064,7 +1066,7 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T ...@@ -1064,7 +1066,7 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.| | values | [ValuesBucket](#valuesbucket) | Yes| Data to update. The value specifies the row of data to be updated in the database. The key-value pair is associated with the column name in the target table.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.| | predicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.|
**Return value** **Return value**
...@@ -1330,7 +1332,7 @@ Queries data in the RDB store based on specified conditions. This API uses a pro ...@@ -1330,7 +1332,7 @@ Queries data in the RDB store based on specified conditions. This API uses a pro
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[ResultSet](../apis/js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| | Promise&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example** **Example**
```js ```js
...@@ -1422,7 +1424,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a ...@@ -1422,7 +1424,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.| | sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Values of the parameters in the SQL statement.| | bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Arguments in the SQL statement.|
| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example** **Example**
...@@ -1450,12 +1452,12 @@ Queries data in the RDB store using the specified SQL statement. This API uses a ...@@ -1450,12 +1452,12 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.| | sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Values of the parameters in the SQL statement.| | bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Arguments in the SQL statement.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[ResultSet](../apis/js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| | Promise&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example** **Example**
```js ```js
...@@ -1481,7 +1483,7 @@ Runs the SQL statement that contains the specified parameters but does not retur ...@@ -1481,7 +1483,7 @@ Runs the SQL statement that contains the specified parameters but does not retur
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.| | sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Values of the parameters in the SQL statement.| | bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Arguments in the SQL statement.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example** **Example**
...@@ -1492,7 +1494,7 @@ rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) { ...@@ -1492,7 +1494,7 @@ rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) {
console.info("Failed to execute SQL, err: " + err) console.info("Failed to execute SQL, err: " + err)
return return
} }
console.info('Create table done.') console.info('Created table successfully.')
}) })
``` ```
...@@ -1509,7 +1511,7 @@ Runs the SQL statement that contains the specified parameters but does not retur ...@@ -1509,7 +1511,7 @@ Runs the SQL statement that contains the specified parameters but does not retur
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.| | sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Values of the parameters in the SQL statement.| | bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Arguments in the SQL statement.|
**Return value** **Return value**
| Type| Description| | Type| Description|
...@@ -1521,7 +1523,7 @@ Runs the SQL statement that contains the specified parameters but does not retur ...@@ -1521,7 +1523,7 @@ Runs the SQL statement that contains the specified parameters but does not retur
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
let promise = rdbStore.executeSql(SQL_CREATE_TABLE) let promise = rdbStore.executeSql(SQL_CREATE_TABLE)
promise.then(() => { promise.then(() => {
console.info('Create table done.') console.info('Created table successfully.')
}).catch((err) => { }).catch((err) => {
console.info("Failed to execute SQL, err: " + err) console.info("Failed to execute SQL, err: " + err)
}) })
...@@ -1637,7 +1639,7 @@ rdbStore.backup("dbBackup.db", function(err) { ...@@ -1637,7 +1639,7 @@ rdbStore.backup("dbBackup.db", function(err) {
console.info('Failed to back up data, err: ' + err) console.info('Failed to back up data, err: ' + err)
return return
} }
console.info('Backup successful.') console.info('Backed up data successfully.')
}) })
``` ```
...@@ -1663,7 +1665,7 @@ Backs up an RDB store. This API uses a promise to return the result. ...@@ -1663,7 +1665,7 @@ Backs up an RDB store. This API uses a promise to return the result.
```js ```js
let promiseBackup = rdbStore.backup("dbBackup.db") let promiseBackup = rdbStore.backup("dbBackup.db")
promiseBackup.then(()=>{ promiseBackup.then(()=>{
console.info('Backup successful.') console.info('Backed up data successfully.')
}).catch((err)=>{ }).catch((err)=>{
console.info('Failed to back up data, err: ' + err) console.info('Failed to back up data, err: ' + err)
}) })
...@@ -1690,7 +1692,7 @@ rdbStore.restore("dbBackup.db", function(err) { ...@@ -1690,7 +1692,7 @@ rdbStore.restore("dbBackup.db", function(err) {
console.info('Failed to restore data, err: ' + err) console.info('Failed to restore data, err: ' + err)
return return
} }
console.info('Restore successful.') console.info('Restored data successfully.')
}) })
``` ```
...@@ -1716,7 +1718,7 @@ Restores an RDB store using a backup file. This API uses a promise to return the ...@@ -1716,7 +1718,7 @@ Restores an RDB store using a backup file. This API uses a promise to return the
```js ```js
let promiseRestore = rdbStore.restore("dbBackup.db") let promiseRestore = rdbStore.restore("dbBackup.db")
promiseRestore.then(()=>{ promiseRestore.then(()=>{
console.info('Restore successful.') console.info('Restored data successfully.')
}).catch((err)=>{ }).catch((err)=>{
console.info('Failed to restore data, err: ' + err) console.info('Failed to restore data, err: ' + err)
}) })
...@@ -1726,7 +1728,7 @@ promiseRestore.then(()=>{ ...@@ -1726,7 +1728,7 @@ promiseRestore.then(()=>{
setDistributedTables(tables: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void setDistributedTables(tables: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
Sets a list of distributed tables. This API uses an asynchronous callback to return the result. Sets distributed tables. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
...@@ -1754,7 +1756,7 @@ rdbStore.setDistributedTables(["EMPLOYEE"], function (err) { ...@@ -1754,7 +1756,7 @@ rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt; setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt;
Sets a list of distributed tables. This API uses a promise to return the result. Sets distributed tables. This API uses a promise to return the result.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
...@@ -1776,7 +1778,7 @@ let promise = rdbStore.setDistributedTables(["EMPLOYEE"]) ...@@ -1776,7 +1778,7 @@ let promise = rdbStore.setDistributedTables(["EMPLOYEE"])
promise.then(() => { promise.then(() => {
console.info("Set distributed tables successfully.") console.info("Set distributed tables successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Failed to set distributed tables, err: " + err) console.info('Failed to set distributed tables, err: ' + err)
}) })
``` ```
...@@ -1784,7 +1786,7 @@ promise.then(() => { ...@@ -1784,7 +1786,7 @@ promise.then(() => {
obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void
Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the database of a remote device is queried. This API uses an asynchronous callback to return the result. Obtains the distributed table name for a remote device based on the local table name. This API uses an asynchronous callback to return the result. The distributed table name is required when the database of a remote device is queried.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
...@@ -1804,7 +1806,7 @@ rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, ...@@ -1804,7 +1806,7 @@ rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err,
console.info('Failed to obtain DistributedTableName, err: ' + err) console.info('Failed to obtain DistributedTableName, err: ' + err)
return return
} }
console.info('Obtained distributed table name successfully, tableName=.' + tableName) console.info('Obtained DistributedTableName successfully, tableName=.' + tableName)
}) })
``` ```
...@@ -1813,7 +1815,7 @@ rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, ...@@ -1813,7 +1815,7 @@ rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err,
obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt; obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt;
Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the database of a remote device is queried. This API uses a promise to return the result. Obtains the distributed table name for a remote device based on the local table name. This API uses a promise to return the result. The distributed table name is used to query the RDB store of the remote device.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
...@@ -1834,7 +1836,7 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -1834,7 +1836,7 @@ Obtains the distributed table name for a remote device based on the local table
```js ```js
let promise = rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE") let promise = rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE")
promise.then((tableName) => { promise.then((tableName) => {
console.info('Obtained distributed table name successfully, tableName= ' + tableName) console.info('Obtained DistributedTableName successfully, tableName=' + tableName)
}).catch((err) => { }).catch((err) => {
console.info('Failed to obtain DistributedTableName, err: ' + err) console.info('Failed to obtain DistributedTableName, err: ' + err)
}) })
...@@ -1855,7 +1857,7 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret ...@@ -1855,7 +1857,7 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| mode | [SyncMode](#syncmode8) | Yes| Data synchronization mode. The value can be **push** or **pull**.| | mode | [SyncMode](#syncmode8) | Yes| Data synchronization mode. The value can be **push** or **pull**.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| **RdbPredicates** object that specifies the data and devices to synchronize.| | predicates | [RdbPredicates](#rdbpredicates) | Yes| **RdbPredicates** object that specifies the data and devices to synchronize.|
| callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes| Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | | callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes| Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example** **Example**
```js ```js
...@@ -1894,7 +1896,7 @@ Synchronizes data between devices. This API uses a promise to return the result. ...@@ -1894,7 +1896,7 @@ Synchronizes data between devices. This API uses a promise to return the result.
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | | Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example** **Example**
```js ```js
...@@ -1947,7 +1949,7 @@ try { ...@@ -1947,7 +1949,7 @@ try {
off(event:'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void off(event:'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
Deletes the specified observer of the RDB store. This API uses a callback to return the result. Unregisters the specified observer of the RDB store. This API uses a callback to return the result.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
...@@ -2009,6 +2011,7 @@ Defines the types of the key and value in a KV pair. ...@@ -2009,6 +2011,7 @@ Defines the types of the key and value in a KV pair.
| -------- | -------- | | -------- | -------- |
| string | [ValueType](#valuetype)\|&nbsp;Uint8Array&nbsp;\|&nbsp;null | | string | [ValueType](#valuetype)\|&nbsp;Uint8Array&nbsp;\|&nbsp;null |
## SyncMode<sup>8+</sup> ## SyncMode<sup>8+</sup>
Defines the database synchronization mode. Defines the database synchronization mode.
......
# Emitter # Emitter
> **NOTE**<br> The **Emitter** module provides APIs for sending and processing in-process events, including the APIs for processing events that are subscribed to in persistent or one-shot manner, unsubscribing from events, and emitting events to the event queue.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. > The initial APIs of this module are supported since API version 7.
## Modules to Import ## Modules to Import
...@@ -17,12 +20,14 @@ None ...@@ -17,12 +20,14 @@ None
Enumerates the event emit priority levels. Enumerates the event emit priority levels.
| Name | Value | Description | **System capability**: SystemCapability.Notification.Emitter
| --------- | ---- | ------------------------------------------------- |
| IMMEDIATE | 0 | The event will be emitted immediately.<br>**System capability**: SystemCapability.Notification.Emitter | | Name | Value | Description |
| HIGH | 1 | The event will be emitted before low-priority events.<br>**System capability**: SystemCapability.Notification.Emitter | | --------- | ---- | ------------------------------------------------- |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority.<br>**System capability**: SystemCapability.Notification.Emitter | | IMMEDIATE | 0 | The event will be emitted immediately. |
| IDLE | 3 | The event will be emitted after all the other events.<br>**System capability**: SystemCapability.Notification.Emitter | | HIGH | 1 | The event will be emitted before low-priority events. |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority. |
| IDLE | 3 | The event will be emitted after all the other events. |
## emitter.on ## emitter.on
...@@ -34,10 +39,10 @@ Subscribes to an event in persistent manner. This API uses a callback to return ...@@ -34,10 +39,10 @@ Subscribes to an event in persistent manner. This API uses a callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------ | | -------- | ----------------------------------- | ---- | ------------------------ |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. | | event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. |
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event.|
**Example** **Example**
...@@ -61,10 +66,10 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve ...@@ -61,10 +66,10 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------ | | -------- | ----------------------------------- | ---- | ------------------------ |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. | | event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. |
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event.|
**Example** **Example**
...@@ -88,9 +93,9 @@ Unsubscribes from an event. ...@@ -88,9 +93,9 @@ Unsubscribes from an event.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------ | | ------- | ------ | ---- | ------ |
| eventId | number | Yes | Event ID. | | eventId | number | Yes | Event ID.|
**Example** **Example**
...@@ -108,10 +113,10 @@ Emits an event to the event queue. ...@@ -108,10 +113,10 @@ Emits an event to the event queue.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------- | ---- | -------------- | | ------ | ------------------------- | ---- | -------------- |
| event | [InnerEvent](#innerevent) | Yes | Event to emit. | | event | [InnerEvent](#innerevent) | Yes | Event to emit. |
| data | [EventData](#eventdata) | No | Data carried by the event. | | data | [EventData](#eventdata) | No | Data carried by the event.|
**Example** **Example**
...@@ -130,17 +135,21 @@ emitter.emit(innerEvent, eventData); ...@@ -130,17 +135,21 @@ emitter.emit(innerEvent, eventData);
## InnerEvent ## InnerEvent
Describes an intra-process event. Describes an in-process event.
| Name | Type | Readable | Writable | Description | **System capability**: SystemCapability.Notification.Emitter
| -------- | ------------------------------- | ---- | ---- | ---------------------------------- |
| eventId | number | Yes | Yes | Event ID, which is used to identify an event.<br>**System capability**: SystemCapability.Notification.Emitter | | Name | Type | Readable| Writable| Description |
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event.<br>**System capability**: SystemCapability.Notification.Emitter | | -------- | ------------------------------- | ---- | ---- | ---------------------------------- |
| eventId | number | Yes | Yes | Event ID, which is used to identify an event.|
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event. |
## EventData ## EventData
Describes the data passed in the event. Describes the data passed in the event.
| Name | Type | Readable | Writable | Description | **System capability**: SystemCapability.Notification.Emitter
| ---- | ------------------ | ---- | ---- | -------------- |
| data | [key: string]: any | Yes | Yes | Data carried by the event. The data type can be String, Integer, or Boolean.<br>**System capability**: SystemCapability.Notification.Emitter | | Name| Type | Readable| Writable| Description |
| ---- | ------------------ | ---- | ---- | -------------- |
| data | [key: string]: any | Yes | Yes | Data carried by the event. The data type can be String, Integer, or Boolean.|
# Input Method Framework # Input Method Framework
The **inputMethod** module provides an input method framework, which can be used to hide the keyboard, obtain the list of installed input methods, display the dialog box for input method selection, and more.
> **NOTE** > **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. > 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.
...@@ -8,14 +10,14 @@ ...@@ -8,14 +10,14 @@
## Modules to Import ## Modules to Import
``` ```
import inputMethod from '@ohos.inputMethod'; import inputMethod from '@ohos.inputmethod';
``` ```
## inputMethod<sup>8+</sup> ## inputMethod<sup>8+</sup>
Provides the constants. Provides the constants.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
...@@ -26,7 +28,7 @@ Provides the constants. ...@@ -26,7 +28,7 @@ Provides the constants.
Describes the input method application attributes. Describes the input method application attributes.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
...@@ -37,15 +39,15 @@ Describes the input method application attributes. ...@@ -37,15 +39,15 @@ Describes the input method application attributes.
getInputMethodController(): InputMethodController getInputMethodController(): InputMethodController
Obtains an [InputMethodController](#InputMethodController) instance. Obtains an **[InputMethodController](#inputmethodcontroller)** instance.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ----------------------------------------- | ---------------------------- |
| [InputMethodController](#InputMethodController) | Returns the current **InputMethodController** instance.| | [InputMethodController](#inputmethodcontroller) | Returns the current **InputMethodController** instance.|
**Example** **Example**
...@@ -57,25 +59,74 @@ Obtains an [InputMethodController](#InputMethodController) instance. ...@@ -57,25 +59,74 @@ Obtains an [InputMethodController](#InputMethodController) instance.
getInputMethodSetting(): InputMethodSetting getInputMethodSetting(): InputMethodSetting
Obtains an [InputMethodSetting](#InputMethodSetting) instance. Obtains an **[InputMethodSetting](#inputmethodsetting8)** instance.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | ---------------------------- | | ----------------------------------------- | ---------------------------- |
| [InputMethodSetting](#InputMethodSetting) | Returns the current **InputMethodSetting** instance.| | [InputMethodSetting](#inputmethodsetting8) | Returns the current **InputMethodSetting** instance.|
**Example** **Example**
```js ```js
var InputMethodSetting = inputMethod.getInputMethodSetting(); var InputMethodSetting = inputMethod.getInputMethodSetting();
``` ```
## inputMethod.switchInputMethod<sup>9+</sup>
switchInputMethod(target: InputmethodProperty, callback: AsyncCallback&lt;boolean&gt;): void;
Switches to another input method. This API uses an asynchronous callback to return the result. This API can be used only in the stage model.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
|target | [InputmethodProperty](#inputmethodproperty8) | Yes| Input method to switch to.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the execution result. |
**Example**
```js
inputMethod.switchInputMethod({packageName:"com.ohos.inputApp", methodId:"InputDemoService"}).then(res => {
prompt.showToast({message:"Input method switched." + this.imeList[this.flag].packageName, duration: 200});
});
```
## inputMethod.switchInputMethod<sup>9+</sup>
switchInputMethod(target: InputmethodProperty): Promise&lt;boolean&gt;
Switches to another input method. This API uses a promise to return the result. This API can be used only in the stage model.
**System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
|target | [InputmethodProperty](#inputmethodproperty8)| Yes| Input method to switch to.|
**Return value**
| Type | Description |
| ----------------------------------------- | ---------------------------- |
| Promise\<boolean> | Promise used to return the execution result. |
**Example**
```js
inputMethod.switchInputMethod({packageName:"com.ohos.inputApp", methodId:"InputDemoService"}).then(res => {
prompt.showToast({message:"Input method switched." + this.imeList[this.flag].packageName, duration: 200});
});
```
## InputMethodController ## InputMethodController
In the following API examples, you must first use [getInputMethodController](#getInputMethodController) to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance. In the following API examples, you must first use **[getInputMethodController](#inputmethodgetinputmethodcontroller)** to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance.
### stopInput ### stopInput
...@@ -83,7 +134,7 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -83,7 +134,7 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void
Hides the keyboard. This API uses an asynchronous callback to return the result. Hides the keyboard. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
...@@ -105,13 +156,13 @@ stopInput(): Promise&lt;boolean&gt; ...@@ -105,13 +156,13 @@ stopInput(): Promise&lt;boolean&gt;
Hides the keyboard. This API uses an asynchronous callback to return the result. Hides the keyboard. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the keyboard is successfully hidden.| | Promise&lt;boolean&gt; | Promise used to return whether the keyboard is successfully hidden. |
**Example** **Example**
...@@ -123,7 +174,7 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. ...@@ -123,7 +174,7 @@ Hides the keyboard. This API uses an asynchronous callback to return the result.
## InputMethodSetting<sup>8+</sup> ## InputMethodSetting<sup>8+</sup>
In the following API examples, you must first use [getInputMethodSetting](#getInputMethodSetting) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance. In the following API examples, you must first use **[getInputMethodSetting](#inputmethodgetinputmethodsetting8)** to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance.
### listInputMethod ### listInputMethod
...@@ -131,13 +182,12 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;) ...@@ -131,13 +182,12 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;)
Obtains the list of installed input methods. This API uses an asynchronous callback to return the result. Obtains the list of installed input methods. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------------------------- | ---- | ---------------------- | | -------- | -------------------------------------------------- | ---- | ---------------------- |
| callback | Array<[InputMethodProperty](#InputMethodProperty)> | Yes | Callback used to return the list of installed input methods.| | callback | Array<[InputMethodProperty](#inputmethodproperty8)> | Yes | Callback used to return the list of installed input methods.|
**Example** **Example**
...@@ -156,13 +206,12 @@ listInputMethod(): Array&lt;InputMethodProperty&gt; ...@@ -156,13 +206,12 @@ listInputMethod(): Array&lt;InputMethodProperty&gt;
Obtains the list of installed input methods. This API uses an asynchronous callback to return the result. Obtains the list of installed input methods. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ---------------------- | | ----------------------------------------------------------- | ---------------------- |
| Promise<Array<[InputMethodProperty](#InputMethodProperty)>> | Promise used to return the list of installed input methods.| | Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return the list of installed input methods. |
**Example** **Example**
...@@ -180,15 +229,16 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void ...@@ -180,15 +229,16 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the execution result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the execution result.|
**Example** **Example**
```js ```js
InputMethodSetting.displayOptionalInputMethod(()=>{ InputMethodSetting.displayOptionalInputMethod(()=>{
console.info('displayOptionalInputMethod is called'); console.info('displayOptionalInputMethod is called');
...@@ -197,17 +247,17 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono ...@@ -197,17 +247,17 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono
### displayOptionalInputMethod ### displayOptionalInputMethod
displayOptionalInputMethod(): Promise&lt;void&gt; displayOptionalInputMethod(): Promise&lt;void&gt;
Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the execution result.| | Promise&lt;void&gt; | Promise used to return the execution result. |
**Example** **Example**
......
# Input Method Engine # Input Method Engine
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. The **inputMethodEngine** module streamlines the interaction between applications and input methods. By calling APIs of this module, applications can accept text input through the input methods, be bound to input method services, request the keyboard to display or hide, listen for the input method status, and much more.
> **NOTE**
> >
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
``` ```
import inputMethodEngine from '@ohos.inputMethodEngine'; import inputMethodEngine from '@ohos.inputmethodengine';
``` ```
## inputMethodEngine ## inputMethodEngine
Defines constant values. Provides the constants.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
...@@ -50,7 +53,7 @@ getInputMethodEngine(): InputMethodEngine ...@@ -50,7 +53,7 @@ getInputMethodEngine(): InputMethodEngine
Obtains an **InputMethodEngine** instance. Obtains an **InputMethodEngine** instance.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
...@@ -60,9 +63,9 @@ Obtains an **InputMethodEngine** instance. ...@@ -60,9 +63,9 @@ Obtains an **InputMethodEngine** instance.
**Example** **Example**
```js ```js
var InputMethodEngine = inputMethodEngine.getInputMethodEngine(); var InputMethodEngine = inputMethodEngine.getInputMethodEngine();
``` ```
## inputMethodEngine.createKeyboardDelegate<a name="createKeyboardDelegate"></a> ## inputMethodEngine.createKeyboardDelegate<a name="createKeyboardDelegate"></a>
...@@ -70,7 +73,7 @@ createKeyboardDelegate(): KeyboardDelegate ...@@ -70,7 +73,7 @@ createKeyboardDelegate(): KeyboardDelegate
Obtains a **KeyboardDelegate** instance. Obtains a **KeyboardDelegate** instance.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
...@@ -80,9 +83,9 @@ Obtains a **KeyboardDelegate** instance. ...@@ -80,9 +83,9 @@ Obtains a **KeyboardDelegate** instance.
**Example** **Example**
```js ```js
var KeyboardDelegate = inputMethodEngine.createKeyboardDelegate(); var KeyboardDelegate = inputMethodEngine.createKeyboardDelegate();
``` ```
## InputMethodEngine<a name="InputMethodEngine"></a> ## InputMethodEngine<a name="InputMethodEngine"></a>
...@@ -94,7 +97,7 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli ...@@ -94,7 +97,7 @@ on(type: 'inputStart', callback: (kbController: KeyboardController, textInputCli
Listens for the input method binding event. This API uses a callback to return the result. Listens for the input method binding event. This API uses a callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
...@@ -105,12 +108,12 @@ Listens for the input method binding event. This API uses a callback to return t ...@@ -105,12 +108,12 @@ Listens for the input method binding event. This API uses a callback to return t
**Example** **Example**
```js ```js
InputMethodEngine.on('inputStart', (kbController, textInputClient) => { InputMethodEngine.on('inputStart', (kbController, textInputClient) => {
KeyboardController = kbController; KeyboardController = kbController;
TextInputClient = textInputClient; TextInputClient = textInputClient;
}); });
``` ```
### off('inputStart') ### off('inputStart')
...@@ -118,7 +121,7 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC ...@@ -118,7 +121,7 @@ off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputC
Cancels listening for the input method binding event. Cancels listening for the input method binding event.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
...@@ -127,11 +130,13 @@ Cancels listening for the input method binding event. ...@@ -127,11 +130,13 @@ Cancels listening for the input method binding event.
| type | string | Yes | Listening type.<br>Set it to **'inputStart'**, which indicates listening for the input method binding event.| | type | string | Yes | Listening type.<br>Set it to **'inputStart'**, which indicates listening for the input method binding event.|
| callback | [KeyboardController](#KeyboardController), [TextInputClient](#TextInputClient) | No| Callback used to return the result.| | callback | [KeyboardController](#KeyboardController), [TextInputClient](#TextInputClient) | No| Callback used to return the result.|
**Example** **Example**
```js ```js
InputMethodEngine.off('inputStart'); InputMethodEngine.off('inputStart');
``` ```
### on('keyboardShow'|'keyboardHide') ### on('keyboardShow'|'keyboardHide')
...@@ -139,22 +144,22 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void ...@@ -139,22 +144,22 @@ on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
Listens for an input method event. Listens for an input method event.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** means to listen for displaying of the input method.<br>- The value **'keyboardHide'** means to listen for hiding of the input method.| | type | string | Yes | Listening type.<br>-&nbsp;The value **'keyboardShow'** means to listen for displaying of the input method.<br>-&nbsp;The value **'keyboardHide'** means to listen for hiding of the input method.|
| callback | void | No | Callback used to return the result. | | callback | void | No | Callback used to return the result. |
**Example** **Example**
```js ```js
InputMethodEngine.on('keyboardShow', (err) => { InputMethodEngine.on('keyboardShow', (err) => {
console.info('keyboardShow'); console.info('keyboardShow');
}); });
``` ```
### off('keyboardShow'|'keyboardHide') ### off('keyboardShow'|'keyboardHide')
...@@ -162,20 +167,21 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void ...@@ -162,20 +167,21 @@ off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
Cancels listening for an input method event. Cancels listening for an input method event.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** means to listen for displaying of the input method.<br>- The value **'keyboardHide'** means to listen for hiding of the input method.| | type | string | Yes | Listening type.<br>-&nbsp;The value **'keyboardShow'** means to listen for displaying of the input method.<br>-&nbsp;The value **'keyboardHide'** means to listen for hiding of the input method.|
| callback | void | No | Callback used to return the result. | | callback | void | No | Callback used to return the result. |
**Example** **Example**
```js ```js
InputMethodEngine.off('keyboardShow'); InputMethodEngine.off('keyboardShow');
``` ```
## KeyboardDelegate<a name="KeyboardDelegate"></a> ## KeyboardDelegate<a name="KeyboardDelegate"></a>
...@@ -187,22 +193,24 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void ...@@ -187,22 +193,24 @@ on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
Listens for a hard keyboard even. This API uses a callback to return the key information. Listens for a hard keyboard even. This API uses a callback to return the key information.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>- The value **'keyDown'** means to listen for pressing of a key.<br>- The value **'keyUp'** means to listen for releasing of a key.| | type | string | Yes | Listening type.<br>-&nbsp;The value **'keyDown'** means to listen for pressing of a key.<br>-&nbsp;The value **'keyUp'** means to listen for releasing of a key.|
| callback | [KeyEvent](#KeyEvent) | Yes| Callback used to return the key information.| | callback | [KeyEvent](#KeyEvent) | Yes| Callback used to return the key information.|
**Example** **Example**
```js ```js
KeyboardDelegate.on('keyDown', (event) => { KeyboardDelegate.on('keyDown', (event) => {
console.info('keyDown'); console.info('keyDown');
}); });
``` ```
### off('keyDown'|'keyUp') ### off('keyDown'|'keyUp')
...@@ -210,20 +218,20 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void ...@@ -210,20 +218,20 @@ off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
Cancels listening for a hard keyboard even. Cancels listening for a hard keyboard even.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>- The value **'keyDown'** means to listen for pressing of a key.<br>- The value **'keyUp'** means to listen for releasing of a key.| | type | string | Yes | Listening type.<br>-&nbsp;The value **'keyDown'** means to listen for pressing of a key.<br>-&nbsp;The value **'keyUp'** means to listen for releasing of a key.|
| callback | [KeyEvent](#KeyEvent) | No | Callback used to return the key information. | | callback | [KeyEvent](#KeyEvent) | No | Callback used to return the key information. |
**Example** **Example**
```js ```js
KeyboardDelegate.off('keyDown'); KeyboardDelegate.off('keyDown');
``` ```
### on('cursorContextChange') ### on('cursorContextChange')
...@@ -231,21 +239,25 @@ on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) = ...@@ -231,21 +239,25 @@ on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) =
Listens for cursor context changes. This API uses a callback to return the cursor information. Listens for cursor context changes. This API uses a callback to return the cursor information.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'cursorContextChange'**, which indicates listening for cursor context changes.| | type | string | Yes | Listening type.<br>Set it to **'cursorContextChange'**, which indicates listening for cursor context changes.|
| callback | number | Yes | Callback used to return the cursor information. | | callback | number | Yes | Callback used to return the cursor information. |
**Example**
**Example**
```js ```js
KeyboardDelegate.on('cursorContextChange', (x, y, height) => { KeyboardDelegate.on('cursorContextChange', (x, y, height) => {
console.info('cursorContextChange'); console.info('cursorContextChange');
}); });
``` ```
### off('cursorContextChange') ### off('cursorContextChange')
...@@ -254,42 +266,46 @@ off(type: 'cursorContextChange', callback?: (x: number, y:number, height:number) ...@@ -254,42 +266,46 @@ off(type: 'cursorContextChange', callback?: (x: number, y:number, height:number)
Cancels listening for cursor context changes. Cancels listening for cursor context changes.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'cursorContextChange'**, which indicates listening for cursor context changes.| | type | string | Yes | Listening type.<br>Set it to **'cursorContextChange'**, which indicates listening for cursor context changes.|
| callback | number | No| Callback used to return the cursor information.| | callback | number | No | Callback used to return the cursor information. |
**Example**
**Example**
```js ```js
KeyboardDelegate.off('cursorContextChange'); KeyboardDelegate.off('cursorContextChange');
```
```
### on('selectionChange') ### on('selectionChange')
on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
Listens for text selection changes. This API uses a callback to return the text selection information. Listens for text selection changes. This API uses a callback to return the text selection information.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'selectionChange'**, which indicates listening for text selection changes.| | type | string | Yes | Listening type.<br>Set it to **'selectionChange'**, which indicates listening for text selection changes.|
| callback | number | Yes | Callback used to return the text selection information. | | callback | number | Yes | Callback used to return the text selection information. |
**Example** **Example**
```js ```js
KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { KeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
console.info('selectionChange'); console.info('selectionChange');
}); });
``` ```
### off('selectionChange') ### off('selectionChange')
...@@ -298,19 +314,21 @@ off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBe ...@@ -298,19 +314,21 @@ off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBe
Cancels listening for text selection changes. Cancels listening for text selection changes.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'selectionChange'**, which indicates listening for text selection changes.| | type | string | Yes | Listening type.<br>Set it to **'selectionChange'**, which indicates listening for text selection changes.|
| callback | number | No| Callback used to return the text selection information.| | callback | number | No | Callback used to return the text selection information. |
**Example** **Example**
```js ```js
KeyboardDelegate.off('selectionChange'); KeyboardDelegate.off('selectionChange');
``` ```
...@@ -320,21 +338,23 @@ on(type: 'textChange', callback: (text: string) => void): void ...@@ -320,21 +338,23 @@ on(type: 'textChange', callback: (text: string) => void): void
Listens for text changes. This API uses a callback to return the current text content. Listens for text changes. This API uses a callback to return the current text content.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'textChange'**, which indicates listening for text changes.| | type | string | Yes | Listening type.<br>Set it to **'textChange'**, which indicates listening for text changes.|
| callback | string | Yes| Callback used to return the current text content.| | callback | string | Yes | Callback used to return the current text content. |
**Example** **Example**
```js ```js
KeyboardDelegate.on('textChange', (text) => { KeyboardDelegate.on('textChange', (text) => {
console.info('textChange'); console.info('textChange');
}); });
``` ```
### off('textChange') ### off('textChange')
...@@ -343,16 +363,16 @@ off(type: 'textChange', callback?: (text: string) => void): void ...@@ -343,16 +363,16 @@ off(type: 'textChange', callback?: (text: string) => void): void
Cancels listening for text changes. Cancels listening for text changes.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Listening type.<br>Set it to **'textChange'**, which indicates listening for text changes.| | type | string | Yes | Listening type.<br>Set it to **'textChange'**, which indicates listening for text changes.|
| callback | string | No| Callback used to return the current text content.| | callback | string | No | Callback used to return the current text content. |
**Example** **Example**
```js ```js
KeyboardDelegate.off('textChange'); KeyboardDelegate.off('textChange');
...@@ -368,7 +388,7 @@ hideKeyboard(callback: AsyncCallback&lt;void&gt;): void ...@@ -368,7 +388,7 @@ hideKeyboard(callback: AsyncCallback&lt;void&gt;): void
Hides the keyboard. This API uses an asynchronous callback to return the result. Hides the keyboard. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
...@@ -388,19 +408,18 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. ...@@ -388,19 +408,18 @@ Hides the keyboard. This API uses an asynchronous callback to return the result.
hideKeyboard(): Promise&lt;void&gt; hideKeyboard(): Promise&lt;void&gt;
Hides the keyboard. This API uses a promise to return the result. Hides the keyboard. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type | Description: | | Type | Description |
| ---------------- | -------- | | ---------------- | -------- |
| Promise&lt;void> | Promise used to return the result.| | Promise&lt;void> | Promise used to return the result.|
**Example** **Example**
```js ```js
KeyboardController.hideKeyboard(); KeyboardController.hideKeyboard();
``` ```
...@@ -415,30 +434,30 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -415,30 +434,30 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result. Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.| | length | number | Yes| Text length.|
| callback | AsyncCallback&lt;string&gt; | Yes| Text returned.| | callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the text.|
**Example** **Example**
```js ```js
TextInputClient.getForward(5,(text) =>{ TextInputClient.getForward(5,(text) =>{
console.info("text = " + text); console.info("text = " + text);
}); });
``` ```
### getForward ### getForward
getForward(length:number): Promise&lt;string&gt; getForward(length:number): Promise&lt;string&gt;
Obtains the specific-length text before the cursor. This API uses a promise to return the result. Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
...@@ -450,14 +469,14 @@ Obtains the specific-length text before the cursor. This API uses a promise to r ...@@ -450,14 +469,14 @@ Obtains the specific-length text before the cursor. This API uses a promise to r
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Text returned. | | Promise&lt;string&gt; | Promise used to return the text. |
**Example** **Example**
```js ```js
var text = TextInputClient.getForward(5); var text = TextInputClient.getForward(5);
console.info("text = " + text); console.info("text = " + text);
``` ```
### getBackward ### getBackward
...@@ -465,30 +484,30 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -465,30 +484,30 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result. Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.| | length | number | Yes| Text length.|
| callback | AsyncCallback&lt;string&gt; | Yes| Text returned.| | callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the text.|
**Example** **Example**
```js ```js
TextInputClient.getBackward(5,(text)=>{ TextInputClient.getBackward(5,(text)=>{
console.info("text = " + text); console.info("text = " + text);
}); });
``` ```
### getBackward ### getBackward
getBackward(length:number): Promise&lt;string&gt; getBackward(length:number): Promise&lt;string&gt;
Obtains the specific-length text after the cursor. This API uses a promise to return the result. Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
...@@ -500,14 +519,14 @@ Obtains the specific-length text after the cursor. This API uses a promise to re ...@@ -500,14 +519,14 @@ Obtains the specific-length text after the cursor. This API uses a promise to re
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Text returned. | | Promise&lt;string&gt; | Promise used to return the text. |
**Example** **Example**
```js ```js
var text = TextInputClient.getBackward(5); var text = TextInputClient.getBackward(5);
console.info("text = " + text); console.info("text = " + text);
``` ```
### deleteForward ### deleteForward
...@@ -515,47 +534,46 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -515,47 +534,46 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result. Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.| | length | number | Yes| Text length.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Returns whether the operation is successful.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.|
**Example** **Example**
```js ```js
TextInputClient.deleteForward(5,(isSuccess)=>{ TextInputClient.deleteForward(5,(isSuccess)=>{
console.info("isSuccess = " + isSuccess); console.info("isSuccess = " + isSuccess);
}); });
``` ```
### deleteForward ### deleteForward
deleteForward(length:number): Promise&lt;boolean&gt; deleteForward(length:number): Promise&lt;boolean&gt;
Deletes the fixed-length text before the cursor. This API uses a promise to return the result. Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | ------ | ------ | ---- | ---------- |
| length | number | Yes| Text length.| | length | number | Yes | Text length.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ---------------------- | -------------- |
| Promise&lt;boolean&gt; | Returns whether the operation is successful. | | Promise&lt;boolean&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
var isSuccess = TextInputClient.deleteForward(5); var isSuccess = TextInputClient.deleteForward(5);
console.info("isSuccess = " + isSuccess); console.info("isSuccess = " + isSuccess);
``` ```
...@@ -565,33 +583,34 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -565,33 +583,34 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result. Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | -------- | ---------------------------- | ---- | -------------- |
| length | number | Yes| Text length.| | length | number | Yes | Text length. |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Returns whether the operation is successful.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
TextInputClient.deleteBackward(5, (isSuccess)=>{ TextInputClient.deleteBackward(5, (isSuccess)=>{
console.info("isSuccess = " + isSuccess); console.info("isSuccess = " + isSuccess);
}); });
``` ```
### deleteBackward ### deleteBackward
deleteBackward(length:number): Promise&lt;boolean&gt; deleteBackward(length:number): Promise&lt;boolean&gt;
Deletes the fixed-length text after the cursor. This API uses a promise to return the result. Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| length | number | Yes| Text length.| | length | number | Yes| Text length.|
...@@ -600,45 +619,48 @@ Deletes the fixed-length text after the cursor. This API uses a promise to retur ...@@ -600,45 +619,48 @@ Deletes the fixed-length text after the cursor. This API uses a promise to retur
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Returns whether the operation is successful. | | Promise&lt;boolean&gt; | Promise used to return the result. |
**Example** **Example**
```js ```js
var isSuccess = TextInputClient.deleteBackward(5);
console.info("isSuccess = " + isSuccess);
```
var isSuccess = TextInputClient.deleteBackward(5);
console.info("isSuccess = " + isSuccess);
```
### sendKeyFunction ### sendKeyFunction
sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
Sets the Enter key to send the text to its target. This API uses an asynchronous callback to return the result. Sets the Enter key to send the text to its target. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| action | number | Yes| Edit box attribute.| | action | number | Yes| Edit box attribute.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Returns whether the operation is successful.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.|
**Example** **Example**
```js ```js
TextInputClient.sendKeyFunction(inputMethod.ENTER_KEY_TYPE_NEXT,(isSuccess)=>{ TextInputClient.sendKeyFunction(inputMethod.ENTER_KEY_TYPE_NEXT,(isSuccess)=>{
console.info("isSuccess = " + isSuccess); console.info("isSuccess = " + isSuccess);
}); });
``` ```
### sendKeyFunction ### sendKeyFunction
sendKeyFunction(action:number): Promise&lt;boolean&gt; sendKeyFunction(action:number): Promise&lt;boolean&gt;
Sets the Enter key to send the text to its target. This API uses a promise to return the result. Sets the Enter key to send the text to its target. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
...@@ -650,14 +672,14 @@ Sets the Enter key to send the text to its target. This API uses a promise to re ...@@ -650,14 +672,14 @@ Sets the Enter key to send the text to its target. This API uses a promise to re
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Returns whether the operation is successful. | | Promise&lt;boolean&gt; | Promise used to return the result. |
**Example** **Example**
```js ```js
var isSuccess = TextInputClient.sendKeyFunction(inputMethod.ENTER_KEY_TYPE_NEXT); var isSuccess = TextInputClient.sendKeyFunction(inputMethod.ENTER_KEY_TYPE_NEXT);
console.info("isSuccess = " + isSuccess); console.info("isSuccess = " + isSuccess);
``` ```
### insertText ### insertText
...@@ -665,30 +687,32 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -665,30 +687,32 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
Inserts text. This API uses an asynchronous callback to return the result. Inserts text. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| text | string | Yes| Text to insert.| | text | string | Yes| Text to insert.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Returns whether the operation is successful.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.|
**Example** **Example**
```js ```js
TextInputClient.insertText("test", (isSuccess)=>{ TextInputClient.insertText("test", (isSuccess)=>{
console.info("isSuccess = " + isSuccess); console.info("isSuccess = " + isSuccess);
}); });
``` ```
### insertText ### insertText
insertText(text:string): Promise&lt;boolean&gt; insertText(text:string): Promise&lt;boolean&gt;
Inserts text. This API uses a promise to return the result. Inserts text. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
...@@ -700,14 +724,14 @@ Inserts text. This API uses a promise to return the result. ...@@ -700,14 +724,14 @@ Inserts text. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Returns whether the operation is successful. | | Promise&lt;boolean&gt; | Promise used to return the result. |
**Example** **Example**
```js ```js
var isSuccess = TextInputClient.insertText("test"); var isSuccess = TextInputClient.insertText("test");
console.info("isSuccess = " + isSuccess); console.info("isSuccess = " + isSuccess);
``` ```
### getEditorAttribute ### getEditorAttribute
...@@ -715,7 +739,7 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void ...@@ -715,7 +739,7 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result. Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Parameters** **Parameters**
...@@ -725,36 +749,36 @@ Obtains the attribute of the edit box. This API uses an asynchronous callback to ...@@ -725,36 +749,36 @@ Obtains the attribute of the edit box. This API uses an asynchronous callback to
**Example** **Example**
```js ```js
TextInputClient.getEditorAttribute((EditorAttribute)=>{ TextInputClient.getEditorAttribute((EditorAttribute)=>{
}); });
``` ```
### getEditorAttribute ### getEditorAttribute
getEditorAttribute(): EditorAttribute getEditorAttribute(): EditorAttribute
Obtains the attribute of the edit box. This API uses a promise to return the result. Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------------ |
| Promise&lt;[EditorAttribute](#EditorAttribute)&gt; | Returns the attribute of the edit box. | | Promise&lt;[EditorAttribute](#EditorAttribute)&gt; | Promise used to return the attribute of the edit box. |
**Example** **Example**
```js ```js
var EditorAttribute = TextInputClient.getEditorAttribute(); var EditorAttribute = TextInputClient.getEditorAttribute();
``` ```
## EditorAttribute<a name="EditorAttribute"></a> ## EditorAttribute<a name="EditorAttribute"></a>
Describes the attribute of the edit box. Describes the attribute of the edit box.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
| Name | Type| Readable| Writable| Description | | Name | Type| Readable| Writable| Description |
| ------------ | -------- | ---- | ---- | ------------------ | | ------------ | -------- | ---- | ---- | ------------------ |
...@@ -765,7 +789,7 @@ Describes the attribute of the edit box. ...@@ -765,7 +789,7 @@ Describes the attribute of the edit box.
Describes the attribute of a key. Describes the attribute of a key.
**System capability**: SystemCapability.Miscservices.InputMethodFramework **System capability**: SystemCapability.MiscServices.InputMethodFramework
| Name | Type| Readable| Writable| Description | | Name | Type| Readable| Writable| Description |
| --------- | -------- | ---- | ---- | ------------ | | --------- | -------- | ---- | ---- | ------------ |
......
# Standard NFC # Standard NFC
Implements Near-Field Communication (NFC). The **nfcController** module implements Near-Field Communication (NFC).
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import** ## **Modules to Import**
...@@ -19,6 +19,8 @@ isNfcAvailable(): boolean ...@@ -19,6 +19,8 @@ isNfcAvailable(): boolean
Checks whether NFC is available. Checks whether NFC is available.
**System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
...@@ -34,7 +36,7 @@ Opens NFC. ...@@ -34,7 +36,7 @@ Opens NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -50,7 +52,7 @@ Closes NFC. ...@@ -50,7 +52,7 @@ Closes NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -64,7 +66,7 @@ isNfcOpen(): boolean ...@@ -64,7 +66,7 @@ isNfcOpen(): boolean
Checks whether NFC is open. Checks whether NFC is open.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -78,7 +80,7 @@ getNfcState(): NfcState ...@@ -78,7 +80,7 @@ getNfcState(): NfcState
Obtains the NFC state. Obtains the NFC state.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -92,7 +94,7 @@ on(type: "nfcStateChange", callback: Callback&lt;NfcState&gt;): void ...@@ -92,7 +94,7 @@ on(type: "nfcStateChange", callback: Callback&lt;NfcState&gt;): void
Subscribes to NFC state changes. Subscribes to NFC state changes.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameter**
...@@ -109,7 +111,7 @@ off(type: "nfcStateChange", callback?: Callback&lt;NfcState&gt;): void ...@@ -109,7 +111,7 @@ off(type: "nfcStateChange", callback?: Callback&lt;NfcState&gt;): void
Unsubscribes from the NFC state changes. Unsubscribes from the NFC state changes.
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameter**
...@@ -140,6 +142,8 @@ Unsubscribes from the NFC state changes. ...@@ -140,6 +142,8 @@ Unsubscribes from the NFC state changes.
Enumerates the NFC states. Enumerates the NFC states.
**System capability**: SystemCapability.Communication.NFC.Core
| Name| Default Value| Description| | Name| Default Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| STATE_OFF | 1 | Off| | STATE_OFF | 1 | Off|
......
# Standard NFC Tag # Standard NFC Tag
Manages Near-Field Communication (NFC) tags. The **nfcTag** module provides methods for managing Near-Field Communication (NFC) tags.
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import** ## **Modules to Import**
...@@ -12,7 +11,6 @@ Manages Near-Field Communication (NFC) tags. ...@@ -12,7 +11,6 @@ Manages Near-Field Communication (NFC) tags.
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
``` ```
## tag.getNfcATag ## tag.getNfcATag
getNfcATag(tagInfo: TagInfo): NfcATag getNfcATag(tagInfo: TagInfo): NfcATag
...@@ -21,7 +19,7 @@ Obtains an **NfcATag** object, which allows access to the tags that use the NFC- ...@@ -21,7 +19,7 @@ Obtains an **NfcATag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -37,7 +35,7 @@ Obtains an **NfcBTag** object, which allows access to the tags that use the NFC- ...@@ -37,7 +35,7 @@ Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -53,7 +51,7 @@ Obtains an **NfcFTag** object, which allows access to the tags that use the NFC- ...@@ -53,7 +51,7 @@ Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -69,10 +67,11 @@ Obtains an **NfcVTag** object, which allows access to the tags that use the NFC- ...@@ -69,10 +67,11 @@ Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
| **Type**| **Description** | | **Type**| **Description** |
| -------- | ---------------- | | -------- | ---------------- |
| NfcVTag | **NfcVTag** object obtained.| | NfcVTag | **NfcVTag** object obtained.|
# Notification # Notification
The **Notification** module provides notification management capabilities, covering notifications, notification slots, notification subscription, notification enabled status, and notification badge status.
Generally, only system applications have the permission to subscribe to and unsubscribe from notifications.
> **NOTE**<br> > **NOTE**<br>
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -21,7 +26,7 @@ Publishes a notification. This API uses an asynchronous callback to return the r ...@@ -21,7 +26,7 @@ Publishes a notification. This API uses an asynchronous callback to return the r
| Name | Readable| Writable| Type | Mandatory| Description | | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | ---- | ------------------------------------------- | ---- | ------------------------------------------- | | -------- | ---- | ---- | ------------------------------------------- | ---- | ------------------------------------------- |
| request | Yes | No |[NotificationRequest](#notificationrequest) | Yes | Notification to publish.| | request | Yes | No |[NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.|
| callback | Yes | No |AsyncCallback\<void\> | Yes | Callback used to return the result. | | callback | Yes | No |AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -85,13 +90,15 @@ Publishes a notification. This API uses an asynchronous callback to return the r ...@@ -85,13 +90,15 @@ Publishes a notification. This API uses an asynchronous callback to return the r
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Readable| Writable| Type | Mandatory| Description | | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | ---- | ----------------------------------------- | ---- | ------------------------------------------- | | -------- | ---- | ---- | ----------------------------------------- | ---- | ------------------------------------------- |
| request | Yes | No |[NotificationRequest](#notificationrequest) | Yes | Notification to publish.| | request | Yes | No |[NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.|
| userId | Yes | No |number | Yes | ID of the user who receives the notification. | | userId | Yes | No |number | Yes | ID of the user who receives the notification. |
| callback | Yes | No |AsyncCallback\<void\> | Yes | Callback used to return the result. | | callback | Yes | No |AsyncCallback\<void\> | Yes | Callback used to return the result. |
...@@ -127,13 +134,15 @@ Publishes a notification. This API uses a promise to return the result. ...@@ -127,13 +134,15 @@ Publishes a notification. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Readable| Writable| Type | Mandatory| Description | | Name | Readable| Writable| Type | Mandatory| Description |
| -------- | ---- | ---- | ----------------------------------------- | ---- | ------------------------------------------- | | -------- | ---- | ---- | ----------------------------------------- | ---- | ------------------------------------------- |
| request | Yes | No |[NotificationRequest](#notificationrequest) | Yes | Notification to publish.| | request | Yes | No |[NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.|
| userId | Yes | No |number | Yes | ID of the user who receives the notification. | | userId | Yes | No |number | Yes | ID of the user who receives the notification. |
**Example** **Example**
...@@ -291,6 +300,8 @@ Adds a notification slot. This API uses an asynchronous callback to return the r ...@@ -291,6 +300,8 @@ Adds a notification slot. This API uses an asynchronous callback to return the r
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -324,6 +335,8 @@ Adds a notification slot. This API uses a promise to return the result. ...@@ -324,6 +335,8 @@ Adds a notification slot. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -405,6 +418,8 @@ Adds multiple notification slots. This API uses an asynchronous callback to retu ...@@ -405,6 +418,8 @@ Adds multiple notification slots. This API uses an asynchronous callback to retu
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -442,6 +457,8 @@ Adds multiple notification slots. This API uses a promise to return the result. ...@@ -442,6 +457,8 @@ Adds multiple notification slots. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -681,6 +698,8 @@ Subscribes to a notification with the subscription information specified. This A ...@@ -681,6 +698,8 @@ Subscribes to a notification with the subscription information specified. This A
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -720,6 +739,8 @@ Subscribes to a notification with the subscription information specified. This A ...@@ -720,6 +739,8 @@ Subscribes to a notification with the subscription information specified. This A
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -754,6 +775,8 @@ Subscribes to a notification with the subscription information specified. This A ...@@ -754,6 +775,8 @@ Subscribes to a notification with the subscription information specified. This A
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -787,6 +810,8 @@ Unsubscribes from a notification. This API uses an asynchronous callback to retu ...@@ -787,6 +810,8 @@ Unsubscribes from a notification. This API uses an asynchronous callback to retu
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -821,6 +846,8 @@ Unsubscribes from a notification. This API uses a promise to return the result. ...@@ -821,6 +846,8 @@ Unsubscribes from a notification. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -853,6 +880,8 @@ Sets whether to enable notification for a specified bundle. This API uses an asy ...@@ -853,6 +880,8 @@ Sets whether to enable notification for a specified bundle. This API uses an asy
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -885,6 +914,8 @@ Sets whether to enable notification for a specified bundle. This API uses a prom ...@@ -885,6 +914,8 @@ Sets whether to enable notification for a specified bundle. This API uses a prom
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -917,6 +948,8 @@ Checks whether notification is enabled for a specified bundle. This API uses an ...@@ -917,6 +948,8 @@ Checks whether notification is enabled for a specified bundle. This API uses an
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters** **Parameters**
| Name | Readable| Writable| Type | Mandatory| Description | | Name | Readable| Writable| Type | Mandatory| Description |
...@@ -946,6 +979,8 @@ Checks whether notification is enabled for a specified bundle. This API uses a p ...@@ -946,6 +979,8 @@ Checks whether notification is enabled for a specified bundle. This API uses a p
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -981,6 +1016,8 @@ Checks whether notification is enabled for this application. This API uses an as ...@@ -981,6 +1016,8 @@ Checks whether notification is enabled for this application. This API uses an as
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1009,6 +1046,8 @@ Checks whether notification is enabled for this application. This API uses a pro ...@@ -1009,6 +1046,8 @@ Checks whether notification is enabled for this application. This API uses a pro
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1041,6 +1080,8 @@ Sets whether to enable the notification badge for a specified bundle. This API u ...@@ -1041,6 +1080,8 @@ Sets whether to enable the notification badge for a specified bundle. This API u
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1073,6 +1114,8 @@ Sets the notification slot for a specified bundle. This API uses a promise to re ...@@ -1073,6 +1114,8 @@ Sets the notification slot for a specified bundle. This API uses a promise to re
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1103,6 +1146,8 @@ Checks whether the notification badge is enabled for a specified bundle. This AP ...@@ -1103,6 +1146,8 @@ Checks whether the notification badge is enabled for a specified bundle. This AP
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1134,6 +1179,8 @@ Checks whether the notification badge is enabled for a specified bundle. This AP ...@@ -1134,6 +1179,8 @@ Checks whether the notification badge is enabled for a specified bundle. This AP
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1169,6 +1216,8 @@ Sets the notification slot for a specified bundle. This API uses an asynchronous ...@@ -1169,6 +1216,8 @@ Sets the notification slot for a specified bundle. This API uses an asynchronous
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1204,6 +1253,8 @@ Sets the notification slot for a specified bundle. This API uses a promise to re ...@@ -1204,6 +1253,8 @@ Sets the notification slot for a specified bundle. This API uses a promise to re
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1237,6 +1288,8 @@ Obtains the notification slots of a specified bundle. This API uses an asynchron ...@@ -1237,6 +1288,8 @@ Obtains the notification slots of a specified bundle. This API uses an asynchron
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1268,6 +1321,8 @@ Obtains the notification slots of a specified bundle. This API uses a promise to ...@@ -1268,6 +1321,8 @@ Obtains the notification slots of a specified bundle. This API uses a promise to
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1303,6 +1358,8 @@ Obtains the number of notification slots of a specified bundle. This API uses an ...@@ -1303,6 +1358,8 @@ Obtains the number of notification slots of a specified bundle. This API uses an
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1334,6 +1391,8 @@ Obtains the number of notification slots of a specified bundle. This API uses a ...@@ -1334,6 +1391,8 @@ Obtains the number of notification slots of a specified bundle. This API uses a
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1369,6 +1428,8 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal ...@@ -1369,6 +1428,8 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1405,6 +1466,8 @@ Removes a notification for a specified bundle. This API uses a promise to return ...@@ -1405,6 +1466,8 @@ Removes a notification for a specified bundle. This API uses a promise to return
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1439,6 +1502,8 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal ...@@ -1439,6 +1502,8 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1470,6 +1535,8 @@ Removes a notification for a specified bundle. This API uses a promise to return ...@@ -1470,6 +1535,8 @@ Removes a notification for a specified bundle. This API uses a promise to return
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1500,6 +1567,8 @@ Removes all notifications for a specified bundle. This API uses an asynchronous ...@@ -1500,6 +1567,8 @@ Removes all notifications for a specified bundle. This API uses an asynchronous
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters** **Parameters**
| Name | Readable| Writable| Type | Mandatory| Description | | Name | Readable| Writable| Type | Mandatory| Description |
...@@ -1529,6 +1598,8 @@ Removes all notifications. This API uses an asynchronous callback to return the ...@@ -1529,6 +1598,8 @@ Removes all notifications. This API uses an asynchronous callback to return the
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1557,6 +1628,8 @@ Removes all notifications for a specified user. This API uses a promise to retur ...@@ -1557,6 +1628,8 @@ Removes all notifications for a specified user. This API uses a promise to retur
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1581,6 +1654,8 @@ Removes all notifications for a specified user. This API uses an asynchronous ca ...@@ -1581,6 +1654,8 @@ Removes all notifications for a specified user. This API uses an asynchronous ca
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1610,6 +1685,8 @@ Removes all notifications for a specified user. This API uses a promise to retur ...@@ -1610,6 +1685,8 @@ Removes all notifications for a specified user. This API uses a promise to retur
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1639,6 +1716,8 @@ Obtains all active notifications. This API uses an asynchronous callback to retu ...@@ -1639,6 +1716,8 @@ Obtains all active notifications. This API uses an asynchronous callback to retu
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1667,7 +1746,9 @@ Obtains all active notifications. This API uses a promise to return the result. ...@@ -1667,7 +1746,9 @@ Obtains all active notifications. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications. **Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.removeGroupByBundle
**Return value** **Return value**
...@@ -1847,6 +1928,8 @@ Removes a notification group for a specified bundle. This API uses an asynchrono ...@@ -1847,6 +1928,8 @@ Removes a notification group for a specified bundle. This API uses an asynchrono
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1880,6 +1963,8 @@ Removes a notification group for a specified bundle. This API uses a promise to ...@@ -1880,6 +1963,8 @@ Removes a notification group for a specified bundle. This API uses a promise to
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1909,6 +1994,8 @@ Sets the DND time. This API uses an asynchronous callback to return the result. ...@@ -1909,6 +1994,8 @@ Sets the DND time. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1944,6 +2031,8 @@ Sets the DND time. This API uses a promise to return the result. ...@@ -1944,6 +2031,8 @@ Sets the DND time. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -1974,6 +2063,8 @@ Sets the DND time for a specified user. This API uses an asynchronous callback t ...@@ -1974,6 +2063,8 @@ Sets the DND time for a specified user. This API uses an asynchronous callback t
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2012,6 +2103,8 @@ Sets the DND time for a specified user. This API uses a promise to return the re ...@@ -2012,6 +2103,8 @@ Sets the DND time for a specified user. This API uses a promise to return the re
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2046,6 +2139,8 @@ Obtains the DND time. This API uses an asynchronous callback to return the resul ...@@ -2046,6 +2139,8 @@ Obtains the DND time. This API uses an asynchronous callback to return the resul
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2074,6 +2169,8 @@ Obtains the DND time. This API uses a promise to return the result. ...@@ -2074,6 +2169,8 @@ Obtains the DND time. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Return value** **Return value**
...@@ -2099,6 +2196,10 @@ Obtains the DND time of a specified user. This API uses an asynchronous callback ...@@ -2099,6 +2196,10 @@ Obtains the DND time of a specified user. This API uses an asynchronous callback
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Readable| Writable| Type | Mandatory| Description | | Name | Readable| Writable| Type | Mandatory| Description |
...@@ -2128,6 +2229,10 @@ Obtains the DND time of a specified user. This API uses a promise to return the ...@@ -2128,6 +2229,10 @@ Obtains the DND time of a specified user. This API uses a promise to return the
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Readable| Writable| Type | Mandatory| Description | | Name | Readable| Writable| Type | Mandatory| Description |
...@@ -2159,6 +2264,8 @@ Checks whether the DND mode is supported. This API uses an asynchronous callback ...@@ -2159,6 +2264,8 @@ Checks whether the DND mode is supported. This API uses an asynchronous callback
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2187,6 +2294,8 @@ Checks whether the DND mode is supported. This API uses a promise to return the ...@@ -2187,6 +2294,8 @@ Checks whether the DND mode is supported. This API uses a promise to return the
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Return value** **Return value**
...@@ -2317,6 +2426,8 @@ Sets whether this device supports distributed notifications. This API uses an as ...@@ -2317,6 +2426,8 @@ Sets whether this device supports distributed notifications. This API uses an as
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2348,6 +2459,8 @@ Sets whether this device supports distributed notifications. This API uses a pro ...@@ -2348,6 +2459,8 @@ Sets whether this device supports distributed notifications. This API uses a pro
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2426,6 +2539,8 @@ Sets whether an application supports distributed notifications based on the bund ...@@ -2426,6 +2539,8 @@ Sets whether an application supports distributed notifications based on the bund
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2456,12 +2571,14 @@ Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundle ...@@ -2456,12 +2571,14 @@ Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundle
## Notification.enableDistributedByBundle<sup>8+</sup> ## Notification.enableDistributedByBundle<sup>8+</sup>
bundleenableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise\<void> enableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise\<void>
Sets whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result. Sets whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2494,6 +2611,8 @@ Obtains whether an application supports distributed notifications based on the b ...@@ -2494,6 +2611,8 @@ Obtains whether an application supports distributed notifications based on the b
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2527,6 +2646,8 @@ Obtains whether an application supports distributed notifications based on the b ...@@ -2527,6 +2646,8 @@ Obtains whether an application supports distributed notifications based on the b
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2563,6 +2684,8 @@ Obtains the notification reminder type. This API uses an asynchronous callback t ...@@ -2563,6 +2684,8 @@ Obtains the notification reminder type. This API uses an asynchronous callback t
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2591,6 +2714,8 @@ Obtains the notification reminder type. This API uses a promise to return the re ...@@ -2591,6 +2714,8 @@ Obtains the notification reminder type. This API uses a promise to return the re
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Return value** **Return value**
...@@ -2608,6 +2733,7 @@ Notification.getDeviceRemindType() ...@@ -2608,6 +2733,7 @@ Notification.getDeviceRemindType()
}); });
``` ```
## Notification.publishAsBundle<sup>9+</sup> ## Notification.publishAsBundle<sup>9+</sup>
publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void
...@@ -2616,14 +2742,15 @@ Publishes an agent-powered notification. This API uses an asynchronous callback ...@@ -2616,14 +2742,15 @@ Publishes an agent-powered notification. This API uses an asynchronous callback
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | | -------------------- | ------------------------------------------- | ---- | --------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | Notification to publish.| | request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.|
| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. |
| userId | number | Yes | ID of the user who receives the notification. | | userId | number | Yes | ID of the user who receives the notification. |
| callback | AsyncCallback | Yes | Callback used to return the result. | | callback | AsyncCallback | Yes | Callback used to return the result. |
...@@ -2663,6 +2790,8 @@ Publishes a notification through the reminder agent. This API uses a promise to ...@@ -2663,6 +2790,8 @@ Publishes a notification through the reminder agent. This API uses a promise to
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
...@@ -2670,7 +2799,7 @@ Publishes a notification through the reminder agent. This API uses a promise to ...@@ -2670,7 +2799,7 @@ Publishes a notification through the reminder agent. This API uses a promise to
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | | -------------------- | ------------------------------------------- | ---- | --------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | Notification to publish.| | request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.|
| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. |
| userId | number | Yes | ID of the user who receives the notification. | | userId | number | Yes | ID of the user who receives the notification. |
...@@ -2707,6 +2836,8 @@ Cancels a notification published by the reminder agent. This API uses an asynchr ...@@ -2707,6 +2836,8 @@ Cancels a notification published by the reminder agent. This API uses an asynchr
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**Parameters** **Parameters**
...@@ -2740,6 +2871,8 @@ Publishes a notification through the reminder agent. This API uses a promise to ...@@ -2740,6 +2871,8 @@ Publishes a notification through the reminder agent. This API uses a promise to
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**Parameters** **Parameters**
...@@ -2762,9 +2895,9 @@ Notification.cancelAsBundle(0, representativeBundle, userId).then(() => { ...@@ -2762,9 +2895,9 @@ Notification.cancelAsBundle(0, representativeBundle, userId).then(() => {
}); });
``` ```
## Notification.enableNotificationSlot<sup>9+</sup> ## Notification.enableNotificationSlot <sup>9+</sup>
enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback<void>): void enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\<void>): void
Sets the enabled status for a notification slot of a specified type. This API uses an asynchronous callback to return the result. Sets the enabled status for a notification slot of a specified type. This API uses an asynchronous callback to return the result.
...@@ -2772,6 +2905,8 @@ Sets the enabled status for a notification slot of a specified type. This API us ...@@ -2772,6 +2905,8 @@ Sets the enabled status for a notification slot of a specified type. This API us
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
...@@ -2791,14 +2926,14 @@ function enableSlotCallback(err) { ...@@ -2791,14 +2926,14 @@ function enableSlotCallback(err) {
Notification.enableNotificationSlot( Notification.enableNotificationSlot(
{ bundle: "ohos.samples.notification", }, { bundle: "ohos.samples.notification", },
notify.SlotType.SOCIAL_COMMUNICATION, Notification.SlotType.SOCIAL_COMMUNICATION,
true, true,
enableSlotCallback); enableSlotCallback);
``` ```
## Notification.enableNotificationSlot<sup>9+</sup> ## Notification.enableNotificationSlot <sup>9+</sup>
enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise<void> enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise\<void>
Sets the enabled status for a notification slot of a specified type. This API uses a promise to return the result. Sets the enabled status for a notification slot of a specified type. This API uses a promise to return the result.
...@@ -2806,6 +2941,8 @@ Sets the enabled status for a notification slot of a specified type. This API us ...@@ -2806,6 +2941,8 @@ Sets the enabled status for a notification slot of a specified type. This API us
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
...@@ -2820,29 +2957,31 @@ Sets the enabled status for a notification slot of a specified type. This API us ...@@ -2820,29 +2957,31 @@ Sets the enabled status for a notification slot of a specified type. This API us
//enableNotificationSlot //enableNotificationSlot
Notification.enableNotificationSlot( Notification.enableNotificationSlot(
{ bundle: "ohos.samples.notification", }, { bundle: "ohos.samples.notification", },
notify.SlotType.SOCIAL_COMMUNICATION, Notification.SlotType.SOCIAL_COMMUNICATION,
true).then(() => { true).then(() => {
console.log('====================>enableNotificationSlot====================>'); console.log('====================>enableNotificationSlot====================>');
}); });
``` ```
## Notification.isNotificationSlotEnabled<sup>9+</sup> ## Notification.isNotificationSlotEnabled <sup>9+</sup>
isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback<boolean>): void isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\<boolean\>): void
Obtains the enabled status of a notification slot of a specified type. This API uses an asynchronous callback to return the result. Obtains the enabled status of the notification slot of a specified type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------- | ---- | ---------------------- | | -------- | ----------------------------- | ---- | ---------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information. |
| type | [SlotType](#slottype) | Yes | Notification slot type. | | type | [SlotType](#slottype) | Yes | Notification slot type. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -2854,20 +2993,22 @@ function getEnableSlotCallback(err, data) { ...@@ -2854,20 +2993,22 @@ function getEnableSlotCallback(err, data) {
Notification.isNotificationSlotEnabled( Notification.isNotificationSlotEnabled(
{ bundle: "ohos.samples.notification", }, { bundle: "ohos.samples.notification", },
notify.SlotType.SOCIAL_COMMUNICATION, Notification.SlotType.SOCIAL_COMMUNICATION,
getEnableSlotCallback); getEnableSlotCallback);
``` ```
## Notification.isNotificationSlotEnabled<sup>9+</sup> ## Notification.isNotificationSlotEnabled <sup>9+</sup>
isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise<boolean> isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\<boolean\>
Obtains the enabled status of a notification slot of a specified type. This API uses a promise to return the result. Obtains the enabled status of the notification slot of a specified type. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
...@@ -2875,30 +3016,180 @@ Obtains the enabled status of a notification slot of a specified type. This API ...@@ -2875,30 +3016,180 @@ Obtains the enabled status of a notification slot of a specified type. This API
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information. |
| type | [SlotType](#slottype) | Yes | Notification slot type.| | type | [SlotType](#slottype) | Yes | Notification slot type.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the enabled status of the notification slot of the specified type.|
**Example** **Example**
```js ```js
//isNotificationSlotEnabled //isNotificationSlotEnabled
Notification.isNotificationSlotEnabled( Notification.isNotificationSlotEnabled(
{ bundle: "ohos.samples.notification", }, { bundle: "ohos.samples.notification", },
notify.SlotType.SOCIAL_COMMUNICATION, Notification.SlotType.SOCIAL_COMMUNICATION
true).then((data) => { ).then((data) => {
console.log('====================>isNotificationSlotEnabled====================>'); console.log('====================>isNotificationSlotEnabled====================>');
}); });
``` ```
## Notification.setSyncNotificationEnabledForUninstallApp<sup>9+</sup>
setSyncNotificationEnabledForUninstallApp(userId: number, enable: boolean, callback: AsyncCallback\<void\>): void
Sets whether to sync notifications to devices where the application is not installed. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes | User ID. |
| enable | boolean | Yes | Whether to sync notifications to devices where the application is not installed. The value **true** means to sync notifications to devices where the application is not installed, and **false** means the opposite.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example**
```js
let userId = 100;
let enable = true;
function setSyncNotificationEnabledForUninstallAppCallback(err) {
console.log('setSyncNotificationEnabledForUninstallAppCallback');
}
Notification.setSyncNotificationEnabledForUninstallApp(userId, enable, setSyncNotificationEnabledForUninstallAppCallback);
```
## Notification.setSyncNotificationEnabledForUninstallApp<sup>9+</sup>
setSyncNotificationEnabledForUninstallApp(userId: number, enable: boolean): Promise\<void>
Sets whether to sync notifications to devices where the application is not installed. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes | User ID. |
| enable | boolean | Yes | Whether to sync notifications to devices where the application is not installed. The value **true** means to sync notifications to devices where the application is not installed, and **false** means the opposite.|
**Example**
```js
let userId = 100;
let enable = true;
Notification.setSyncNotificationEnabledForUninstallApp(userId, enable)
.then((data) => {
console.log('setSyncNotificationEnabledForUninstallApp, data:', data);
})
.catch((err) => {
console.log('setSyncNotificationEnabledForUninstallApp, err:', err);
});
```
## Notification.getSyncNotificationEnabledForUninstallApp<sup>9+</sup>
getSyncNotificationEnabledForUninstallApp(userId: number, callback: AsyncCallback\<boolean>): void
Checks whether notifications are synced to devices where the application is not installed. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes | User ID. |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result. The value **true** means that notifications are synced to devices where the application is not installed, and **false** means the opposite.|
**Example**
```js
let userId = 100;
function getSyncNotificationEnabledForUninstallAppCallback(err, data) {
console.log('getSyncNotificationEnabledForUninstallAppCallback, data: ', data);
}
Notification.getSyncNotificationEnabledForUninstallApp(userId, getSyncNotificationEnabledForUninstallAppCallback);
```
## Notification.getSyncNotificationEnabledForUninstallApp<sup>9+</sup>
getSyncNotificationEnabledForUninstallApp(userId: number): Promise\<boolean>
Checks whether notifications are synced to devices where the application is not installed. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes | User ID. |
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result. The value **true** means that notifications are synced to devices where the application is not installed, and **false** means the opposite.|
**Example**
```js
let userId = 100;
Notification.getSyncNotificationEnabledForUninstallApp(userId)
.then((data) => {
console.log('getSyncNotificationEnabledForUninstallApp, data: ', data);
})
.catch((err) => {
console.log('getSyncNotificationEnabledForUninstallApp, err: ', err);
});
```
## NotificationSubscriber ## NotificationSubscriber
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
### onConsume ### onConsume
onConsume?:(data: [SubscribeCallbackData](#subscribecallbackdata)) onConsume?: (data: [SubscribeCallbackData](#subscribecallbackdata)) => void
Callback for receiving notifications. Callback for receiving notifications.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -2940,12 +3231,14 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -2940,12 +3231,14 @@ Notification.subscribe(subscriber, subscribeCallback);
### onCancel ### onCancel
onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) => void
Callback for removing notifications. Callback for removing notifications.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -2978,12 +3271,14 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -2978,12 +3271,14 @@ Notification.subscribe(subscriber, subscribeCallback);
### onUpdate ### onUpdate
onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap)) onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap)) => void
Callback for notification sorting updates. Callback for notification sorting updates.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -3014,12 +3309,14 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3014,12 +3309,14 @@ Notification.subscribe(subscriber, subscribeCallback);
### onConnect ### onConnect
onConnect?:void onConnect?:() => void
Callback for subscription. Callback for subscription.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Example** **Example**
```javascript ```javascript
...@@ -3044,12 +3341,14 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3044,12 +3341,14 @@ Notification.subscribe(subscriber, subscribeCallback);
### onDisconnect ### onDisconnect
onDisconnect?:void onDisconnect?:() => void
Callback for unsubscription. Callback for unsubscription.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Example** **Example**
```javascript ```javascript
...@@ -3074,12 +3373,14 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3074,12 +3373,14 @@ Notification.subscribe(subscriber, subscribeCallback);
### onDestroy ### onDestroy
onDestroy?:void onDestroy?:() => void
Callback for service disconnection. Callback for service disconnection.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Example** **Example**
```javascript ```javascript
...@@ -3104,17 +3405,19 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3104,17 +3405,19 @@ Notification.subscribe(subscriber, subscribeCallback);
### onDoNotDisturbDateChange<sup>8+</sup> ### onDoNotDisturbDateChange<sup>8+</sup>
onDoNotDisturbDateChange?:(mode: Notification.[DoNotDisturbDate](#donotdisturbdate8)) onDoNotDisturbDateChange?:(mode: notification.[DoNotDisturbDate](#donotdisturbdate8)) => void
Callback for DND time setting updates. Callback for DND time setting updates.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- | | ------------ | ------------------------ | ---- | -------------------------- |
| mode | Notification.[DoNotDisturbDate](#donotdisturbdate8) | Yes| DND time setting updates.| | mode | notification.[DoNotDisturbDate](#donotdisturbdate8) | Yes| DND time setting updates.|
**Example** **Example**
```javascript ```javascript
...@@ -3140,12 +3443,14 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3140,12 +3443,14 @@ Notification.subscribe(subscriber, subscribeCallback);
### onEnabledNotificationChanged<sup>8+</sup> ### onEnabledNotificationChanged<sup>8+</sup>
onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata8)) onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata8)) => void
Listens for the notification enable status changes. This API uses an asynchronous callback to return the result. Listens for the notification enable status changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -3201,7 +3506,7 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3201,7 +3506,7 @@ Notification.subscribe(subscriber, subscribeCallback);
| ------ | ---- | --- | ------- | ---- | ---------------- | | ------ | ---- | --- | ------- | ---- | ---------------- |
| bundle | Yes | No | string | Yes | Bundle name of the application. | | bundle | Yes | No | string | Yes | Bundle name of the application. |
| uid | Yes | No | number | Yes | UID of the application. | | uid | Yes | No | number | Yes | UID of the application. |
| enable | Yes | No | boolean | Yes | Notification enable status of the application.| | enable | Yes | No | boolean | Yes | Notification enabled status of the application.|
## DoNotDisturbDate<sup>8+</sup> ## DoNotDisturbDate<sup>8+</sup>
...@@ -3300,7 +3605,7 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3300,7 +3605,7 @@ Notification.subscribe(subscriber, subscribeCallback);
| title | Yes | Yes | string | Yes | Button title. | | title | Yes | Yes | string | Yes | Button title. |
| wantAgent | Yes | Yes | WantAgent | Yes | **WantAgent** of the button.| | wantAgent | Yes | Yes | WantAgent | Yes | **WantAgent** of the button.|
| extras | Yes | Yes | { [key: string]: any } | No | Extra information of the button. | | extras | Yes | Yes | { [key: string]: any } | No | Extra information of the button. |
| userInput<sup>9+</sup> | Yes | Yes | [NotificationUserInput](#notificationuserinput8) | No | User input object. | | userInput<sup>8+</sup> | Yes | Yes | [NotificationUserInput](#notificationuserinput8) | No | User input object. |
## NotificationBasicContent ## NotificationBasicContent
...@@ -3425,14 +3730,16 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3425,14 +3730,16 @@ Notification.subscribe(subscriber, subscribeCallback);
| creatorPid | Yes | No | number | No | PID used for creating the notification. | | creatorPid | Yes | No | number | No | PID used for creating the notification. |
| creatorUserId<sup>8+</sup>| Yes | No | number | No | ID of the user who creates the notification. | | creatorUserId<sup>8+</sup>| Yes | No | number | No | ID of the user who creates the notification. |
| hashCode | Yes | No | string | No | Unique ID of the notification. | | hashCode | Yes | No | string | No | Unique ID of the notification. |
| classification | Yes | Yes | string | No | Notification category. | | classification | Yes | Yes | string | No | Notification category.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| groupName<sup>8+</sup>| Yes | Yes | string | No | Group notification name. | | groupName<sup>8+</sup>| Yes | Yes | string | No | Group notification name. |
| template<sup>8+</sup> | Yes | Yes | [NotificationTemplate](#notificationtemplate8) | No | Notification template. | | template<sup>8+</sup> | Yes | Yes | [NotificationTemplate](#notificationtemplate8) | No | Notification template. |
| isRemoveAllowed<sup>8+</sup> | Yes | No | boolean | No | Whether the notification can be removed. | | isRemoveAllowed<sup>8+</sup> | Yes | No | boolean | No | Whether the notification can be removed.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| source<sup>8+</sup> | Yes | No | number | No | Notification source. | | source<sup>8+</sup> | Yes | No | number | No | Notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| distributedOption<sup>8+</sup> | Yes | Yes | [DistributedOptions](#distributedoptions8) | No | Option of distributed notification. | | distributedOption<sup>8+</sup> | Yes | Yes | [DistributedOptions](#distributedoptions8) | No | Option of distributed notification. |
| deviceId<sup>8+</sup> | Yes | No | string | No | Device ID of the notification source. | | deviceId<sup>8+</sup> | Yes | No | string | No | Device ID of the notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| notificationFlags<sup>8+</sup> | Yes | No | [NotificationFlags](#notificationflags8) | No | Notification flags. | | notificationFlags<sup>8+</sup> | Yes | No | [NotificationFlags](#notificationflags8) | No | Notification flags. |
| removalWantAgent<sup>9+</sup> | Yes | Yes | WantAgent | No | **WantAgent** instance to which the notification will be redirected when it is removed. |
| badgeNumber<sup>9+</sup> | Yes | Yes | number | No | Number of notifications displayed on the application icon. |
## DistributedOptions<sup>8+</sup> ## DistributedOptions<sup>8+</sup>
...@@ -3444,7 +3751,7 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3444,7 +3751,7 @@ Notification.subscribe(subscriber, subscribeCallback);
| isDistributed | Yes | Yes | boolean | No | Whether the notification is a distributed notification. | | isDistributed | Yes | Yes | boolean | No | Whether the notification is a distributed notification. |
| supportDisplayDevices | Yes | Yes | Array\<string> | Yes | Types of the devices to which the notification can be synchronized. | | supportDisplayDevices | Yes | Yes | Array\<string> | Yes | Types of the devices to which the notification can be synchronized. |
| supportOperateDevices | Yes | Yes | Array\<string> | No | Devices on which notification can be enabled. | | supportOperateDevices | Yes | Yes | Array\<string> | No | Devices on which notification can be enabled. |
| remindType | Yes | No | number | No | Notification reminder type. | | remindType | Yes | No | number | No | Notification reminder type.<br>**System API**: This is a system API and cannot be called by third-party applications. |
## NotificationSlot ## NotificationSlot
...@@ -3535,3 +3842,16 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3535,3 +3842,16 @@ Notification.subscribe(subscriber, subscribeCallback);
| IDLE_REMIND | 1 | The device is not in use. | | IDLE_REMIND | 1 | The device is not in use. |
| ACTIVE_DONOT_REMIND | 2 | The device is in use. No notification is required. | | ACTIVE_DONOT_REMIND | 2 | The device is in use. No notification is required. |
| ACTIVE_REMIND | 3 | The device is in use. | | ACTIVE_REMIND | 3 | The device is in use. |
## SourceType<sup>8+</sup>
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value | Description |
| -------------------- | --- | -------------------- |
| TYPE_NORMAL | 0 | Normal notification. |
| TYPE_CONTINUOUS | 1 | Continuous notification. |
| TYPE_TIMER | 2 | Timed notification. |
...@@ -17,9 +17,9 @@ import request from '@ohos.request'; ...@@ -17,9 +17,9 @@ import request from '@ohos.request';
## Constraints ## Constraints
HTTPS is supported by default. To support HTTP, you need to add **network** to the **config.json** file and set the **cleartextTraffic** attribute to **true**. HTTPS is supported by default in the FA model. To support HTTP, add **network** to the **config.json** file and set the **cleartextTraffic** attribute to **true**.
``` ```js
var config = { var config = {
"deviceConfig": { "deviceConfig": {
"default": { "default": {
...@@ -32,6 +32,9 @@ var config = { ...@@ -32,6 +32,9 @@ var config = {
} }
``` ```
The **cleartextTraffic** attribute is not involved during the development of applications in the stage model.
## Constants ## Constants
...@@ -39,28 +42,28 @@ var config = { ...@@ -39,28 +42,28 @@ var config = {
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
| Name | Type | Readable | Writable | Description | | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| NETWORK_MOBILE | number | Yes | No | Whether download is allowed when the cellular network is used. | | NETWORK_MOBILE | number | Yes| No| Whether download is allowed on a mobile network.|
| NETWORK_WIFI | number | Yes | No | Whether download is allowed on a WLAN. | | NETWORK_WIFI | number | Yes| No| Whether download is allowed on a WLAN.|
| ERROR_CANNOT_RESUME<sup>7+</sup> | number | Yes | No | Failure to resume the download due to an error. | | ERROR_CANNOT_RESUME<sup>7+</sup> | number | Yes| No| Failure to resume the download due to an error.|
| ERROR_DEVICE_NOT_FOUND<sup>7+</sup> | number | Yes | No | Failure to find a storage device such as a memory card. | | ERROR_DEVICE_NOT_FOUND<sup>7+</sup> | number | Yes| No| Failure to find a storage device such as a memory card.|
| ERROR_FILE_ALREADY_EXISTS<sup>7+</sup> | number | Yes | No | Failure to download the file because it already exists. | | ERROR_FILE_ALREADY_EXISTS<sup>7+</sup> | number | Yes| No| Failure to download the file because it already exists.|
| ERROR_FILE_ERROR<sup>7+</sup> | number | Yes | No | File operation failure. | | ERROR_FILE_ERROR<sup>7+</sup> | number | Yes| No| File operation failure.|
| ERROR_HTTP_DATA_ERROR<sup>7+</sup> | number | Yes | No | HTTP transmission failure. | | ERROR_HTTP_DATA_ERROR<sup>7+</sup> | number | Yes| No| HTTP transmission failure.|
| ERROR_INSUFFICIENT_SPACE<sup>7+</sup> | number | Yes | No | Insufficient storage space. | | ERROR_INSUFFICIENT_SPACE<sup>7+</sup> | number | Yes| No| Insufficient storage space.|
| ERROR_TOO_MANY_REDIRECTS<sup>7+</sup> | number | Yes | No | Error caused by too many network redirections. | | ERROR_TOO_MANY_REDIRECTS<sup>7+</sup> | number | Yes| No| Error caused by too many network redirections.|
| ERROR_UNHANDLED_HTTP_CODE<sup>7+</sup> | number | Yes | No | Unidentified HTTP code. | | ERROR_UNHANDLED_HTTP_CODE<sup>7+</sup> | number | Yes| No| Unidentified HTTP code.|
| ERROR_UNKNOWN<sup>7+</sup> | number | Yes | No | Unknown error. | | ERROR_UNKNOWN<sup>7+</sup> | number | Yes| No| Unknown error.|
| PAUSED_QUEUED_FOR_WIFI<sup>7+</sup> | number | Yes | No | Download paused and queuing for a WLAN connection, because the file size exceeds the maximum value allowed by a cellular network session. | | PAUSED_QUEUED_FOR_WIFI<sup>7+</sup> | number | Yes| No| Download paused and queuing for a WLAN connection, because the file size exceeds the maximum value allowed by a mobile network session.|
| PAUSED_UNKNOWN<sup>7+</sup> | number | Yes | No | Download paused due to unknown reasons. | | PAUSED_UNKNOWN<sup>7+</sup> | number | Yes| No| Download paused due to unknown reasons.|
| PAUSED_WAITING_FOR_NETWORK<sup>7+</sup> | number | Yes | No | Download paused due to a network connection problem, for example, network disconnection. | | PAUSED_WAITING_FOR_NETWORK<sup>7+</sup> | number | Yes| No| Download paused due to a network connection problem, for example, network disconnection.|
| PAUSED_WAITING_TO_RETRY<sup>7+</sup> | number | Yes | No | Download paused and then retried. | | PAUSED_WAITING_TO_RETRY<sup>7+</sup> | number | Yes| No| Download paused and then retried.|
| SESSION_FAILED<sup>7+</sup> | number | Yes | No | Download failure without retry. | | SESSION_FAILED<sup>7+</sup> | number | Yes| No| Download failure without retry.|
| SESSION_PAUSED<sup>7+</sup> | number | Yes | No | Download paused. | | SESSION_PAUSED<sup>7+</sup> | number | Yes| No| Download paused.|
| SESSION_PENDING<sup>7+</sup> | number | Yes | No | Download pending. | | SESSION_PENDING<sup>7+</sup> | number | Yes| No| Download pending.|
| SESSION_RUNNING<sup>7+</sup> | number | Yes | No | Download in progress. | | SESSION_RUNNING<sup>7+</sup> | number | Yes| No| Download in progress.|
| SESSION_SUCCESSFUL<sup>7+</sup> | number | Yes | No | Successful download. | | SESSION_SUCCESSFUL<sup>7+</sup> | number | Yes| No| Successful download.|
## request.upload ## request.upload
...@@ -69,30 +72,36 @@ upload(config: UploadConfig): Promise&lt;UploadTask&gt; ...@@ -69,30 +72,36 @@ upload(config: UploadConfig): Promise&lt;UploadTask&gt;
Uploads files. This API uses a promise to return the result. Uploads files. This API uses a promise to return the result.
This API can be used only in the FA model.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload **System capability**: SystemCapability.MiscServices.Upload
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [UploadConfig](#uploadconfig) | Yes | Configurations of the upload. | | config | [UploadConfig](#uploadconfig) | Yes| Upload configurations.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[UploadTask](#uploadtask)&gt; | Promise used to return the **UploadTask** object. | | Promise&lt;[UploadTask](#uploadtask)&gt; | Promise used to return the **UploadTask** object.|
**Example** **Example**
```js ```js
let file1 = { filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" };
let data = { name: "name123", value: "123" };
let header = { key1: "value1", key2: "value2" };
let uploadTask; let uploadTask;
request.upload({ url: 'https://patch', header: header, method: "POST", files: [file1], data: [data] }).then((data) => { let uploadConfig = {
url: 'https://patch',
header: { key1: "value1", key2: "value2" },
method: "POST",
files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }],
data: [{ name: "name123", value: "123" }],
};
request.upload(uploadConfig).then((data) => {
uploadTask = data; uploadTask = data;
}).catch((err) => { }).catch((err) => {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
...@@ -106,25 +115,31 @@ upload(config: UploadConfig, callback: AsyncCallback&lt;UploadTask&gt;): void ...@@ -106,25 +115,31 @@ upload(config: UploadConfig, callback: AsyncCallback&lt;UploadTask&gt;): void
Uploads files. This API uses an asynchronous callback to return the result. Uploads files. This API uses an asynchronous callback to return the result.
This API can be used only in the FA model.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload **System capability**: SystemCapability.MiscServices.Upload
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [UploadConfig](#uploadconfig) | Yes | Configurations of the upload. | | config | [UploadConfig](#uploadconfig) | Yes| Upload configurations.|
| callback | AsyncCallback&lt;[UploadTask](#uploadtask)&gt; | No | Callback used to return the **UploadTask** object. | | callback | AsyncCallback&lt;[UploadTask](#uploadtask)&gt; | No| Callback used to return the **UploadTask** object.|
**Example** **Example**
```js ```js
let file1 = { filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" };
let data = { name: "name123", value: "123" };
let header = { key1: "value1", key2: "value2" };
let uploadTask; let uploadTask;
request.upload({ url: 'https://patch', header: header, method: "POST", files: [file1], data: [data] }, (err, data) => { let uploadConfig = {
url: 'https://patch',
header: { key1: "value1", key2: "value2" },
method: "POST",
files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }],
data: [{ name: "name123", value: "123" }],
};
request.upload(uploadConfig, (err, data) => {
if (err) { if (err) {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
return; return;
...@@ -132,7 +147,86 @@ Uploads files. This API uses an asynchronous callback to return the result. ...@@ -132,7 +147,86 @@ Uploads files. This API uses an asynchronous callback to return the result.
uploadTask = data; uploadTask = data;
}); });
``` ```
## request.upload<sup>9+</sup>
upload(context: BaseContext, config: UploadConfig): Promise&lt;UploadTask&gt;
Uploads files. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | BaseContext | Yes| Application-based context.|
| config | [UploadConfig](#uploadconfig) | Yes| Upload configurations.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[UploadTask](#uploadtask)&gt; | Promise used to return the **UploadTask** object.|
**Example**
```js
let uploadTask;
let uploadConfig = {
url: 'https://patch',
header: { key1: "value1", key2: "value2" },
method: "POST",
files: { filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" },
data: { name: "name123", value: "123" },
};
request.upload(globalThis.abilityContext, uploadConfig).then((data) => {
uploadTask = data;
}).catch((err) => {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
});
```
## request.upload<sup>9+</sup>
upload(context: BaseContext, config: UploadConfig, callback: AsyncCallback&lt;UploadTask&gt;): void
Uploads files. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | BaseContext | Yes| Application-based context.|
| config | [UploadConfig](#uploadconfig) | Yes| Upload configurations.|
| callback | AsyncCallback&lt;[UploadTask](#uploadtask)&gt; | No| Callback used to return the **UploadTask** object.|
**Example**
```js
let uploadTask;
let uploadConfig = {
url: 'https://patch',
header: { key1: "value1", key2: "value2" },
method: "POST",
files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }],
data: [{ name: "name123", value: "123" }],
};
request.upload(globalThis.abilityContext, uploadConfig, (err, data) => {
if (err) {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
return;
}
uploadTask = data;
});
```
## UploadTask ## UploadTask
...@@ -143,7 +237,7 @@ Implements file uploads. Before using any APIs of this class, you must obtain an ...@@ -143,7 +237,7 @@ Implements file uploads. Before using any APIs of this class, you must obtain an
on(type: 'progress', callback:(uploadedSize: number, totalSize: number) =&gt; void): void on(type: 'progress', callback:(uploadedSize: number, totalSize: number) =&gt; void): void
Subscribes to the upload progress event. This API uses an asynchronous callback to return the result. Subscribes to an upload event. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -151,17 +245,17 @@ Subscribes to the upload progress event. This API uses an asynchronous callback ...@@ -151,17 +245,17 @@ Subscribes to the upload progress event. This API uses an asynchronous callback
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the event to subscribe to. The value is **progress** (upload progress). | | type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (upload progress).|
| callback | function | Yes | Callback for the upload progress event. | | callback | function | Yes| Callback for the upload progress event.|
**callback** parameters Parameters of the callback function
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uploadedSize | number | Yes | Size of the uploaded files, in KB. | | uploadedSize | number | Yes| Size of the uploaded files, in KB.|
| totalSize | number | Yes | Total size of the files to upload, in KB. | | totalSize | number | Yes| Total size of the files to upload, in KB.|
**Example** **Example**
...@@ -177,7 +271,7 @@ Subscribes to the upload progress event. This API uses an asynchronous callback ...@@ -177,7 +271,7 @@ Subscribes to the upload progress event. This API uses an asynchronous callback
on(type: 'headerReceive', callback: (header: object) =&gt; void): void on(type: 'headerReceive', callback: (header: object) =&gt; void): void
Subscribes to the **headerReceive** event, which is triggered when an HTTP response header is received. This API uses an asynchronous callback to return the result. Subscribes to an upload event. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -185,16 +279,16 @@ Subscribes to the **headerReceive** event, which is triggered when an HTTP respo ...@@ -185,16 +279,16 @@ Subscribes to the **headerReceive** event, which is triggered when an HTTP respo
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the event to subscribe to. The value is **'headerReceive'** (response header). | | type | string | Yes| Type of the event to subscribe to. The value is **'headerReceive'** (response header).|
| callback | function | Yes | Callback for the HTTP Response Header event. | | callback | function | Yes| Callback for the HTTP Response Header event.|
**callback** parameters Parameters of the callback function
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| header | object | Yes | HTTP Response Header. | | header | object | Yes| HTTP Response Header.|
**Example** **Example**
...@@ -210,7 +304,7 @@ Subscribes to the **headerReceive** event, which is triggered when an HTTP respo ...@@ -210,7 +304,7 @@ Subscribes to the **headerReceive** event, which is triggered when an HTTP respo
off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) =&gt; void): void off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) =&gt; void): void
Unsubscribes from the upload progress event. This API uses an asynchronous callback to return the result. Unsubscribes from an upload event. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -218,17 +312,17 @@ Unsubscribes from the upload progress event. This API uses an asynchronous callb ...@@ -218,17 +312,17 @@ Unsubscribes from the upload progress event. This API uses an asynchronous callb
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the event to unsubscribe from. The value is **'progress'** (upload progress). | | type | string | Yes| Type of the event to unsubscribe from. The value is **'progress'** (upload progress).|
| callback | function | No | Callback for the upload progress event. | | callback | function | No| Callback for the upload progress event.|
**callback** parameters Parameters of the callback function
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uploadedSize | number | Yes | Size of the uploaded files, in KB. | | uploadedSize | number | Yes| Size of the uploaded files, in KB.|
| totalSize | number | Yes | Total size of the files to upload, in KB. | | totalSize | number | Yes| Total size of the files to upload, in KB.|
**Example** **Example**
...@@ -244,7 +338,7 @@ Unsubscribes from the upload progress event. This API uses an asynchronous callb ...@@ -244,7 +338,7 @@ Unsubscribes from the upload progress event. This API uses an asynchronous callb
off(type: 'headerReceive', callback?: (header: object) =&gt; void): void off(type: 'headerReceive', callback?: (header: object) =&gt; void): void
Unsubscribes from the **headerReceive** event. This API uses an asynchronous callback to return the result. Unsubscribes from an upload event. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -252,16 +346,16 @@ Unsubscribes from the **headerReceive** event. This API uses an asynchronous cal ...@@ -252,16 +346,16 @@ Unsubscribes from the **headerReceive** event. This API uses an asynchronous cal
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the event to unsubscribe from. The value is **'headerReceive'** (response header). | | type | string | Yes| Type of the event to unsubscribe from. The value is **'headerReceive'** (response header).|
| callback | function | No | Callback for the HTTP Response Header event. | | callback | function | No| Callback for the HTTP Response Header event.|
**callback** parameters Parameters of the callback function
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| header | object | Yes | HTTP Response Header. | | header | object | Yes| HTTP Response Header.|
**Example** **Example**
...@@ -285,9 +379,9 @@ Removes this upload task. This API uses a promise to return the result. ...@@ -285,9 +379,9 @@ Removes this upload task. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the task removal result. If **true** is returned, the task is removed. If **false** is returned, the task fails to be removed. | | Promise&lt;boolean&gt; | Promise used to return the task removal result. If **true** is returned, the task is removed. If **false** is returned, the task fails to be removed.|
**Example** **Example**
...@@ -316,9 +410,9 @@ Removes this upload task. This API uses an asynchronous callback to return the r ...@@ -316,9 +410,9 @@ Removes this upload task. This API uses an asynchronous callback to return the r
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -339,37 +433,42 @@ Removes this upload task. This API uses an asynchronous callback to return the r ...@@ -339,37 +433,42 @@ Removes this upload task. This API uses an asynchronous callback to return the r
## UploadConfig ## UploadConfig
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload **System capability**: SystemCapability.MiscServices.Upload
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| url | string | Yes | Resource URL. | | url | string | Yes| Resource URL.|
| header | object | Yes | HTTP or HTTPS header added to an upload request. | | header | object | Yes| HTTP or HTTPS header added to an upload request.|
| method | string | Yes | Request method, which can be **POST** or **PUT**. The default value is **POST**. | | method | string | Yes| Request method, which can be **'POST'** or **'PUT'**. The default value is **'POST'**.|
| files | Array&lt;[File](#file)&gt; | Yes | List of files to upload, which is submitted through **multipart/form-data**. | | files | Array&lt;[File](#file)&gt; | Yes| List of files to upload, which is submitted through **multipart/form-data**.|
| data | Array&lt;[RequestData](#requestdata)&gt; | Yes | Form data in the request body. | | data | Array&lt;[RequestData](#requestdata)&gt; | Yes| Form data in the request body.|
## File ## File
**System capability**: SystemCapability.MiscServices.Upload **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| filename | string | No | File name in the header when **multipart** is used. | | filename | string | No| File name in the header when **multipart** is used.|
| name | string | No | Name of a form item when **multipart** is used. The default value is **file**. | | name | string | No| Name of a form item when **multipart** is used. The default value is **file**.|
| uri | string | Yes | Local path for storing files.<br/>The **dataability** and **internal** protocol types are supported. However, the **internal** protocol type supports only temporary directories. Below are examples:<br>dataability:///com.domainname.dataability.persondata/person/10/file.txt<br>internal://cache/path/to/file.txt | | uri | string | Yes| Local path for storing files.<br>The **dataability** and **internal** protocol types are supported. However, the **internal** protocol type supports only temporary directories. Below are examples:<br>dataability:///com.domainname.dataability.persondata/person/10/file.txt<br><br>internal://cache/path/to/file.txt |
| type | string | No | Type of the file content. By default, the type is obtained based on the extension of the file name or URI. | | type | string | No| Type of the file content. By default, the type is obtained based on the extension of the file name or URI.|
## RequestData ## RequestData
**System capability**: SystemCapability.MiscServices.Upload **Required permissions**: ohos.permission.INTERNET
| Name | Type | Mandatory | Description | **System capability**: SystemCapability.MiscServices.Download
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| name | string | Yes | Name of a form element. | | name | string | Yes| Name of a form element.|
| value | string | Yes | Value of a form element. | | value | string | Yes| Value of a form element.|
## request.download ## request.download
...@@ -378,21 +477,23 @@ download(config: DownloadConfig): Promise&lt;DownloadTask&gt; ...@@ -378,21 +477,23 @@ download(config: DownloadConfig): Promise&lt;DownloadTask&gt;
Downloads files. This API uses a promise to return the result. Downloads files. This API uses a promise to return the result.
This API can be used only in the FA model.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [DownloadConfig](#downloadconfig) | Yes | Configurations of the download. | | config | [DownloadConfig](#downloadconfig) | Yes| Download configurations.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[DownloadTask](#downloadtask)&gt; | Promise used to return the result. | | Promise&lt;[DownloadTask](#downloadtask)&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -412,16 +513,18 @@ download(config: DownloadConfig, callback: AsyncCallback&lt;DownloadTask&gt;): v ...@@ -412,16 +513,18 @@ download(config: DownloadConfig, callback: AsyncCallback&lt;DownloadTask&gt;): v
Downloads files. This API uses an asynchronous callback to return the result. Downloads files. This API uses an asynchronous callback to return the result.
This API can be used only in the FA model.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [DownloadConfig](#downloadconfig) | Yes | Configurations of the download. | | config | [DownloadConfig](#downloadconfig) | Yes| Download configurations.|
| callback | AsyncCallback&lt;[DownloadTask](#downloadtask)&gt; | No | Callback used to return the result. | | callback | AsyncCallback&lt;[DownloadTask](#downloadtask)&gt; | No| Callback used to return the result.|
**Example** **Example**
...@@ -437,7 +540,72 @@ Downloads files. This API uses an asynchronous callback to return the result. ...@@ -437,7 +540,72 @@ Downloads files. This API uses an asynchronous callback to return the result.
}); });
``` ```
## request.download<sup>9+</sup>
download(context: BaseContext, config: DownloadConfig): Promise&lt;DownloadTask&gt;
Downloads files. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | BaseContext | Yes| Application-based context.|
| config | [DownloadConfig](#downloadconfig) | Yes| Download configurations.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[DownloadTask](#downloadtask)&gt; | Promise used to return the result.|
**Example**
```js
let downloadTask;
request.download(globalThis.abilityContext, { url: 'https://xxxx/xxxx.hap' }).then((data) => {
downloadTask = data;
}).catch((err) => {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
})
```
## request.download<sup>9+</sup>
download(context: BaseContext, config: DownloadConfig, callback: AsyncCallback&lt;DownloadTask&gt;): void;
Downloads files. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | BaseContext | Yes| Application-based context.|
| config | [DownloadConfig](#downloadconfig) | Yes| Download configurations.|
| callback | AsyncCallback&lt;[DownloadTask](#downloadtask)&gt; | No| Callback used to return the result.|
**Example**
```js
let downloadTask;
request.download(globalThis.abilityContext, { url: 'https://xxxx/xxxxx.hap',
filePath: 'xxx/xxxxx.hap'}, (err, data) => {
if (err) {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
return;
}
downloadTask = data;
});
```
## DownloadTask ## DownloadTask
Implements file downloads. Implements file downloads.
...@@ -447,7 +615,7 @@ Implements file downloads. ...@@ -447,7 +615,7 @@ Implements file downloads.
on(type: 'progress', callback:(receivedSize: number, totalSize: number) =&gt; void): void on(type: 'progress', callback:(receivedSize: number, totalSize: number) =&gt; void): void
Subscribes to the download progress event. This API uses an asynchronous callback to return the result. Subscribes to a download event. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -455,17 +623,17 @@ Subscribes to the download progress event. This API uses an asynchronous callbac ...@@ -455,17 +623,17 @@ Subscribes to the download progress event. This API uses an asynchronous callbac
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the event to subscribe to. The value is **'progress'** (download progress). | | type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (download progress).|
| callback | function | Yes | Callback for the download progress event. | | callback | function | Yes| Callback for the download progress event.|
**callback** parameters Parameters of the callback function
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| receivedSize | number | Yes | Size of the downloaded files, in KB. | | receivedSize | number | Yes| Size of the downloaded files, in KB.|
| totalSize | number | Yes | Total size of the files to download, in KB. | | totalSize | number | Yes| Total size of the files to download, in KB.|
**Example** **Example**
...@@ -481,7 +649,7 @@ Subscribes to the download progress event. This API uses an asynchronous callbac ...@@ -481,7 +649,7 @@ Subscribes to the download progress event. This API uses an asynchronous callbac
off(type: 'progress', callback?: (receivedSize: number, totalSize: number) =&gt; void): void off(type: 'progress', callback?: (receivedSize: number, totalSize: number) =&gt; void): void
Unsubscribes from the download progress event. This API uses an asynchronous callback to return the result. Unsubscribes from a download event. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -489,17 +657,17 @@ Unsubscribes from the download progress event. This API uses an asynchronous cal ...@@ -489,17 +657,17 @@ Unsubscribes from the download progress event. This API uses an asynchronous cal
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the event to unsubscribe from. The value is **'progress'** (download progress). | | type | string | Yes| Type of the event to unsubscribe from. The value is **'progress'** (download progress).|
| callback | function | No | Callback for the download progress event. | | callback | function | No| Callback for the download progress event.|
**callback** parameters Parameters of the callback function
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| receivedSize | number | Yes | Size of the downloaded files, in KB. | | receivedSize | number | Yes| Size of the downloaded files.|
| totalSize | number | Yes | Total size of the files to download, in KB. | | totalSize | number | Yes| Total size of the files to download.|
**Example** **Example**
...@@ -523,10 +691,10 @@ Subscribes to a download event. This API uses an asynchronous callback to return ...@@ -523,10 +691,10 @@ Subscribes to a download event. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Event type.<br/>- **'complete'**: download task completion event.<br/>- **'pause'**: download task pause event.<br/>- **'remove'**: download task removal event. | | type | string | Yes| Type of the event to subscribe to.<br>- **'complete'**: download task completion event.<br>- **'pause'**: download task pause event.<br>- **'remove'**: download task removal event.|
| callback | function | Yes | Callback used to return the result. | | callback | function | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -542,7 +710,7 @@ Subscribes to a download event. This API uses an asynchronous callback to return ...@@ -542,7 +710,7 @@ Subscribes to a download event. This API uses an asynchronous callback to return
off(type: 'complete'|'pause'|'remove', callback?:() =&gt; void): void off(type: 'complete'|'pause'|'remove', callback?:() =&gt; void): void
Unsubscribes from the download event. This API uses an asynchronous callback to return the result. Unsubscribes from a download event. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -550,10 +718,10 @@ Unsubscribes from the download event. This API uses an asynchronous callback to ...@@ -550,10 +718,10 @@ Unsubscribes from the download event. This API uses an asynchronous callback to
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Event type.<br/>- **'complete'**: download task completion event.<br/>- **'pause'**: download task pause event.<br/>- **'remove'**: download task removal event. | | type | string | Yes| Type of the event to unsubscribe from.<br>- **'complete'**: download task completion event.<br>- **'pause'**: download task pause event.<br>- **'remove'**: download task removal event.|
| callback | function | No | Callback used to return the result. | | callback | function | No| Callback used to return the result.|
**Example** **Example**
...@@ -577,16 +745,16 @@ Subscribes to the download task failure event. This API uses an asynchronous cal ...@@ -577,16 +745,16 @@ Subscribes to the download task failure event. This API uses an asynchronous cal
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the subscribed event. The value is **'fail'** (download failure). | | type | string | Yes| Type of the event to subscribe to. The value is **'fail'** (download failure).|
| callback | function | Yes | Callback for the download task failure event. | | callback | function | Yes| Callback for the download task failure event.|
**callback** parameters Parameters of the callback function
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| err | number | Yes | Error code of the download failure. For details about the error cause, see [ERROR_*](#constants). | | err | number | Yes| Error code of the download failure. For details about the error codes, see [ERROR_*](#constants).|
**Example** **Example**
...@@ -610,16 +778,16 @@ Unsubscribes from the download task failure event. This API uses an asynchronous ...@@ -610,16 +778,16 @@ Unsubscribes from the download task failure event. This API uses an asynchronous
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Type of the event to unsubscribe from. The value is **'fail'** (download failure). | | type | string | Yes| Type of the event to unsubscribe from. The value is **'fail'** (download failure).|
| callback | function | No | Callback for the download task failure event. | | callback | function | No| Callback for the download task failure event.|
**callback** parameters Parameters of the callback function
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| err | number | Yes | Error code of the download failure. For details about the error cause, see [ERROR_*](#constants). | | err | number | Yes| Error code of the download failure. For details about the error codes, see [ERROR_*](#constants).|
**Example** **Example**
...@@ -643,9 +811,9 @@ Removes this download task. This API uses a promise to return the result. ...@@ -643,9 +811,9 @@ Removes this download task. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the task removal result. | | Promise&lt;boolean&gt; | Promise used to return the task removal result.|
**Example** **Example**
...@@ -674,9 +842,9 @@ Removes this download task. This API uses an asynchronous callback to return the ...@@ -674,9 +842,9 @@ Removes this download task. This API uses an asynchronous callback to return the
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the task removal result. | | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the task removal result.|
**Example** **Example**
...@@ -706,10 +874,9 @@ Queries this download task. This API uses a promise to return the result. ...@@ -706,10 +874,9 @@ Queries this download task. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
**Parameters** **Parameters**
| Type| Description|
| Type | Description |
| -------- | -------- | | -------- | -------- |
| Promise&lt;[DownloadInfo](#downloadinfo7)&gt; | Promise used to return the download task information. | | Promise&lt;[DownloadInfo](#downloadinfo7)&gt; | Promise used to return the download task information.|
**Example** **Example**
...@@ -734,9 +901,9 @@ Queries this download task. This API uses an asynchronous callback to return the ...@@ -734,9 +901,9 @@ Queries this download task. This API uses an asynchronous callback to return the
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[DownloadInfo](#downloadinfo7)&gt; | Yes | Callback used to return the download task information. | | callback | AsyncCallback&lt;[DownloadInfo](#downloadinfo7)&gt; | Yes| Callback used to return the download task information.|
**Example** **Example**
...@@ -755,7 +922,7 @@ Queries this download task. This API uses an asynchronous callback to return the ...@@ -755,7 +922,7 @@ Queries this download task. This API uses an asynchronous callback to return the
queryMimeType(): Promise&lt;string&gt; queryMimeType(): Promise&lt;string&gt;
Queries **MimeType** of this download task. This API uses a promise to return the result. Queries the **MimeType** of this download task. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -763,9 +930,9 @@ Queries **MimeType** of this download task. This API uses a promise to return th ...@@ -763,9 +930,9 @@ Queries **MimeType** of this download task. This API uses a promise to return th
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;string&gt; | Promise used to return **MimeType** of the download task. | | Promise&lt;string&gt; | Promise used to return the **MimeType** of the download task.|
**Example** **Example**
...@@ -782,7 +949,7 @@ Queries **MimeType** of this download task. This API uses a promise to return th ...@@ -782,7 +949,7 @@ Queries **MimeType** of this download task. This API uses a promise to return th
queryMimeType(callback: AsyncCallback&lt;string&gt;): void; queryMimeType(callback: AsyncCallback&lt;string&gt;): void;
Queries **MimeType** of this download task. This API uses an asynchronous callback to return the result. Queries the **MimeType** of this download task. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -790,9 +957,9 @@ Queries **MimeType** of this download task. This API uses an asynchronous callba ...@@ -790,9 +957,9 @@ Queries **MimeType** of this download task. This API uses an asynchronous callba
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return **MimeType** of the download task. | | callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the **MimeType** of the download task.|
**Example** **Example**
...@@ -819,9 +986,9 @@ Pauses this download task. This API uses a promise to return the result. ...@@ -819,9 +986,9 @@ Pauses this download task. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the download task pause result. | | Promise&lt;void&gt; | Promise used to return the download task pause result.|
**Example** **Example**
...@@ -850,9 +1017,9 @@ Pauses this download task. This API uses an asynchronous callback to return the ...@@ -850,9 +1017,9 @@ Pauses this download task. This API uses an asynchronous callback to return the
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -883,9 +1050,9 @@ Resumes this download task. This API uses a promise to return the result. ...@@ -883,9 +1050,9 @@ Resumes this download task. This API uses a promise to return the result.
**Parameters** **Parameters**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -915,9 +1082,9 @@ Resumes this download task. This API uses an asynchronous callback to return the ...@@ -915,9 +1082,9 @@ Resumes this download task. This API uses an asynchronous callback to return the
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -938,34 +1105,38 @@ Resumes this download task. This API uses an asynchronous callback to return the ...@@ -938,34 +1105,38 @@ Resumes this download task. This API uses an asynchronous callback to return the
## DownloadConfig ## DownloadConfig
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| url | string | Yes | Resource URL. | | url | string | Yes| Resource URL.|
| header | object | No | HTTP or HTTPS header added to a download request. | | header | object | No| HTTP or HTTPS header added to a download request.|
| enableMetered | boolean | No | Download allowed in metered connections. | | enableMetered | boolean | No| Download allowed in metered connections.|
| enableRoaming | boolean | No | Download allowed on a roaming network. | | enableRoaming | boolean | No| Download allowed on a roaming network.|
| description | string | No | Description of the download session. | | description | string | No| Description of the download session.|
| filePath<sup>7+</sup> | string | No | Download path. (The default path is **'internal://cache/'**.<br/>- filePath:'workspace/test.txt': The **workspace** directory is created in the default path to store files.<br/>- filePath:'test.txt': Files are stored in the default path.<br/>- filePath:'workspace/': The **workspace** directory is created in the default path to store files. | | filePath<sup>7+</sup> | string | No| Download path. (The default path is **'internal://cache/'**.)<br>- filePath:'workspace/test.txt': The **workspace** directory is created in the default path to store files.<br>- filePath:'test.txt': Files are stored in the default path.<br>- filePath:'workspace/': The **workspace** directory is created in the default path to store files.|
| networkType | number | No | Network type allowed for download. | | networkType | number | No| Network type allowed for download.|
| title | string | No | Title of the download session. | | title | string | No| Title of the download session.|
## DownloadInfo<sup>7+</sup> ## DownloadInfo<sup>7+</sup>
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| downloadId | number | Yes | ID of the downloaded file. | | downloadId | number | Yes| ID of the downloaded file.|
| failedReason | number | No | Download failure cause, which can be any constant of [ERROR_*](#constants). | | failedReason | number | No| Download failure cause, which can be any constant of [ERROR_*](#constants).|
| fileName | string | Yes | Name of the downloaded file. | | fileName | string | Yes| Name of the downloaded file.|
| filePath | string | Yes | URI of the saved file. | | filePath | string | Yes| URI of the saved file.|
| pausedReason | number | No | Reason for session pause, which can be any constant of [PAUSED_*](#constants). | | pausedReason | number | No| Reason for session pause, which can be any constant of [PAUSED_*](#constants).|
| status | number | Yes | Download status code, which can be any constant of [SESSION_*](#constants). | | status | number | Yes| Download status code, which can be any constant of [SESSION_*](#constants).|
| targetURI | string | Yes | URI of the downloaded file. | | targetURI | string | Yes| URI of the downloaded file.|
| downloadTitle | string | Yes | Title of the downloaded file. | | downloadTitle | string | Yes| Title of the downloaded file.|
| downloadTotalBytes | number | Yes | Total size of the downloaded file (int bytes). | | downloadTotalBytes | number | Yes| Total size of the files to download (int bytes).|
| description | string | Yes | Description of the file to download. | | description | string | Yes| Description of the file to download.|
| downloadedBytes | number | Yes | Size of the files downloaded (int bytes). | | downloadedBytes | number | Yes| Size of the files downloaded (int bytes).|
# Button # Button
The **\<Button>** component can be used to create different types of buttons.
> **NOTE**<br> > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
The **&lt;Button&gt;** component represents a component that can trigger actions.
## Required Permissions ## Required Permissions
None None
...@@ -30,15 +29,15 @@ Supported ...@@ -30,15 +29,15 @@ Supported
| stateEffect | boolean | No | true | Whether to enable the state switchover effect when a button is pressed. When the state is set to **false**, the state switchover effect is disabled. | | stateEffect | boolean | No | true | Whether to enable the state switchover effect when a button is pressed. When the state is set to **false**, the state switchover effect is disabled. |
- Button(label?: string, options?: { type?: ButtonType, stateEffect?: boolean }) - Button(label?: ResourceStr, options?: { type?: ButtonType, stateEffect?: boolean })
Creates a button component based on text content. In this case, the **&lt;Button&gt;** component cannot contain child components. Creates a button component based on text content. In this case, the **\<Button>** component cannot contain child components.
**Table 2** value parameters **Table 2** Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| label | string | No | - | Button text. | | label | [ResourceStr](../../ui/ts-types.md) | No | - | Button text. |
| options | Object | No | - | For details, see the **options** parameters. | | options | Object | No | - | For details, see the **options** parameters. |
...@@ -67,7 +66,8 @@ Supported ...@@ -67,7 +66,8 @@ Supported
## Example ## Example
``` ```ts
// xxx.ets
@Entry @Entry
@Component @Component
struct ButtonExample { struct ButtonExample {
...@@ -78,6 +78,7 @@ struct ButtonExample { ...@@ -78,6 +78,7 @@ struct ButtonExample {
Button('Ok', { type: ButtonType.Normal, stateEffect: true }).borderRadius(8).backgroundColor(0x317aff).width(90) Button('Ok', { type: ButtonType.Normal, stateEffect: true }).borderRadius(8).backgroundColor(0x317aff).width(90)
Button({ type: ButtonType.Normal, stateEffect: true }) { Button({ type: ButtonType.Normal, stateEffect: true }) {
Row() { Row() {
// You are advised to reference an image by using $r to create a Resource object.
Image($r('app.media.loading')).width(20).height(20).margin({ left: 12 }) Image($r('app.media.loading')).width(20).height(20).margin({ left: 12 })
Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 }) Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 })
}.alignItems(VerticalAlign.Center) }.alignItems(VerticalAlign.Center)
......
...@@ -91,7 +91,11 @@ struct ProgressExample { ...@@ -91,7 +91,11 @@ struct ProgressExample {
Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row({ space: 40 }) { Row({ space: 40 }) {
Progress({ value: 10, type: ProgressType.Capsule }).width(100).height(50) Progress({ value: 10, type: ProgressType.Capsule }).width(100).height(50)
Progress({ value: 20, total: 150, type: ProgressType.Capsule }).color(Color.Grey).value(50).width(100).height(50) Progress({ value: 20, total: 150, type: ProgressType.Capsule })
.color(Color.Grey)
.value(50)
.width(100)
.height(50)
} }
}.width('100%').margin({ top: 30 }) }.width('100%').margin({ top: 30 })
} }
......
# Slider # Slider
> **NOTE**<br> > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
The **&lt;Slider&gt;** component is used to quickly adjust settings, such as the volume and brightness. The *\<Slider>** component is used to quickly adjust settings, such as the volume and brightness.
## Required Permissions ## Required Permissions
...@@ -15,7 +16,7 @@ None ...@@ -15,7 +16,7 @@ None
## Child Components ## Child Components
None Not supported
## APIs ## APIs
...@@ -45,7 +46,7 @@ Slider(value:{value?: number, min?: number, max?: number, step?: number, style?: ...@@ -45,7 +46,7 @@ Slider(value:{value?: number, min?: number, max?: number, step?: number, style?:
Touch target configuration is not supported. Touch target configuration is not supported.
| Name | Type | Default Value | Description | | Name | Type | Default Value | Description |
| ------------- | ------- | ------------- | -------------------------------------------------------------------- | | ------------- | ------- | ------------- | ---------------------------------------- |
| blockColor | Color | - | Color of the slider. | | blockColor | Color | - | Color of the slider. |
| trackColor | Color | - | Background color of the slider. | | trackColor | Color | - | Background color of the slider. |
| selectedColor | Color | - | Color of the slider rail that has been slid. | | selectedColor | Color | - | Color of the slider rail that has been slid. |
...@@ -62,17 +63,18 @@ Among all the universal events, only **OnAppear** and **OnDisAppear** are suppor ...@@ -62,17 +63,18 @@ Among all the universal events, only **OnAppear** and **OnDisAppear** are suppor
| onChange(callback: (value: number, mode: SliderChangeMode) =&gt; void) | Callback invoked when the slider slides.<br/>**value**: current progress.<br/>**mode**: dragging state. | | onChange(callback: (value: number, mode: SliderChangeMode) =&gt; void) | Callback invoked when the slider slides.<br/>**value**: current progress.<br/>**mode**: dragging state. |
- SliderChangeMode enums - SliderChangeMode enums
| Name | Description | | Name | Value | Description |
| ------ | ----------------------------------- | | ------ | ----- | ----------------------------------- |
| Begin | The user starts to drag the slider. | | Begin | 0 | The user starts to drag the slider. |
| Moving | The user is dragging the slider. | | Moving | 1 | The user is dragging the slider. |
| End | The user stops dragging the slider. | | End | 2 | The user stops dragging the slider. |
## Example ## Example
``` ```ts
// xxx.ets
@Entry @Entry
@Component @Component
struct SliderExample { struct SliderExample {
......
# CanvasGradient # CanvasGradient
> **NOTE**<br> > **NOTE**
>
> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
...@@ -18,11 +19,11 @@ Adds a color stop for the **CanvasGradient** object based on the specified offse ...@@ -18,11 +19,11 @@ Adds a color stop for the **CanvasGradient** object based on the specified offse
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| offset | number | Yes | 0 | Proportion of the distance between the color stop and the start point to the total length. The value ranges from 0 to 1. | | offset | number | Yes | 0 | Proportion of the distance between the color stop and the start point to the total length. The value ranges from 0 to 1. |
| color | string | Yes | 'ffffff' | Gradient color to set. | | color | string | Yes | '#ffffff'| Gradient color to set. |
- Example - Example
```ts
``` // xxx.ets
@Entry @Entry
@Component @Component
struct Page45 { struct Page45 {
...@@ -37,9 +38,9 @@ Adds a color stop for the **CanvasGradient** object based on the specified offse ...@@ -37,9 +38,9 @@ Adds a color stop for the **CanvasGradient** object based on the specified offse
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
var grad = this.context.createLinearGradient(50,0, 300,100) var grad = this.context.createLinearGradient(50,0, 300,100)
this.grad.addColorStop(0.0, 'red') grad.addColorStop(0.0, 'red')
this.grad.addColorStop(0.5, 'white') grad.addColorStop(0.5, 'white')
this.grad.addColorStop(1.0, 'green') grad.addColorStop(1.0, 'green')
this.context.fillStyle = grad this.context.fillStyle = grad
this.context.fillRect(0, 0, 500, 500) this.context.fillRect(0, 0, 500, 500)
}) })
......
# Scroll # Scroll
> **NOTE**
> - This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
> - When a **\<List>** is nested in this component, you are advised to specify the width and height of the **\<List>** under scenarios where consistently high performance is required. If the width and height are not specified, this component will load all content of the **\<List>**.
> **NOTE**<br>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
The **\<Scroll>** component scrolls the content when the layout size of a component exceeds the viewport of its parent component.
The **<Scroll\>** component scrolls the content when the layout size of a component exceeds the viewport of its parent component.
## Required Permissions ## Required Permissions
None None.
## Child Components ## Child Components
...@@ -26,34 +26,44 @@ Scroll(scroller?: Scroller) ...@@ -26,34 +26,44 @@ Scroll(scroller?: Scroller)
## Attributes ## Attributes
| Name | Type | Default Value | Description | | Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- | | -------------- | ---------------------------------------- | ------------------------ | --------- |
| scrollable | ScrollDirection | ScrollDirection.Vertical | Scroll method. | | scrollable | ScrollDirection | ScrollDirection.Vertical | Scroll method. |
| scrollBar | [BarState](ts-appendix-enums.md#barstate-enums) | Auto | Scroll bar status. | | scrollBar | [BarState](ts-appendix-enums.md#barstate-enums)| ScrollDirection.Auto | Scrollbar status. |
| scrollBarColor | Color | - | Color of the scroll bar. | | scrollBarColor | Color | - | Color of the scrollbar.|
| scrollBarWidth | Length | - | Width of the scrollbar. | | scrollBarWidth | Length | - | Width of the scrollbar.|
- ScrollDirection - ScrollDirection enums
| Name | Description | | Name | Description |
| -------- | -------- | | ---------- | ---------- |
| Horizontal | Only horizontal scrolling is supported. | | Horizontal | Only horizontal scrolling is supported.|
| Vertical | Only vertical scrolling is supported. | | Vertical | Only vertical scrolling is supported.|
| None | Scrolling is disabled. | | None | Scrolling is disabled. |
## Events
| Name | Description |
| ---------------------------------------- | ----------------------------- |
| onScrollBegin<sup>9+</sup>(dx: number, dy: number)&nbsp;=&gt;&nbsp;{ dxRemain: number, dyRemain: number } | Invoked when scrolling starts.<br>Parameters:<br>- **dx**: amount to scroll by in the horizontal direction.<br>- **dy**: amount to scroll by in the vertical direction.<br>Return value:<br>- **dxRemain**: remaining amount to scroll by in the horizontal direction.<br>- **dyRemain**: remaining amount to scroll by in the vertical direction.|
| onScroll(xOffset:&nbsp;number,&nbsp;yOffset:&nbsp;number)&nbsp;=&gt;&nbsp;void | Invoked to return the horizontal and vertical offsets during scrolling when the specified scroll event occurs.|
| onScrollEdge(side:&nbsp;Edge)&nbsp;=&gt;&nbsp;void | Invoked when scrolling reaches the edge. |
| onScrollEnd()&nbsp;=&gt;&nbsp;void | Invoked when scrolling stops. |
> **NOTE**
> If the **onScrollBegin** event and **scrollBy** API are used to implement nested scrolling, you must set **edgeEffect** of the scrolling child node to **None**. For example, if a **\<List>** is nested in the **\<Scroll>** component, the **edgeEffect** attribute of the **\<List>** must be set to **EdgeEffect.None**.
## Scroller ## Scroller
Controller of the scrollable container component. You can bind this component to the container component and use it to control the scrolling of the container component. Currently, this component can be bound to the **<List\>** and **<Scroll\>** components. Controller of the scrollable container component. You can bind this component to a container component and use it to control the scrolling of that component. Currently, this component can be bound to the **\<List>** and **\<Scroll>** components.
### Objects to Import ### Objects to Import
``` ```
scroller: Scroller = new Scroller() scroller: Scroller = new Scroller()
``` ```
### scroller.scrollTo ### scrollTo
scrollTo(value: { xOffset: number | string, yOffset: number | string, animation?: { duration: number, curve: Curve } }): void scrollTo(value: { xOffset: number | string, yOffset: number | string, animation?: { duration: number, curve: Curve } }): void
...@@ -63,13 +73,13 @@ Scrolls to the specified position. ...@@ -63,13 +73,13 @@ Scrolls to the specified position.
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | --------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
| xOffset | Length | Yes | - | Horizontal scrolling offset. | | xOffset | Length | Yes | - | Horizontal scrolling offset. |
| yOffset | Length | Yes | - | Vertical scrolling offset. | | yOffset | Length | Yes | - | Vertical scrolling offset. |
| animation | {<br/>duration: number,<br/>curve: Curve \|<br/>CubicBezier \|<br/>SpringCurve<br/>} | No | | Animation configuration, which includes the following:<br/>- **duration**: scrolling duration.<br/>- **curve**: scrolling curve. | | animation | {<br>duration:&nbsp;number,<br>curve:&nbsp;[Curve](ts-animatorproperty.md)&nbsp;\|<br>CubicBezier&nbsp;\|<br>SpringCurve<br>} | No | | Animation configuration, which includes the following:<br>- **duration**: scrolling duration.<br>- **curve**: scrolling curve.|
### scroller.scrollEdge ### scrollEdge
scrollEdge(value: Edge): void scrollEdge(value: Edge): void
...@@ -78,12 +88,13 @@ Scrolls to the edge of the container. ...@@ -78,12 +88,13 @@ Scrolls to the edge of the container.
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type| Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | ----- | ---- | ---- | ---- | --------- |
| value | Edge | Yes | - | Edge position to scroll to. | | value | Edge | Yes | - | Edge position to scroll to.|
### scroller.scrollPage ### scrollPage
scrollPage(value: { next: boolean, direction?: Axis }): void scrollPage(value: { next: boolean, direction?: Axis }): void
...@@ -91,13 +102,14 @@ Scrolls to the next or previous page. ...@@ -91,13 +102,14 @@ Scrolls to the next or previous page.
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | --------- | ------- | ---- | ---- | ------------------------------ |
| next | boolean | Yes | - | Whether to turn to the next page. The value **true** means to scroll to the next page, and the value **false** means to scroll to the previous page. | | next | boolean | Yes | - | Whether to turn to the next page. The value **true** means to scroll to the next page, and **false** means to scroll to the previous page.|
| direction | Axis | No | - | Scrolling direction: horizontal or vertical. |
### scroller.currentOffset ### currentOffset
scroller.currentOffset(): Object currentOffset(): Object
Obtains the scrolling offset. Obtains the scrolling offset.
...@@ -105,41 +117,51 @@ Obtains the scrolling offset. ...@@ -105,41 +117,51 @@ Obtains the scrolling offset.
- Return value - Return value
| Type | Description | | Type | Description |
| -------- | -------- | | ------------------------------------------------------- | ------------------------------------------------------------ |
| {<br/>xOffset: number,<br/>yOffset: number<br/>} | - **xOffset**: horizontal scrolling offset.<br/>- **yOffset**: vertical scrolling offset. | | {<br>xOffset:&nbsp;number,<br>yOffset:&nbsp;number<br>} | **xOffset**: horizontal scrolling offset.<br>**yOffset**: vertical scrolling offset. |
### scroller.scrollToIndex ### scrollToIndex
scroller.scrollToIndex(value: number): void scrollToIndex(value: number): void
Scrolls to the specified index. Scrolls to the item with the specified index.
> **NOTE**<br> > **NOTE**
> Only the **<List\>** component is supported. > Only the **\<List>** component is supported.
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | ----- | ------ | ---- | ---- | ----------------- |
| value | number | Yes | - | Index of the item to be scrolled to in the list. | | value | number | Yes | - | Index of the item to be scrolled to in the list.|
## Events ### scrollBy
| Name | Description | scrollBy(dx: Length, dy: Length): void
| -------- | -------- |
| onScroll(xOffset: number, yOffset: number) =&gt; void | Invoked to return the horizontal and vertical scrolling offsets when the specified scroll event occurs. |
| onScrollEdge(side: Edge) =&gt; void | Invoked when an item is scrolled to the edge. |
| onScrollEnd() =&gt; void | Invoked when scrolling stops. |
## Example Scrolls by the specified amount.
``` > **NOTE**
> Only the **\<Scroll>** component is supported.
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| ----- | ------ | ---- | ---- | ----------------- |
| dx | Length | Yes | - | Amount to scroll by in the horizontal direction.|
| dy | Length | Yes | - | Amount to scroll by in the vertical direction.|
## Example
```ts
// xxx.ets
@Entry @Entry
@Component @Component
struct ScrollExample { struct ScrollExample {
...@@ -152,14 +174,20 @@ struct ScrollExample { ...@@ -152,14 +174,20 @@ struct ScrollExample {
Column() { Column() {
ForEach(this.arr, (item) => { ForEach(this.arr, (item) => {
Text(item.toString()) Text(item.toString())
.width('90%').height(150).backgroundColor(0xFFFFFF) .width('90%')
.borderRadius(15).fontSize(16).textAlign(TextAlign.Center) .height(150)
.backgroundColor(0xFFFFFF)
.borderRadius(15)
.fontSize(16)
.textAlign(TextAlign.Center)
.margin({ top: 10 }) .margin({ top: 10 })
}, item => item) }, item => item)
}.width('100%') }.width('100%')
} }
.scrollable(ScrollDirection.Vertical).scrollBar(BarState.On) .scrollable(ScrollDirection.Vertical)
.scrollBarColor(Color.Gray).scrollBarWidth(30) .scrollBar(BarState.On)
.scrollBarColor(Color.Gray)
.scrollBarWidth(30)
.onScroll((xOffset: number, yOffset: number) => { .onScroll((xOffset: number, yOffset: number) => {
console.info(xOffset + ' ' + yOffset) console.info(xOffset + ' ' + yOffset)
}) })
...@@ -171,17 +199,17 @@ struct ScrollExample { ...@@ -171,17 +199,17 @@ struct ScrollExample {
}) })
Button('scroll 100') Button('scroll 100')
.onClick(() => {// Click to scroll down 100.0. .onClick(() => { // Click to scroll down 100.0.
this.scroller.scrollTo({ xOffset: 0, yOffset: this.scroller.currentOffset().yOffset + 100 }) this.scroller.scrollTo({ xOffset: 0, yOffset: this.scroller.currentOffset().yOffset + 100 })
}) })
.margin({ top: 10, left: 20 }) .margin({ top: 10, left: 20 })
Button('back top') Button('back top')
.onClick(() => {// Click to go back to the top. .onClick(() => { // Click to go back to the top.
this.scroller.scrollEdge(Edge.Top) this.scroller.scrollEdge(Edge.Top)
}) })
.margin({ top: 60, left: 20 }) .margin({ top: 60, left: 20 })
Button('next page') Button('next page')
.onClick(() => {// Click to scroll down to the bottom. .onClick(() => { // Click to scroll down to the bottom.
this.scroller.scrollPage({ next: true }) this.scroller.scrollPage({ next: true })
}) })
.margin({ top: 110, left: 20 }) .margin({ top: 110, left: 20 })
...@@ -191,3 +219,58 @@ struct ScrollExample { ...@@ -191,3 +219,58 @@ struct ScrollExample {
``` ```
![en-us_image_0000001256978363](figures/en-us_image_0000001256978363.gif) ![en-us_image_0000001256978363](figures/en-us_image_0000001256978363.gif)
```ts
@Entry
@Component
struct NestedScroll {
@State listPosition: number = 0 // 0 indicates scrolling to the top of the list, 1 indicates scrolling to the center of the list, and 2 indicates scrolling to the bottom of the list.
private arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
private scroller: Scroller = new Scroller()
build() {
Flex() {
Scroll(this.scroller) {
Column() {
Text("Scroll Area")
.width("100%").height("40%").backgroundColor(0X330000FF)
.fontSize(16).textAlign(TextAlign.Center)
List({ space: 20 }) {
ForEach(this.arr, (item) => {
ListItem() {
Text("ListItem" + item)
.width("100%").height("100%").borderRadius(15)
.fontSize(16).textAlign(TextAlign.Center).backgroundColor(Color.White)
}.width("100%").height(100)
}, item => item)
}
.width("100%").height("50%").edgeEffect(EdgeEffect.None)
.onReachStart(() => {
this.listPosition = 0
})
.onReachEnd(() => {
this.listPosition = 2
})
.onScrollBegin((dx: number, dy: number) => {
if ((this.listPosition == 0 && dy >= 0) || (this.listPosition == 2 && dy <= 0)) {
this.scroller.scrollBy(0, -dy)
return { dxRemain: dx, dyRemain: 0 }
}
this.listPosition = 1;
return { dxRemain: dx, dyRemain: dy }
})
Text("Scroll Area")
.width("100%").height("40%").backgroundColor(0X330000FF)
.fontSize(16).textAlign(TextAlign.Center)
}
}
.width("100%").height("100%")
}.width('100%').height('100%').backgroundColor(0xDCDCDC).padding(20)
}
}
```
![NestedScroll](figures/NestedScroll.gif)
# Button
The **\<Button>** component can be used to create different types of buttons.
> **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
## Required Permissions
None
## Child Components
Supported
## APIs
- Button(options?: {type?: ButtonType, stateEffect?: boolean})
**Table 1** options parameters
| Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- |
| type | ButtonType | No | Capsule | Button type. |
| stateEffect | boolean | No | true | Whether to enable the state switchover effect when a button is pressed. When the state is set to **false**, the state switchover effect is disabled. |
- Button(label?: ResourceStr, options?: { type?: ButtonType, stateEffect?: boolean })
Creates a button component based on text content. In this case, the **\<Button>** component cannot contain child components.
**Table 2** Parameters
| Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- |
| label | [ResourceStr](../../ui/ts-types.md) | No | - | Button text. |
| options | Object | No | - | For details, see the **options** parameters. |
## Attributes
| Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- |
| type | ButtonType | Capsule | Button type. |
| stateEffect | boolean | true | Whether to enable the state switchover effect. When the state is set to **false**, the state switchover effect is disabled. |
**ButtonType** enums
| Name | Description |
| -------- | -------- |
| Capsule | Capsule-type button (the round corner is half of the height by default). |
| Circle | Circle button. |
| Normal | Normal button (without rounded corners by default). |
> **NOTE**
> - The rounded corner of a button is set by using [Border](ts-universal-attributes-border.md). (The rounded corner cannot be set by using a border API.)
> - When the button type is **Capsule**, the **borderRadius** settings do not take effect, and the rounded corner of the button is always half of the button height.
> - When the button type is **Circle**, the value of **borderRadius** is used as the button radius. If **borderRadius** is not set, the button radius is half of the width or height, whichever is smaller.
> - The button text is set using the [common text style](ts-universal-attributes-text-style.md).
## Example
```ts
// xxx.ets
@Entry
@Component
struct ButtonExample {
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
Text('Common button').fontSize(9).fontColor(0xCCCCCC)
Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Button('Ok', { type: ButtonType.Normal, stateEffect: true }).borderRadius(8).backgroundColor(0x317aff).width(90)
Button({ type: ButtonType.Normal, stateEffect: true }) {
Row() {
// You are advised to reference an image by using $r to create a Resource object.
Image($r('app.media.loading')).width(20).height(20).margin({ left: 12 })
Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 })
}.alignItems(VerticalAlign.Center)
}.borderRadius(8).backgroundColor(0x317aff).width(90)
Button('Disable', { type: ButtonType.Normal, stateEffect: false }).opacity(0.5)
.borderRadius(8).backgroundColor(0x317aff).width(90)
}
Text('Capsule button').fontSize(9).fontColor(0xCCCCCC)
Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Button('Ok', { type: ButtonType.Capsule, stateEffect: true }).backgroundColor(0x317aff).width(90)
Button({ type: ButtonType.Capsule, stateEffect: true }) {
Row() {
Image($r('app.media.loading')).width(20).height(20).margin({ left: 12 })
Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 })
}.alignItems(VerticalAlign.Center).width(90)
}.backgroundColor(0x317aff)
.onClick((event: ClickEvent) => {
AlertDialog.show({ message: 'The login is successful' })
})
Button('Disable', { type: ButtonType.Capsule, stateEffect: false }).opacity(0.5)
.backgroundColor(0x317aff).width(90)
}
Text('Circle button').fontSize(9).fontColor(0xCCCCCC)
Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.Wrap }) {
Button({ type: ButtonType.Circle, stateEffect: true }) {
Image($r('app.media.ic_public_app_filled')).width(20).height(20)
}.width(55).height(55).backgroundColor(0x317aff)
Button({ type: ButtonType.Circle, stateEffect: true }) {
Image($r('app.media.ic_public_delete_filled')).width(30).height(30)
}.width(55).height(55).margin({ left: 20 }).backgroundColor(0xF55A42)
}
}.height(400).padding({ left: 35, right: 35, top: 35 })
}
}
```
![en-us_image_0000001257138341](figures/en-us_image_0000001257138341.gif)
# @Component # @Component
A struct decorated by **@Component** has the componentization capability and can serve as an independent component. This type of component is also called a custom component, and its UI structure is described in the **build** method. Custom components have the following features:
A struct decorated by @Component has the componentization capability and can serve as an independent component. This type of component is also called a custom component, and its UI structure is described in the build method. Custom components have the following features:
- Composability: Custom components can be used with preset or other components, as well as common attributes and methods. - Composability: Custom components can be used with preset or other components, as well as common attributes and methods.
- Chain call<sup>9+</sup>: Universal attributes can be invoked in chain call mode to change the component style.
- Reusable: Custom components can be reused by other components and used as different instances in different parent components or containers. - Reusable: Custom components can be reused by other components and used as different instances in different parent components or containers.
- Lifecycle: Custom components provide callbacks for service logic processing throughout the lifecycle. - Lifecycle: Custom components provide callbacks for service logic processing throughout the lifecycle.
- Data-driven update: The UI of custom components can be automatically updated based on the data of state variables. - Data-driven update: The UI of custom components can be automatically updated based on the data of state variables.
For details about componentization, see [About @Component](ts-function-build.md). For details about componentization, see [About @Component](ts-custom-component-initialization.md).
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**: > **NOTE**
> - The build method must be defined for a custom component.
> >
> - Custom constructors are prohibited for custom components. > - The **build** method must be defined for a custom component.
>- Custom constructors are prohibited for custom components.
The following code illustrates how to create a custom component named MyComponent: The following code illustrates how to create a custom component named **MyComponent**:
```
```ts
@Component @Component
struct MyComponent { struct MyComponent {
build() { build() {
...@@ -37,12 +35,13 @@ struct MyComponent { ...@@ -37,12 +35,13 @@ struct MyComponent {
``` ```
The build method of MyComponent is executed during initial rendering. When the component status changes, the build method will be executed again. The **build** method of **MyComponent** is executed during initial rendering. When the component status changes, the **build** method will be executed again.
The following code illustrates how to use MyComponent: The following code illustrates how to use **MyComponent**:
```
```ts
@Component @Component
struct ParentComponent { struct ParentComponent {
build() { build() {
...@@ -56,9 +55,10 @@ struct ParentComponent { ...@@ -56,9 +55,10 @@ struct ParentComponent {
``` ```
MyComponent can be applied multiple times and reused in different components, as shown in the code below: **MyComponent** can be applied multiple times and reused in different components, as shown in the code below:
```
```ts
@Component @Component
struct ParentComponent { struct ParentComponent {
build() { build() {
...@@ -76,12 +76,47 @@ struct ParentComponent { ...@@ -76,12 +76,47 @@ struct ParentComponent {
} }
} }
private aboutToAppear() { aboutToAppear() {
console.log('ParentComponent: Just created, about to become rendered first time.') console.log('ParentComponent: Just created, about to become rendered first time.')
} }
private aboutToDisappear() { aboutToDisappear() {
console.log('ParentComponent: About to be removed from the UI.') console.log('ParentComponent: About to be removed from the UI.')
} }
} }
``` ```
Universal attributes can be invoked in chain call mode to diversify component styles.
> **NOTE**
>
> This feature is supported since API version 9.
>
> The chain call for custom components does not support trailing closures in the following scenario: When the custom component is initialized, the component name is followed by a pair of braces ({}) to form a trailing closure (as in `Index(){}`). You can consider a trailing closure as a container and add content to it, as in `{Column(){Text("content")}`.
```ts
@Entry
@Component
struct Index {
@State bannerValue: string = 'Hello,world';
build() {
Column() {
Chind({ ChindBannerValue:$bannerValue })
.height(60)
.width(250)
.border({ width:5, color:Color.Red, radius:10, style: BorderStyle.Dotted })
}
}
}
@Component
struct Chind {
@Link ChindBannerValue: string;
build() {
Column() {
Text(this.ChindBannerValue)
.fontSize(30)
}
}
}
```
...@@ -14,17 +14,17 @@ A component can access only one **LocalStorage** instance, and a **LocalStorage* ...@@ -14,17 +14,17 @@ A component can access only one **LocalStorage** instance, and a **LocalStorage*
## @LocalStorageLink Decorator ## @LocalStorageLink Decorator
Two-way data binding can be established between a component and the **LocalStorage** through the component's state variable decorated by **@LocalStorageLink(*key*)**. Wherein, **key** is the attribute key value in the **LocalStorage**. When a component that contains a **@LocalStorageLink** decorated state variable is created, the state variable is initialized with the initial value of the **LocalStorage**. If no initial value is assigned for the **LocalStorage**, the state variable will use the value defined by **@LocalStorageLink**. Changes made to this variable in the component will be first synchronized to the **LocalStorage**, and then to other components of the bound ability. Two-way data binding can be established between a component and the **LocalStorage** through the component's state variable decorated by **@LocalStorageLink(*key*)**. Wherein, **key** is the attribute key value in the **LocalStorage**. When a component that contains a **@LocalStorageLink** decorated state variable is created, the state variable is initialized with the value predefined in the **LocalStorage**. If no initial value is assigned in the **LocalStorage**, the state variable will use the value defined by **@LocalStorageLink**. Changes made to this variable in the component will be first synchronized to the **LocalStorage**, and then to other components of the bound ability.
## @LocalStorageProp Decorator ## @LocalStorageProp Decorator
One-way data binding can be established between a component and the **LocalStorage** through the component's state variable decorated by **@LocalStorageLink(*key*)**. Wherein, **key** is the attribute key value in the **LocalStorage**. When a component that contains a **@LocalStorageProp** decorated state variable is created, the state variable is initialized with the value predefined in the **LocalStorage**. Changes made to the value in the **LocalStorage** will cause all UI components of the bound ability to update the state. One-way data binding can be established between a component and the **LocalStorage** through the component's state variable decorated by **@LocalStorageProp(*key*)**. Wherein, **key** is the attribute key value in the **LocalStorage**. When a component that contains a **@LocalStorageProp** decorated state variable is created, the state variable is initialized with the value predefined in the **LocalStorage**. Changes made to the value in the **LocalStorage** will cause all UI components of the bound ability to update the state.
> **NOTE** > **NOTE**
> >
> If a **LocalStorage** instance has initial values assigned when being created, these values will be used for the **@LocalStorageLink** and **@LocalStorageProp** decorated state variables in the component. Otherwise, the initial values assigned for **@LocalStorageLink** and **@LocalStorageProp** will be used instead. > If a **LocalStorage** instance has initial values assigned when being created, these values will be used for the **@LocalStorageLink** and **@LocalStorageProp** decorated state variables in the component. Otherwise, the initial values assigned for **@LocalStorageLink** and **@LocalStorageProp** will be used instead.
## LocalStorage APIs ## LocalStorage
### constructor ### constructor
...@@ -34,12 +34,28 @@ Creates and initializes a **LocalStorage** instance. ...@@ -34,12 +34,28 @@ Creates and initializes a **LocalStorage** instance.
**Parameters** **Parameters**
| Name | Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| ---------------------- | ------ | :--: | ------ | ------------------------------------------------------------ | | ---------------------- | ------ | :--: | ---- | ---------------------------------------- |
| initializingProperties | Object | No | - | Object attributes and their values returned by **object.keys(obj)**.| | initializingProperties | Object | No | - | Object attributes and their values returned by **object.keys(obj)**.|
### GetShared
static GetShared(): LocalStorage
Obtains the current shared **LocalStorage** object.
This API can be used only in the stage model.
**Return value**
| Type | Description |
| ----------------------------- | ----------------- |
| [LocalStorage](#localstorage) | **LocalStorage** object.|
### has ### has
has(propName: string): boolean has(propName: string): boolean
...@@ -48,14 +64,14 @@ Checks whether the **LocalStorage** contains the specified attribute value. ...@@ -48,14 +64,14 @@ Checks whether the **LocalStorage** contains the specified attribute value.
**Parameters** **Parameters**
| Name | Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | ------ | :--: | ------ | -------------- | | -------- | ------ | :--: | ---- | ------- |
| propName | string | Yes | - | Attribute value.| | propName | string | Yes | - | Attribute value.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------------------- | | ------- | ------------- |
| boolean | Whether the attribute value is contained.| | boolean | Whether the attribute value is contained.|
...@@ -68,14 +84,14 @@ Obtains the value corresponding to the given key. ...@@ -68,14 +84,14 @@ Obtains the value corresponding to the given key.
**Parameters** **Parameters**
| Name | Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | ------ | :--: | ------ | ------------------- | | -------- | ------ | :--: | ---- | ----------- |
| propName | string | Yes | - | Key of the value to obtain.| | propName | string | Yes | - | Key of the value to obtain.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------------------------------------- | | -------------- | ---------------------------------------- |
| T \| undefined | Returns the value if it is found; returns **undefined** otherwise.| | T \| undefined | Returns the value if it is found; returns **undefined** otherwise.|
...@@ -88,15 +104,15 @@ Sets the value for the given key. ...@@ -88,15 +104,15 @@ Sets the value for the given key.
**Parameters** **Parameters**
| Name | Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | ------ | :--: | ------ | ----------------- | | -------- | ------ | :--: | ---- | ----------- |
| propName | string | Yes | - | Key of the value to set. | | propName | string | Yes | - | Key of the value to set. |
| newValue | T | Yes | - | Value to set.| | newValue | T | Yes | - | Value to set.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ----------------------------------------------------- | | ------- | ----------------------------------- |
| boolean | Returns **true** if the value is successfully set for the key; returns **false** otherwise.| | boolean | Returns **true** if the value is successfully set for the key; returns **false** otherwise.|
...@@ -109,16 +125,16 @@ Creates or updates the value for the given key. ...@@ -109,16 +125,16 @@ Creates or updates the value for the given key.
**Parameters** **Parameters**
| Name | Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | ------ | :--: | ------ | ----------------------- | | -------- | ------ | :--: | ---- | -------------- |
| propName | string | Yes | - | Key of the value to create or update.| | propName | string | Yes | - | Key of the value to create or update. |
| newValue | T | Yes | - | Value to create or update.| | newValue | T | Yes | - | Value to create or update.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------------------------------------------------------ | | ------- | ---------------------------------------- |
| boolean | Updates the value of the attribute and returns **true** if an attribute that has the same name as the specified key exists; creates an attribute with the specified value as its default value and returns **false** otherwise. **true** cannot be returned for **undefined** or **null**.| | boolean | Updates the value of the attribute and returns **true** if an attribute that has the same name as the specified key exists; creates an attribute with the specified value of the T type as its default value and returns **false** otherwise. **true** cannot be returned for **undefined** or **null**.|
...@@ -130,14 +146,14 @@ Establishes two-way data binding between an attribute and this **LocalStorage** ...@@ -130,14 +146,14 @@ Establishes two-way data binding between an attribute and this **LocalStorage**
**Parameters** **Parameters**
| Name | Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | ------ | :--: | ------ | ---------------------- | | -------- | ------ | :--: | ---- | ----------- |
| propName | string | Yes | - | Key of the target attribute.| | propName | string | Yes | - | Key of the target attribute.|
**Return value** **Return value**
| Type| Description | | Type | Description |
| ---- | ------------------------------------------------------------ | | ---- | ---------------------------------------- |
| T | Returns the two-way data binding if an attribute that has the same name as the specified key exists; returns **undefined** otherwise.| | T | Returns the two-way data binding if an attribute that has the same name as the specified key exists; returns **undefined** otherwise.|
...@@ -146,20 +162,20 @@ Establishes two-way data binding between an attribute and this **LocalStorage** ...@@ -146,20 +162,20 @@ Establishes two-way data binding between an attribute and this **LocalStorage**
setAndLink\<T>(propName: string, defaultValue: T): T setAndLink\<T>(propName: string, defaultValue: T): T
Establishes two-way data binding between an attribute and this **LocalStorage** instance. Establishes two-way data binding between an attribute and this **LocalStorage** instance. This API works in a way similar to the **link** API.
**Parameters** **Parameters**
| Name | Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| ------------ | ------ | :--: | ------ | -------------------- | | ------------ | ------ | :--: | ---- | ----------- |
| propName | string | Yes | - | Key of the target attribute. | | propName | string | Yes | - | Key of the target attribute.|
| defaultValue | T | Yes | - | Default value of the target attribute to set.| | defaultValue | T | Yes | - | Default value to set. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------- | ------------------------------------------------------------ | | ------------------------------------- | ---------------------------------------- |
| [@Link](ts-component-states-link.md)| Returns the two-way data binding if an attribute that has the same name as the specified key exists; creates an attribute with the specified value as its default value and returns the attribute otherwise.| | [@Link](ts-component-states-link.md ) | Returns the value corresponding to the specified key if the key is stored in the **LocalStorage**; creates and returns a **Link** instance with the specified value as its default value otherwise|
...@@ -171,15 +187,15 @@ Establishes one-way data binding with an attribute to update its status. ...@@ -171,15 +187,15 @@ Establishes one-way data binding with an attribute to update its status.
**Parameters** **Parameters**
| Name | Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | ------ | :--: | ------ | ----------------------- | | -------- | ------ | :--: | ---- | ------------- |
| propName | string | Yes | - | Key of the target attribute.| | propName | string | Yes | - | Key of the target attribute.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------ | ------------------------------------------------------------ | | ------------------------------------ | ---------------------------------------- |
| [@Prop](ts-component-states-prop.md) | Returns the one-way data binding if an attribute that has the same name as the specified key exists; returns **undefined** otherwise. Note that the variables returned are immutable variables, which are applicable to variable and immutable state variables.| | [@Prop](ts-component-states-prop.md) | Returns one-way binding to an attribute with a given key if the attribute exists; returns **undefined** otherwise. This means that attribute changes made through the **LocalStorage** will be synchronized to the variable or component, but attribute changes made by the variable or component will be synchronized to the **LocalStorage**. Note that the variables returned are immutable variables, which are applicable to mutable and immutable state variables. |
...@@ -187,20 +203,20 @@ Establishes one-way data binding with an attribute to update its status. ...@@ -187,20 +203,20 @@ Establishes one-way data binding with an attribute to update its status.
setAndProp\<T>(propName: string, defaultValue: T): T setAndProp\<T>(propName: string, defaultValue: T): T
Works in a way similar to the **Prop** API and sets up one-way data binding with the **localStorage**. Sets up one-way data binding with the **localStorage**. This API works in a way similar to the **Prop** API.
**Parameters** **Parameters**
| Name | Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| ------------ | ------ | :--: | ------ | --------------------------- | | ------------ | ------ | :--: | ---- | --------------- |
| propName | string | Yes | - | Key value in the key-value pair to be saved.| | propName | string | Yes | - | Key value in the key-value pair to be saved.|
| defaultValue | T | Yes | - | Default value created. | | defaultValue | T | Yes | - | Default value to set. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------ | ------------------------------------------------------------ | | ------------------------------------ | ---------------------------------------- |
| [@Prop](ts-component-states-prop.md) | Returns the value corresponding to the key if the current key is stored in the **LocalStorage**; creates and returns a **Prop** instance corresponding to the default value if the key has not been created.| | [@Prop](ts-component-states-prop.md) | Returns the value corresponding to the specified key if the key is stored in the **LocalStorage**; creates and returns a **Prop** instance with the specified value as its default value otherwise.|
...@@ -212,15 +228,15 @@ Deletes the key-value pair specified by key. ...@@ -212,15 +228,15 @@ Deletes the key-value pair specified by key.
**Parameters** **Parameters**
| Name | Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | ------ | :--: | ------ | --------------------- | | -------- | ------ | :--: | ---- | ------------ |
| propName | string | Yes | - | Key value of the attribute to be deleted.| | propName | string | Yes | - | Key value of the attribute to be deleted.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------------------------------------------------------ | | ------- | ---------------------------------------- |
| boolean | Deletes the key-value pair for the specified key. Returns **true** if the key-value pair exists and is successfully deleted; returns **false** otherwise.| | boolean | Returns **true** if the key-value pair exists and is successfully deleted; returns **false** otherwise.|
...@@ -233,7 +249,7 @@ Searches for all keys. ...@@ -233,7 +249,7 @@ Searches for all keys.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------------------------- | | -------------- | -------------- |
| array\<string> | Returns an array of strings containing all keys.| | array\<string> | Returns an array of strings containing all keys.|
...@@ -247,7 +263,7 @@ Number of existing key-value pairs. ...@@ -247,7 +263,7 @@ Number of existing key-value pairs.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ------------------ | | ------ | --------- |
| number | Number of key-value pairs.| | number | Number of key-value pairs.|
...@@ -261,13 +277,13 @@ Deletes all attributes. ...@@ -261,13 +277,13 @@ Deletes all attributes.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------------------------------------------------------ | | ------- | --------------------------------- |
| boolean | Deletes all attributes. If any of the attributes is being referenced by a state variable, **false** is returned.| | boolean | Returns **true** if all attributes are deleted; returns **false** if any of the attributes is being referenced by a state variable.|
### Example 1 (Creating a LocalStorage in an Ability) ### Example 1 (Creating a LocalStorage in an Ability)
```javascript ```ts
import Ability from '@ohos.appLication.Ability' import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
storage : LocalStorage storage : LocalStorage
onCreate(want) { onCreate(want) {
...@@ -296,7 +312,7 @@ export default class MainAbility extends Ability { ...@@ -296,7 +312,7 @@ export default class MainAbility extends Ability {
The @Component decorated component obtains data. The @Component decorated component obtains data.
``` ```ts
let storage = LocalStorage.GetShared() let storage = LocalStorage.GetShared()
@Entry(storage) @Entry(storage)
@Component @Component
...@@ -318,15 +334,15 @@ struct LocalStorageComponent { ...@@ -318,15 +334,15 @@ struct LocalStorageComponent {
### Example 2 (Defining LocalStorage on the Entry Page) ### Example 2 (Defining LocalStorage on the Entry Page)
``` ```ts
let storage = new LocalStorage({"PropA":47}); let storage = new LocalStorage({"PropA":47});
@Entry(storage) @Entry(storage)
@Component @Component
struct ComA { struct ComA {
@LocalStorageLink("PropA") storLink : number = 1; @LocalStorageLink("PropA") storLink: number = 1;
build() { build() {
Column() { Column() {
Text(`Parent from LocalStorage $(this.storLink)`) Text(`Parent from LocalStorage ${ this.storLink }`)
.onClick(()=>this.storLink+=1) .onClick(()=>this.storLink+=1)
Child() Child()
} }
...@@ -336,10 +352,10 @@ struct ComA { ...@@ -336,10 +352,10 @@ struct ComA {
@Component @Component
struct Child{ struct Child{
@LocalStorageLink("PropA") storLink : number = 1; @LocalStorageLink("PropA") storLink: number = 1;
build() { build() {
Text(`Parent from LocalStorage $(this.storLink)`) Text(`Parent from LocalStorage ${ this.storLink }`)
.onClick(()=>this.storLink1+=1) .onClick(()=>this.storLink+=1)
} }
} }
``` ```
...@@ -29,9 +29,9 @@ Ability框架在API 8及更早版本使用FA模型。FA模型中Ability分为Pag ...@@ -29,9 +29,9 @@ Ability框架在API 8及更早版本使用FA模型。FA模型中Ability分为Pag
## 相关实例 ## 相关实例
针对Ability开发,有以下相关实例可供参考: 针对Ability开发,有以下相关实例可供参考:
- [`DistributeCalc`:分布式计算器(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/Preset/DistributeCalc) - [`DistributedCalc`:分布式计算器(JS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/common/DistributeCalc)
- [`DistributeGraffiti`:分布式涂鸦(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/DistributedGraffiti) - [`DistributedCalc`:分布式计算器(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/Preset/DistributeCalc)
- [`DistributeGraffiti`:分布式涂鸦(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/DistributedGraffiti)
- [分布式调度启动远程FA(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/RemoteStartFA) - [分布式调度启动远程FA(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/RemoteStartFA)
- [分布式新闻客户端(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/NewsDemo) - [分布式新闻客户端(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/NewsDemo)
- [分布式手写板(eTS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/DistributeDatabaseDrawEts) - [分布式手写板(eTS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/DistributeDatabaseDrawEts)
......
...@@ -311,4 +311,4 @@ URI示例: ...@@ -311,4 +311,4 @@ URI示例:
针对DataAbility开发,有以下相关实例可供参考: 针对DataAbility开发,有以下相关实例可供参考:
- [`DataAbility`:DataAbility的创建与访问(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/DataAbility) - [`DataAbility`:DataAbility的创建与访问(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/DataAbility)
...@@ -350,5 +350,5 @@ onUpdate(formId) { ...@@ -350,5 +350,5 @@ onUpdate(formId) {
## 相关实例 ## 相关实例
针对FA模型卡片提供方的开发,有以下相关实例可供参考: 针对FA模型卡片提供方的开发,有以下相关实例可供参考:
- [`FormAbility`:FA模型卡片(JS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/FormAbility) - [`FormAbility`:FA模型卡片(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/FormAbility)
- [`FormLauncher`:卡片使用方(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/FormLauncher) - [`FormLauncher`:卡片使用方(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/FormLauncher)
\ No newline at end of file \ No newline at end of file
...@@ -227,4 +227,4 @@ export default { ...@@ -227,4 +227,4 @@ export default {
针对PageAbility开发,有以下相关实例可供参考: 针对PageAbility开发,有以下相关实例可供参考:
- [`DMS`:分布式Demo(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/DMS) - [`DMS`:分布式Demo(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/DMS)
\ No newline at end of file \ No newline at end of file
...@@ -430,5 +430,5 @@ export default { ...@@ -430,5 +430,5 @@ export default {
## 相关实例 ## 相关实例
针对ServiceAbility开发,有以下相关实例可供参考: 针对ServiceAbility开发,有以下相关实例可供参考:
- [`ServiceAbility`:ServiceAbility的创建与使用(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/ServiceAbility) - [`ServiceAbility`:ServiceAbility的创建与使用(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/ServiceAbility)
- [`DMS`:分布式Demo(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/ability/DMS) - [`DMS`:分布式Demo(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/DMS)
...@@ -320,4 +320,4 @@ struct Index { ...@@ -320,4 +320,4 @@ struct Index {
## 相关实例 ## 相关实例
针对Stage模型Ability开发,有以下相关示例可供参考: 针对Stage模型Ability开发,有以下相关示例可供参考:
- [`StageCallAbility`:StageCallAbility的创建与使用(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/ability/StageCallAbility) - [`StageCallAbility`:StageCallAbility的创建与使用(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/StageCallAbility)
...@@ -97,4 +97,4 @@ ...@@ -97,4 +97,4 @@
![stageprocessmodel](figures/stageprocessmodel.png) ![stageprocessmodel](figures/stageprocessmodel.png)
## 相关实例 ## 相关实例
针对Stage模型下的Ability开发,有以下相关实例可供参考: 针对Stage模型下的Ability开发,有以下相关实例可供参考:
- [`MissionManager`:系统任务管理(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/ability/MissionManager) - [`MissionManager`:系统任务管理(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/MissionManager)
...@@ -250,4 +250,4 @@ try { ...@@ -250,4 +250,4 @@ try {
## 相关实例 ## 相关实例
针对Stage模型本地Call功能开发,有以下相关实例可供参考: 针对Stage模型本地Call功能开发,有以下相关实例可供参考:
- [`StageCallAbility`:StageCallAbility的创建与使用(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/ability/StageCallAbility) - [`StageCallAbility`:StageCallAbility的创建与使用(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/StageCallAbility)
...@@ -361,4 +361,4 @@ onUpdate(formId) { ...@@ -361,4 +361,4 @@ onUpdate(formId) {
## 相关实例 ## 相关实例
针对Stage模型卡片提供方的开发,有以下相关实例可供参考: 针对Stage模型卡片提供方的开发,有以下相关实例可供参考:
- [`FormExtAbility`:Stage模型卡片(eTS JS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/ability/FormExtAbility) - [`FormExtAbility`:Stage模型卡片(eTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/FormExtAbility)
\ No newline at end of file \ No newline at end of file
...@@ -75,4 +75,4 @@ OpenHarmony当前不支持三方应用创建ServiceExtensionAbility。 ...@@ -75,4 +75,4 @@ OpenHarmony当前不支持三方应用创建ServiceExtensionAbility。
## 相关实例 ## 相关实例
针对ServiceExtensionAbility开发,有以下相关实例可供参考: 针对ServiceExtensionAbility开发,有以下相关实例可供参考:
- [`ServiceExtAbility`:StageExtAbility的创建与使用(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/ability/ServiceExtAbility) - [`ServiceExtAbility`:StageExtAbility的创建与使用(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/ServiceExtAbility)
...@@ -74,5 +74,5 @@ httpRequest.request( ...@@ -74,5 +74,5 @@ httpRequest.request(
## 相关实例 ## 相关实例
针对HTTP数据请求,有以下相关实例可供参考: 针对HTTP数据请求,有以下相关实例可供参考:
- [`Http`:数据请求(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/Network/Http) - [`Http:`数据请求(eTS)(API9))](https://gitee.com/openharmony/applications_app_samples/tree/master/Network/Http)
- [使用HTTP实现与服务端通信(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/SmartChatEtsOH) - [使用HTTP实现与服务端通信(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/SmartChatEtsOH)
\ No newline at end of file
...@@ -125,6 +125,6 @@ UDP与TCP流程大体类似,下面以TCP为例: ...@@ -125,6 +125,6 @@ UDP与TCP流程大体类似,下面以TCP为例:
## 相关实例 ## 相关实例
针对Socket连接开发,有以下相关实例可供参考: 针对Socket连接开发,有以下相关实例可供参考:
- [`Socket`:Socket 连接(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/Network/Socket) - [`Socket`:Socket 连接(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/Network/Socket)
- [使用UDP实现与服务端通信(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/UdpDemoOH) - [使用UDP实现与服务端通信(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/UdpDemoOH)
- [使用TCP实现与服务端通信(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/TcpSocketDemo) - [使用TCP实现与服务端通信(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/TcpSocketDemo)
\ No newline at end of file
...@@ -87,4 +87,4 @@ WebSocket连接功能主要由webSocket模块提供。使用该功能需要申 ...@@ -87,4 +87,4 @@ WebSocket连接功能主要由webSocket模块提供。使用该功能需要申
## 相关实例 ## 相关实例
针对WebSocket连接的开发,有以下相关实例可供参考: 针对WebSocket连接的开发,有以下相关实例可供参考:
- [`WebSocket`:WebSocket(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/Network/WebSocket) - [`WebSocket`:WebSocket(eTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/Network/WebSocket)
\ No newline at end of file \ No newline at end of file
...@@ -256,11 +256,7 @@ ...@@ -256,11 +256,7 @@
``` ```
## 相关实例 ## 相关实例
针对分布式数据对象,有以下开发实例可供参考: 针对分布式数据对象,有以下相关实例可供参考:
- [`DistributedNote`:分布式备忘录(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/data/DistributedNote) - [`DistributedNote`:分布式备忘录(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/data/DistributedNote)
- [`DistributedObjectDms`:分布式跑马灯(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/data/DistributedObjectDms)
- [备忘录应用](https://gitee.com/openharmony/distributeddatamgr_objectstore/tree/master/samples/distributedNotepad)
在备忘录应用中,当某一个设备上的备忘录事件发生变更时,通过分布式数据对象将事件变更同步在可信组网内的其他设备上,比如新增备忘录事件、编辑事件标题和内容、清空事件列表
等。
...@@ -29,11 +29,13 @@ ...@@ -29,11 +29,13 @@
以单版本分布式数据库为例,说明开发步骤。 以单版本分布式数据库为例,说明开发步骤。
1. 导入模块。 1. 导入模块。
```js ```js
import distributedData from '@ohos.data.distributedData'; import distributedData from '@ohos.data.distributedData';
``` ```
2. 根据配置构造分布式数据库管理类实例。 2. 根据配置构造分布式数据库管理类实例。
1. 根据应用上下文创建`kvManagerConfig`对象。 1. 根据应用上下文创建`kvManagerConfig`对象。
2. 创建分布式数据库管理器实例。 2. 创建分布式数据库管理器实例。
...@@ -62,6 +64,7 @@ ...@@ -62,6 +64,7 @@
``` ```
3. 获取/创建分布式数据库。 3. 获取/创建分布式数据库。
1. 声明需要创建的分布式数据库ID描述。 1. 声明需要创建的分布式数据库ID描述。
2. 创建分布式数据库,建议关闭自动同步功能(`autoSync:false`),需要同步时主动调用`sync`接口。 2. 创建分布式数据库,建议关闭自动同步功能(`autoSync:false`),需要同步时主动调用`sync`接口。
...@@ -95,6 +98,7 @@ ...@@ -95,6 +98,7 @@
> 组网设备间同步数据的场景,建议在应用启动时打开分布式数据库,获取数据库的句柄。在该句柄(如示例中的`kvStore`)的生命周期内无需重复创建数据库,可直接使用句柄对数据库进行数据的插入等操作。 > 组网设备间同步数据的场景,建议在应用启动时打开分布式数据库,获取数据库的句柄。在该句柄(如示例中的`kvStore`)的生命周期内无需重复创建数据库,可直接使用句柄对数据库进行数据的插入等操作。
4. 订阅分布式数据变化。 4. 订阅分布式数据变化。
以下为订阅单版本分布式数据库数据变化通知的代码示例: 以下为订阅单版本分布式数据库数据变化通知的代码示例:
```js ```js
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) { kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) {
...@@ -103,6 +107,7 @@ ...@@ -103,6 +107,7 @@
``` ```
5. 将数据写入分布式数据库。 5. 将数据写入分布式数据库。
1. 构造需要写入分布式数据库的`Key`(键)和`Value`(值)。 1. 构造需要写入分布式数据库的`Key`(键)和`Value`(值)。
2. 将键值数据写入分布式数据库。 2. 将键值数据写入分布式数据库。
...@@ -125,6 +130,7 @@ ...@@ -125,6 +130,7 @@
``` ```
6. 查询分布式数据库数据。 6. 查询分布式数据库数据。
1. 构造需要从单版本分布式数据库中查询的`Key`(键)。 1. 构造需要从单版本分布式数据库中查询的`Key`(键)。
2. 从单版本分布式数据库中获取数据。 2. 从单版本分布式数据库中获取数据。
...@@ -149,6 +155,7 @@ ...@@ -149,6 +155,7 @@
``` ```
7. 同步数据到其他设备。 7. 同步数据到其他设备。
选择同一组网环境下的设备以及同步模式,进行数据同步。 选择同一组网环境下的设备以及同步模式,进行数据同步。
> **说明**: > **说明**:
...@@ -182,8 +189,12 @@ ...@@ -182,8 +189,12 @@
}); });
``` ```
## 相关实例 ## 相关实例
针对分布式数据开发,有以下相关实例可供参考: 针对分布式数据开发,有以下相关实例可供参考:
- [`DistributedDataGobang`:分布式五子棋(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/data/DistributedDataGobang)
- [`DDMQuery`:结果集与谓词(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/data/DDMQuery) - [`DistributedCalc`:分布式计算器(JS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/common/DistributeCalc)
- [`KvStore`:分布式数据库(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/data/Kvstore) - [`DistributedCalc`:分布式计算器(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/Preset/DistributeCalc)
- [`DistributedDataGobang`:分布式五子棋(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/data/DistributedDataGobang)
- [`DDMQuery`:结果集与谓词(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/data/DDMQuery)
- [`KvStore`:分布式数据库(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/data/Kvstore)
- [分布式数据库(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Data/JsDistributedData) - [分布式数据库(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Data/JsDistributedData)
\ No newline at end of file
...@@ -173,4 +173,4 @@ ...@@ -173,4 +173,4 @@
## 相关实例 ## 相关实例
针对首选项开发,有以下相关实例可供参考: 针对首选项开发,有以下相关实例可供参考:
- [`Preferences`:首选项(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/data/Preferences) - [`Preferences`:首选项(eTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/data/Preferences)
\ No newline at end of file \ No newline at end of file
...@@ -360,5 +360,5 @@ ...@@ -360,5 +360,5 @@
## 相关实例 ## 相关实例
针对关系型数据库开发,有以下相关实例可供参考: 针对关系型数据库开发,有以下相关实例可供参考:
- [`DistributedRdb`:分布式关系型数据库(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/data/DistributedRdb) - [`DistributedRdb`:分布式关系型数据库(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/data/DistributedRdb)
- [关系型数据库(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Data/JSRelationshipData) - [关系型数据库(JS)(API8)](https://gitee.com/openharmony/codelabs/tree/master/Data/JSRelationshipData)
...@@ -438,5 +438,5 @@ import stats from '@ohos.bundleState'; ...@@ -438,5 +438,5 @@ import stats from '@ohos.bundleState';
``` ```
## 相关实例 ## 相关实例
针对设备使用信息统计,有以下相关实例可供参考: 针对设备使用信息统计,有以下相关实例可供参考:
- [`DeviceUsageStatistics`:设备使用信息统计(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/device/DeviceUsageStatistics) - [`DeviceUsageStatistics`:设备使用信息统计(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/device/DeviceUsageStatistics)
...@@ -139,4 +139,4 @@ ...@@ -139,4 +139,4 @@
针对传感器开发,有以下相关实例可供参考: 针对传感器开发,有以下相关实例可供参考:
- [`Sensor`:传感器(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/device/Sensor) - [`Sensor`:传感器(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/device/Sensor)
\ No newline at end of file \ No newline at end of file
...@@ -155,4 +155,4 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ...@@ -155,4 +155,4 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
``` ```
## 相关实例 ## 相关实例
针对USB管理开发,有以下相关实例可供参考: 针对USB管理开发,有以下相关实例可供参考:
- [`USBManager`:USB管理(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/device/USBManager) - [`USBManager`:USB管理(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/device/USBManager)
...@@ -89,4 +89,4 @@ ...@@ -89,4 +89,4 @@
针对振动开发,有以下相关实例可供参考: 针对振动开发,有以下相关实例可供参考:
- [`Vibrator`:振动(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/device/Vibrator) - [`Vibrator`:振动(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/device/Vibrator)
\ No newline at end of file \ No newline at end of file
...@@ -96,4 +96,4 @@ ...@@ -96,4 +96,4 @@
针对应用事件开发,有以下相关实例可供参考: 针对应用事件开发,有以下相关实例可供参考:
- [`JsDotTest`:测试打点(JS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/DFX/JsDotTest) - [`JsDotTest`:测试打点(JS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/DFX/JsDotTest)
\ No newline at end of file \ No newline at end of file
...@@ -256,7 +256,7 @@ export class AudioDemo { ...@@ -256,7 +256,7 @@ export class AudioDemo {
针对音频播放开发,有以下相关实例可供参考: 针对音频播放开发,有以下相关实例可供参考:
- [`JsDistributedMusicPlayer`:分布式音乐播放(JS)(API7)](https://gitee.com/openharmony/app_samples/tree/master/ability/JsDistributedMusicPlayer) - [`JsDistributedMusicPlayer:`分布式音乐播放(JS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ability/JsDistributedMusicPlayer)
- [`JsAudioPlayer`:音频播放和管理(JS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/media/JsAudioPlayer) - [`JsAudioPlayer`:音频播放和管理(JS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/media/JsAudioPlayer)
- [`eTsAudioPlayer`: 音频播放器(eTS)(API8)](https://gitee.com/openharmony/app_samples/blob/master/media/Recorder/entry/src/main/ets/MainAbility/pages/Play.ets) - [`eTsAudioPlayer`: 音频播放器(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/blob/master/media/Recorder/entry/src/main/ets/MainAbility/pages/Play.ets)
- [音频播放器(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/Media/Audio_OH_ETS) - [音频播放器(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/Media/Audio_OH_ETS)
\ No newline at end of file
...@@ -190,7 +190,7 @@ export class AudioRecorderDemo { ...@@ -190,7 +190,7 @@ export class AudioRecorderDemo {
针对音频录制开发,有以下相关实例可供参考: 针对音频录制开发,有以下相关实例可供参考:
- [`Recorder`:录音机(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/media/Recorder) - [`Recorder:`录音机(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/media/Recorder)
- [`JsRecorder`:录音机(JS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/media/JSRecorder) - [`JsRecorder`:录音机(JS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/media/JSRecorder)
- [`eTsAudioPlayer`: 音频播放器(eTS)(API8)](https://gitee.com/openharmony/app_samples/blob/master/media/Recorder/entry/src/main/ets/MainAbility/pages/Play.ets) - [`eTsAudioPlayer`: 音频播放器(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/blob/master/media/Recorder/entry/src/main/ets/MainAbility/pages/Play.ets)
- [音频播放器(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/Media/Audio_OH_ETS) - [音频播放器(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/Media/Audio_OH_ETS)
...@@ -302,5 +302,5 @@ public async init(surfaceId: any) { ...@@ -302,5 +302,5 @@ public async init(surfaceId: any) {
针对图片开发,有以下相关实例可供参考: 针对图片开发,有以下相关实例可供参考:
- [`Image`:图片处理(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/media/Image) - [`Image`:图片处理(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/media/Image)
- [`GamePuzzle`:拼图(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/media/GamePuzzle) - [`GamePuzzle`:拼图(eTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/media/GamePuzzle)
\ No newline at end of file \ No newline at end of file
...@@ -445,5 +445,5 @@ export class VideoPlayerDemo { ...@@ -445,5 +445,5 @@ export class VideoPlayerDemo {
## 相关实例 ## 相关实例
针对视频播放开发,有以下相关实例可供参考: 针对视频播放开发,有以下相关实例可供参考:
- [`VideoPlayer`:视频播放(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/media/VideoPlayer) - [`VideoPlayer:`视频播放(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/media/VideoPlayer)
- [视频播放器(eTS)(API 9)](https://gitee.com/openharmony/codelabs/tree/master/Media/VideoPlayerStage) - [视频播放器(eTS)(API 9)](https://gitee.com/openharmony/codelabs/tree/master/Media/VideoPlayerStage)
\ No newline at end of file
...@@ -643,6 +643,6 @@ export default { ...@@ -643,6 +643,6 @@ export default {
``` ```
## 相关实例 ## 相关实例
针对Native API的开发,有以下相关实例可供参考: 针对Native API的开发,有以下相关实例可供参考:
- [`NativeAPI`:NativeAPI(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/Native/NativeAPI) - [`NativeAPI`:NativeAPI(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/Native/NativeAPI)
- [第一个Native C++应用(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NativeAPI/NativeTemplateDemo) - [第一个Native C++应用(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NativeAPI/NativeTemplateDemo)
- [Native Component(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NativeAPI/XComponent) - [Native Component(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/NativeAPI/XComponent)
\ No newline at end of file
...@@ -174,6 +174,6 @@ if (this.subscriber != null) { ...@@ -174,6 +174,6 @@ if (this.subscriber != null) {
针对公共事件开发,有以下相关实例可供参考: 针对公共事件开发,有以下相关实例可供参考:
- [`CommonEvent`:订阅公共事件(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/Notification/CommonEvent) - [`CommonEvent`:订阅公共事件(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/Notification/CommonEvent)
...@@ -262,6 +262,6 @@ Notification.cancel(1, "label", cancelCallback) ...@@ -262,6 +262,6 @@ Notification.cancel(1, "label", cancelCallback)
针对通知开发,有以下相关可供参考: 针对通知开发,有以下相关可供参考:
- [`Notification`:订阅、发送通知(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/Notification/Notification) - [`Notification:`订阅、发送通知(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/Notification/Notification)
- [`Notification`:通知(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/common/Notification) - [`Notification`:通知(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/common/Notification)
...@@ -233,3 +233,8 @@ ...@@ -233,3 +233,8 @@
![zh-cn_image_0000001363934589](figures/zh-cn_image_0000001363934589.png) ![zh-cn_image_0000001363934589](figures/zh-cn_image_0000001363934589.png)
恭喜您已经使用JS语言开发(FA模型)完成了第一个OpenHarmony应用,快来[探索更多的OpenHarmony功能](../application-dev-guide.md)吧。 恭喜您已经使用JS语言开发(FA模型)完成了第一个OpenHarmony应用,快来[探索更多的OpenHarmony功能](../application-dev-guide.md)吧。
## 相关实例
针对使用JS语言开发(FA模型),有以下相关实例可供参考:
- [`JsHelloWorld`:你好世界(JS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/common/JsHelloWorld)
...@@ -11,10 +11,6 @@ ...@@ -11,10 +11,6 @@
## 系统能力
SystemCapability.BundleManager.BundleFramework
## BundleInstaller.install ## BundleInstaller.install
install(bundleFilePaths: Array&lt;string&gt;, param: InstallParam, callback: AsyncCallback&lt;InstallStatus&gt;): void; install(bundleFilePaths: Array&lt;string&gt;, param: InstallParam, callback: AsyncCallback&lt;InstallStatus&gt;): void;
...@@ -29,6 +25,8 @@ ohos.permission.INSTALL_BUNDLE ...@@ -29,6 +25,8 @@ ohos.permission.INSTALL_BUNDLE
SystemCapability.BundleManager.BundleFramework SystemCapability.BundleManager.BundleFramework
**系统API:** 此接口为系统接口,三方应用不支持调用
**参数:** **参数:**
| 名称 | 类型 | 必填 | 描述 | | 名称 | 类型 | 必填 | 描述 |
...@@ -51,6 +49,8 @@ ohos.permission.INSTALL_BUNDLE ...@@ -51,6 +49,8 @@ ohos.permission.INSTALL_BUNDLE
SystemCapability.BundleManager.BundleFramework SystemCapability.BundleManager.BundleFramework
**系统API:** 此接口为系统接口,三方应用不支持调用
**参数:** **参数:**
| 名称 | 类型 | 必填 | 描述 | | 名称 | 类型 | 必填 | 描述 |
...@@ -59,7 +59,7 @@ SystemCapability.BundleManager.BundleFramework ...@@ -59,7 +59,7 @@ SystemCapability.BundleManager.BundleFramework
| param | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 | | param | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 |
| callback | AsyncCallback&lt;[InstallStatus](#installstatus)&gt; | 是 | 程序启动作为入参的回调函数,返回安装状态信息。 | | callback | AsyncCallback&lt;[InstallStatus](#installstatus)&gt; | 是 | 程序启动作为入参的回调函数,返回安装状态信息。 |
## BundleInstaller.recover ## BundleInstaller.recover<sup>8+</sup>
recover(bundleName: string, param: InstallParam, callback: AsyncCallback&lt;InstallStatus&gt;): void; recover(bundleName: string, param: InstallParam, callback: AsyncCallback&lt;InstallStatus&gt;): void;
...@@ -73,6 +73,8 @@ ohos.permission.INSTALL_BUNDLE ...@@ -73,6 +73,8 @@ ohos.permission.INSTALL_BUNDLE
SystemCapability.BundleManager.BundleFramework SystemCapability.BundleManager.BundleFramework
**系统API:** 此接口为系统接口,三方应用不支持调用
**参数:** **参数:**
| 名称 | 类型 | 必填 | 描述 | | 名称 | 类型 | 必填 | 描述 |
...@@ -81,17 +83,34 @@ SystemCapability.BundleManager.BundleFramework ...@@ -81,17 +83,34 @@ SystemCapability.BundleManager.BundleFramework
| param | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 | | param | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 |
| callback | AsyncCallback&lt;[InstallStatus](#installstatus)&gt; | 是 | 程序启动作为入参的回调函数,返回安装状态信息。 | | callback | AsyncCallback&lt;[InstallStatus](#installstatus)&gt; | 是 | 程序启动作为入参的回调函数,返回安装状态信息。 |
## HashParam<sup>9+</sup>
应用程序安装卸载信息
**系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework
**系统API:** 此接口为系统接口,三方应用不支持调用
| 名称 | 类型 | 说明 |
| ---------- | ------ | ---------------- |
| moduleName | string | 应用程序模块名称 |
| hashValue | string | 哈希值 |
## InstallParam ## InstallParam
应用程序安装卸载信息 应用程序安装卸载信息
**系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework
**系统API:** 此接口为系统接口,三方应用不支持调用
| 名称 | 类型 | 说明 | | 名称 | 类型 | 说明 |
| ----------- | ------- | ------------------ | | ------------------------------ | ------------------------------ | ------------------ |
| userId | number | 指示用户id | | userId | number | 指示用户id |
| installFlag | number | 指示安装标志 | | installFlag | number | 指示安装标志 |
| isKeepData | boolean | 指示参数是否有数据 | | isKeepData | boolean | 指示参数是否有数据 |
| hashParams<sup>9+</sup> | Array<[HashParam](#hashparam)> | 哈希值参数 |
| crowdtestDeadline<sup>9+</sup> | number | 测试包的被杀死时间 |
## InstallStatus ## InstallStatus
...@@ -99,6 +118,8 @@ SystemCapability.BundleManager.BundleFramework ...@@ -99,6 +118,8 @@ SystemCapability.BundleManager.BundleFramework
**系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework
**系统API:** 此接口为系统接口,三方应用不支持调用
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------ | | ------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------ |
| status | bundle.[InstallErrorCode](js-apis-Bundle.md#installerrorcode) | 是 | 否 | 表示安装或卸载错误状态码 | | status | bundle.[InstallErrorCode](js-apis-Bundle.md#installerrorcode) | 是 | 否 | 表示安装或卸载错误状态码 |
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
**系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework
**系统API:** 此接口为系统接口,三方应用不支持调用
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| -------------- | ------ | ---- | ---- | -------------- | | -------------- | ------ | ---- | ---- | -------------- |
| permissionName | string | 是 | 否 | 用户权限名称 | | permissionName | string | 是 | 否 | 用户权限名称 |
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
**系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework
**系统API:** 此接口为系统接口,三方应用不支持调用
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------------------- | ------ | ---- | ---- | -------------------- | | ------------------------- | ------ | ---- | ---- | -------------------- |
| targetBundle | string | 是 | 否 | 快捷方式的目标捆绑包 | | targetBundle | string | 是 | 否 | 快捷方式的目标捆绑包 |
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
## RemoteAbilityInfo ## RemoteAbilityInfo
**系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.DistributedBundleFramework
**系统API:** 此接口为系统接口,三方应用不支持调用
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------- | -------------------------------------------- | ---- | ---- | ----------------------- | | ----------- | -------------------------------------------- | ---- | ---- | ----------------------- |
......
...@@ -2004,7 +2004,7 @@ eventEmitter.on('prepare', () => { ...@@ -2004,7 +2004,7 @@ eventEmitter.on('prepare', () => {
}); });
media.createVideoRecorder((err, recorder) => { media.createVideoRecorder((err, recorder) => {
if (err == null && recorder) != null) { if (err == null && recorder != null) {
videoRecorder = recorder; videoRecorder = recorder;
console.info('createVideoRecorder success'); console.info('createVideoRecorder success');
eventEmitter.emit('prepare'); // prepare事件触发 eventEmitter.emit('prepare'); // prepare事件触发
......
...@@ -29,7 +29,7 @@ createTimer(options: TimerOptions, callback: AsyncCallback&lt;number&gt;): void ...@@ -29,7 +29,7 @@ createTimer(options: TimerOptions, callback: AsyncCallback&lt;number&gt;): void
| options | TimerOptions | 是 | const TIMER_TYPE_REALTIME: 设置为系统启动时间定时器,否则为walltime定时器; <br/>const TIMER_TYPE_WAKEUP: 设置为唤醒定时器,否则为非唤醒; <br/>const TIMER_TYPE_EXACT: 设置为精准定时器,否则为非精准定时器; <br/>const TIMER_TYPE_IDLE: number: 设置为IDLE模式定时器,否则为非IDLE模式定时器(暂不支持) | | options | TimerOptions | 是 | const TIMER_TYPE_REALTIME: 设置为系统启动时间定时器,否则为walltime定时器; <br/>const TIMER_TYPE_WAKEUP: 设置为唤醒定时器,否则为非唤醒; <br/>const TIMER_TYPE_EXACT: 设置为精准定时器,否则为非精准定时器; <br/>const TIMER_TYPE_IDLE: number: 设置为IDLE模式定时器,否则为非IDLE模式定时器(暂不支持) |
| repeat | boolean | 是 | true 为循环定时器,false为单次定时器。 | | repeat | boolean | 是 | true 为循环定时器,false为单次定时器。 |
| interval | number | 否 | 如果是循环定时器,repeat值应大于5000毫秒,非重复定时器置为0。 | | interval | number | 否 | 如果是循环定时器,repeat值应大于5000毫秒,非重复定时器置为0。 |
| wantAgent| wantAgent | 否 | 设置通知的wantagent,定时器到期后通知。 | | wantAgent| wantAgent | 否 | 设置通知的wantagent,定时器到期后通知。(支持拉起鸿蒙应用MainAbility,暂不支持拉起SA) |
**返回值:** **返回值:**
...@@ -40,17 +40,21 @@ createTimer(options: TimerOptions, callback: AsyncCallback&lt;number&gt;): void ...@@ -40,17 +40,21 @@ createTimer(options: TimerOptions, callback: AsyncCallback&lt;number&gt;): void
**示例:** **示例:**
```js ```js
export default {
systemTimer () {
var options = { var options = {
type:TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat: false
} }
systemTime.createTimer(options, (error, data) => { systemTimer.createTimer(options, (error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.createTimer ` + JSON.stringify(error)); console.error(`failed to systemTime.createTimer ` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.createTimer success data : ` + JSON.stringify(data)); console.log(`systemTime.createTimer success data : ` + JSON.stringify(data));
}); });
}
}
``` ```
...@@ -69,7 +73,7 @@ createTimer(options: TimerOptions): Promise&lt;number&gt; ...@@ -69,7 +73,7 @@ createTimer(options: TimerOptions): Promise&lt;number&gt;
| options | TimerOptions | 是 | const TIMER_TYPE_REALTIME: 设置为系统启动时间定时器,否则为walltime定时器; <br/>const TIMER_TYPE_WAKEUP: 设置为唤醒定时器,否则为非唤醒; <br/>const TIMER_TYPE_EXACT: 设置为精准定时器,否则为非精准定时器; <br/>const TIMER_TYPE_IDLE: number: 设置为IDLE模式定时器,否则为非IDLE模式定时器(暂不支持) | | options | TimerOptions | 是 | const TIMER_TYPE_REALTIME: 设置为系统启动时间定时器,否则为walltime定时器; <br/>const TIMER_TYPE_WAKEUP: 设置为唤醒定时器,否则为非唤醒; <br/>const TIMER_TYPE_EXACT: 设置为精准定时器,否则为非精准定时器; <br/>const TIMER_TYPE_IDLE: number: 设置为IDLE模式定时器,否则为非IDLE模式定时器(暂不支持) |
| repeat | boolean | 是 | true 为循环定时器,false为单次定时器。 | | repeat | boolean | 是 | true 为循环定时器,false为单次定时器。 |
| interval | number | 否 | 如果是循环定时器,repeat值应大于5000毫秒,非重复定时器置为0。 | | interval | number | 否 | 如果是循环定时器,repeat值应大于5000毫秒,非重复定时器置为0。 |
| wantAgent| wantAgent | 否 | 设置通知的wantagent,定时器到期后通知。 | | wantAgent| wantAgent | 否 | 设置通知的wantagent,定时器到期后通知。(支持拉起鸿蒙应用MainAbility,暂不支持拉起SA) |
**返回值:** **返回值:**
...@@ -80,15 +84,19 @@ createTimer(options: TimerOptions): Promise&lt;number&gt; ...@@ -80,15 +84,19 @@ createTimer(options: TimerOptions): Promise&lt;number&gt;
**示例:** **示例:**
```js ```js
export default {
systemTimer () {
var options = { var options = {
type:TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
systemTime.createTimer(options).then((data) => { systemTimer.createTimer(options).then((data) => {
console.log(`systemTime.createTimer success data : ` + JSON.stringify(data)); console.log(`systemTime.createTimer success data : ` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.createTimer because ` + JSON.stringify(error)); console.error(`failed to systemTime.createTimer because ` + JSON.stringify(error));
}); });
}
}
``` ```
...@@ -111,18 +119,22 @@ startTimer(timer: number, triggerTime: number, callback: AsyncCallback&lt;void&g ...@@ -111,18 +119,22 @@ startTimer(timer: number, triggerTime: number, callback: AsyncCallback&lt;void&g
**示例:** **示例:**
```js ```js
export default {
systemTimer () {
var options = { var options = {
type:TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.Timer(options)
systemTime.startTimer(timerId, 10000, (error, data) => { systemTimer.startTimer(timerId, 10000, (error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.startTimer ` + JSON.stringify(error)); console.error(`failed to systemTime.startTimer ` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.startTimer success data : ` + JSON.stringify(data)); console.log(`systemTime.startTimer success data : ` + JSON.stringify(data));
}); });
}
}
``` ```
## systemTime.startTimer ## systemTime.startTimer
...@@ -144,16 +156,20 @@ startTimer(timer: number, triggerTime: number): Promise&lt;void&gt; ...@@ -144,16 +156,20 @@ startTimer(timer: number, triggerTime: number): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
export default {
systemTimer (){
var options = { var options = {
type:TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.Timer(options)
systemTime.startTimer(timerId, 10000).then((data) => { systemTimer.startTimer(timerId, 10000).then((data) => {
console.log(`systemTime.startTimer success data : ` + JSON.stringify(data)); console.log(`systemTime.startTimer success data : ` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.startTimer because ` + JSON.stringify(error)); console.error(`failed to systemTime.startTimer because ` + JSON.stringify(error));
}); });
}
}
``` ```
...@@ -174,19 +190,23 @@ stopTimer(timer: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -174,19 +190,23 @@ stopTimer(timer: number, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
export default {
systemTimer () {
var options = { var options = {
type:TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.Timer(options)
let startTimerRes = systemTimer.startTimer(timerId, 100000) systemTimer.startTimer(timerId, 100000)
systemTime.stopTimer(timerId, (error, data) => { systemTimer.stoptTimer(timerId, 10000, (error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.stopTimer ` + JSON.stringify(error)); console.error(`failed to systemTime.startTimer ` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.stopTimer success data : ` + JSON.stringify(data)); console.log(`systemTime.startTimer success data : ` + JSON.stringify(data));
}); });
}
}
``` ```
...@@ -207,17 +227,21 @@ stopTimer(timer: number): Promise&lt;void&gt; ...@@ -207,17 +227,21 @@ stopTimer(timer: number): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
export default {
systemTimer (){
var options = { var options = {
type:TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.Timer(options)
let startTimerRes = systemTimer.startTimer(timerId, 100000) systemTimer.startTimer(timerId, 100000)
systemTime.stopTimer(timerId).then((data) => { systemTimer.stoptTimer(timerId, 10000).then((data) => {
console.log(`systemTime.stopTimer success data : ` + JSON.stringify(data)); console.log(`systemTime.startTimer success data : ` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.stopTimer because ` + JSON.stringify(error)); console.error(`failed to systemTime.startTimer because ` + JSON.stringify(error));
}); });
}
}
``` ```
...@@ -238,20 +262,24 @@ destroyTimer(timer: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -238,20 +262,24 @@ destroyTimer(timer: number, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
export default {
systemTimer () {
var options = { var options = {
type:TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.Timer(options)
let startTimerRes = systemTimer.startTimer(timerId, 100000) systemTimer.startTimer(timerId, 100000)
let stopTimerRes = systemTimer.stopTimer(timerId) systemTimer.stopTimer(timerId)
systemTime.destroyTimer(timerId, (error, data) => { systemTimer.destroyTimer(timerId, (error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.destroyTimer ` + JSON.stringify(error)); console.error(`failed to systemTime.startTimer ` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.destroyTimer success data : ` + JSON.stringify(data)); console.log(`systemTime.startTimer success data : ` + JSON.stringify(data));
}); });
}
}
``` ```
...@@ -272,16 +300,20 @@ destroyTimer(timer: number): Promise&lt;void&gt; ...@@ -272,16 +300,20 @@ destroyTimer(timer: number): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
export default {
systemTimer (){
var options = { var options = {
type:TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false repeat:false
} }
let timerId = systemTimer.Timer(options) let timerId = systemTimer.Timer(options)
let startTimerRes = systemTimer.startTimer(timerId, 100000) systemTimer.startTimer(timerId, 100000)
let stopTimerRes = systemTimer.stopTimer(timerId) systemTimer.stopTimer(timerId)
systemTime.destroyTimer(timerId).then((data) => { systemTimer.destroytTimer(timerId, 10000).then((data) => {
console.log(`systemTime.destroyTimer success data : ` + JSON.stringify(data)); console.log(`systemTime.startTimer success data : ` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.destroyTimer because ` + JSON.stringify(error)); console.error(`failed to systemTime.startTimer because ` + JSON.stringify(error));
}); });
}
}
``` ```
\ No newline at end of file
...@@ -7,6 +7,8 @@ WebGL标准图形API,对应OpenGL ES 2.0特性集。更多信息请参考[WebG ...@@ -7,6 +7,8 @@ WebGL标准图形API,对应OpenGL ES 2.0特性集。更多信息请参考[WebG
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
> WebGL遵循OpenGL协议,不支持多线程调用。
## 调用方式 ## 调用方式
......
...@@ -7,6 +7,8 @@ WebGL标准图形API,对应OpenGL ES 3.0特性集。更多信息请参考[WebG ...@@ -7,6 +7,8 @@ WebGL标准图形API,对应OpenGL ES 3.0特性集。更多信息请参考[WebG
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
> WebGL2遵循OpenGL协议,不支持多线程调用。
## 调用方式 ## 调用方式
......
...@@ -91,11 +91,11 @@ import window from '@ohos.window'; ...@@ -91,11 +91,11 @@ import window from '@ohos.window';
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------------------------------------- | -------- | ---- | ---- | ------------------------------------------------------------ | | -------------------------------------- | -------- | ---- | ---- | ------------------------------------------------------------ |
| statusBarColor | string | | 是 | 状态栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 | | statusBarColor | string | | 是 | 状态栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 |
| isStatusBarLightIcon<sup>7+</sup> | boolean | 否 | 是 | 状态栏图标是否为高亮状态。 | | isStatusBarLightIcon<sup>7+</sup> | boolean | 否 | 是 | 状态栏图标是否为高亮状态。 |
| statusBarContentColor<sup>8+</sup> | string | 否 | 是 | 状态栏文字颜色。 | | statusBarContentColor<sup>8+</sup> | string | 否 | 是 | 状态栏文字颜色。 |
| navigationBarColor | string | | 是 | 导航栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 | | navigationBarColor | string | | 是 | 导航栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 |
| isNavigationBarLightIcon<sup>7+</sup> | boolean | 否 | | 导航栏图标是否为高亮状态。 | | isNavigationBarLightIcon<sup>7+</sup> | boolean | 否 | | 导航栏图标是否为高亮状态。 |
| navigationBarContentColor<sup>8+</sup> | string | 否 | 是 | 导航栏文字颜色。 | | navigationBarContentColor<sup>8+</sup> | string | 否 | 是 | 导航栏文字颜色。 |
## Orientation<sup>9+</sup> ## Orientation<sup>9+</sup>
...@@ -129,11 +129,11 @@ import window from '@ohos.window'; ...@@ -129,11 +129,11 @@ import window from '@ohos.window';
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| --------------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ | | --------------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ |
| type | [WindowType](#windowtype) | 是 | | 当前属性改变的系统栏类型,仅支持类型为导航栏、状态栏的系统栏。 | | type | [WindowType](#windowtype) | 是 | | 当前属性改变的系统栏类型,仅支持类型为导航栏、状态栏的系统栏。 |
| isEnable | boolean | 是 | | 当前系统栏是否显示。 | | isEnable | boolean | 是 | | 当前系统栏是否显示。 |
| region | [Rect](#rect) | 是 | | 当前系统栏的位置及大小。 | | region | [Rect](#rect) | 是 | | 当前系统栏的位置及大小。 |
| backgroundColor | string | 是 | | 系统栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 | | backgroundColor | string | 是 | | 系统栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 |
| contentColor | string | 是 | | 系统栏文字颜色。 | | contentColor | string | 是 | | 系统栏文字颜色。 |
## SystemBarTintState<sup>8+</sup> ## SystemBarTintState<sup>8+</sup>
...@@ -146,7 +146,7 @@ import window from '@ohos.window'; ...@@ -146,7 +146,7 @@ import window from '@ohos.window';
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ---------- | --------------------------------------------------- | ---- | ---- | ---------------------------- | | ---------- | --------------------------------------------------- | ---- | ---- | ---------------------------- |
| displayId | number | 是 | 否 | 当前物理屏幕id。 | | displayId | number | 是 | 否 | 当前物理屏幕id。 |
| regionTint | Array<[SystemBarRegionTint](#systembarregiontint8)> | 是 | | 当前已改变的所有系统栏信息。 | | regionTint | Array<[SystemBarRegionTint](#systembarregiontint8)> | 是 | | 当前已改变的所有系统栏信息。 |
## Rect<sup>7+</sup> ## Rect<sup>7+</sup>
...@@ -1227,7 +1227,8 @@ getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise&lt;[AvoidArea](#av ...@@ -1227,7 +1227,8 @@ getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise&lt;[AvoidArea](#av
**示例:** **示例:**
```js ```js
let promise = windowClass.getAvoidArea(); var type = window.AvoidAreaType.TYPE_SYSTEM;
let promise = windowClass.getAvoidArea(type);
promise.then((data)=> { promise.then((data)=> {
console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
}).catch((err)=>{ }).catch((err)=>{
......
...@@ -77,15 +77,15 @@ caretPosition(value: number): void ...@@ -77,15 +77,15 @@ caretPosition(value: number): void
@Entry @Entry
@Component @Component
struct SearchExample { struct SearchExample {
@State changevalue: string = '' @State changeValue: string = ''
@State submitvalue: string = '' @State submitValue: string = ''
controller: SearchController = new SearchController() controller: SearchController = new SearchController()
build() { build() {
Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
Text(this.submitvalue) Text(this.submitValue)
Text(this.changevalue) Text(this.changeValue)
Search({value: this.changevalue, placeholder: 'Type to search', controller: this.controller}) Search({value: this.changeValue, placeholder: 'Type to search', controller: this.controller})
.searchButton('Search') .searchButton('Search')
.width(400) .width(400)
.height(35) .height(35)
...@@ -93,10 +93,10 @@ struct SearchExample { ...@@ -93,10 +93,10 @@ struct SearchExample {
.placeholderColor(Color.Grey) .placeholderColor(Color.Grey)
.placeholderFont({ size: 26, weight: 10, family: 'serif', style: FontStyle.Normal }) .placeholderFont({ size: 26, weight: 10, family: 'serif', style: FontStyle.Normal })
.onSubmit((value: string) => { .onSubmit((value: string) => {
this.submitvalue = value this.submitValue = value
}) })
.onChange((value: string) => { .onChange((value: string) => {
this.changevalue += value this.changeValue = value
}) })
.margin({ top: 30, left:10, right:10 }) .margin({ top: 30, left:10, right:10 })
} }
......
# Path2D对象 # Path2D对象
> **说明:** > **说明:**
>
> 从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
...@@ -13,17 +14,19 @@ addPath(path: Object): void ...@@ -13,17 +14,19 @@ addPath(path: Object): void
将另一个路径添加到当前的路径对象中。 将另一个路径添加到当前的路径对象中。
- 参数 **参数:**
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- |
| path | Object | 是 | null | 需要添加到当前路径的路径对象 |
- 示例 | 参数 | 类型 | 必填 | 默认值 | 描述 |
```ts | -------- | -------- | -------- | -------- | -------- |
| path | Object | 是 | null | 需要添加到当前路径的路径对象 |
**示例:**
```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct AddPath { struct AddPath {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
...@@ -44,10 +47,10 @@ addPath(path: Object): void ...@@ -44,10 +47,10 @@ addPath(path: Object): void
.width('100%') .width('100%')
.height('100%') .height('100%')
} }
} }
``` ```
![zh-cn_image_0000001238712467](figures/zh-cn_image_0000001238712467.png) ![zh-cn_image_0000001238712467](figures/zh-cn_image_0000001238712467.png)
## closePath ## closePath
...@@ -56,12 +59,13 @@ closePath(): void ...@@ -56,12 +59,13 @@ closePath(): void
将路径的当前点移回到路径的起点,当前点到起点间画一条直线。如果形状已经闭合或只有一个点,则此功能不执行任何操作。 将路径的当前点移回到路径的起点,当前点到起点间画一条直线。如果形状已经闭合或只有一个点,则此功能不执行任何操作。
- 示例 **示例:**
```ts
```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct ClosePath { struct ClosePath {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private path2Db: Path2D = new Path2D() private path2Db: Path2D = new Path2D()
...@@ -83,10 +87,10 @@ closePath(): void ...@@ -83,10 +87,10 @@ closePath(): void
.width('100%') .width('100%')
.height('100%') .height('100%')
} }
} }
``` ```
![zh-cn_image_0000001193872542](figures/zh-cn_image_0000001193872542.png) ![zh-cn_image_0000001193872542](figures/zh-cn_image_0000001193872542.png)
## moveTo ## moveTo
...@@ -95,16 +99,18 @@ moveTo(x: number, y: number): void ...@@ -95,16 +99,18 @@ moveTo(x: number, y: number): void
将路径的当前坐标点移动到目标点,移动过程中不绘制线条。 将路径的当前坐标点移动到目标点,移动过程中不绘制线条。
- 参数 **参数:**
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- | | 参数 | 类型 | 必填 | 默认值 | 描述 |
| x | number | 是 | 0 | 目标点X轴坐标 | | -------- | -------- | -------- | -------- | -------- |
| y | number | 是 | 0 | 目标点Y轴坐标 | | x | number | 是 | 0 | 目标点X轴坐标 |
| y | number | 是 | 0 | 目标点Y轴坐标 |
**示例:**
- 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct MoveTo { struct MoveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -140,16 +146,18 @@ lineTo(x: number, y: number): void ...@@ -140,16 +146,18 @@ lineTo(x: number, y: number): void
从当前点绘制一条直线到目标点。 从当前点绘制一条直线到目标点。
- 参数 **参数:**
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- | | 参数 | 类型 | 必填 | 默认值 | 描述 |
| x | number | 是 | 0 | 目标点X轴坐标 | | -------- | -------- | -------- | -------- | -------- |
| y | number | 是 | 0 | 目标点Y轴坐标 | | x | number | 是 | 0 | 目标点X轴坐标 |
| y | number | 是 | 0 | 目标点Y轴坐标 |
**示例:**
- 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct LineTo { struct LineTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -186,20 +194,22 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, ...@@ -186,20 +194,22 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number,
创建三次贝赛尔曲线的路径。 创建三次贝赛尔曲线的路径。
- 参数 **参数:**
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- | | 参数 | 类型 | 必填 | 默认值 | 描述 |
| cp1x | number | 是 | 0 | 第一个贝塞尔参数的x坐标值。 | | -------- | -------- | -------- | -------- | -------- |
| cp1y | number | 是 | 0 | 第一个贝塞尔参数的y坐标值。 | | cp1x | number | 是 | 0 | 第一个贝塞尔参数的x坐标值。 |
| cp2x | number | 是 | 0 | 第二个贝塞尔参数的x坐标值。 | | cp1y | number | 是 | 0 | 第一个贝塞尔参数的y坐标值。 |
| cp2y | number | 是 | 0 | 第二个贝塞尔参数的y坐标值。 | | cp2x | number | 是 | 0 | 第二个贝塞尔参数的x坐标值。 |
| x | number | 是 | 0 | 路径结束时的x坐标值。 | | cp2y | number | 是 | 0 | 第二个贝塞尔参数的y坐标值。 |
| y | number | 是 | 0 | 路径结束时的y坐标值。 | | x | number | 是 | 0 | 路径结束时的x坐标值。 |
| y | number | 是 | 0 | 路径结束时的y坐标值。 |
- 示例
**示例:**
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct BezierCurveTo { struct BezierCurveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -232,18 +242,20 @@ quadraticCurveTo(cpx: number, cpy: number, x: number ,y: number): void ...@@ -232,18 +242,20 @@ quadraticCurveTo(cpx: number, cpy: number, x: number ,y: number): void
创建二次贝赛尔曲线的路径。 创建二次贝赛尔曲线的路径。
- 参数 **参数:**
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- | | 参数 | 类型 | 必填 | 默认值 | 描述 |
| cpx | number | 是 | 0 | 贝塞尔参数的x坐标值。 | | -------- | -------- | -------- | -------- | -------- |
| cpy | number | 是 | 0 | 贝塞尔参数的y坐标值。 | | cpx | number | 是 | 0 | 贝塞尔参数的x坐标值。 |
| x | number | 是 | 0 | 路径结束时的x坐标值。 | | cpy | number | 是 | 0 | 贝塞尔参数的y坐标值。 |
| y | number | 是 | 0 | 路径结束时的y坐标值。 | | x | number | 是 | 0 | 路径结束时的x坐标值。 |
| y | number | 是 | 0 | 路径结束时的y坐标值。 |
**示例:**
- 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct QuadraticCurveTo { struct QuadraticCurveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -277,7 +289,8 @@ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, ...@@ -277,7 +289,8 @@ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number,
绘制弧线路径。 绘制弧线路径。
- 参数 **参数:**
| 参数 | 类型 | 必填 | 默认值 | 描述 | | 参数 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| x | number | 是 | 0 | 弧线圆心的x坐标值。 | | x | number | 是 | 0 | 弧线圆心的x坐标值。 |
...@@ -287,10 +300,11 @@ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, ...@@ -287,10 +300,11 @@ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number,
| endAngle | number | 是 | 0 | 弧线的终止弧度。 | | endAngle | number | 是 | 0 | 弧线的终止弧度。 |
| anticlockwise | boolean | 否 | false | 是否逆时针绘制圆弧。 | | anticlockwise | boolean | 否 | false | 是否逆时针绘制圆弧。 |
- 示例 **示例:**
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct Arc { struct Arc {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -322,7 +336,8 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void ...@@ -322,7 +336,8 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
依据圆弧经过的点和圆弧半径创建圆弧路径。 依据圆弧经过的点和圆弧半径创建圆弧路径。
- 参数 **参数:**
| 参数 | 类型 | 必填 | 默认值 | 描述 | | 参数 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| x1 | number | 是 | 0 | 圆弧经过的第一个点的x坐标值。 | | x1 | number | 是 | 0 | 圆弧经过的第一个点的x坐标值。 |
...@@ -331,10 +346,11 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void ...@@ -331,10 +346,11 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
| y2 | number | 是 | 0 | 圆弧经过的第二个点的y坐标值。 | | y2 | number | 是 | 0 | 圆弧经过的第二个点的y坐标值。 |
| radius | number | 是 | 0 | 圆弧的圆半径值。 | | radius | number | 是 | 0 | 圆弧的圆半径值。 |
- 示例 **示例:**
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct ArcTo { struct ArcTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -367,7 +383,8 @@ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number ...@@ -367,7 +383,8 @@ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number
在规定的矩形区域绘制一个椭圆。 在规定的矩形区域绘制一个椭圆。
- 参数 **参数:**
| 参数 | 类型 | 必填 | 默认值 | 描述 | | 参数 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| x | number | 是 | 0 | 椭圆圆心的x轴坐标。 | | x | number | 是 | 0 | 椭圆圆心的x轴坐标。 |
...@@ -379,10 +396,11 @@ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number ...@@ -379,10 +396,11 @@ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number
| endAngle | number | 是 | 0 | 椭圆绘制的结束点角度,以弧度表示。 | | endAngle | number | 是 | 0 | 椭圆绘制的结束点角度,以弧度表示。 |
| anticlockwise | number | 否 | 0 | 是否以逆时针方向绘制椭圆,0为顺时针,1为逆时针。(可选参数,默认为0) | | anticlockwise | number | 否 | 0 | 是否以逆时针方向绘制椭圆,0为顺时针,1为逆时针。(可选参数,默认为0) |
- 示例 **示例:**
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct CanvasExample { struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -415,7 +433,8 @@ rect(x: number, y: number, width: number, height: number): void ...@@ -415,7 +433,8 @@ rect(x: number, y: number, width: number, height: number): void
创建矩形路径。 创建矩形路径。
- 参数 **参数:**
| 参数 | 类型 | 必填 | 默认值 | 描述 | | 参数 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| x | number | 是 | 0 | 指定矩形的左上角x坐标值。 | | x | number | 是 | 0 | 指定矩形的左上角x坐标值。 |
...@@ -423,10 +442,11 @@ rect(x: number, y: number, width: number, height: number): void ...@@ -423,10 +442,11 @@ rect(x: number, y: number, width: number, height: number): void
| width | number | 是 | 0 | 指定矩形的宽度。 | | width | number | 是 | 0 | 指定矩形的宽度。 |
| height | number | 是 | 0 | 指定矩形的高度。 | | height | number | 是 | 0 | 指定矩形的高度。 |
- 示例 **示例:**
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct CanvasExample { struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
......
# Swiper # Swiper
> **说明:** > **说明:**
>
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
...@@ -21,45 +22,91 @@ ...@@ -21,45 +22,91 @@
Swiper(value:{controller?: SwiperController}) Swiper(value:{controller?: SwiperController})
- 参数 **参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| ---------- | ------------------------------------- | ---- | ---- | -------------------- |
| controller | [SwiperController](#swipercontroller) | 否 | null | 给组件绑定一个控制器,用来控制组件翻页。 |
| 参数名 | 参数类型 | 必填 | 参数描述 |
| ---------- | ------------------------------------- | ---- | -------------------- |
| controller | [SwiperController](#swipercontroller) | 否 | 给组件绑定一个控制器,用来控制组件翻页。<br/>默认值:null |
## 属性
| 名称 | 参数类型 | 默认值 | 描述 | ## 属性
| --------------------------- | ---------------------------------------- | ---------- | ---------------------------------------- |
| index | number | 0 | 设置当前在容器中显示的子组件的索引值。 |
| autoPlay | boolean | false | 子组件是否自动播放,自动播放状态下,导航点不可操作。 |
| interval | number | 3000 | 使用自动播放时播放的时间间隔,单位为毫秒。 |
| indicator | boolean | true | 是否启用导航点指示器。 |
| loop | boolean | true | 是否开启循环。 <br>设置为true时表示开启循环,在LazyForEach懒循环加载模式下,加载的组件数量建议大于5个。 |
| duration | number | 400 | 子组件切换的动画时长,单位为毫秒。 |
| vertical | boolean | false | 是否为纵向滑动。 |
| itemSpace | Length | 0 | 设置子组件与子组件之间间隙。 |
| cachedCount<sup>8+</sup> | number | 1 | 设置预加载子组件个数。 |
| disableSwipe<sup>8+</sup> | boolean | false | 禁用组件滑动切换功能。 |
| curve<sup>8+</sup> | [Curve](ts-animatorproperty.md#Curve枚举说明) \| Curves | Curve.Ease | 设置Swiper的动画曲线,默认为淡入淡出曲线,常用曲线参考[Curve枚举说明](ts-animatorproperty.md#Curve枚举说明),也可以通过插值计算模块提供的接口创建自定义的Curves([插值曲线对象](ts-interpolation-calculation.md))。 |
| indicatorStyle<sup>8+</sup> | {<br/>left?:&nbsp;Length,<br/>top?:&nbsp;Length,<br/>right?:&nbsp;Length,<br/>bottom?:&nbsp;Length,<br/>size?:&nbsp;Length,<br/>color?:&nbsp;Color,<br/>selectedColor?:&nbsp;Color<br/>} | - | 设置indicator样式:<br/>-&nbsp;left:&nbsp;设置导航点距离Swiper组件左边的距离。<br/>-&nbsp;top:&nbsp;设置导航点距离Swiper组件顶部的距离。<br/>-&nbsp;right:&nbsp;设置导航点距离Swiper组件右边的距离。<br/>-&nbsp;bottom:&nbsp;设置导航点距离Swiper组件底部的距离。<br/>-&nbsp;size:&nbsp;设置导航点的直径。<br/>-&nbsp;color:&nbsp;设置导航点的颜色。<br/>-&nbsp;selectedColor:&nbsp;设置选中的导航点的颜色。 |
不支持[Menu控制](ts-universal-attributes-menu.md)
| 名称 | 参数类型 | 描述 |
| --------------------------- | ---------------------------------------- | ---------------------------------------- |
| index | number | 设置当前在容器中显示的子组件的索引值。<br/>默认值:0 |
| autoPlay | boolean | 子组件是否自动播放,自动播放状态下,导航点不可操作。<br/>默认值:false |
| interval | number | 使用自动播放时播放的时间间隔,单位为毫秒。<br/>默认值:3000 |
| indicator | boolean | 是否启用导航点指示器。<br/>默认值:true |
| loop | boolean | 是否开启循环。<br>设置为true时表示开启循环,在LazyForEach懒循环加载模式下,加载的组件数量建议大于5个。<br/>默认值:true |
| duration | number | 子组件切换的动画时长,单位为毫秒。<br/>默认值:400 |
| vertical | boolean | 是否为纵向滑动。<br/>默认值:false |
| itemSpace | Length | 设置子组件与子组件之间间隙。<br/>默认值:0 |
| displayMode | SwiperDisplayMode | 主轴方向上元素排列的模式,优先以displayCount设置的个数显示,displayCount未设置时本属性生效。<br/>默认值:SwiperDisplayMode.Stretch |
| cachedCount<sup>8+</sup> | number | 设置预加载子组件个数。<br/>默认值:1 |
| disableSwipe<sup>8+</sup> | boolean | 禁用组件滑动切换功能。<br/>默认值:false |
| curve<sup>8+</sup> | [Curve](ts-animatorproperty.md#Curve枚举说明) \| string | 设置Swiper的动画曲线,默认为淡入淡出曲线,常用曲线参考[Curve枚举说明](ts-animatorproperty.md#Curve枚举说明),也可以通过插值计算模块提供的接口创建自定义的Curves([插值曲线对象](ts-interpolation-calculation.md))。<br/>默认值:Curve.Ease |
| indicatorStyle<sup>8+</sup> | {<br/>left?:&nbsp;Length,<br/>top?:&nbsp;Length,<br/>right?:&nbsp;Length,<br/>bottom?:&nbsp;Length,<br/>size?:&nbsp;Length,<br/>color?:&nbsp;Color,<br/>selectedColor?:&nbsp;Color<br/>} | 设置indicator样式:<br/>-&nbsp;left:&nbsp;设置导航点距离Swiper组件左边的距离。<br/>-&nbsp;top:&nbsp;设置导航点距离Swiper组件顶部的距离。<br/>-&nbsp;right:&nbsp;设置导航点距离Swiper组件右边的距离。<br/>-&nbsp;bottom:&nbsp;设置导航点距离Swiper组件底部的距离。<br/>-&nbsp;size:&nbsp;设置导航点的直径。<br/>-&nbsp;color:&nbsp;设置导航点的颜色。<br/>-&nbsp;selectedColor:&nbsp;设置选中的导航点的颜色。 |
| displayCount<sup>8+</sup> | number\|string | 设置元素显示个数。<br/>默认值:1 |
| effectMode<sup>8+</sup> | EdgeEffect | 滑动效果,目前支持的滑动效果参见EdgeEffect的枚举说明。<br/>默认值:EdgeEffect.Spring |
## SwiperDisplayMode枚举说明
| 名称 | 描述 |
| ----------- | ------------------------------------------ |
| Stretch | Swiper滑动一页的宽度为Swiper组件自身的宽度。|
| AutoLinear | Swiper滑动一页的宽度为子组件宽度中的最大值。|
## EdgeEffect枚举说明
| 名称 | 描述 |
| ------ | ------------------------------------------------------------------------- |
| Spring | 弹性物理动效,滑动到边缘后可以通过触摸事件继续滑动一段距离,松手后回弹。 |
| Fade | 滑动到边缘后,可以通过触摸事件继续滑动一段阴影,松手后阴影回弹。 |
| None | 滑动到边缘后无效果。 |
## SwiperController ## SwiperController
Swiper容器组件的控制器,可以将此对象绑定至Swiper组件,然后通过它控制翻页。 Swiper容器组件的控制器,可以将此对象绑定至Swiper组件,然后通过它控制翻页。
| 接口名称 | 功能描述 | ### showNext
| ------------------- | ------ |
| showNext():void | 翻至下一页。 | showNext(): void
| showPrevious():void | 翻至上一页。 |
翻至下一页。
### showPrevious
showPrevious(): void
翻至上一页。
### finishAnimation
finishAnimation(callback?: () => void): void
停止播放动画。
**参数:**
| 参数名 | 参数类型 | 必填项 | 参数描述 |
| --------- | ---------- | ------ | -------- |
| callback | () => void | 是 | 动画结束的回调。 |
## 事件 ## 事件
| 名称 | 功能描述 | ### onChange
| ---------------------------------------- | ------------------ |
| onChange(&nbsp;index:&nbsp;number)&nbsp;=&gt;&nbsp;void | 当前显示的组件索引变化时触发该事件。 | onChange(&nbsp;index:&nbsp;number)&nbsp;=&gt;&nbsp;void
当前显示的组件索引变化时触发该事件。
**参数:**
| 参数名 | 参数类型 | 必填项 | 参数描述 |
| --------- | ---------- | ------ | -------- |
| index | number | 是 | 当前显示元素的索引。 |
## 示例 ## 示例
......
...@@ -710,8 +710,8 @@ fillRect(x: number, y: number, w: number, h: number): void ...@@ -710,8 +710,8 @@ fillRect(x: number, y: number, w: number, h: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct FillRect { struct FillRect {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -755,8 +755,8 @@ strokeRect(x: number, y: number, w: number, h: number): void ...@@ -755,8 +755,8 @@ strokeRect(x: number, y: number, w: number, h: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct StrokeRect { struct StrokeRect {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -799,8 +799,8 @@ clearRect(x: number, y: number, w: number, h: number): void ...@@ -799,8 +799,8 @@ clearRect(x: number, y: number, w: number, h: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct ClearRect { struct ClearRect {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -844,8 +844,8 @@ fillText(text: string, x: number, y: number): void ...@@ -844,8 +844,8 @@ fillText(text: string, x: number, y: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct FillText { struct FillText {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -888,8 +888,8 @@ strokeText(text: string, x: number, y: number): void ...@@ -888,8 +888,8 @@ strokeText(text: string, x: number, y: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct StrokeText { struct StrokeText {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -940,8 +940,8 @@ measureText(text: string): TextMetrics ...@@ -940,8 +940,8 @@ measureText(text: string): TextMetrics
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct MeasureText { struct MeasureText {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -983,8 +983,8 @@ stroke(path?: Path2D): void ...@@ -983,8 +983,8 @@ stroke(path?: Path2D): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct Stroke { struct Stroke {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1022,8 +1022,8 @@ beginPath(): void ...@@ -1022,8 +1022,8 @@ beginPath(): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct BeginPath { struct BeginPath {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1069,8 +1069,8 @@ moveTo(x: number, y: number): void ...@@ -1069,8 +1069,8 @@ moveTo(x: number, y: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct MoveTo { struct MoveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1114,8 +1114,8 @@ lineTo(x: number, y: number): void ...@@ -1114,8 +1114,8 @@ lineTo(x: number, y: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct LineTo { struct LineTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1153,8 +1153,8 @@ closePath(): void ...@@ -1153,8 +1153,8 @@ closePath(): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct ClosePath { struct ClosePath {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1200,8 +1200,8 @@ createPattern(image: ImageBitmap, repetition: string): CanvasPattern ...@@ -1200,8 +1200,8 @@ createPattern(image: ImageBitmap, repetition: string): CanvasPattern
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct CreatePattern { struct CreatePattern {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1249,8 +1249,8 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, ...@@ -1249,8 +1249,8 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number,
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct BezierCurveTo { struct BezierCurveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1296,8 +1296,8 @@ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void ...@@ -1296,8 +1296,8 @@ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct QuadraticCurveTo { struct QuadraticCurveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1345,8 +1345,8 @@ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, ...@@ -1345,8 +1345,8 @@ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number,
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct Arc { struct Arc {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1392,8 +1392,8 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void ...@@ -1392,8 +1392,8 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct ArcTo { struct ArcTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1443,8 +1443,8 @@ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number ...@@ -1443,8 +1443,8 @@ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct CanvasExample { struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1489,8 +1489,8 @@ rect(x: number, y: number, width: number, height: number): void ...@@ -1489,8 +1489,8 @@ rect(x: number, y: number, width: number, height: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct CanvasExample { struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1526,8 +1526,8 @@ fill(): void ...@@ -1526,8 +1526,8 @@ fill(): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct Fill { struct Fill {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1563,8 +1563,8 @@ clip(): void ...@@ -1563,8 +1563,8 @@ clip(): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct Clip { struct Clip {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1608,8 +1608,8 @@ rotate(rotate: number): void ...@@ -1608,8 +1608,8 @@ rotate(rotate: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct Rotate { struct Rotate {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1651,8 +1651,8 @@ scale(x: number, y: number): void ...@@ -1651,8 +1651,8 @@ scale(x: number, y: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct Scale { struct Scale {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1706,8 +1706,8 @@ transform方法对应一个变换矩阵,想对一个图形进行变化的时 ...@@ -1706,8 +1706,8 @@ transform方法对应一个变换矩阵,想对一个图形进行变化的时
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct Transform { struct Transform {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1759,8 +1759,8 @@ setTransfrom方法使用的参数和transform()方法相同,但setTransform() ...@@ -1759,8 +1759,8 @@ setTransfrom方法使用的参数和transform()方法相同,但setTransform()
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct SetTransform { struct SetTransform {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1805,8 +1805,8 @@ translate(x: number, y: number): void ...@@ -1805,8 +1805,8 @@ translate(x: number, y: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct Translate { struct Translate {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1861,8 +1861,8 @@ drawImage(image: ImageBitmap | PixelMap, sx: number, sy: number, sWidth: number, ...@@ -1861,8 +1861,8 @@ drawImage(image: ImageBitmap | PixelMap, sx: number, sy: number, sWidth: number,
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct Index { struct Index {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -1961,8 +1961,8 @@ putImageData(imageData: Object, dx: number, dy: number, dirtyX?: number, dirtyY? ...@@ -1961,8 +1961,8 @@ putImageData(imageData: Object, dx: number, dy: number, dirtyX?: number, dirtyY?
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct PutImageData { struct PutImageData {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -2004,8 +2004,8 @@ restore(): void ...@@ -2004,8 +2004,8 @@ restore(): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct CanvasExample { struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -2038,8 +2038,8 @@ save(): void ...@@ -2038,8 +2038,8 @@ save(): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct CanvasExample { struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -2080,8 +2080,8 @@ createLinearGradient(x0: number, y0: number, x1: number, y1: number): void ...@@ -2080,8 +2080,8 @@ createLinearGradient(x0: number, y0: number, x1: number, y1: number): void
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct CreateLinearGradient { struct CreateLinearGradient {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
...@@ -2132,8 +2132,8 @@ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, ...@@ -2132,8 +2132,8 @@ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number,
- 示例 - 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct CreateRadialGradient { struct CreateRadialGradient {
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
......
...@@ -171,5 +171,5 @@ ...@@ -171,5 +171,5 @@
针对访问控制,有以下相关实例可供参考: 针对访问控制,有以下相关实例可供参考:
- [`AbilityAccessCtrl`:访问权限控制(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/Safety/AbilityAccessCtrl) - [`AbilityAccessCtrl`:访问权限控制(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/Safety/AbilityAccessCtrl)
- [为应用添加运行时权限(eTS)(API 9)](https://gitee.com/openharmony/codelabs/tree/master/Ability/AccessPermission) - [为应用添加运行时权限(eTS)(API 9)](https://gitee.com/openharmony/codelabs/tree/master/Ability/AccessPermission)
\ No newline at end of file
...@@ -53,4 +53,4 @@ radio模块提供了获取当前网络信号信息的方法。observer模块为 ...@@ -53,4 +53,4 @@ radio模块提供了获取当前网络信号信息的方法。observer模块为
## 相关实例 ## 相关实例
针对蜂窝网络数据开发,有以下相关实例可供参考: 针对蜂窝网络数据开发,有以下相关实例可供参考:
- [`MobileNetwork`:蜂窝数据(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/Telephony/MobileNetwork) - [`MobileNetwork`:蜂窝数据(eTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/Telephony/MobileNetwork)
\ No newline at end of file \ No newline at end of file
...@@ -704,4 +704,4 @@ WebGL主要帮助开发者在前端开发中完成图形图像的相关处理, ...@@ -704,4 +704,4 @@ WebGL主要帮助开发者在前端开发中完成图形图像的相关处理,
针对WebGL开发,有以下相关实例可供参考: 针对WebGL开发,有以下相关实例可供参考:
- [`JsWbgGL`:WebGL(JS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/Graphics/JsWebGL) - [`JsWbgGL`:WebGL(JS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/Graphics/JsWebGL)
...@@ -404,3 +404,7 @@ class MainAbility extends Ability { ...@@ -404,3 +404,7 @@ class MainAbility extends Ability {
} }
}; };
``` ```
## 相关实例
针对window开发(Stage模型),有以下相关实例可供参考:
- [`Window`:窗口(eTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/Graphics/Window)
\ No newline at end of file
...@@ -24,5 +24,5 @@ display.getDefaultDisplay().then((disp) => { ...@@ -24,5 +24,5 @@ display.getDefaultDisplay().then((disp) => {
``` ```
## 相关实例 ## 相关实例
针对屏幕属性开发,有以下相关实例可供参考: 针对屏幕属性开发,有以下相关实例可供参考:
- [`Screen`:屏幕属性(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/device/Screen) - [`Screen`:屏幕属性(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/device/Screen)
...@@ -37,5 +37,5 @@ screenshot.save(ScreenshotOptions).then((image) => { ...@@ -37,5 +37,5 @@ screenshot.save(ScreenshotOptions).then((image) => {
``` ```
## 相关实例 ## 相关实例
针对屏幕截图开发,有以下相关实例可供参考: 针对屏幕截图开发,有以下相关实例可供参考:
- [`Screenshot`:屏幕截图(eTS)(API9)](https://gitee.com/openharmony/app_samples/tree/master/Basic/Screenshot) - [`Screenshot`:屏幕截图(eTS)(API9)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/Basic/Screenshot)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册