diff --git a/en/application-dev/background-agent-scheduled-reminder/Readme-EN.md b/en/application-dev/background-agent-scheduled-reminder/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..7f4083e641ecf002e40313deaed5a9616ad32913 --- /dev/null +++ b/en/application-dev/background-agent-scheduled-reminder/Readme-EN.md @@ -0,0 +1,4 @@ +# Agent-Powered Scheduled Reminders + +- [Overview](background-agent-scheduled-reminder-overview.md) +- [Development Guidelines](background-agent-scheduled-reminder-guide.md) diff --git a/en/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-guide.md b/en/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..dedcdc819a68c2bf70b47106adadcfa3a3e74402 --- /dev/null +++ b/en/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-guide.md @@ -0,0 +1,683 @@ +# Development Guidelines + +## When to Use + +You can set your application to call the **ReminderRequest** class to create scheduled reminders for countdown timers, calendar events, and alarm clocks. When the created reminders are published, the timing and pop-up notification functions of your application will be taken over by the reminder agent in the background, even when your application is frozen or exits. + +## Available APIs + +**reminderAgent** encapsulates the methods for publishing and canceling reminders. + +**Table 1** Major APIs in reminderAgent + + + + + + + + + + + + + + + + + + + + + + + + + +

API

+

Description

+

function publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void;

+

function publishReminder(reminderReq: ReminderRequest): Promise<number>;

+

Publishes a scheduled reminder.

+

The maximum number of valid notifications (excluding expired ones that will not pop up again) is 30 for one application and 2000 for the entire system.

+

function cancelReminder(reminderId: number, callback: AsyncCallback<void>): void;

+

function cancelReminder(reminderId: number): Promise<void>;

+

Cancels a specified reminder. (The value of reminderId is obtained from the return value of publishReminder.)

+

function getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void;

+

function getValidReminders(): Promise<Array<ReminderRequest>>;

+

Obtains all valid reminders set by the current application.

+

function cancelAllReminders(callback: AsyncCallback<void>): void;

+

function cancelAllReminders(): Promise<void>;

+

Cancels all reminders set by the current application.

+

function addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void;

+

function addNotificationSlot(slot: NotificationSlot): Promise<void>;

+

Registers a NotificationSlot instance to be used by the reminder.

+

function removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback<void>): void;

+

function removeNotificationSlot(slotType: notification.SlotType): Promise<void>;

+

Removes a NotificationSlot instance of a specified type.

+
+ +**ActionButtonType** enumerates types of buttons displayed in a reminder notification. + +**Table 2** ActionButtonType enumeration + + + + + + + + + + +

Name

+

Description

+

ACTION_BUTTON_TYPE_CLOSE

+

Close button, which can be tapped to stop the reminder alert tone, close the reminder notification, and cancel the reminder snoozing.

+
+ +**ReminderType** enumerates the reminder types. + +**Table 3** ReminderType enumeration + + + + + + + + + + + + + + + + +

Name

+

Description

+

REMINDER_TYPE_TIMER

+

Countdown reminder.

+

REMINDER_TYPE_CALENDAR

+

Calendar reminder.

+

REMINDER_TYPE_ALARM

+

Alarm reminder.

+
+ +**ActionButton** defines a button displayed in the reminder notification. + +**Table 4** ActionButton instance + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

title

+

string

+

Yes

+

Text on the button.

+

type

+

ActionButtonType

+

Yes

+

Button type.

+
+ +**WantAgent** sets the package and ability that are redirected to when the reminder notification is clicked. + +**Table 5** WantAgent instance + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

pkgName

+

string

+

Yes

+

Name of the package redirected to when the reminder notification is clicked.

+

abilityName

+

string

+

Yes

+

Name of the ability redirected to when the reminder notification is clicked.

+
+ +**MaxScreenWantAgent** sets the name of the target package and ability to start automatically when the reminder arrives and the device is not in use. If the device is in use, a notification will be displayed. + +**Table 6** MaxScreenWantAgent instance + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

pkgName

+

string

+

Yes

+

Name of the package that is automatically started when the reminder arrives and the device is not in use.

+

abilityName

+

string

+

Yes

+

Name of the ability that is automatically started when the reminder arrives and the device is not in use.

+
+ +**ReminderRequest** defines the reminder to publish. + +**Table 7** ReminderRequest instance + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

reminderType

+

ReminderType

+

Yes

+

Type of the reminder.

+

actionButton

+

[ActionButton?, ActionButton?]

+

No

+

Action button displayed in the reminder notification.

+

wantAgent

+

WantAgent

+

No

+

Information about the ability that is redirected to when the notification is clicked.

+

maxScreenWantAgent

+

MaxScreenWantAgent

+

No

+

Information about the ability that is automatically started when the reminder arrives. If the device is in use, a notification will be displayed.

+

ringDuration

+

number

+

No

+

Ring duration.

+

snoozeTimes

+

number

+

No

+

Number of reminder snooze times.

+

timeInterval

+

number

+

No

+

Reminder snooze interval.

+

title

+

string

+

No

+

Reminder title.

+

content

+

string

+

No

+

Reminder content.

+

expiredContent

+

string

+

No

+

Extended content to be displayed when the reminder expires.

+

snoozeContent

+

string

+

No

+

Extended content to be displayed when the reminder is snoozing.

+

notificationId

+

number

+

No

+

Notification ID used by the reminder. For details, see the API reference of the NotificationRequest.setNotificationId(int id) method.

+

slotType

+

SlotType

+

No

+

Type of the slot used by the reminder

+
+ +**ReminderRequestCalendar** extends **ReminderRequest** and defines a reminder for a calendar event. + +The earliest reminder time must be later than the current time. + +**Table 8** ReminderRequestCalendar instance + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

dateTime

+

LocalDateTime

+

Yes

+

Reminder time.

+

repeatMonths

+

Array<number>

+

No

+

Months in which the reminder repeats.

+

repeatDays

+

Array<number>

+

No

+

Date on which the reminder repeats.

+
+ +**ReminderRequestAlarm** extends **ReminderRequest** and defines a reminder for the alarm clock. + +**Table 9** ReminderRequestAlarm instance + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

hour

+

number

+

Yes

+

Hour portion of the reminder time.

+

minute

+

number

+

Yes

+

Minute portion of the reminder time.

+

daysOfWeek

+

Array<number>

+

No

+

Days of a week when the reminder repeats.

+
+ +**ReminderRequestTimer** extends **ReminderRequest** and defines a reminder for a scheduled timer. + +**Table 10** ReminderRequestTimer instance + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

triggerTimeInSeconds

+

number

+

Yes

+

Number of seconds in the countdown timer.

+
+ +**LocalDateTime** defines a **LocalDateTime** instance. + +**Table 11** LocalDateTime instance + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

year

+

number

+

Yes

+

Year.

+

month

+

number

+

Yes

+

Month.

+

day

+

number

+

Yes

+

Date.

+

hour

+

number

+

Yes

+

Hour.

+

minute

+

number

+

Yes

+

Minute.

+

second

+

number

+

No

+

Second.

+
+ +## How to Develop + +>![](../public_sys-resources/icon-note.gif) **NOTE:** +>To publish a reminder, your application needs to apply for the **ohos.permission.PUBLISH\_AGENT\_REMINDER** permission. + +Publish a 10-second countdown reminder. + +1. Define a countdown timer instance. + + ``` + import reminderAgent from '@ohos.reminderAgent'; + import notification from '@ohos.notification'; + export default { + timer: { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: 10, + actionButton: [ + { + title: "close", + type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE + } + ], + wantAgent: { + pkgName: "com.huawei.phone", + abilityName: "com.huawei.phone.MainAbility" + }, + maxScreenWantAgent: { + pkgName: "com.huawei.phone", + abilityName: "com.huawei.phone.MainAbility" + }, + title: "this is title", + content: "this is content", + expiredContent: "this reminder has expired", + notificationId: 100, + slotType: notification.SlotType.SOCIAL_COMMUNICATION + } + } + ``` + +2. Publish the reminder. + + ``` + startTimer() { + reminderAgent.publishReminder(this.timer, (err, reminderId) =>{ + this.printInfo(JSON.stringify(err)); + this.printInfo("reminderId:" + reminderId); + }); + } + ``` + + HTML page code: + + ``` +
+ +
+ ``` + + +Sample code for defining a calendar reminder instance: + +``` +calendar: { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_CALENDAR, + dateTime: { + year: 2050, + month: 7, + day: 30, + hour: 11, + minute: 14, + second: 30 + }, + repeatMonths: [0], + repeatDays: [0], + actionButton: [ + { + title: "close", + type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE + }, + { + title: "snooze", + type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_SNOOZE + }, + ], + wantAgent: { + pkgName: "com.huawei.phone", + abilityName: "com.huawei.phone.MainAbility" + }, + maxScreenWantAgent: { + pkgName: "com.huawei.phone", + abilityName: "com.huawei.phone.MainAbility" + }, + ringDuration: 5, + snoozeTimes: 2, + timeInterval: 5, + title: "this is title", + content: "this is content", + expiredContent: "this reminder has expired", + snoozeContent: "remind later", + notificationId: 100, + slotType: notification.SlotType.SOCIAL_COMMUNICATION +} +``` + +Sample code for defining an alarm reminder instance: + +``` +alarm: { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, + hour: 11, + minute: 14, + daysOfWeek: [0], + actionButton: [ + { + title: "close", + type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE + }, + { + title: "snooze", + type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_SNOOZE + }, + ], + wantAgent: { + pkgName: "com.huawei.phone", + abilityName: "com.huawei.phone.MainAbility" + }, + maxScreenWantAgent: { + pkgName: "com.huawei.phone", + abilityName: "com.huawei.phone.MainAbility" + }, + ringDuration: 5, + snoozeTimes: 2, + timeInterval: 5, + title: "this is title", + content: "this is content", + expiredContent: "this reminder has expired", + snoozeContent: "remind later", + notificationId: 100, + slotType: notification.SlotType.SOCIAL_COMMUNICATION +} +``` + diff --git a/en/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-overview.md b/en/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..32f0b858f30ce9f6dcec7c979f7c196ecc42e42c --- /dev/null +++ b/en/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-overview.md @@ -0,0 +1,4 @@ +# Overview + +Your application can call the **ReminderRequest** class to create scheduled reminders for countdown timers, calendar events, and alarm clocks. When the created reminders are published, the timing and pop-up notification functions of your application will be taken over by the reminder agent in the background, even when your application is frozen or exits. + diff --git a/en/application-dev/database/Readme-EN.md b/en/application-dev/database/Readme-EN.md index 9e68a292b434f94c7711e79aa8452e911590c998..2555d715a720db4389f502176f9c84226717fcce 100644 --- a/en/application-dev/database/Readme-EN.md +++ b/en/application-dev/database/Readme-EN.md @@ -1,4 +1,11 @@ -# Distributed Data Service +# Data Management -- [Distributed Data Service Overview](database-mdds-overview.md) -- [Distributed Data Service Development](database-mdds-guidelines.md) +- Distributed Data Service + - [Distributed Data Service Overview](database-mdds-overview.md) + - [Distributed Data Service Development](database-mdds-guidelines.md) +- Relational Database Overview + - [RDB Overview](database-relational-overview.md) + - [RDB Development](database-relational-guidelines.md) +- Lightweight Data Store + - [Lightweight Data Store Overview](database-preference-overview.md) + - [Lightweight Data Store Development](database-preference-guidelines.md) \ No newline at end of file diff --git a/en/application-dev/database/database-relational-development.md b/en/application-dev/database/database-relational-development.md new file mode 100644 index 0000000000000000000000000000000000000000..2411dd2c9a15ce0976587dd3caa74e31e7777ce5 --- /dev/null +++ b/en/application-dev/database/database-relational-development.md @@ -0,0 +1,671 @@ +# RDB Development + +## When to Use + +On the basis of the SQLite database, the RDB allows you to operate data with or without native SQL statements. An RDB is also called RDB store. + +## Available APIs + +**Creating and Deleting an RDB Store** + +The following table describes APIs available for creating and deleting an RDB store. + +**Table 1** APIs for creating and deleting an RDB store + + + + + + + + + + + + + + + + + + + + + + + + +

Class

+

API

+

Description

+

dataRdb

+

getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): void

+

Obtains an RDB store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a callback to return the result.

+
  • config: configuration of the RDB store.
  • version: version of the RDB store.
  • callback: callback invoked to return the RDB store.
+

dataRdb

+

getRdbStore(config: StoreConfig, version: number): Promise<RdbStore>

+

Obtains an RDB store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a promise to return the result.

+
  • config: configuration of the RDB store.
  • version: version of the RDB store.
+

dataRdb

+

deleteRdbStore(name: string, callback: AsyncCallback<void>): void

+

Deletes an RDB store. This method uses a callback to return the result.

+
  • name: name of the RDB store to delete.
  • callback: callback invoked to return the result. If the RDB store is deleted, true will be returned. Otherwise, false will be returned.
+

dataRdb

+

deleteRdbStore(name: string): Promise<void>

+

Deletes an RDB store. This method uses a promise to return the result.

+
  • name: name of the RDB store to delete.
+
+ +**Managing Data in an RDB Store** + +The RDB provides APIs for inserting, deleting, modifying, and querying data in the local RDB store. + +- **Inserting data** + + The RDB provides methods for inserting data through **ValuesBucket** in a data table. If the data is inserted successfully, the row number of the data inserted is returned; otherwise, **-1** is returned. + + **Table 2** APIs for inserting data to a data table + + + + + + + + + + + + + + + + +

Class

+

API

+

Description

+

RdbStore

+

insert(name: string, values: ValuesBucket, callback: AsyncCallback<number>):void

+

Inserts a row of data into a table. This method uses a callback to return the result.

+
  • name: name of the target table.
  • values: data to be inserted into the table.
  • 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(name: string, values: ValuesBucket): Promise<number>

+

Inserts a row of data into a table. This method uses a promise to return the result.

+
  • name: name of the target table.
  • values: data to be inserted into the table.
+
+ +- **Updating data** + + Call the **update\(\)** method to pass the new data and specify the update conditions by using **RdbPredicates**. If the data is successfully updated, the row number of the updated data is returned; otherwise, **0** is returned. + + **Table 3** APIs for updating data + + + + + + + + + + + + + + + + +

Class

+

API

+

Description

+

RdbStore

+

update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void

+

Updates the data that meets the conditions specified by the RdbPredicates object. This method uses a callback to return the result.

+
  • values: data to update, which is stored in ValuesBucket.
  • rdbPredicates: conditions for updating data.
  • callback: callback invoked to return the number of rows updated.
+

RdbStore

+

update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise

+

Updates the data that meets the conditions specified by the RdbPredicates object. This method uses a promise to return the result.

+
  • values: data to update, which is stored in ValuesBucket.
  • rdbPredicates: conditions for updating data.
+
+ +- **Deleting data** + + Call the **delete\(\)** method to delete data meeting the conditions specified by **RdbPredicates**. If the data is deleted, the row number of the deleted data is returned; otherwise, **0** is returned. + + **Table 4** APIs for deleting data + + + + + + + + + + + + + + + + +

Class

+

API

+

Description

+

RdbStore

+

delete(rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void

+

Deletes data based on the conditions specified by RdbPredicates. This method uses a callback to return the result.

+
  • rdbPredicates: conditions for deleting data.
  • callback: callback invoked to return the number of rows deleted.
+

RdbStore

+

delete(rdbPredicates: RdbPredicates): Promise

+

Deletes data based on the conditions specified by RdbPredicates. This method uses a promise to return the result.

+
  • rdbPredicates: conditions for deleting data.
+
+ +- **Querying data** + + You can query data in the RDB in either of the following ways: + + - Call the **query** method to query data based on the predicates, without passing any SQL statement. + - Run the native SQL statement. + + **Table 5** APIs for querying data + + + + + + + + + + + + + + + + + + + + + + + + +

Class

+

API

+

Description

+

RdbStore

+

query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback<ResultSet>): void;

+

Queries data in the database based on specified conditions. This method uses a callback to return the result.

+
  • rdbPredicates: conditions for querying data.
+
  • columns: columns to query. If this parameter is not specified, the query applies to all columns.
  • callback: callback invoked to return the result. If the operation is successful, a ResultSet object will be returned.
+

RdbStore

+

query(rdbPredicates: RdbPredicates, columns: Array): Promise<ResultSet>;

+

Queries data in the database based on specified conditions. This method uses a promise to return the result.

+
  • rdbPredicates: conditions for querying data.
+
  • columns: columns to query. If this parameter is not specified, the query applies to all columns.
+

RdbStore

+

querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void

+

Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result.

+
  • sql: SQL statement.
+
  • bindArgs: arguments in the SQL statement.
  • callback: callback invoked to return the result. If the operation is successful, a ResultSet object will be returned.
+

RdbStore

+

querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet>

+

Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result.

+
  • sql: SQL statement.
+
  • bindArgs: arguments in the SQL statement.
+
+ + +**Using Predicates** + +The RDB provides **RdbPredicates** for you to set database operation conditions. + +**Table 6** APIs for RDB predicates + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Class

+

API

+

Description

+

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.

+
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
+

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.

+
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
+

RdbPredicates

+

beginWrap(): RdbPredicates

+

Adds a left parenthesis to the RdbPredicates.

+
  • RdbPredicates: RdbPredicates with a left parenthesis.
+

RdbPredicates

+

endWrap(): RdbPredicates

+

Adds a right parenthesis to the RdbPredicates.

+
  • RdbPredicates: RdbPredicates with a right parenthesis.
+

RdbPredicates

+

or(): RdbPredicates

+

Adds the OR condition to the RdbPredicates.

+
  • RdbPredicates: RdbPredicates with the OR condition.
+

RdbPredicates

+

and(): RdbPredicates

+

Adds the AND condition to the RdbPredicates.

+
  • RdbPredicates: RdbPredicates with the AND condition.
+

RdbPredicates

+

contains(field: string, value: string): RdbPredicats

+

Sets the RdbPredicates to match a string containing the specified value.

+
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
+

RdbPredicates

+

beginsWith(field: string, value: string): RdbPredicates

+

Sets the RdbPredicates to match a string that starts with the specified value.

+
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: 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.

+
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
+

RdbPredicates

+

isNull(field: string): RdbPredicates

+

Sets the RdbPredicates to match the field whose value is null.

+
  • field: column name in the database table.
  • RdbPredicates: RdbPredicates object that matches the specified field.
+

RdbPredicates

+

isNotNull(field: string): RdbPredicates

+

Sets the RdbPredicates to match the field whose value is not null.

+
  • field: column name in the database table.
  • RdbPredicates: 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.

+
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
+

RdbPredicates

+

glob(field: string, value: string): RdbPredicates

+

Sets the RdbPredicates to match the specified string.

+
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: 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.

+
  • field: column name in the database table.
  • low: minimum value that matches the RdbPredicates.
  • high: maximum value that matches the RdbPredicates.
  • RdbPredicates: 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.

+
  • field: column name in the database table.
  • low: minimum value that matches the RdbPredicates.
  • high: maximum value that matches the RdbPredicates.
  • RdbPredicates: 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.

+
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: 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.

+
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: 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.

+
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: 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.

+
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: 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.

+
  • field: column name in the database table.
  • RdbPredicates: 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.

+
  • field: column name in the database table.
  • RdbPredicates: RdbPredicates object that matches the specified field.
+

RdbPredicates

+

distinct(): RdbPredicates

+

Sets the RdbPredicates to filter out duplicate records.

+
  • RdbPredicates: RdbPredicates that can filter out duplicate records.
+

RdbPredicates

+

limitAs(value: number): RdbPredicates

+

Sets the RdbPredicates to specify the maximum number of records to match in a column.

+
  • value: maximum number of records in a column.
  • RdbPredicates: RdbPredicates that can be used to set the maximum number of records to match in a column.
+

RdbPredicates

+

offsetAs(rowOffset: number): RdbPredicates

+

Sets the RdbPredicates to specify the start position of the returned result.

+
  • rowOffset: start position of the returned result. The value is a positive integer.
  • RdbPredicates: RdbPredicates object that specifies the start position of the returned result.
+

RdbPredicates

+

groupBy(fields: Array<string>): RdbPredicates

+

Sets the RdbPredicates to group rows that have the same value into summary rows.

+
  • fields: names of the columns grouped for querying data.
  • RdbPredicates: RdbPredicates that groups rows that have the same value.
+

RdbPredicates

+

indexedBy(indexName: string): RdbPredicates

+

Sets the RdbPredicates object to specify the index column.

+
  • indexName: name of the index column.
  • RdbPredicates: RdbPredicates object that specifies the index column.
+

RdbPredicates

+

in(field: string, value: Array<ValueType>): RdbPredicates

+

Sets the RdbPredicates to match the field with data type Array<ValueType> and value within the specified range.

+
  • field: column name in the database table.
+
  • value: array of ValueType to match.
  • RdbPredicates: RdbPredicates object that matches the specified field.
+

RdbPredicates

+

notIn(field: string, value: Array<ValueType>): RdbPredicates

+

Sets the RdbPredicates to match the field with data type Array<ValueType> and value out of the specified range.

+
  • field: column name in the database table.
+
  • value: array of ValueType to match.
  • RdbPredicates: RdbPredicates object that matches the specified field.
+
+ +**Using the Result Set** + +A result set can be regarded as rows 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**. + +>![](public_sys-resources/icon-notice.gif) **NOTICE:** +>After a result set is used, you must call the **close\(\)** method to close it explicitly. + +**Table 7** APIs for using the result set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Class

+

API

+

Description

+

ResultSet

+

goTo(offset:number): boolean

+

Moves the result set forwards or backwards by an offset relative to its current position.

+

ResultSet

+

goToRow(position: number): boolean

+

Moves the result set to a specified row.

+

ResultSet

+

goToNextRow(): boolean

+

Moves the result set to the next row.

+

ResultSet

+

goToPreviousRow(): boolean

+

Moves the result set to the previous row.

+

ResultSet

+

getColumnIndex(columnName: string): number

+

Obtains the column index based on the specified column name.

+

ResultSet

+

getColumnName(columnIndex: number): string

+

Obtains the column name based on the specified column index.

+

ResultSet

+

goToFirstRow(): boolean

+

Checks whether the result set is located in the first row.

+

ResultSet

+

goToLastRow(): boolean

+

Checks whether the result set is located in the last row.

+

ResultSet

+

getString(columnIndex: number): string

+

Obtains the values in the specified column of the current row, in strings.

+

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 values in the specified column of the current row are null.

+

ResultSet

+

close(): void

+

Closes the result set.

+
+ +**Encrypting an RDB Store** + +You can encrypt an RDB store. + +When creating an RDB store, you can add a key for security purposes. After that, the RDB store can be accessed only with the correct key. You can change the key but cannot delete it. + +Once an RDB store is created without a key, you cannot add a key any longer. + +**Table 8** APIs for changing the key + + + + + + + + + + + + + + + + +

Class

+

API

+

Description

+

RdbStore

+

changeEncryptKey(newEncryptKey:Uint8Array, callback: AsyncCallback<number>):void;

+

Changes the encryption key for an RDB store. This method uses a callback to return the result. If the key is changed, 0 is returned. Otherwise, a non-zero value is returned.

+

RdbStore

+

changeEncryptKey(newEncryptKey:Uint8Array): Promise<number>;

+

Changes the encryption key for an RDB store. This method uses a promise to return the result. If the key is changed, 0 is returned. Otherwise, a non-zero value is returned.

+
+ +## How to Develop + +1. Create an RDB store. + + 1. Configure the RDB attributes, including the name and storage mode of the database and whether it is read-only. + 2. Initialize the table structure and related data in the database. + 3. Create an RDB store. + + The sample code is as follows: + + ``` + import dataRdb 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 STORE_CONFIG = {name: "rdbstore.db",} + + let rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); + await rdbStore.executeSql(CREATE_TABLE_TEST); + ``` + +2. Insert data. + + 1. Create a **ValuesBucket** object to store the data you need to insert. + 2. Call the **insert\(\)** method to insert data into the RDB store. + + The sample code is as follows: + + ``` + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket = {"name": "Tom", "age": 18, "salary": 100.5, "blobType": u8,} + let insertPromise = rdbStore.insert("test", valueBucket) + ``` + +3. Query data. + + 1. Create an **RdbPredicates** object to specify query conditions. + 2. Call the **query \(\)** method to query data in the RDB store. + 3. Call the **ResultSet\(\)** method to obtain the query result. + + The sample code is as follows: + + ``` + let predicates = new dataRdb.RdbPredicates("test"); + predicates.equalTo("name", "Tom") + let resultSet = await rdbStore.query(predicates) + + resultSet.goToFirstRow() + const id = await resultSet.getLong(resultSet.getColumnIndex("id")) + const name = await resultSet.getString(resultSet.getColumnIndex("name")) + const age = await resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) + + resultSet.close() + ``` + + diff --git a/en/application-dev/database/database-relational-overview.md b/en/application-dev/database/database-relational-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..cd675b9701e9e22147833d1fb7b471f420af2f12 --- /dev/null +++ b/en/application-dev/database/database-relational-overview.md @@ -0,0 +1,42 @@ +# RDB Overview + +The relational database \(RDB\) manages data based on relational models. With the underlying SQLite database, the RDB provides a complete mechanism for managing local databases. To satisfy different needs in complicated scenarios, the RDB offers a series of methods for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements. + +## Basic Concepts + +- **RDB** + + A type of database based on the relational model of data. The RDB stores data in rows and columns. An RDB is also called RDB store. + +- **Predicate** + + A representation of the property or feature of a data entity, or the relationship between data entities. It is mainly used to define operation conditions. + +- **Result set** + + A set of query results used to access the data. You can access the required data in a result set in flexible modes. + +- **SQLite database** + + A lightweight open-source relational database management system that complies with Atomicity, Consistency, Isolation, and Durability \(ACID\). + + +## Working Principles + +The RDB provides a common operation interface for external systems. It uses the SQLite as the underlying persistent storage engine, which supports all SQLite database features. + +**Figure 1** How RDB works +![](figures/how-rdb-works.png "how-rdb-works") + +## Default Settings + +- The default database logging mode is write-ahead logging \(WAL\). +- The default database flush mode is Full mode. +- The default shared memory used by the OpenHarmony database is 2 MB. + +## Constraints + +- A maximum of four connection pools can be connected to an RDB to manage read and write operations. + +- To ensure data accuracy, the RDB supports only one write operation at a time. + diff --git a/en/application-dev/database/figures/en-us_image_0000001199139454.png b/en/application-dev/database/figures/en-us_image_0000001199139454.png new file mode 100644 index 0000000000000000000000000000000000000000..ca52bd43d384c5b2d06fe19623b50e0c66ba6295 Binary files /dev/null and b/en/application-dev/database/figures/en-us_image_0000001199139454.png differ diff --git a/en/application-dev/database/figures/how-rdb-works.png b/en/application-dev/database/figures/how-rdb-works.png new file mode 100644 index 0000000000000000000000000000000000000000..35e10dc3a07aef0e85a8f02332c3c6cd9d605448 Binary files /dev/null and b/en/application-dev/database/figures/how-rdb-works.png differ diff --git a/en/application-dev/database/lightweight-data-store-development.md b/en/application-dev/database/lightweight-data-store-development.md new file mode 100644 index 0000000000000000000000000000000000000000..856257581cb3e9fb7e34f7a3aee01d470bfcf794 --- /dev/null +++ b/en/application-dev/database/lightweight-data-store-development.md @@ -0,0 +1,272 @@ +# Lightweight Data Store Development + +## When to Use + +The lightweight data store is ideal for storing lightweight and frequently used data, but not for storing a large amount of data or data with frequent changes. The application data is persistently stored on a device in the form of files. Note that the instance accessed by an application contains all data of the file. The data is always loaded to the memory of the device until the application removes it from the memory. The application can perform data operations using the **Storage** APIs. + +## Available APIs + +The lightweight data store provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value pairs. Keys are of the string type, and values can be of the number, string, or Boolean type. + +**Creating a Storage Instance** + +Create a **Storage** instance for data operations. A **Storage** instance is created after data is read from a specified file and loaded to the instance. + +**Table 1** API for creating a **Storage** instance + + + + + + + + + + + + +

Package Name

+

Method

+

Description

+

ohos.data.storage

+

getStorage(path: string): Promise<Storage>;

+

Obtains the Storage singleton corresponding to a file for data operations.

+
+ +**Writing Data** + +Call the **put\(\)** method to add or modify data in a **Storage** instance. + +**Table 2** API for writing data + + + + + + + + + + + + +

Class

+

Method

+

Description

+

Storage

+

put(key: string, value: ValueType): Promise<void>;

+

Writes data of the number, string, and Boolean types.

+
+ +**Reading Data** + +Call the **get\(\)** method to read data from a **Storage** instance. + +**Table 3** API for reading data + + + + + + + + + + + + +

Class

+

Method

+

Description

+

Storage

+

get(key: string, defValue: ValueType): Promise<ValueType>;

+

Reads data of the number, string, and Boolean types.

+
+ +**Storing Data Persistently** + +Call the **flush\(\)** method to write the cached data back to its text file for persistent storage. + +**Table 4** API for data persistence + + + + + + + + + + + + +

Class

+

Method

+

Description

+

Storage

+

flush(): Promise<void>;

+

Writes data in the Storage instance back to its file through an asynchronous thread.

+
+ +**Observing Data Changes** + +Specify **StorageObserver** as the callback to subscribe to data changes. When the value of the subscribed key is changed and the **flush\(\)** method is executed, **StorageObserver** will be invoked. + +**Table 5** APIs for subscribing to data changes + + + + + + + + + + + + + + + + +

Class

+

Method

+

Description

+

Storage

+

on(type: 'change', callback: Callback<StorageObserver>): void;

+

Subscribes to data changes.

+

Storage

+

off(type: 'change', callback: Callback<StorageObserver>): void;

+

Unsubscribes from data changes.

+
+ +**Deleting Data** + +Use the following APIs to delete a **Storage** instance or data file. + +**Table 6** APIs for deleting data + + + + + + + + + + + + + + + + +

Package Name

+

Method

+

Description

+

ohos.data.storage

+

deleteStorage(path: string): Promise<void>;

+

Deletes a Storage instance from the cache and deletes its file from the device.

+

ohos.data.storage

+

removeStorageFromCache(path: string): Promise<void>;

+

Deletes a Storage instance from the cache to release memory.

+
+ +## How to Develop + +1. Import **@ohos.data.storage** and related modules to the development environment. + + ``` + import dataStorage from '@ohos.data.storage' + import featureAbility from '@ohos.ability.featureAbility' // Used to obtain the file storage path. + ``` + +2. Create a **Storage** instance. + + Read the specified file and load its data to the **Storage** instance for data operations. + + ``` + var context = featureAbility.getContext() + var path = await context.getFilesDir() + let promise = dataStorage.getStorage(path + '/mystore') + ``` + + +1. Write data. + + Use the **put\(\)** method of the **Storage** class to write data to the cached **Storage** instance. + + ``` + promise.then((storage) => { + let getPromise = storage.put('startup', 'auto') // Save data to the Storage instance. + getPromise.then(() => { + console.info("Put the value of startup successfully.") + }).catch((err) => { + console.info("Put the value of startup failed with err: " + err) + }) + }).catch((err) => { + console.info("Get the storage failed") + }) + ``` + + +1. Read data. + + Use the **get\(\)** method of the **Storage** class to read data. + + ``` + promise.then((storage) => { + let getPromise = storage.get('startup', 'default') + getPromise.then((value) => { + console.info("The value of startup is " + value) + }).catch((err) => { + console.info("Get the value of startup failed with err: " + err) + }) + }).catch((err) => { + console.info("Get the storage failed") + }) + ``` + + +1. Store data persistently. + + Use the **flush** or **flushSync** method to flush data in the **Storage** instance to its file. + + ``` + storage.flush(); + ``` + +2. Observe data changes. + + Specify **StorageObserver** as the callback to subscribe to data changes for an application. When the value of the subscribed key is changed and the **flush\(\)** method is executed, **StorageObserver** will be invoked. Unregister the **StorageObserver** when it is no longer required. + + ``` + promise.then((storage) => { + var observer = function (key) { + console.info("The key of " + key + " changed.") + } + storage.on('change', observer) + storage.putSync('startup', 'auto') // Modify data in the Storage instance. + storage.flushSync() // Trigger the StorageObserver callback. + + storage.off(...change..., observer) // Unsubscribe from the data changes. + }).catch((err) => { + console.info("Get the storage failed") + }) + ``` + + +1. Delete the specified file. + + Use the **deleteStorage** method to delete the **Storage** singleton of the specified file from the memory, and delete the specified file, its backup file, and damaged files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will occur. The deleted data and files cannot be restored. + + ``` + let promise = dataStorage.deleteStorage(path + '/mystore') + promise.then(() => { + console.info("Deleted successfully.") + }).catch((err) => { + console.info("Deleted failed with err: " + err) + }) + ``` + + diff --git a/en/application-dev/database/lightweight-data-store-overview.md b/en/application-dev/database/lightweight-data-store-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..45639c75e8ad5d1b3f68c79da90fbc598af7e840 --- /dev/null +++ b/en/application-dev/database/lightweight-data-store-overview.md @@ -0,0 +1,31 @@ +# Lightweight Data Store Overview + +Lightweight data store is applicable to access and persistence operations on the data in key-value pairs. When an application accesses a lightweight **Storage** instance, data in the **Storage** instance will be cached in the memory for faster access. The cached data can also be written back to the text file for persistent storage. Since file read and write consume system resources, you are advised to minimize the frequency of reading and writing persistent files. + +## Basic Concepts + +- **Key-Value data structure** + + A type of data structure. The key is the unique identifier for a piece of data, and the value is the specific data being identified. + +- **Non-relational database** + + A database not in compliance with the atomicity, consistency, isolation, and durability \(ACID\) database management properties of relational data transactions. The data in a non-relational database is independent. + + +## Working Principles + +1. When an application loads data from a specified **Storage** file to a **Storage** instance, the system stores the instance in the memory through a static container. Each file of an application or process has only one **Storage** instance in the memory, till the application removes the instance from the memory or deletes the **Storage** file. +2. When obtaining a **Storage** instance, the application can read data from or write data to the instance. The data in the **Storage** instance can be flushed to its **Storage** file by calling the **flush** or **flushSync** method. + +**Figure 1** How lightweight data store works + + +![](figures/en-us_image_0000001199139454.png) + +## Constraints + +- **Storage** instances are loaded to the memory. To minimize non-memory overhead, the number of data records stored in a **Storage** instance cannot exceed 10,000. Delete the instances that are no longer used in a timely manner. +- The key in the key-value pairs is of the string type. It cannot be empty or exceed 80 characters. +- If the value in the key-value pairs is of the string type, it can be empty or contain a maximum of 8192 characters. + diff --git a/en/application-dev/media/figures/playback-status.png b/en/application-dev/media/figures/playback-status.png deleted file mode 100755 index e0777e28838f6d2455233f2068339f8548f50c67..0000000000000000000000000000000000000000 Binary files a/en/application-dev/media/figures/playback-status.png and /dev/null differ diff --git a/en/application-dev/reference/apis/Readme-EN.md b/en/application-dev/reference/apis/Readme-EN.md index 85bf1c75e1ae29a122a70fd5d0ef47f411f9b2ca..47a186f0c126877789c41f0b93923e72a500ed24 100644 --- a/en/application-dev/reference/apis/Readme-EN.md +++ b/en/application-dev/reference/apis/Readme-EN.md @@ -9,6 +9,7 @@ - Event Notification - [CommonEvent Module](js-apis-commonEvent.md) - [Notification Module](js-apis-notification.md) + - [Reminder Agent](js-apis-reminderAgent.md) - Resource Management - [Resource Manager](js-apis-resource-manager.md) - [Internationalization \(intl\) ](js-apis-intl.md) @@ -63,6 +64,9 @@ - Language Base Class Library - [Obtaining Process Information](js-apis-process.md) - [URL String Parsing](js-apis-url.md) + - [URI String Parsing](js-apis-uri.md) - [Util](js-apis-util.md) + - [XML Parsing and Generation](js-apis-xml.md) + - [XML-to-JavaScript Conversion](js-apis-convertxml.md) - [Worker Startup](js-apis-worker.md) diff --git a/en/application-dev/reference/apis/js-apis-Context.md b/en/application-dev/reference/apis/js-apis-Context.md index e2b51f2e3cdf0468fe08a8913d4630b80c28269a..ad42e566a0c64f94801f982541cdd5382d96c55c 100644 --- a/en/application-dev/reference/apis/js-apis-Context.md +++ b/en/application-dev/reference/apis/js-apis-Context.md @@ -1,28 +1,5 @@ # Context Module -## Applicable Devices - -| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| SmartVision Device| -| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | ------------ | -| Context.getOrCreateLocalDir(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| Context.getOrCreateLocalDir() | Yes| Yes| Yes| Yes| No| No| -| Context.verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| Context.verifyPermission(permission: string, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| Context.verifyPermission(permission: string, options?: PermissionOptions) | Yes| Yes| Yes| Yes| No| No| -| Context.requestPermissionsFromUser(permissions: Array\, requestCode: number, resultCallback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| Context.getApplicationInfo(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| Context.getApplicationInfo() | Yes| Yes| Yes| Yes| No| No| -| Context.getBundleName(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| Context.getBundleName() | Yes| Yes| Yes| Yes| No| No| -| Context.getProcessInfo(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| Context.getProcessInfo() | Yes| Yes| Yes| Yes| No| No| -| Context.getElementName(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| Context.getElementName() | Yes| Yes| Yes| Yes| No| No| -| Context.getProcessName(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| Context.getProcessName() | Yes| Yes| Yes| Yes| No| No| -| Context.getCallingBundle(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| Context.getCallingBundle() | Yes| Yes| Yes| Yes| No| No| - ## Modules to Import ```js diff --git a/en/application-dev/reference/apis/js-apis-commonEvent.md b/en/application-dev/reference/apis/js-apis-commonEvent.md index e3f7238a1279728877203071f3e2bfd5b391fa2e..9ef873e163d62b5391c97a0941ef1226c09cd6a1 100644 --- a/en/application-dev/reference/apis/js-apis-commonEvent.md +++ b/en/application-dev/reference/apis/js-apis-commonEvent.md @@ -3,17 +3,6 @@ **Note:** The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -## Applicable Devices - -| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| -| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | -| CommonEvent.publish(event: string, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| -| CommonEvent.publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| -| CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| -| CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo) | Yes| Yes| Yes| Yes| No| -| CommonEvent.subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| -| CommonEvent.unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\) | Yes| Yes| Yes| Yes| No| - ## Required Permissions | Common Event Macro| Common Event Name| Subscriber Permissions| diff --git a/en/application-dev/reference/apis/js-apis-convertxml.md b/en/application-dev/reference/apis/js-apis-convertxml.md new file mode 100644 index 0000000000000000000000000000000000000000..7d3d923d94128325d197e6fda5d97c8c08752cd6 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-convertxml.md @@ -0,0 +1,277 @@ +# XML-to-JavaScript Conversion + +>![](public_sys-resources/icon-note.gif) **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 + +``` +import convertxml from '@ohos.convertxml'; +``` + +## Required Permissions + +None + +## ConvertXML + +### convert + +convert\(xml: string, options?: ConvertOptions\) : Object + +Converts an XML text into a JavaScript object. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

xml

+

string

+

Yes

+

XML text to convert.

+

options

+

ConvertOptions

+

No

+

Settings of the convert operation.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

JavaScript object.

+
+ +- Example + + ``` + var xml = + '' + + '' + + ' Happy' + + ' Work' + + ' Play' + + ''; + var conv = new convertxml.ConvertXML(); + var result1 = conv.convert(xml, {trim: false, ignoreDeclaration: false}); + console.log(result1) + ``` + + +## ConvertOptions + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

trim

+

boolean

+

No

+

Whether to trim the whitespace characters before and after the text. The default value is false.

+

ignoreDeclaration

+

boolean

+

No

+

Whether to ignore the XML declaration. The default value is false.

+

ignoreInstruction

+

boolean

+

No

+

Whether to ignore the XML processing instruction. The default value is false.

+

ignoreAttributes

+

boolean

+

No

+

Whether to print attributes across multiple lines and indent attributes. The default value is false.

+

ignoreComment

+

boolean

+

No

+

Whether to ignore element comments. The default value is false.

+

ignoreCDATA

+

boolean

+

No

+

Whether to ignore the element's CDATA information. The default value is false.

+

ignoreDoctype

+

boolean

+

No

+

Whether to ignore the element's Doctype information. The default value is false.

+

ignoreText

+

boolean

+

No

+

Whether to ignore the element's text information. The default value is false.

+

declarationKey

+

string

+

No

+

Name of the attribute key for declaration in the output object. The default value is _declaration.

+

instructionKey

+

string

+

No

+

Name of the attribute key for instruction in the output object. The default value is _instruction.

+

attributesKey

+

string

+

No

+

Name of the attribute key for attributes in the output object. The default value is _attributes.

+

textKey

+

string

+

No

+

Name of the attribute key for text in the output object. The default value is _text.

+

cdataKey

+

string

+

No

+

Name of the attribute key for CDATA in the output object. The default value is _cdata.

+

doctypeKey

+

string

+

No

+

Name of the attribute key for Doctype in the output object. The default value is _doctype.

+

commentKey

+

string

+

No

+

Name of the attribute key for comment in the output object. The default value is _comment.

+

parentKey

+

string

+

No

+

Name of the attribute key for parent in the output object. The default value is _parent.

+

typeKey

+

string

+

No

+

Name of the attribute key for type in the output object. The default value is _type.

+

nameKey

+

string

+

No

+

Name of the attribute key for name in the output object. The default value is _name.

+

elementsKey

+

string

+

No

+

Name of the attribute key for elements in the output object. The default value is _elements.

+
+ diff --git a/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md b/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md index 39d8c92342f998da7e18b8731e47a0f9929a5b92..dc09e186854d248a51cb7c1260de5db3febb3dee 100644 --- a/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md +++ b/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md @@ -1,33 +1,4 @@ -### DataAbilityHelper Module (JavaScript SDK APIs) - -#### Applicable Devices - -| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| SmartVision Device| -| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | ------------ | -| DataAbilityHelper.openFile(uri: string, mode: string, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.openFile(uri: string, mode: string) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.on(type: 'dataChange', uri: string, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.off(type: 'dataChange', uri: string, callback?: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback>) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.getFileTypes(uri: string, mimeTypeFilter: string) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.getType(uri: string, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.getType(uri: string) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.normalizeUri(uri: string) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.denormalizeUri(uri: string, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.denormalizeUri(uri: string) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.notifyChange(uri: string, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.notifyChange(uri: string) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.insert(uri: string, valuesBucket: rdb.ValuesBucket) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.batchInsert(uri: string, valuesBuckets: Array, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.batchInsert(uri: string, valuesBuckets: Array) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.delete(uri: string, predicates: dataAbility.DataAbilityPredicates) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.query(uri: string, columns: Array\, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| DataAbilityHelper.query(uri: string, columns: Array\, predicates: dataAbility.DataAbilityPredicates) | Yes| Yes| Yes| Yes| No| No| +# DataAbilityHelper Module (JavaScript SDK APIs) #### Modules to Import diff --git a/en/application-dev/reference/apis/js-apis-featureAbility.md b/en/application-dev/reference/apis/js-apis-featureAbility.md index 88279ca8591d41229d43084cc1cd4dda603dd107..c07e862c47c43c70bff819c4e2e4d41ed23c2bce 100644 --- a/en/application-dev/reference/apis/js-apis-featureAbility.md +++ b/en/application-dev/reference/apis/js-apis-featureAbility.md @@ -1,27 +1,5 @@ # FeatureAbility Module (JavaScript) -#### Applicable Devices - -| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| SmartVision Device| -| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | ------------ | -| FeatureAbility.startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\): void | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.startAbility(parameter: StartAbilityParameter): Promise\ | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.acquireDataAbilityHelper(uri: string): DataAbilityHelper | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\): void | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.startAbilityForResult(parameter: StartAbilityParameter): Promise\ | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\): void | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.terminateSelfWithResult(parameter: AbilityResult): Promise\ | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.hasWindowFocus(callback: AsyncCallback\): void | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.hasWindowFocus(): Promise\ | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.getWant(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.getWant(): void | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.getContext(): Context | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.terminateSelf(callback: AsyncCallback\): void | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.terminateSelf(): Promise\ | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.connectAbility(request: Want, options:ConnectOptions): number | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.disconnectAbility(connection: number, callback:AsyncCallback\): void | Yes| Yes| Yes| Yes| No| No| -| FeatureAbility.disconnectAbility(connection: number): Promise\ | Yes| Yes| Yes| Yes| No| No| - #### Constraints APIs of the **FeatureAbility** module can be called only by Page abilities. diff --git a/en/application-dev/reference/apis/js-apis-i18n.md b/en/application-dev/reference/apis/js-apis-i18n.md index 6f684c8c06d674c9cc43cc409acd1c2e962129f7..0763a1598728414c51ec8036cbe2243235d012b0 100644 --- a/en/application-dev/reference/apis/js-apis-i18n.md +++ b/en/application-dev/reference/apis/js-apis-i18n.md @@ -1,10 +1,10 @@ -# Internationalization \(i18n\) +# Internationalization (i18n) + >![](../../public_sys-resources/icon-note.gif) **NOTE:** >- The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. >- This module contains enhanced i18n APIs, which are not defined in ECMA 402. - ## Modules to Import ``` @@ -21,9 +21,10 @@ getDisplayLanguage\(language: string, locale: string, sentenceCase?: boolean\): Obtains the localized script for the specified language. -- Parameters +- Parameters + - - - - -

Name

Type

@@ -163,6 +164,58 @@ Obtains the localized script for the specified country. ``` +## i18n.isRTL8+ + +isRTL\(locale: string\): boolean + +Checks whether the localized script for the specified language is displayed from right to left. + +- Parameters + + + + + + + + + + + + +

Name

+

Type

+

Description

+

locale

+

string

+

Locale ID.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates that the localized script is displayed from right to left, and value false indicates the opposite.

+
+ +- Example + + ``` + i18n.isRTL("zh-CN");// Since Chinese is not written from right to left, false is returned. + i18n.isRTL("ar-EG");// Since Arabic is written from right to left, true is returned. + ``` + + ## i18n.getSystemLanguage getSystemLanguage\(\): string @@ -253,3 +306,2086 @@ Obtains the system locale. ``` +## i18n.getCalendar8+ + +getCalendar\(locale: string, type? : string\): Calendar + +Obtains a **Calendar** object. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

locale

+

string

+

Yes

+

Valid locale value, for example, zh-Hans-CN.

+

type

+

string

+

No

+

Valid calendar type. Currently, the valid types are as follows: buddhist, chinese, coptic, ethiopic, hebrew, gregory, indian, islamic_civil, islamic_tbla, islamic_umalqura, japanese, and persian. If this parameter is left unspecified, the default calendar type of the specified locale is used.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Calendar

+

Calendar object.

+
+ +- Example + + ``` + i18n.getCalendar("zh-Hans", "gregory"); + ``` + + +## Calendar8+ + +### setTime8+ + +setTime\(date: Date\): void + +Sets the date for this **Calendar** object. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

date

+

Date

+

Yes

+

Date to be set for the Calendar object.

+
+ + +- Example + + ``` + var calendar = I18n.getCalendar("en-US", "gregory"); + var date = new Date(2021, 10, 7, 8, 0, 0, 0); + calendar.setTime(date); + ``` + + +### setTime8+ + +setTime\(time: number\): void + +Sets the date and time for this **Calendar** object. The value is represented by the number of milliseconds that have elapsed since the Unix epoch \(00:00:00 UTC on January 1, 1970\). + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

time

+

number

+

Yes

+

Number of milliseconds that have elapsed since the Unix epoch.

+
+ + +- Example + + ``` + var calendar = I18n.getCalendar("en-US", "gregory"); + calendar.setTime(10540800000); + ``` + + +### set8+ + +set\(year: number, month: number, date:number, hour?: number, minute?: number, second?: number\): void + +Sets the year, month, day, hour, minute, and second for this **Calendar** object. + +- Parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

year

+

number

+

Yes

+

Year to set.

+

month

+

number

+

Yes

+

Month to set.

+

date

+

number

+

Yes

+

Day to set.

+

hour

+

number

+

No

+

Hour to set.

+

minute

+

number

+

No

+

Minute to set.

+

second

+

number

+

No

+

Second to set.

+
+ +- Example + + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 + ``` + + +### setTimeZone8+ + +setTimeZone\(timezone: string\): void + +Sets the time zone of this **Calendar** object. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

timezone

+

string

+

Yes

+

Time zone, for example, Asia/Shanghai.

+
+ +- Example + + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setTimeZone("Asia/Shanghai"); + ``` + + +### getTimeZone8+ + +getTimeZone\(\): string + +Obtains the time zone of this **Calendar** object. + +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Time zone of the Calendar object.

+
+ +- Example + + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setTimeZone("Asia/Shanghai"); + calendar.getTimeZone(); // Asia/Shanghai" + ``` + + +### getFirstDayOfWeek8+ + +getFirstDayOfWeek\(\): number + +Obtains the start day of a week for this **Calendar** object. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Start day of a week. The value 1 indicates Sunday, and value 7 indicates Saturday.

+
+ + +- Example + + ``` + var calendar = I18n.getCalendar("en-US", "gregory"); + calendar.getFirstDayOfWeek(); + ``` + + +### setFirstDayOfWeek8+ + +setFirstDayOfWeek\(value: number\): void + +Sets the start day of a week for this **Calendar** object. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

value

+

number

+

No

+

Start day of a week. The value 1 indicates Sunday, and value 7 indicates Saturday.

+
+ +- Example + + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setFirstDayOfWeek(0); + ``` + + +### getMinimalDaysInFirstWeek8+ + +getMinimalDaysInFirstWeek\(\): number + +Obtains the minimum number of days in the first week of a year. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Minimum number of days in the first week of a year.

+
+ +- Example + + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.getMinimalDaysInFirstWeek(); + ``` + + +### setMinimalDaysInFirstWeek8+ + +setMinimalDaysInFirstWeek\(value: number\): void + +Sets the minimum number of days in the first week of a year. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

value

+

number

+

No

+

Minimum number of days in the first week of a year.

+
+ +- Example + + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setMinimalDaysInFirstWeek(3); + ``` + + +### get8+ + +get\(field: string\): number + +Obtains the value of the specified field in the **Calendar** object. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Value of the specified field in the Calendar object. Currently, the valid fields are as follows: era, year, month, week_of_year, week_of_month, date, day_of_year, day_of_week, day_of_week_in_month, hour, hour_of_day, minute, second, millisecond, zone_offset, dst_offset, year_woy, dow_local, extended_year, julian_day, milliseconds_in_day, and is_leap_month.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Value of the specified field. For example, if the year in the internal date of this Calendar object is 1990, the get("year") function will return 1990.

+
+ +- Example + + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 + calendar.get("hour_of_day"); // 8 + ``` + + +### getDisplayName8+ + +getDisplayName\(locale: string\): string + +Obtains the name of the **Calendar** object displayed for the specified locale. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

locale

+

string

+

Yes

+

Locale for which the name of the Calendar object is displayed. For example, if locale is en-US, the name of the Buddhist calendar will be Buddhist Calendar.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Name of the Calendar object displayed for the specified locale.

+
+ +- Example + + ``` + var calendar = i18n.getCalendar("en-US", "buddhist"); + calendar.getDisplayName("zh"); // Obtain the name of the Buddhist calendar in zh. + ``` + + +### isWeekend8+ + +isWeekend\(date?: Date\): boolean + +Checks whether the specified date in this **Calendar** object is a weekend. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

date

+

Date

+

No

+

Specified date in this Calendar object. If this parameter is left unspecified, the system checks whether the current date in the Calendar object is a weekend.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates that the date is a weekend, and value false indicates a weekday.

+
+ +- Example + + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setTime(2021, 11, 11, 8, 0, 0); // Set the time to 2021.11.11 08:00:00. + calendar.isWeekend(); // false + var date = new Date(2011, 11, 6, 9, 0, 0); + calendar.isWeekend(date); // true + ``` + + +## PhoneNumberFormat8+ + +### constructor8+ + +constructor\(country: string, options?: PhoneNumberFormatOptions\) + +Creates a **PhoneNumberFormat** object. + +Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

country

+

string

+

Yes

+

Country or region to which the phone number to be formatted belongs.

+

options

+

PhoneNumberFormatOptions

+

No

+

Options of the PhoneNumberFormat object.

+
+ +- Example + + ``` + var phoneNumberFormat= new i18n.PhoneNumberFormat("CN", {"type": "E164"}); + ``` + + +### isValidNumber8+ + +isValidNumber\(number: string\): boolean + +Checks whether the format of the specified phone number is valid. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

number

+

string

+

Yes

+

Phone number to be checked.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates the phone number format is valid, and value false indicates the opposite.

+
+ + +- Example + + ``` + var phonenumberfmt = new i18n.PhoneNumberFormat("CN"); + phonenumberfmt.isValidNumber("15812312312"); + ``` + + +### format8+ + +format\(number: string\): string + +Formats a phone number. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

number

+

string

+

Yes

+

Phone number to be formatted.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Formatted phone number.

+
+ + +- Example + + ``` + var phonenumberfmt = new i18n.PhoneNumberFormat("CN"); + phonenumberfmt.format("15812312312"); + ``` + + +## PhoneNumberFormatOptions8+ + +Defines the options for this **PhoneNumberFormat** object. + + + + + + + + + + + + + + + + +

Name

+

Type

+

Readable

+

Writable

+

Description

+

type

+

string

+

Yes

+

Yes

+

Format type of a phone number. The available options are as follows: E164, INTERNATIONAL, NATIONAL, and RFC3966.

+
+ +## UnitInfo8+ + +Defines the measurement unit information. + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Readable

+

Writable

+

Description

+

unit

+

string

+

Yes

+

Yes

+

Name of the measurement unit, for example, meter, inch, or cup.

+

measureSystem

+

string

+

Yes

+

Yes

+

Measurement system. The value can be SI, US, or UK.

+
+ +## Util8+ + +### unitConvert8+ + +unitConvert\(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string\): string + +Converts one measurement unit into another and formats the unit based on the specified locale and style. + +- Parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

fromUnit

+

UnitInfo

+

Yes

+

Measurement unit to be converted.

+

toUnit

+

UnitInfo

+

Yes

+

Measurement unit to be converted to.

+

value

+

number

+

Yes

+

Value of the measurement unit to be converted.

+

locale

+

string

+

Yes

+

Locale used for formatting, for example, zh-Hans-CN.

+

style

+

string

+

No

+

Style used for formatting. The value can be long, short, or medium.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Character string obtained after formatting based on the measurement unit specified by toUnit.

+
+ + +- Example + + ``` + I18n.Util.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long"); + ``` + + +## i18n.getInstance8+ + +getInstance\(locale?: string\): IndexUtil + +Creates an **IndexUtil** object. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

locale

+

string

+

No

+

A string containing locale information, including the language, optional script, and region.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

IndexUtil

+

IndexUtil object mapping to the specified locale.

+
+ + +- Example + + ``` + var indexUtil= i18n.getInstance("zh-CN"); + ``` + + +## IndexUtil8+ + +### getIndexList8+ + +getIndexList\(\): Array + +Obtains the index list for this **locale** object. + +- Return values + + + + + + + + + + +

Type

+

Description

+

Array<string>

+

Index list for this locale.

+
+ + +- Example + + ``` + var indexUtil = i18n.getInstance("zh-CN"); + var indexList = indexUtil.getIndexList(); + ``` + + +### addLocale8+ + +addLocale\(locale: string\) + +Adds the index of the new **locale** object to the index list. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

locale

+

string

+

Yes

+

A string containing locale information, including the language, optional script, and region.

+
+ + +- Example + + ``` + var indexUtil = i18n.getInstance("zh-CN"); + indexUtil.addLocale("en-US"); + ``` + + +### getIndex8+ + +getIndex\(text: string\): string + +Obtains the index of a **text** object. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

text

+

string

+

Yes

+

text object whose index is to be obtained.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Index of the text object.

+
+ + +- Example + + ``` + var indexUtil= i18n.getInstance("zh-CN"); + indexUtil.getIndex("hi"); // Return h. + ``` + + +## Character8+ + +### isDigit8+ + +isDigit\(char: string\): boolean + +Checks whether the input character string is comprised of digits. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

char

+

string

+

Yes

+

Input character.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates that the input character is a digit, and value false indicates the opposite.

+
+ + +- Example + + ``` + var isdigit = Character.isDigit("1"); // Return true. + ``` + + +### isSpaceChar8+ + +isSpaceChar\(char: string\): boolean + +Checks whether the input character is comprised of space. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

char

+

string

+

Yes

+

Input character.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates that the input character is a space, and value false indicates the opposite.

+
+ + +- Example + + ``` + var isspacechar = Character.isSpaceChar("a"); // Return false. + ``` + + +### isWhitespace8+ + +isWhitespace\(char: string\): boolean + +Checks whether the input character is comprised of white space. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

char

+

string

+

Yes

+

Input character.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates that the input character is a white space, and value false indicates the opposite.

+
+ + +- Example + + ``` + var iswhitespace = Character.isWhitespace("a"); // Return false. + ``` + + +### isRTL8+ + +isRTL\(char: string\): boolean + +Checks whether the input character string is of the right to left \(RTL\) language. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

char

+

string

+

Yes

+

Input character.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates that the input character is of the RTL language, and value false indicates the opposite.

+
+ + +- Example + + ``` + var isrtl = Character.isRTL("a"); // Return false. + ``` + + +### isIdeograph8+ + +isIdeograph\(char: string\): boolean + +Checks whether the input character string is comprised of ideographic characters. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

char

+

string

+

Yes

+

Input character.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates that the input character is an ideographic character, and value false indicates the opposite.

+
+ + +- Example + + ``` + var isideograph = Character.isIdeograph("a"); // Return false. + ``` + + +### isLetter8+ + +isLetter\(char: string\): boolean + +Checks whether the input character string is comprised of letters. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

char

+

string

+

Yes

+

Input character.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates that the input character is a letter, and value false indicates the opposite.

+
+ + +- Example + + ``` + var isletter = Character.isLetter("a"); // Return true. + ``` + + +### isLowerCase8+ + +isLowerCase\(char: string\): boolean + +Checks whether the input character is comprised of lowercase letters. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

char

+

string

+

Yes

+

Input character.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates that the input character is a lowercase letter, and value false indicates the opposite.

+
+ + +- Example + + ``` + var islowercase = Character.isLowerCase("a"); // Return true. + ``` + + +### isUpperCase8+ + +isUpperCase\(char: string\): boolean + +Checks whether the input character is comprised of uppercase letters. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

char

+

string

+

Yes

+

Input character.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates that the input character is an uppercase letter, and value false indicates the opposite.

+
+ + +- Example + + ``` + var isuppercase = Character.isUpperCase("a"); // Return false. + ``` + + +### getType8+ + +getType\(char: string\): string + +Obtains the type of the input character string. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

char

+

string

+

Yes

+

Input character.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Type of the input character.

+
+ + +- Example + + ``` + var type = Character.getType("a"); + ``` + + +## i18n.getLineInstance8+ + +getLineInstance\(locale: string\): BreakIterator + +Obtains a [BreakIterator](#section1312302611613) object for text segmentation. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

locale

+

string

+

Yes

+

Valid locale value, for example, zh-Hans-CN. The BreakIterator object segments text according to the rules of the specified locale.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

BreakIterator

+

Break iterator used for text segmentation.

+
+ +- Example + + ``` + i18n.getLineInstance("en"); + ``` + + +## BreakIterator8+ + +### setLineBreakText8+ + +setLineBreakText\(text: string\): void + +Sets the text to be processed by the [BreakIterator](#section1312302611613) object. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

text

+

string

+

Yes

+

Text to be processed by the BreakIterator object.

+
+ + +- Example + + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + ``` + + +### getLineBreakText8+ + +getLineBreakText\(\): string + +Obtains the text being processed by the [BreakIterator](#section1312302611613) object. + +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Text being processed by the BreakIterator object.

+
+ + +- Example + + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.getLineBreakText(); // Apple is my favorite fruit. + ``` + + +### current8+ + +current\(\): number + +Obtains the position of the [BreakIterator](#section1312302611613) object in the text being processed. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Position of the BreakIterator object in the text being processed.

+
+ + +- Example + + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + breakIter.current(); // 0 + ``` + + +### first8+ + +first\(\): number + +Puts the [BreakIterator](#section1312302611613) object to the first text boundary, which is always at the beginning of the processed text. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Offset to the first text boundary of the processed text.

+
+ + +- Example + + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + breakIter.first(); // 0 + ``` + + +### last8+ + +last\(\): number + +Puts the [BreakIterator](#section1312302611613) object to the last text boundary, which is always the next position after the end of the processed text. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Offset of the last text boundary of the processed text.

+
+ + +- Example + + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.last(); // 27 + ``` + + +### next8+ + +next\(index?: number\): number + +Moves the [BreakIterator](#section1312302611613) object backward by the specified number of text boundaries if the specified index is a positive number. If the index is a negative number, the [BreakIterator](#section1312302611613) object will be moved forward by the corresponding number of text boundaries. If no index is specified, the index will be treated as **1**. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

index

+

number

+

No

+

Number of text boundaries by which the BreakIterator object is moved. A positive value indicates that the text boundary is moved backward, and a negative value indicates the opposite. If no index is specified, the index will be treated as 1.

+
+ + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Position of the BreakIterator object in the text after it is moved by the specified number of text boundaries. The value -1 is returned if the position of the BreakIterator object is outside of the processed text after it is moved by the specified number of text boundaries.

+
+ + +- Example + + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.first(); // 0 + iterator.next(); // 6 + iterator.next(10); // -1 + ``` + + +### previous8+ + +previous\(\): number + +Moves the [BreakIterator](#section1312302611613) object to the previous text boundary. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Position of the BreakIterator object in the text after it is moved to the previous text boundary. The value -1 is returned if the position of the BreakIterator object is outside of the processed text after it is moved by the specified number of text boundaries.

+
+ + +- Example + + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.first(); // 0 + iterator.next(3); // 12 + iterator.previous(); // 9 + ``` + + +### following8+ + +following\(offset: number\): number + +Moves the [BreakIterator](#section1312302611613) object to the text boundary after the position specified by the offset. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

offset

+

number

+

Yes

+

Offset to the position before the text boundary to which the BreakIterator object is moved.

+
+ + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

The value -1 is returned if the text boundary to which the BreakIterator object is moved is outside of the processed text.

+
+ + +- Example + + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.following(0); // 6 + iterator.following(100); // -1 + iterator.current(); // 27 + ``` + + +### isBoundary8+ + +isBoundary\(offset: number\): boolean + +Checks whether the position specified by the offset is a text boundary. If **true** is returned, the [BreakIterator](#section1312302611613) object is moved to the position specified by the offset. If **false** is returned, the [BreakIterator](#section1312302611613) object is moved to the text boundary after the position specified by the offset, which is equivalent to calling [following\(offset\)](#section1743155314301). + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

offset

+

number

+

Yes

+

Position to check.

+
+ + +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

The value true indicates that the position specified by the offset is a text boundary, and value false indicates the opposite.

+
+ + +- Example + + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.isBoundary(0); // true; + iterator.isBoundary(5); // false; + ``` + diff --git a/en/application-dev/reference/apis/js-apis-intl.md b/en/application-dev/reference/apis/js-apis-intl.md index 7d182fd07eb55b848088f153625278a4e469e405..f18b8b8bf316bb4b680d03cef06dbcd19e14bbfe 100644 --- a/en/application-dev/reference/apis/js-apis-intl.md +++ b/en/application-dev/reference/apis/js-apis-intl.md @@ -1,10 +1,9 @@ -# Internationalization \(intl\) +# Internationalization (intl) >![](../../public_sys-resources/icon-note.gif) **NOTE:** >- The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. >- This module contains standard i18n APIs, which are defined in ECMA 402. - ## Modules to Import ``` @@ -17,7 +16,7 @@ None ## Locale -### Attributes +### Attributes - - - - - - - - -

Name

@@ -40,7 +39,7 @@ None

No

Language associated with the locale.

+

Language associated with the locale, for example, zh.

script

@@ -51,7 +50,7 @@ None

No

Script type of the language.

+

Script type of the language, for example, Hans.

region

@@ -62,7 +61,7 @@ None

No

Region associated with the locale.

+

Region associated with the locale, for example, CN.

baseName

@@ -73,7 +72,7 @@ None

No

Basic information about the locale.

+

Basic key information about the locale, which consists of the language, script, and region, for example, zh-Hans-CN.

caseFirst

@@ -84,7 +83,7 @@ None

No

Whether case is taken into account for the locale's collation rules.

+

Whether case is taken into account for the locale's collation rules. The value can be upper, lower, or false.

calendar

@@ -95,7 +94,7 @@ None

No

Calendar for the locale.

+

Calendar for the locale. The value can be buddhist, chinese, coptic, dangi, ethioaa, ethiopic, gregory, hebrew, indian, islamic, islamic-umalqura, islamic-tbla, islamic-civil, islamic-rgsa, iso8601, japanese, persian, roc, or islamicc.

collation

@@ -106,7 +105,7 @@ None

No

Collation rules for the locale.

+

Collation rules for the locale. The value can be any of the following: big5han, compat, dict, direct, ducet, eor, gb2312, phonebk, phonetic, pinyin, reformed, searchjl, stroke, trad, unihan, and zhuyin.

hourCycle

@@ -117,7 +116,7 @@ None

No

Time system for the locale.

+

Time system for the locale. The value can be h11, h12, h23, or h24.

numberingSystem

@@ -128,7 +127,7 @@ None

No

Numbering system for the locale.

+

Numbering system for the locale. The value can be any of the following: adlm, ahom, arab, arabext, bali, beng, bhks, brah, cakm, cham, deva, diak, fullwide, gong, gonm, gujr, guru, hanidec, hmng, hmnp, java, kali, khmr, knda, lana, lanatham, laoo, latn, lepc, limb, mathbold, mathdbl, mathmono, mathsanb, mathsans, mlym, modi, mong, mroo, mtei, mymr, mymrshan, mymrtlng, newa, nkoo, olck, orya, osma, rohg, saur, segment, shrd, sind, sinh, sora, sund, takr, talu, tamldec, telu, thai, tibt, tirh, vaii, wara, and wcho.

numeric

@@ -145,9 +144,9 @@ None
-### constructor +### constructor -constructor\(locale: string, options?:options\) +constructor\(locale: string, options?: options\) Creates a **Locale** object. @@ -173,15 +172,6 @@ Creates a **Locale** object.

A string containing locale information, including the language, optional script, and locale.

options

-

options

-

No

-

Options for creating the Locale object.

-
@@ -193,7 +183,7 @@ Creates a **Locale** object. ``` -### toString +### toString toString\(\): string @@ -225,7 +215,7 @@ Converts locale information to a string. ``` -### maximize +### maximize maximize\(\): Locale @@ -240,7 +230,7 @@ Maximizes information of the **Locale** object. If the script and locale infor -

Locale

+

Locale

Locale object with the maximized information.

@@ -257,7 +247,7 @@ Maximizes information of the **Locale** object. If the script and locale infor ``` -### minimize +### minimize minimize\(\): Locale @@ -272,7 +262,7 @@ Minimizes information of the **Locale** object. If the script and locale infor -

Locale

+

Locale

Locale object with the minimized information.

@@ -291,9 +281,9 @@ Minimizes information of the **Locale** object. If the script and locale infor ## DateTimeFormat -### constructor +### constructor -constructor\(locale: string, options?:DateTimeOptions\) +constructor\(locale: string, options?: DateTimeOptions\) Creates a **DateTimeOptions** object for the specified locale. @@ -321,11 +311,11 @@ Creates a **DateTimeOptions** object for the specified locale.

options

-

DateTimeOptions

+

DateTimeOptions

No

-

Options of the DateTimeFormat object.

+

Options for creating a DateTimeFormat object.

@@ -339,9 +329,9 @@ Creates a **DateTimeOptions** object for the specified locale. ``` -### constructor +### constructor -constructor\(locales: Array, options?:DateTimeOptions\) +constructor\(locales: Array, options?: DateTimeOptions\) Creates a **DateTimeOptions** object for the specified array of locales. @@ -369,11 +359,11 @@ Creates a **DateTimeOptions** object for the specified array of locales.

options

-

DateTimeOptions

+

DateTimeOptions

No

-

Options of the DateTimeFormat object.

+

Options for creating a DateTimeFormat object.

@@ -387,9 +377,9 @@ Creates a **DateTimeOptions** object for the specified array of locales. ``` -### format +### format -format\(date: Date\): string; +format\(date: Date\): string Formats the specified date and time. @@ -445,9 +435,9 @@ Formats the specified date and time. ``` -### formatRange +### formatRange -formatRange\(fromDate: Date, toDate: Date\): string; +formatRange\(fromDate: Date, toDate: Date\): string Formats the specified date range. @@ -513,11 +503,11 @@ Formats the specified date range. ``` -### resolvedOptions +### resolvedOptions resolvedOptions\(\): DateTimeOptions -Obtains the options of the **DateTimeFormat** object. +Obtains the formatting options for **DateTimeFormat** object. - Return values @@ -528,9 +518,9 @@ Obtains the options of the **DateTimeFormat** object. -

DateTimeOptions

+

DateTimeOptions

-

Options of the DateTimeFormat object.

+

Formatting options for DateTimeFormat objects.

@@ -545,193 +535,7 @@ Obtains the options of the **DateTimeFormat** object. ``` -## NumberFormat - -### constructor - -constructor\(locale: string, options?:NumberOptions\) - -Creates a **NumberFormat** object for the specified locale. - -Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string

-

Yes

-

A string containing locale information, including the language, optional script, and locale.

-

options

-

NumberOptions

-

No

-

Options of the NumberFormat object.

-
- -- Example - - ``` - var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"}); - ``` - - -### constructor - -constructor\(locales: Array, options?:NumberOptions\) - -Creates a **NumberFormat** object for the specified array of locales. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locales

-

Array<string>

-

Yes

-

An array of strings containing locale information.

-

options

-

NumberOptions

-

No

-

Options of the NumberFormat object.

-
- - -- Example - - ``` - var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); - ``` - - -### format - -format\(number: number\): string; - -Formats a number. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

number

-

number

-

Yes

-

Number to be formatted.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Formatted number.

-
- - -- Example - - ``` - var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); - numfmt.format(1223); - ``` - - -### resolvedOptions - -resolvedOptions\(\): NumberOptions - -Obtains the options of the **NumberFormat** object. - -- Return values - - - - - - - - - - -

Type

-

Description

-

NumberOptions

-

Options of the NumberFormat object.

-
- - -- Example - - ``` - var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); - numfmt.resolvedOptions(); - ``` - - -## DateTimeOptions +## DateTimeOptions Provides the options for the **DateTimeFormat** object. @@ -756,7 +560,7 @@ Provides the options for the **DateTimeFormat** object.

No

-

Locale information.

+

Locale, for example, zh-Hans-CN.

dateStyle

@@ -789,7 +593,7 @@ Provides the options for the **DateTimeFormat** object.

Yes

-

Hour cycle. The value can be h11, h12, h23, or h24.

+

Time system for the locale. The value can be h11, h12, h23, or h24.

timeZone

@@ -811,7 +615,7 @@ Provides the options for the **DateTimeFormat** object.

Yes

-

Numbering system.

+

Numbering system for the locale. The value can be any of the following: adlm, ahom, arab, arabext, bali, beng, bhks, brah, cakm, cham, deva, diak, fullwide, gong, gonm, gujr, guru, hanidec, hmng, hmnp, java, kali, khmr, knda, lana, lanatham, laoo, latn, lepc, limb, mathbold, mathdbl, mathmono, mathsanb, mathsans, mlym, modi, mong, mroo, mtei, mymr, mymrshan, mymrtlng, newa, nkoo, olck, orya, osma, rohg, saur, segment, shrd, sind, sinh, sora, sund, takr, talu, tamldec, telu, thai, tibt, tirh, vaii, wara, and wcho.

hour12

@@ -960,94 +764,291 @@ Provides the options for the **DateTimeFormat** object. -## NumberOptions +## NumberFormat -Provides the device capability. +### constructor - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + +

Name

-

Parameter Type

-

Readable

-

Writable

-

Description

-

locale

-

string

-

Yes

-

No

-

Locale information.

-

currency

-

string

-

Yes

-

Yes

-

Currency for the specified locale.

-

currencySign

-

string

-

Yes

-

Yes

-

Currency symbol.

-

currencyDisplay

-

string

-

Yes

-

Yes

-

Currency display mode. The value can be symbol, narrowSymbol, code, or name.

-

unit

-

string

-

Yes

-

Yes

-

Currency unit.

-

unitDisplay

-

string

-

Yes

-

Yes

-

Currency unit display format. The value can be long, short, or medium.

-

signDisplay

-

string

-

Yes

+constructor\(locale: string, options?: NumberOptions\) + +Creates a **NumberFormat** object for the specified locale. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

locale

+

string

+

Yes

+

A string containing locale information, including the language, optional script, and locale.

+

options

+

NumberOptions

+

No

+

Options for creating a NumberFormat object.

+
+ +- Example + + ``` + var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"}); + ``` + + +### constructor + +constructor\(locales: Array, options?: NumberOptions\) + +Creates a **NumberFormat** object for the specified array of locales. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

locales

+

Array<string>

+

Yes

+

An array of strings containing locale information.

+

options

+

NumberOptions

+

No

+

Options for creating a NumberFormat object.

+
+ + +- Example + + ``` + var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); + ``` + + +### format + +format\(number: number\): string; + +Formats a number. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

number

+

number

+

Yes

+

Number to be formatted.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Formatted number.

+
+ + +- Example + + ``` + var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); + numfmt.format(1223); + ``` + + +### resolvedOptions + +resolvedOptions\(\): NumberOptions + +Obtains the options of the **NumberFormat** object. + +- Return values + + + + + + + + + + +

Type

+

Description

+

NumberOptions

+

Options of the NumberFormat object.

+
+ + +- Example + + ``` + var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); + numfmt.resolvedOptions(); + ``` + + +## NumberOptions + +Provides the device capability. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1106,7 +1107,7 @@ Provides the device capability. - - - - - - -

Name

+

Parameter Type

+

Readable

+

Writable

+

Description

+

locale

+

string

+

Yes

+

No

+

Locale, for example, zh-Hans-CN.

+

currency

+

string

+

Yes

+

Yes

+

Currency unit, for example, EUR, CNY, or USD.

+

currencySign

+

string

+

Yes

+

Yes

+

Currency unit symbol. The value can be symbol, narrowSymbol, code, or name.

+

currencyDisplay

+

string

+

Yes

+

Yes

+

Currency display mode. The value can be symbol, narrowSymbol, code, or name.

+

unit

+

string

+

Yes

+

Yes

+

Unit name, for example, meter, inch, or hectare.

+

unitDisplay

+

string

+

Yes

+

Yes

+

Unit display format. The value can be long, short, or medium.

+

unitUsage

+

string

+

Yes

+

Yes

+

Unit use case. The value can be any of the following: default, area-land-agricult, area-land-commercl, area-land-residntl, length-person, length-person-small, length-rainfall, length-road, length-road-small, length-snowfall, length-vehicle, length-visiblty, length-visiblty-small, length-person-informal, length-person-small-informal, length-road-informal, speed-road-travel, speed-wind, temperature-person, temperature-weather, and volume-vehicle-fuel.

+

signDisplay

+

string

+

Yes

Yes

Yes

Numbering system.

+

Numbering system for the locale. The value can be any of the following: adlm, ahom, arab, arabext, bali, beng, bhks, brah, cakm, cham, deva, diak, fullwide, gong, gonm, gujr, guru, hanidec, hmng, hmnp, java, kali, khmr, knda, lana, lanatham, laoo, latn, lepc, limb, mathbold, mathdbl, mathmono, mathsanb, mathsans, mlym, modi, mong, mroo, mtei, mymr, mymrshan, mymrtlng, newa, nkoo, olck, orya, osma, rohg, saur, segment, shrd, sind, sinh, sora, sund, takr, talu, tamldec, telu, thai, tibt, tirh, vaii, wara, and wcho.

useGrouping

@@ -1117,7 +1118,7 @@ Provides the device capability.

Yes

Whether to enable grouping for display.

+

Whether to use grouping for display.

miniumumIntegerDigits

@@ -1128,7 +1129,7 @@ Provides the device capability.

Yes

Minimum number of integer digits.

+

Minimum number of digits allowed in the integer part of a number. The value ranges from 1 to 21.

miniumumFractionDigits

@@ -1139,7 +1140,7 @@ Provides the device capability.

Yes

Minimum number of fraction digits.

+

Minimum number of digits in the fraction part of a number. The value ranges from 0 to 20.

maxiumumFractionDigits

@@ -1150,7 +1151,7 @@ Provides the device capability.

Yes

Maximum number of fraction digits.

+

Maximum number of digits in the fraction part of a number. The value ranges from 1 to 21.

miniumumSignificantDigits

@@ -1161,7 +1162,7 @@ Provides the device capability.

Yes

Minimum number of significant digits.

+

Minimum number of the least significant digits. The value ranges from 1 to 21.

maxiumumSignificantDigits

@@ -1172,9 +1173,824 @@ Provides the device capability.

Yes

Maximum number of significant digits.

+

Maximum number of the least significant digits. The value ranges from 1 to 21.

+## Collator8+ + +### constructor8+ + +constructor\(\) + +Creates a **Collator** object. + +- Example + + ``` + var collator = new Intl.Collator(); + ``` + + +### constructor8+ + +constructor\(locale: string | Array, options?: CollatorOptions\) + +Creates a **Collator** object based on the specified locale and options. + +Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

locale

+

string|Array<string>

+

Yes

+

A string containing locale information, including the language, optional script, and locale.

+

options

+

CollatorOptions

+

No

+

Options for creating a Collator object.

+
+ +- Example + + ``` + var collator = new Intl.Collator("zh-CN", {"localeMatcher": "lookup", "usage": "sort"}); + ``` + + +### compare8+ + +compare\(first: string, second: string\): number + +Compares two strings based on the sorting policy of the **Collator**. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

first

+

string

+

Yes

+

First string to compare.

+

second

+

string

+

Yes

+

Second string to compare.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Comparison result. If the value is a negative number, the first string is before the second string. If the value of number is 0, the first string is equal to the second string. If the value of number is a positive number, the first string is after the second string.

+
+ + +- Example + + ``` + var collator = new intl.Collator("zh-Hans"); + collator.compare("first", "second"); + ``` + + +### resolvedOptions8+ + +resolvedOptions\(\): CollatorOptions + +Returns properties reflecting the locale and collation options of a **Collator** object. + +- Return values + + + + + + + + + + +

Type

+

Description

+

CollatorOptions

+

Properties of the Collator object.

+
+ + +- Example + + ``` + var collator = new intl.Collator("zh-Hans"); + var options = collator.resolvedOptions(); + ``` + + +## CollatorOptions8+ + +Represents the properties of a **Collator** object. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Parameter Type

+

Readable

+

Writable

+

Description

+

localeMatcher

+

string

+

Yes

+

Yes

+

Locale matching algorithm. The value can be lookup or best fit.

+

usage

+

string

+

Yes

+

Yes

+

Whether the comparison is for sorting or for searching. The value can be sort or search.

+

sensitivity

+

string

+

Yes

+

Yes

+

Differences in the strings that lead to non-zero return values. The value can be base, accent, case, or variant.

+

ignorePunctuation

+

boolean

+

Yes

+

Yes

+

Whether punctuation is ignored. The value can be true or false.

+

collation

+

string

+

Yes

+

Yes

+

Sorting policy. The value can be any of the following: big5han, compat, dict, direct, ducet, eor, gb2312, phonebk, phonetic, pinyin, reformed, searchjl, stroke, trad, unihan, and zhuyin.

+

numeric

+

boolean

+

Yes

+

Yes

+

Whether numeric collation is used. The value can be true or false.

+

caseFirst

+

string

+

Yes

+

Yes

+

Whether upper case or lower case is sorted first. The value can be upper, lower, or false.

+
+ +## PluralRules8+ + +### constructor8+ + +constructor\(\) + +Create a **PluralRules** object. + +- Example + + ``` + var pluralRules = new Intl.PluralRules(); + ``` + + +### constructor8+ + +constructor\(locale: string | Array, options?: PluralRulesOptions\) + +Creates a **PluralRules** object based on the specified locale and options. + +Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

locale

+

string|Array<string>

+

Yes

+

A string containing locale information, including the language, optional script, and locale.

+

options

+

PluralRulesOptions

+

No

+

Options for creating a PluralRules object.

+
+ +- Example + + ``` + var pluralRules= new Intl.PluraRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"}); + ``` + + +### select8+ + +select\(n: number\): string + +Obtains a string that represents the singular-plural type of the specified number. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

n

+

number

+

Yes

+

Number for which the singular-plural type is to be obtained.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Singular-plural type. The options are as follows: zero, one, two, few, many, and others.

+
+ + +- Example + + ``` + var pluralRules = new intl.PluralRules("zh-Hans"); + pluralRules.select(1); + ``` + + +## PluralRulesOptions8+ + +Represents the properties of a **PluralRules** object. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Parameter Type

+

Readable

+

Writable

+

Description

+

localeMatcher

+

string

+

Yes

+

Yes

+

Locale matching algorithm. The value can be lookup or best fit.

+

type

+

string

+

Yes

+

Yes

+

Sorting type. The value can be cardinal or ordinal.

+

minimumIntegerDigits

+

number

+

Yes

+

Yes

+

Minimum number of digits allowed in the integer part of a number. The value ranges from 1 to 21.

+

minimumFractionDigits

+

number

+

Yes

+

Yes

+

Minimum number of digits in the fraction part of a number. The value ranges from 0 to 20.

+

maximumFractionDigits

+

number

+

Yes

+

Yes

+

Maximum number of digits in the fraction part of a number. The value ranges from 1 to 21.

+

minimumSignificantDigits

+

number

+

Yes

+

Yes

+

Minimum number of the least significant digits. The value ranges from 1 to 21.

+

maximumSignificantDigits

+

number

+

Yes

+

Yes

+

Maximum number of the least significant digits. The value ranges from 1 to 21.

+
+ +## RelativeTimeFormat8+ + +### constructor8+ + +constructor\(\) + +Creates a **RelativeTimeFormat** object. + +- Example + + ``` + var relativetimefmt = new Intl.RelativeTimeFormat(); + ``` + + +### constructor8+ + +constructor\(locale: string | Array, options?: RelativeTimeFormatInputOptions\) + +Creates a **RelativeTimeFormat** object based on the specified locale and options. + +Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

locale

+

string|Array<string>

+

Yes

+

A string containing locale information, including the language, optional script, and locale.

+

options

+

RelativeTimeFormatInputOptions

+

No

+

Options for creating a RelativeTimeFormat object.

+
+ +- Example + + ``` + var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"}); + ``` + + +### format8+ + +format\(value: numeric, unit: string\): string + +Formats the value and unit based on the specified locale and formatting options. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

value

+

numeric

+

Yes

+

Value to format.

+

unit

+

string

+

Yes

+

Unit to format. The value can be year, quarter, month, week, day, hour, minute, or second.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Relative time after formatting.

+
+ + +- Example + + ``` + var relativetimefmt = new Intl.RelativeTimeFormat("zh-CN"); + relativetimefmt.format(3, "quarter") + ``` + + +### formatToParts8+ + +formatToParts\(value: numeric, unit: string\): Array + +Returns an array of **RelativeTimeFormat** objects in parts for locale-aware formatting. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

value

+

numeric

+

Yes

+

Value to format.

+

unit

+

string

+

Yes

+

Unit to format. The value can be year, quarter, month, week, day, hour, minute, or second.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Array<Object>

+

An array of RelativeTimeFormat objects in parts.

+
+ + +- Example + + ``` + var relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"}); + var parts = relativetimefmt.format(10, "seconds"); + ``` + + +### resolvedOptions8+ + +resolvedOptions\(\): RelativeTimeFormatResolvedOptions + +Obtains the formatting options for **RelativeTimeFormat** objects. + +- Return values + + + + + + + + + + +

Type

+

Description

+

RelativeTimeFormatResolvedOptions

+

Formatting options for RelativeTimeFormat objects.

+
+ + +- Example + + ``` + var relativetimefmt= new Intl.RelativeTimeFormat("en-GB"); + relativetimefmt.resolvedOptions(); + ``` + + +## RelativeTimeFormatInputOptions8+ + +Represents the properties of a **RelativeTimeFormat** object. + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Parameter Type

+

Readable

+

Writable

+

Description

+

localeMatcher

+

string

+

Yes

+

Yes

+

Locale matching algorithm. The value can be lookup or best fit.

+

numeric

+

string

+

Yes

+

Yes

+

Format of the output message. The value can be always or auto.

+

style

+

string

+

Yes

+

Yes

+

Length of the internationalized message. The value can be long, short, or narrow.

+
+ +## RelativeTimeFormatResolvedOptions8+ + +Represents the properties of a **RelativeTimeFormat** object. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Parameter Type

+

Readable

+

Writable

+

Description

+

locale

+

string

+

Yes

+

Yes

+

A string containing locale information, including the language, optional script, and locale.

+

numeric

+

string

+

Yes

+

Yes

+

Format of the output message. The value can be always or auto.

+

style

+

string

+

Yes

+

Yes

+

Length of the internationalized message. The value can be long, short, or narrow.

+

numberingSystem

+

string

+

Yes

+

Yes

+

Numbering system.

+
diff --git a/en/application-dev/reference/apis/js-apis-notification.md b/en/application-dev/reference/apis/js-apis-notification.md index 1e4bbafcd5e8928ab009a869bddfbb2debb8f1c4..1105fa9acb63775bd860a5cb611b65ebec77a255 100644 --- a/en/application-dev/reference/apis/js-apis-notification.md +++ b/en/application-dev/reference/apis/js-apis-notification.md @@ -1,88 +1,5 @@ # Notification Module -## Applicable Devices - -| API | Phone | Tablet | Smart TV | Wearable | -| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -| Notification.publish(request: NotificationRequest, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.publish(request: NotificationRequest) | Yes | Yes | Yes | Yes | -| Notification.cancel(id: number, label: string, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.cancel(id:number, label?:string) | Yes | Yes | Yes | Yes | -| Notification.cancel(id: number, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.cancelAll(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.cancelAll() | Yes | Yes | Yes | Yes | -| Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.addSlot(slot: NotificationSlot) | Yes | Yes | Yes | Yes | -| Notification.addSlot(type: SlotType, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.addSlot(type: SlotType) | Yes | Yes | Yes | Yes | -| Notification.addSlots(slots: Array\, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.addSlots(slots: Array\) | Yes | Yes | Yes | Yes | -| Notification.getSlot(slotType: SlotType, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.getSlot(slotType: SlotType) | Yes | Yes | Yes | Yes | -| Notification.getSlots(callback: AsyncCallback>) | Yes | Yes | Yes | Yes | -| Notification.getSlots() | Yes | Yes | Yes | Yes | -| Notification.removeSlot(slotType: SlotType, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.removeSlot(slotType: SlotType) | Yes | Yes | Yes | Yes | -| Notification.removeAllSlots(callback: AsyncCallback\): void | Yes | Yes | Yes | Yes | -| Notification.removeAllSlots(): Promise\ | Yes | Yes | Yes | Yes | -| Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo) | Yes | Yes | Yes | Yes | -| Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.unsubscribe(subscriber: NotificationSubscriber) | Yes | Yes | Yes | Yes | -| Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.enableNotification(bundle: BundleOption, enable: boolean) | Yes | Yes | Yes | Yes | -| Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.isNotificationEnabled(bundle: BundleOption) | Yes | Yes | Yes | Yes | -| Notification.isNotificationEnabled(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.isNotificationEnabled() | Yes | Yes | Yes | Yes | -| Notification.displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.displayBadge(bundle: BundleOption, enable: boolean) | Yes | Yes | Yes | Yes | -| Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.isBadgeDisplayed(bundle: BundleOption) | Yes | Yes | Yes | Yes | -| Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot) | Yes | Yes | Yes | Yes | -| Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>) | Yes | Yes | Yes | Yes | -| Notification.getSlotsByBundle(bundle: BundleOption) | Yes | Yes | Yes | Yes | -| Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.getSlotNumByBundle(bundle: BundleOption) | Yes | Yes | Yes | Yes | -| Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.remove(bundle: BundleOption, notificationKey: NotificationKey) | Yes | Yes | Yes | Yes | -| Notification.remove(hashCode: string, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.remove(hashCode: string) | Yes | Yes | Yes | Yes | -| Notification.removeAll(bundle: BundleOption, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.removeAll(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.removeAll(bundle?: BundleOption) | Yes | Yes | Yes | Yes | -| Notification.getAllActiveNotifications(callback: AsyncCallback>) | Yes | Yes | Yes | Yes | -| Notification.getAllActiveNotifications() | Yes | Yes | Yes | Yes | -| Notification.getActiveNotificationCount(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.getActiveNotificationCount() | Yes | Yes | Yes | Yes | -| Notification.getActiveNotifications(callback: AsyncCallback>) | Yes | Yes | Yes | Yes | -| Notification.getActiveNotifications() | Yes | Yes | Yes | Yes | -| Notification.cancelGroup(groupName: string, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.cancelGroup(groupName: string) | Yes | Yes | Yes | Yes | -| Notification.removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.removeGroupByBundle(bundle: BundleOption, groupName: string) | Yes | Yes | Yes | Yes | -| Notification.setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.setDoNotDisturbDate(date: DoNotDisturbDate) | Yes | Yes | Yes | Yes | -| Notification.getDoNotDisturbDate(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.getDoNotDisturbDate() | Yes | Yes | Yes | Yes | -| Notification.supportDoNotDisturbMode(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| Notification.supportDoNotDisturbMode() | Yes | Yes | Yes | Yes | -| WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| WantAgent.getWantAgent(info: WantAgentInfo): Promise\ | Yes | Yes | Yes | Yes | -| WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| WantAgent.getBundleName(agent: WantAgent): Promise\ | Yes | Yes | Yes | Yes | -| WantAgent.getUid(agent: WantAgent, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| WantAgent.getUid(agent: WantAgent): Promise\ | Yes | Yes | Yes | Yes | -| WantAgent.getWant(agent: WantAgent, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| WantAgent.getWant(agent: WantAgent): Promise\ | Yes | Yes | Yes | Yes | -| WantAgent.cancel(agent: WantAgent, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| WantAgent.cancel(agent: WantAgent): Promise\ | Yes | Yes | Yes | Yes | -| WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\) | Yes | Yes | Yes | Yes | -| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | -| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise\ | Yes | Yes | Yes | Yes | - ## Required Permissions diff --git a/en/application-dev/reference/apis/js-apis-particleAbility.md b/en/application-dev/reference/apis/js-apis-particleAbility.md index 128d8282ba250fc4e887bd178e90308ee015b114..9d4a14ccbeaf81d49fc1de51156613cde3812bda 100644 --- a/en/application-dev/reference/apis/js-apis-particleAbility.md +++ b/en/application-dev/reference/apis/js-apis-particleAbility.md @@ -1,18 +1,5 @@ # ParticleAbility Module -## Applicable Devices - -| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| SmartVision Device| -| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | ------------ | -| particleAbility.startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\: void | Yes| Yes| Yes| Yes| No| No| -| particleAbility.startAbility(parameter: StartAbilityParameter): Promise\ | Yes| Yes| Yes| Yes| No| No| -| particleAbility.terminateSelf(callback: AsyncCallback\): void | Yes| Yes| Yes| Yes| No| No| -| particleAbility.terminateSelf(): Promise\ | Yes| Yes| Yes| Yes| No| No| -| particleAbility.acquireDataAbilityHelper(uri: string): DataAbilityHelper | Yes| Yes| Yes| Yes| No| No| -| particleAbility.connectAbility(request: Want, options:ConnectOptions): number | Yes| Yes| Yes| Yes| No| No| -| particleAbility.disconnectAbility(connection: number, callback:AsyncCallback\): void | Yes| Yes| Yes| Yes| No| No| -| particleAbility.disconnectAbility(connection: number): Promise\ | Yes| Yes| Yes| Yes| No| No| - ## Constraints The ParticleAbility module is used to perform operations on abilities of the Data and Service types. diff --git a/en/application-dev/reference/apis/js-apis-process.md b/en/application-dev/reference/apis/js-apis-process.md index 34fc52c05097d07cd12caffa8f2952492cfc95b7..3d828c219c168585c2de6fdccbb29dc230073ff9 100644 --- a/en/application-dev/reference/apis/js-apis-process.md +++ b/en/application-dev/reference/apis/js-apis-process.md @@ -1,4 +1,4 @@ -# Obtaining Process Information +# Obtaining Process Information >![](../../public_sys-resources/icon-note.gif) **NOTE:** >The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -80,7 +80,7 @@ None

No

An array with supplementary group IDs.

+

Array with supplementary group IDs.

pid

@@ -105,12 +105,23 @@ None

Parent process ID (PPID) of a process.

tid8+

+

number

+

Yes

+

No

+

Thread ID (TID) of a process.

+
## ChildProcess -Allows a process to obtain the standard input and output of its child processes, send signals, and close its child processes. +Provides methods for a process to obtain the standard input and output of its child processes, send signals, and close its child processes. ### Attributes @@ -200,7 +211,6 @@ Waits until the child process ends. This method uses a promise to return the exi - Example ``` - import process from '@ohos.process'; var child = process.runCmd('ls'); var result = child.wait(); result.then(val=>{ @@ -235,7 +245,6 @@ Obtains the standard output of the child process. - Example ``` - import process from '@ohos.process'; var child = process.runCmd('ls'); var result = child.wait(); child.getOutput.then(val=>{ @@ -270,7 +279,6 @@ Obtains the standard error output of the child process. - Example ``` - import process from '@ohos.process'; var child = process.runCmd('madir test.text'); var result = child.wait(); child.getErrorOutput.then(val=>{ @@ -288,7 +296,6 @@ Closes the child process in running. - Example ``` - import process from '@ohos.process'; var child = process.runCmd('sleep 5; ls'); child.close(); ``` @@ -328,12 +335,443 @@ Sends a signal to the specified child process to terminate it. - Example ``` - import process from '@ohos.process'; var child = process.runCmd('sleep 5; ls'); child.kill(9); ``` +## process.isIsolatedProcess8+ + +isIsolatedProcess\(\): boolean + +Checks whether the process is isolated. + +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

Returns true if the process is isolated; returns false otherwise.

+
+ + +- Example + + ``` + var result = process.isIsolatedProcess(); + ``` + + +## process.isAppUid8+ + +isAppUid\(v:number\): boolean + +Checks whether a UID belongs to this app. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

v

+

number

+

Yes

+

UID.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

Returns true if the UID is the app's UID; returns false otherwise.

+
+ + +- Example + + ``` + var result = process.isAppUid(688); + ``` + + +## process.is64Bit8+ + +is64Bit\(\): boolean + +Checks whether the operating environment is of 64-bit. + +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

Returns true if the operating environment is of 64-bit; returns false otherwise.

+
+ +- Example + + ``` + var ressult = process.is64Bit(); + ``` + + +## process.getUidForName8+ + +getUidForName\(v:string\): number + +Obtains the process UID based on the process name. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

v

+

string

+

Yes

+

Process name.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Process UID.

+
+ +- Example + + ``` + var pres = process.getUidForName("tool") + ``` + + +## process.getThreadPriority8+ + +getThreadPriority\(v:number\): number + +Obtains the thread priority based on the specified TID. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

v

+

number

+

Yes

+

TID.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Priority of the thread.

+
+ +- Example + + ``` + var tid = process.tid; + var pres = process.getThreadPriority(tid); + ``` + + +## process.getStartRealtime8+ + +getStartRealtime\(\) :number + +Obtains the duration, in milliseconds, from the time the system starts to the time the process starts. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Time duration obtained.

+
+ + +- Example + + ``` + var realtime = process.getStartRealtime(); + ``` + + +## process.getAvailableCores8+ + +getAvailableCores\(\) :number\[\] + +Obtains the number of CPU cores available for the current process on a multi-core device. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number[]

+

Number of cores available for the process.

+
+ + +- Example + + ``` + var result = getAvailableCores(); + ``` + + +## process.getPastCputime8+ + +getPastCputime\(\) :number + +Obtains the CPU time \(in milliseconds\) from the time the process starts to the current time. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

CPU time obtained.

+
+ + +- Example + + ``` + var result = process.getPastCputime() ; + ``` + + +## process.getSystemConfig8+ + +getSystemConfig\(name:number\): number + +Obtains the system configuration. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

name

+

number

+

Yes

+

System configuration parameter name.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

System configuration obtained.

+
+ +- Example + + ``` + var _SC_ARG_MAX = 0 + var pres = process.getSystemConfig(_SC_ARG_MAX) + ``` + + +## process.getEnvironmentVar8+ + +getEnvironmentVar\(name:string\): string + +Obtains the value of an environment variable. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

name

+

string

+

Yes

+

Environment variable name.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Value of the environment variable.

+
+ +- Example + + ``` + var pres = process.getEnvironmentVar("PATH") + ``` + + ## process.runCmd runCmd\(command: string, options?: \{ timeout : number, killSignal : number | string, maxBuffer : number \}\) : ChildProcess @@ -437,12 +875,11 @@ Forks a new process to run a shell command and returns the **ChildProcess** ob - Example ``` - import process from '@ohos.process'; var child = process.runCmd('ls', { maxBuffer : 2 }); var result = child.wait(); child.getOutput.then(val=>{ console.log("child.getOutput = " + val); - } + }) ``` @@ -455,7 +892,6 @@ Aborts a process and generates a core file. This method will cause a process to - Example ``` - import process from '@ohos.process'; process.abort(); ``` @@ -520,7 +956,6 @@ Stores the events triggered by the user. - Example ``` - import process from '@ohos.process'; process.on("data", (e)=>{ console.log("data callback"); }) @@ -569,7 +1004,7 @@ Deletes the event stored by the user.

boolean

-

Whether the event is deleted.

+

Returns true if the event is deleted; returns false otherwise.

@@ -578,7 +1013,6 @@ Deletes the event stored by the user. - Example ``` - import process from '@ohos.process'; process.on("data", (e)=>{ console.log("data callback"); }) @@ -590,7 +1024,7 @@ Deletes the event stored by the user. exit\(code: number\): void -Terminates a process. +Terminates this process. - Parameters @@ -620,7 +1054,6 @@ Terminates a process. - Example ``` - import process from '@ohos.process'; process.exit(0); ``` @@ -629,12 +1062,11 @@ Terminates a process. cwd\(\): string -Obtains the working directory of the process. +Obtains the working directory of this process. - Example ``` - import process from '@ohos.process'; var path = process.cwd(); ``` @@ -643,7 +1075,7 @@ Obtains the working directory of the process. chdir\(dir: string\): void -Changes the working directory of the process. +Changes the working directory of this process. - Parameters @@ -673,7 +1105,6 @@ Changes the working directory of the process. - Example ``` - import process from '@ohos.process'; process.chdir('/system'); ``` @@ -682,7 +1113,7 @@ Changes the working directory of the process. uptime\(\): number -Obtains the running time of the process. +Obtains the running time of this process. - Return values @@ -704,7 +1135,6 @@ Obtains the running time of the process. - Example ``` - import process from '@ohos.process'; var time = process.uptime(); ``` @@ -760,7 +1190,7 @@ Sends a signal to the specified process to terminate it.

boolean

-

Whether the signal is sent successfully.

+

Returns true if the signal is sent successfully; returns false otherwise.

@@ -769,7 +1199,6 @@ Sends a signal to the specified process to terminate it. - Example ``` - import process from '@ohos.process' var pres = process.pid var result = that.kill(pres, 28) ``` diff --git a/en/application-dev/reference/apis/js-apis-reminderAgent.md b/en/application-dev/reference/apis/js-apis-reminderAgent.md new file mode 100644 index 0000000000000000000000000000000000000000..9522366139b7fd8e2e73a4630eefeb279e063315 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-reminderAgent.md @@ -0,0 +1,1199 @@ +# Reminder Agent + +>**NOTE:** +>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. + +## Applicable Devices + + + + + + + + + + + + + + +

Phone

+

Tablet

+

Smart TV

+

Wearable

+

Yes

+

Yes

+

Yes

+

Yes

+
+ +## Modules to Import + +``` +import reminderAgent from '@ohos.reminderAgent'; +``` + +## Required Permissions + +ohos.permission.PUBLISH\_AGENT\_REMINDER + +## reminderAgent.publishReminder + +publishReminder\(reminderReq: ReminderRequest, callback: AsyncCallback\): void + +Publishes an agent-powered reminder. This method uses an asynchronous callback to return the published reminder's ID. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

reminderReq

+

ReminderRequest

+

Yes

+

Reminder to be published.

+

callback

+

AsyncCallback<number>

+

Yes

+

Asynchronous callback used to return the result.

+
+ +- Example + + ``` + export default { + data: { + timer: { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: 3 + } + }, + startTimer() { + reminderAgent.publishReminder(timer, (err, reminderId) => { + console.log("reminderId = " + reminderId); + }); + } + } + ``` + + +## reminderAgent.publishReminder + +publishReminder\(reminderReq: ReminderRequest\): Promise + +Publishes an agent-powered reminder. This method uses a promise callback to return the published reminder's ID. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

reminderReq

+

ReminderRequest

+

Yes

+

Reminder to be published.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<number>

+

Promise used to return the result.

+
+ +- Example + + ``` + export default { + data: { + timer: { + reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, + triggerTimeInSeconds: 3 + } + }, + startTimer() { + reminderAgent.publishReminder(this.timer).then((reminderId) => { + console.log("reminderId = " + reminderId); + }); + } + } + ``` + + +## reminderAgent.cancelReminder + +cancelReminder\(reminderId: number, callback: AsyncCallback\): void + +Cancels the reminder with the specified ID. This method uses an asynchronous callback to return the cancellation result. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

reminderId

+

number

+

Yes

+

ID of the reminder to cancel.

+

callback

+

AsyncCallback<void>

+

Yes

+

Asynchronous callback used to return the result.

+
+ +- Example + +``` +export default { + cancel() { + reminderAgent.cancelReminder(1, (err, data) => { + console.log("do next"); + }); + } +} +``` + +## reminderAgent.cancelReminder + +cancelReminder\(reminderId: number\): Promise + +Cancels the reminder with the specified ID. This method uses a promise to return the cancellation result. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

reminderId

+

number

+

Yes

+

ID of the reminder to cancel.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<void>

+

Promise used to return the result.

+
+ +- Example + +``` +export default { + cancel() { + reminderAgent.cancelReminder(1).then(() => { + console.log("do next"); + }); + } +} +``` + +## reminderAgent.getValidReminders + +getValidReminders\(callback: AsyncCallback\>\): void + +Obtains all valid \(not yet expired\) reminders set by the current application. This method uses an asynchronous callback to return the reminders. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

callback

+

AsyncCallback<Array<ReminderRequest>>

+

Yes

+

Asynchronous callback used to return an array of all valid reminders set by the current application.

+
+ +- Example + +``` +reminderAgent.getValidReminders((err, reminders) => { + for (let i = 0; i < reminders.length; i++) { + console.log("getValidReminders = " + reminders[i]); + console.log("getValidReminders, reminderType = " + reminders[i].reminderType); + for (let j = 0; j < reminders[i].actionButton.length; j++) { + console.log("getValidReminders, actionButton.title = " + reminders[i].actionButton[j].title); + console.log("getValidReminders, actionButton.type = " + reminders[i].actionButton[j].type); + } + console.log("getValidReminders, wantAgent.pkgName = " + reminders[i].wantAgent.pkgName); + console.log("getValidReminders, wantAgent.abilityName = " + reminders[i].wantAgent.abilityName); + console.log("getValidReminders, maxScreenWantAgent.pkgName = " + reminders[i].maxScreenWantAgent.pkgName); + console.log("getValidReminders, maxScreenWantAgent.abilityName = " + reminders[i].maxScreenWantAgent.abilityName); + console.log("getValidReminders, ringDuration = " + reminders[i].ringDuration); + console.log("getValidReminders, snoozeTimes = " + reminders[i].snoozeTimes); + console.log("getValidReminders, timeInterval = " + reminders[i].timeInterval); + console.log("getValidReminders, title = " + reminders[i].title); + console.log("getValidReminders, content = " + reminders[i].content); + console.log("getValidReminders, expiredContent = " + reminders[i].expiredContent); + console.log("getValidReminders, snoozeContent = " + reminders[i].snoozeContent); + console.log("getValidReminders, notificationId = " + reminders[i].notificationId); + console.log("getValidReminders, slotType = " + reminders[i].slotType); + } +}) +``` + +## reminderAgent.getValidReminders + +getValidReminders\(\): Promise\> + +Obtains all valid \(not yet expired\) reminders set by the current application. This method uses a promise to return the reminders. + +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<Array<ReminderRequest>>

+

Promise used to return an array of all valid reminders set by the current application.

+
+ +- Example + +``` +reminderAgent.getValidReminders().then((reminders) => { + for (let i = 0; i < reminders.length; i++) { + console.log("getValidReminders = " + reminders[i]); + console.log("getValidReminders, reminderType = " + reminders[i].reminderType); + for (let j = 0; j < reminders[i].actionButton.length; j++) { + console.log("getValidReminders, actionButton.title = " + reminders[i].actionButton[j].title); + console.log("getValidReminders, actionButton.type = " + reminders[i].actionButton[j].type); + } + console.log("getValidReminders, wantAgent.pkgName = " + reminders[i].wantAgent.pkgName); + console.log("getValidReminders, wantAgent.abilityName = " + reminders[i].wantAgent.abilityName); + console.log("getValidReminders, maxScreenWantAgent.pkgName = " + reminders[i].maxScreenWantAgent.pkgName); + console.log("getValidReminders, maxScreenWantAgent.abilityName = " + reminders[i].maxScreenWantAgent.abilityName); + console.log("getValidReminders, ringDuration = " + reminders[i].ringDuration); + console.log("getValidReminders, snoozeTimes = " + reminders[i].snoozeTimes); + console.log("getValidReminders, timeInterval = " + reminders[i].timeInterval); + console.log("getValidReminders, title = " + reminders[i].title); + console.log("getValidReminders, content = " + reminders[i].content); + console.log("getValidReminders, expiredContent = " + reminders[i].expiredContent); + console.log("getValidReminders, snoozeContent = " + reminders[i].snoozeContent); + console.log("getValidReminders, notificationId = " + reminders[i].notificationId); + console.log("getValidReminders, slotType = " + reminders[i].slotType); + } +}) +``` + +## reminderAgent.cancelAllReminders + +cancelAllReminders\(callback: AsyncCallback\): void + +Cancels all reminders set by the current application. This method uses an asynchronous callback to return the cancellation result. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

callback

+

AsyncCallback<void>

+

Yes

+

Asynchronous callback used to return the result.

+
+ +- Example + +``` +reminderAgent.cancelAllReminders((err, data) =>{ + console.log("do next")} +) +``` + +## reminderAgent.cancelAllReminders + +cancelAllReminders\(\): Promise + +Cancels all reminders set by the current application. This method uses a promise to return the cancellation result. + +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<void>

+

Promise used to return the result.

+
+ +- Example + +``` +reminderAgent.cancelAllReminders().then(() => { + console.log("do next")} +) +``` + +## reminderAgent.addNotificationSlot + +addNotificationSlot\(slot: NotificationSlot, callback: AsyncCallback\): void + +Adds a reminder notification slot. This method uses an asynchronous callback to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

slot

+

NotificationSlot

+

Yes

+

Reminder notification slot to add.

+

callback

+

AsyncCallback<void>

+

Yes

+

Asynchronous callback used to return the result.

+
+ +- Example + +``` +export default { + data: { + mySlot: { + type: 3, + sound: "/sdcard/music2.mp3" + } + }, + addSlot() { + reminderAgent.addNotificationSlot(this.mySlot, (err, data) => { + console.log("do next"); + }); + } +} +``` + +## reminderAgent.addNotificationSlot + +addNotificationSlot\(slot: NotificationSlot\): Promise + +Adds a reminder notification slot. This method uses a promise to return the result. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

slot

+

NotificationSlot

+

Yes

+

Reminder notification slot to add.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<void>

+

Promise used to return the result.

+
+ +- Example + +``` +export default { + data: { + mySlot: { + type: 3, + sound: "/sdcard/music2.mp3" + } + }, + addSlot() { + reminderAgent.addNotificationSlot(this.mySlot).then(() => { + console.log("do next"); + }); + } +} +``` + +## reminderAgent.removeNotificationSlot + +removeNotificationSlot\(slotType: notification.SlotType, callback: AsyncCallback\): void + +Removes a **NotificationSlot** instance of a specified type. This method uses an asynchronous callback to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

slotType

+

notification.SlotType

+

Yes

+

Type of the reminder notification slot to remove.

+

callback

+

AsyncCallback<void>

+

Yes

+

Asynchronous callback used to return the result.

+
+ +- Example + +``` +export default { + removeSlot() { + reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err, data) => { + console.log("do next"); + }); + } +} +``` + +## reminderAgent.removeNotificationSlot + +removeNotificationSlot\(slotType: notification.SlotType\): Promise + +Removes a **NotificationSlot** instance of a specified type. This method uses a promise to return the result. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

slotType

+

notification.SlotType

+

Yes

+

Type of the reminder notification slot to remove.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<void>

+

Promise used to return the result.

+
+ +- Example + +``` +export default { + removeSlot() { + reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() => { + console.log("do next"); + }); + } +} +``` + +## ActionButtonType + +Enumerates button types. + + + + + + + + + + + + + + + + +

Name

+

Default Value

+

Description

+

ACTION_BUTTON_TYPE_CLOSE

+

0

+

Button for closing the reminder.

+

ACTION_BUTTON_TYPE_SNOOZE

+

1

+

Button for snoozing the reminder.

+
+ +## ReminderType + +Enumerates reminder types. + + + + + + + + + + + + + + + + + + + + +

Name

+

Default Value

+

Description

+

REMINDER_TYPE_TIMER

+

0

+

Countdown reminder.

+

REMINDER_TYPE_CALENDAR

+

1

+

Calendar reminder.

+

REMINDER_TYPE_ALARM

+

2

+

Alarm reminder.

+
+ +## ActionButton + +Defines a button displayed in the reminder notification. + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

title

+

string

+

Yes

+

Text on the button.

+

type

+

ActionButtonType

+

Yes

+

Button type.

+
+ +## WantAgent + +Sets the package and ability that are redirected to when the reminder notification is clicked. + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

pkgName

+

string

+

Yes

+

Name of the package redirected to when the reminder notification is clicked.

+

abilityName

+

string

+

Yes

+

Name of the ability that is redirected to when the reminder notification is clicked.

+
+ +## MaxScreenWantAgent + +Sets the name of the target package and ability to start automatically when the reminder arrives and the device is not in use. If the device is in use, a notification will be displayed. + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

pkgName

+

string

+

Yes

+

Name of the package that is automatically started when the reminder arrives and the device is not in use.

+

abilityName

+

string

+

Yes

+

Name of the ability that is automatically started when the reminder arrives and the device is not in use.

+
+ +## ReminderRequest + +Defines the reminder to publish. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

reminderType

+

ReminderType

+

Yes

+

Type of the reminder.

+

actionButton

+

[ActionButton?, ActionButton?]

+

No

+

Action button displayed in the reminder notification. (The parameter is optional. Up to two buttons are supported.)

+

wantAgent

+

WantAgent

+

No

+

Information about the ability that is redirected to when the notification is clicked.

+

maxScreenWantAgent

+

MaxScreenWantAgent

+

No

+

Information about the ability that is automatically started when the reminder arrives. If the device is in use, a notification will be displayed.

+

ringDuration

+

number

+

No

+

Ringing duration.

+

snoozeTimes

+

number

+

No

+

Number of reminder snooze times.

+

timeInterval

+

number

+

No

+

Reminder snooze interval.

+

title

+

string

+

No

+

Reminder title.

+

content

+

string

+

No

+

Reminder content.

+

expiredContent

+

string

+

No

+

Content to be displayed after the reminder expires.

+

snoozeContent

+

string

+

No

+

Content to be displayed when the reminder is snoozing.

+

notificationId

+

number

+

No

+

Notification ID used by the reminder. If there are reminders with the same notification ID, the later one will overwrite the earlier one.

+

slotType

+

notification.SlotType

+

No

+

Type of the slot used by the reminder.

+
+ +## ReminderRequestCalendar + +ReminderRequestCalendar extends ReminderRequest + +Defines a reminder for a calendar event. + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

dateTime

+

LocalDateTime

+

Yes

+

Reminder time.

+

repeatMonths

+

Array<number>

+

No

+

Month in which the reminder repeats.

+

repeatDays

+

Array<number>

+

No

+

Date on which the reminder repeats.

+
+ +## ReminderRequestAlarm + +ReminderRequestAlarm extends ReminderRequest + +Defines a reminder for the alarm clock. + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

hour

+

number

+

Yes

+

Hour portion of the reminder time.

+

minute

+

number

+

Yes

+

Minute portion of the reminder time.

+

daysOfWeek

+

Array<number>

+

No

+

Days of a week when the reminder repeats.

+
+ +## ReminderRequestTimer + +Defines a **ReminderRequestTimer** instance, which extends **ReminderRequest**. + +Defines a reminder for a scheduled timer. + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

triggerTimeInSeconds

+

number

+

Yes

+

Number of seconds in the countdown timer.

+
+ +## LocalDateTime + +Sets the time information for a calendar reminder. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

year

+

number

+

Yes

+

Year.

+

month

+

number

+

Yes

+

Month.

+

day

+

number

+

Yes

+

Date.

+

hour

+

number

+

Yes

+

Hour.

+

minute

+

number

+

Yes

+

Minute.

+

second

+

number

+

No

+

Second.

+
+ diff --git a/en/application-dev/reference/apis/js-apis-resource-manager.md b/en/application-dev/reference/apis/js-apis-resource-manager.md index d90f8aef6a156bfc2eb68a8d639aa001831d4f11..355e1fb4dfe5ef566498788dbd412b3d368ec3ad 100644 --- a/en/application-dev/reference/apis/js-apis-resource-manager.md +++ b/en/application-dev/reference/apis/js-apis-resource-manager.md @@ -1,9 +1,9 @@ -# Resource Manager +# Resource Manager + >![](../../public_sys-resources/icon-note.gif) **NOTE:** >The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. - ## Modules to Import ``` @@ -362,8 +362,6 @@ Enumerates screen density types. Provides the device configuration. -### Attributes - @@ -406,8 +404,6 @@ Provides the device configuration. Provides the device capability. -### Attributes -

Name

@@ -450,6 +446,10 @@ Provides the device capability. Provides the capability of accessing application resources. +>![](../public_sys-resources/icon-note.gif) **NOTE:** +>- The methods involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm. +>- Resource files are defined in the **resources** directory of the project. You can obtain the resource ID from **$r\(resource address\).id**, for example, **$r\(?app.string.test?\).id**. + ### getString getString\(resId: number, callback: AsyncCallback\): void @@ -494,7 +494,7 @@ Obtains the string corresponding to the specified resource ID. This method uses ``` resourceManager.getResourceManager((error, mgr) => { - mgr.getString(0x1000000, (error, value) => { + mgr.getString($r('app.string.test').id, (error, value) => { if (error != null) { console.log(value); } else { @@ -557,7 +557,7 @@ Obtains the string corresponding to the specified resource ID. This method uses ``` resourceManager.getResourceManager((error, mgr) => { - mgr.getString(0x1000000).then(value => { + mgr.getString($r('app.string.test').id).then(value => { console.log(value); }).catch(error => { console.log("getstring promise " + error); @@ -610,7 +610,7 @@ Obtains the array of strings corresponding to the specified resource ID. This me ``` resourceManager.getResourceManager((error, mgr) => { - mgr.getStringArray(0x1000000, (error, value) => { + mgr.getStringArray($r('app.strarray.test').id, (error, value) => { if (error != null) { console.log(value); } else { @@ -663,7 +663,7 @@ Obtains the array of strings corresponding to the specified resource ID. This me - @@ -673,7 +673,7 @@ Obtains the array of strings corresponding to the specified resource ID. This me ``` resourceManager.getResourceManager((error, mgr) => { - mgr.getStringArray(0x1000000).then(value => { + mgr.getStringArray($r('app.strarray.test').id).then(value => { console.log(value); }).catch(error => { console.log("getstring promise " + error); @@ -712,7 +712,7 @@ Obtains the content of the media file corresponding to the specified resource ID - @@ -726,7 +726,7 @@ Obtains the content of the media file corresponding to the specified resource ID ``` resourceManager.getResourceManager((error, mgr) => { - mgr.getMedia(0x1000000, (error, value) => { + mgr.getMedia($r('app.media.test').id, (error, value) => { if (error != null) { console.log(value); } else { @@ -777,7 +777,7 @@ Obtains the content of the media file corresponding to the specified resource ID - @@ -789,7 +789,7 @@ Obtains the content of the media file corresponding to the specified resource ID ``` resourceManager.getResourceManager((error, mgr) => { - mgr.getMedia(0x1000000).then(value => { + mgr.getMedia($r('app.media.test').id).then(value => { console.log(value); }).catch(error => { console.log("getstring promise " + error); @@ -842,7 +842,7 @@ Obtains the Base64 code of the image corresponding to the specified resource ID. ``` resourceManager.getResourceManager((error, mgr) => { - mgr.getMediaBase64(0x1000000, (error, value) => { + mgr.getMediaBase64($r('app.media.test').id, (error, value) => { if (error != null) { console.log(value); } else { @@ -905,7 +905,7 @@ Obtains the Base64 code of the image corresponding to the specified resource ID. ``` resourceManager.getResourceManager((error, mgr) => { - mgr.getMediaBase64(0x1000000).then(value => { + mgr.getMediaBase64($r('app.media.test').id).then(value => { console.log(value); }).catch(error => { console.log("getstring promise " + error); @@ -1131,7 +1131,7 @@ Obtains the specified number of singular-plural strings corresponding to the spe ``` resourceManager.getResourceManager((error, mgr) => { - mgr.getPluralString(0x1000000, 1, (error, value) => { + mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => { if (error != null) { console.log(value); } else { @@ -1203,7 +1203,7 @@ Obtains the specified number of singular-plural strings corresponding to the spe ``` resourceManager.getResourceManager((error, mgr) => { - mgr.getPluralString(0x1000000, 1).then(value => { + mgr.getPluralString($r("app.plural.test").id, 1).then(value => { console.log(value); }).catch(error => { console.log("getstring promise " + error); @@ -1212,3 +1212,118 @@ Obtains the specified number of singular-plural strings corresponding to the spe ``` +### getRawFile8+ + +getRawFile\(path: string, callback: AsyncCallback\): void + +Obtains the content of rawfile in the specified path. This method uses an asynchronous callback to return the result. + +- Parameters + + +

Name

Promise<Array<string>>

Array of character strings corresponding to the specified resource ID.

+

Array of strings corresponding to the specified resource ID.

callback

AsyncCallback<Array<Uint8Array>>

+

AsyncCallback<Uint8Array>

Yes

Promise<Array<Uint8Array>>

+

Promise<Uint8Array>

Promise used to return the content of the obtained media file.

+ + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

path

+

string

+

Yes

+

Path of the rawfile.

+

callback

+

AsyncCallback<Uint8Array>

+

Yes

+

Asynchronous callback used to return the rawfile content, in byte arrays.

+
+ +- Example + + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getRawFile("test.xml", (error, value) => { + if (error != null) { + console.log(value); + } else { + console.log(value); + } + }); + }); + ``` + + +### getRawFile8+ + +getRawFile\(path: string\): Promise + +Obtains the content of the rawfile in the specified path. This method uses a promise to return the result. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

path

+

string

+

Yes

+

Path of the rawfile.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<Uint8Array>

+

Promise used to return the rawfile content, in byte arrays.

+
+ +- Example + + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getRawFile("test.xml").then(value => { + console.log(value); + }).catch(error => { + console.log("getrawfile promise " + error); + }); + }); + ``` + diff --git a/en/application-dev/reference/apis/js-apis-system-time.md b/en/application-dev/reference/apis/js-apis-system-time.md index e851eec1055856e6d5a97f45bb45199143ea742d..d7cedf77c5f9d2c403e243952dba0ba3e8974564 100644 --- a/en/application-dev/reference/apis/js-apis-system-time.md +++ b/en/application-dev/reference/apis/js-apis-system-time.md @@ -3,30 +3,6 @@ >![](../../public_sys-resources/icon-note.gif) **NOTE:** >The APIs of this module are supported since API version 7. -## Applicable Devices - - - - - - - - - - - - - - -

Phone

-

Tablet

-

Smart TV

-

Wearable

-

Yes

-

Yes

-

Yes

-

Yes

-
## Modules to Import diff --git a/en/application-dev/reference/apis/js-apis-uri.md b/en/application-dev/reference/apis/js-apis-uri.md new file mode 100644 index 0000000000000000000000000000000000000000..c3eb105e1c4a8b56a4de085d61c4d9abd76c9fae --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-uri.md @@ -0,0 +1,338 @@ +# URI String Parsing + +>![](../../public_sys-resources/icon-note.gif) **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 + +``` +import uri from '@ohos.uri' +``` + +## Required Permissions + +None + +## URI + +### Attributes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Readable

+

Writable

+

Description

+

scheme

+

string

+

Yes

+

No

+

Protocol in the URI.

+

userinfo

+

string

+

Yes

+

No

+

User information in the URI.

+

host

+

string

+

Yes

+

No

+

Host name (without the port number) in the URI.

+

port

+

string

+

Yes

+

No

+

Port number in the URI.

+

path

+

string

+

Yes

+

No

+

Path in the URI.

+

query

+

string

+

Yes

+

No

+

Query part in the URI.

+

fragment

+

string

+

Yes

+

No

+

Fragment part in the URI.

+

authority

+

string

+

Yes

+

No

+

Authority part in the URI.

+

ssp

+

string

+

Yes

+

No

+

Scheme-specific part in the URI.

+
+ +### constructor + +constructor\(uri: string\) + +A constructor used to create a URI instance. + +- Parameters + + + + + + + + + + + + + + + + +

Name

+

Type

+

Readable

+

Writable

+

Description

+

url

+

string

+

Yes

+

Yes

+

Input parameter object.

+
+ + +- Example + + ``` + var mm = 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; + new uri.URI(mm); // Output 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; + ``` + + ``` + new uri.URI('http://username:password@host:8080'); // Output 'http://username:password@host:8080'; + ``` + + +### toString + +toString\(\): string + +Obtains the query string applicable to this URL. + +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Website address in a serialized string.

+
+ + +- Example + + ``` + const url = new uri.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); + url.toString() + ``` + + +### equals + +equals\(other: URI\): boolean + +Checks whether this URI is the same as another URI object. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

other

+

URI

+

Yes

+

URI object to compare.

+
+ + +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

Returns true if the two URIs are the same; returns false otherwise.

+
+ + +- Example + + ``` + const uriInstance = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); + const uriInstance1 = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment'); + uriInstance.equals(uriInstance1); + ``` + + +### checkIsAbsolute + +checkIsAbsolute\(\): boolean + +Checks whether this URI is an absolute URI \(whether the scheme component is defined\). + +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

Returns true if the URI is an absolute URI; returns false otherwise.

+
+ + +- Example + + ``` + const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080?query=pppppp'); + uriInstance.checkIsAbsolute(); + ``` + + +### normalize + +normalize\(\): URI + +Normalizes the path of this URI. + +- Return values + + + + + + + + + + +

Type

+

Description

+

URI

+

URI with the normalized path.

+
+ + +- Example + + ``` + const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp'); + let uriInstance1 = uriInstance.normalize(); + uriInstance1.path; + ``` + + diff --git a/en/application-dev/reference/apis/js-apis-useriam-userauth.md b/en/application-dev/reference/apis/js-apis-useriam-userauth.md index e05a6fdd45fa03a6c9c47e5114b6f728816f3880..267445bbd619c466f4416e2647c6782e19c61465 100644 --- a/en/application-dev/reference/apis/js-apis-useriam-userauth.md +++ b/en/application-dev/reference/apis/js-apis-useriam-userauth.md @@ -3,30 +3,6 @@ >**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. -## Applicable Devices - - - - - - - - - - - - - - -

Phone

-

Tablet

-

Smart TV

-

Wearable

-

Yes

-

Yes

-

No

-

No

-
## Modules to Import diff --git a/en/application-dev/reference/apis/js-apis-worker.md b/en/application-dev/reference/apis/js-apis-worker.md index ff388df2f05e45d5831d4d72102bdfd6a04ae854..53879bb88fdee523a3f5fdbd0ebc61113c3cc367 100644 --- a/en/application-dev/reference/apis/js-apis-worker.md +++ b/en/application-dev/reference/apis/js-apis-worker.md @@ -1,6 +1,6 @@ # Worker Startup ->![](../../public_sys-resources/icon-note.gif) **NOTE:** +>**NOTE:** >The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import @@ -131,13 +131,13 @@ A constructor used to create a worker instance. - Return values -

Name

+ - @@ -148,8 +148,7 @@ A constructor used to create a worker instance. - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js", {name:"first worker"}); + const workerInstance = new worker.Worker("workers/worker.js", {name:"first worker"}); ``` @@ -196,13 +195,14 @@ Sends a message to the worker thread. The data is transferred using the structur - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js"); - worker.postMessage("hello world"); - - const worker = new worker.Worker("workers/worker.js"); + const workerInstance = new worker.Worker("workers/worker.js"); + workerInstance.postMessage("hello world"); + ``` + + ``` + const workerInstance = new worker.Worker("workers/worker.js"); var buffer = new ArrayBuffer(8); - worker.postMessage(buffer, [buffer]); + workerInstance.postMessage(buffer, [buffer]); ``` @@ -249,9 +249,8 @@ Adds an event listener to the worker. - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.on("alert", (e)=>{ + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.on("alert", (e)=>{ console.log("alert listener callback"); }) ``` @@ -300,9 +299,8 @@ Adds an event listener to the worker and removes the event listener automaticall - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js"); - worker.once("alert", (e)=>{ + const workerInstance = new worker.Worker("workers/worker.js"); + workerInstance.once("alert", (e)=>{ console.log("alert listener callback"); }) ``` @@ -351,9 +349,8 @@ Removes an event listener for the worker. - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js"); - worker.off("alert"); + const workerInstance = new worker.Worker("workers/worker.js"); + workerInstance.off("alert"); ``` @@ -366,9 +363,8 @@ Terminates the worker thread to stop the worker from receiving messages. - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.terminate() + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.terminate() ``` @@ -406,9 +402,8 @@ Defines the event handler to be called when the worker exits. The handler is exe - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.onexit = function(e) { + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.onexit = function(e) { console.log("onexit") } ``` @@ -448,9 +443,8 @@ Defines the event handler to be called when an exception occurs during worker ex - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.onerror = function(e) { + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.onerror = function(e) { console.log("onerror") } ``` @@ -490,9 +484,8 @@ Defines the event handler to be called when the host thread receives a message c - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.onmessage = function(e) { + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.onmessage = function(e) { console.log("onerror") } ``` @@ -532,9 +525,8 @@ Defines the event handler to be called when the worker receives a message that c - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.onmessageerror= function(e) { + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.onmessageerror= function(e) { console.log("onmessageerror") } ``` @@ -585,9 +577,8 @@ Adds an event listener to the worker. - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.addEventListener("alert", (e)=>{ + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.addEventListener("alert", (e)=>{ console.log("alert listener callback"); }) ``` @@ -636,9 +627,8 @@ Removes an event listener for the worker. - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.removeEventListener("alert") + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.removeEventListener("alert") ``` @@ -676,7 +666,7 @@ Dispatches the event defined for the worker. - Return values -

Type

Description

worker

+

Worker

Returns the worker instance created; returns undefined if the worker instance fails to be created.

Name

+ @@ -693,9 +683,8 @@ Dispatches the event defined for the worker. - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.dispatchEvent({type:"alert"}) + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.dispatchEvent({type:"alert"}) ``` @@ -708,9 +697,8 @@ Removes all event listeners for the worker. - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.removeAllListener({type:"alert"}) + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.removeAllListener({type:"alert"}) ``` @@ -762,13 +750,15 @@ Sends a message to the host thread from the worker. ``` // main.js - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.postMessage("hello world") - worker.onmessage = function(e) { + import worker from "@ohos.worker"; + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.postMessage("hello world") + workerInstance.onmessage = function(e) { console.log("receive data from worker.js") } - + ``` + + ``` // worker.js import worker from "@ohos.worker"; const parentPort = worker.parentPort; @@ -789,8 +779,10 @@ Closes the worker thread to stop the worker from receiving messages. ``` // main.js import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - + const workerInstance = new worker.Worker("workers/worker.js") + ``` + + ``` // worker.js import worker from "@ohos.worker"; const parentPort = worker.parentPort; @@ -836,9 +828,11 @@ Defines the event handler to be called when the worker thread receives a message ``` // main.js import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - worker.postMessage("hello world") - + const workerInstance = new worker.Worker("workers/worker.js") + workerInstance.postMessage("hello world") + ``` + + ``` // worker.js import worker from "@ohos.worker"; const parentPort = worker.parentPort; @@ -884,8 +878,10 @@ Defines the event handler to be called when the worker receives a message that c ``` // main.js import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - + const workerInstance = new worker.Worker("workers/worker.js") + ``` + + ``` // worker.js import worker from "@ohos.worker"; const parentPort = worker.parentPort; @@ -1004,7 +1000,7 @@ Specifies the callback to invoke. - Return values -

Type

Description

Name

+ @@ -1021,9 +1017,8 @@ Specifies the callback to invoke. - Example ``` - import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js"); - worker.addEventListener("alert", (e)=>{ + const workerInstance = new worker.Worker("workers/worker.js"); + workerInstance.addEventListener("alert", (e)=>{ console.log("alert listener callback"); }) ``` @@ -1215,8 +1210,10 @@ Defines the event handler to be called when an exception occurs during worker ex ``` // main.js import worker from '@ohos.worker'; - const worker = new worker.Worker("workers/worker.js") - + const workerInstance = new worker.Worker("workers/worker.js") + ``` + + ``` // worker.js import worker from "@ohos.worker"; const parentPort = worker.parentPort diff --git a/en/application-dev/reference/apis/js-apis-xml.md b/en/application-dev/reference/apis/js-apis-xml.md new file mode 100644 index 0000000000000000000000000000000000000000..98ff62e6a3926a15f049b6a18d98d8f9a463c2b4 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-xml.md @@ -0,0 +1,976 @@ +# XML Parsing and Generation + +>![](../../public_sys-resources/icon-note.gif) **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 + +``` +import xml from '@ohos.xml'; +``` + +## Required Permissions + +None + +## XmlSerializer + +### constructor + +constructor\(buffer: ArrayBuffer | DataView, encoding?: string\) + +A constructor used to create an **XmlSerializer** instance. + +- Parameters + + +

Type

Description

+ + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

buffer

+

ArrayBuffer | DataView

+

Yes

+

ArrayBuffer or DataView for storing the XML information to write.

+

encoding

+

string

+

No

+

Encoding format.

+
+ + +- Example + + ``` + var arrayBuffer = new ArrayBuffer(1024); + var bufView = new DataView(arrayBuffer); + var thatSer = new xml.XmlSerializer(bufView); + ``` + + +### setAttributes + +setAttributes\(name: string, value: string\): void + +Sets an attribute. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

name

+

string

+

Yes

+

Key of the attribute.

+

value

+

string

+

Yes

+

Value of the attribute.

+
+ +- Example + + ``` + var thatSer = new xml.XmlSerializer(bufView); + thatSer.setAttributes("importance", "high"); + ``` + + +### addEmptyElement + +addEmptyElement\(name: string\): void + +Adds an empty element. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

name

+

string

+

Yes

+

Name of the empty element to add.

+
+ + +- Example + + ``` + var thatSer = new xml.XmlSerializer(bufView); + thatSer.addEmptyElement("b"); // => + ``` + + +### setDeclaration + +setDeclaration\(\): void + +Sets a declaration. + +- Example + + ``` + var thatSer = new xml.XmlSerializer(bufView); + thatSer.setDeclaration() // => ; + ``` + + +### startElement + +startElement\(name: string\): void + +Writes the start tag based on the given element name. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

name

+

string

+

Yes

+

Name of the element.

+
+ + +- Example + + ``` + var arrayBuffer = new ArrayBuffer(1024); + var thatSer = new xml.XmlSerializer(arrayBuffer); + thatSer.startElement("notel"); + thatSer.endElement();// => ''; + ``` + + +### endElement + +endElement\(\): void + +Writes the end tag of the element. + +- Example + + ``` + var thatSer = new xml.XmlSerializer(bufView); + thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); + thatSer.startElement("table"); + thatSer.setAttributes("importance", "high"); + thatSer.setText("Happy"); + endElement(); // => Happy + ``` + + +### setNamespace + +setNamespace\(prefix: string, namespace: string\): void + +Sets the namespace for an element tag. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

prefix

+

string

+

Yes

+

Prefix of the element and its child elements.

+

namespace

+

string

+

Yes

+

Namespace to set.

+
+ + +- Example + + ``` + var arrayBuffer = new ArrayBuffer(1024); + var thatSer = new xml.XmlSerializer(arrayBuffer); + thatSer.setDeclaration(); + thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); + thatSer.startElement("note"); + thatSer.endElement();// = >'\r\n'; + ``` + + +### setComment + +setComment\(text: string\): void + +Sets the comment. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

text

+

string

+

Yes

+

Comment to set.

+
+ + +- Example + + ``` + var arrayBuffer = new ArrayBuffer(1024); + var thatSer = new xml.XmlSerializer(arrayBuffer); + thatSer.startElement("note"); + thatSer.setComment("Hi!"); + thatSer.endElement(); // => '\r\n \r\n'; + ``` + + +### setCDATA + +setCDATA\(text: string\): void + +Sets CDATA attributes. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

text

+

string

+

Yes

+

CDATA attribute to set.

+
+ + +- Example + + ``` + var arrayBuffer = new ArrayBuffer(1028); + var thatSer = new xml.XmlSerializer(arrayBuffer); + thatSer.setCDATA('root SYSTEM') // => ''; + ``` + + +### setText + +setText\(text: string\): void + +Sets **Text**. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

text

+

string

+

Yes

+

Content of the Text to set.

+
+ + +- Example + + ``` + var arrayBuffer = new ArrayBuffer(1024); + var thatSer = new xml.XmlSerializer(arrayBuffer); + thatSer.startElement("note"); + thatSer.setAttributes("importance", "high"); + thatSer.setText("Happy1"); + thatSer.endElement(); // => 'Happy1'; + ``` + + +### setDocType + +setDocType\(text: string\): void + +Sets **DocType**. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

text

+

string

+

Yes

+

Content of DocType to set.

+
+ + +- Example + + ``` + var arrayBuffer = new ArrayBuffer(1024); + var thatSer = new xml.XmlSerializer(arrayBuffer); + thatSer.setDocType('root SYSTEM'); // => ''; + ``` + + +## XmlPullParser + +### XmlPullParser + +constructor\(buffer: ArrayBuffer | DataView, encoding?: string\) + +Creates and returns an **XmlPullParser** object. The **XmlPullParser** object passes two parameters. The first parameter is the memory of the **ArrayBuffer** or **DataView** type, and the second parameter is the file format \(UTF-8 by default\). + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

buffer

+

ArrayBuffer | DataView

+

Yes

+

ArrayBuffer or DataView that contains XML text information.

+

encoding

+

string

+

No

+

Encoding format. Only UTF-8 is supported.

+
+ + +- Example + + ``` + var strXml = + '' + + '' + + ' Happy' + + ' Work' + + ' Play' + + ''; + var arrayBuffer = new ArrayBuffer(strXml.length*2); + var bufView = new Uint8Array(arrayBuffer); + var strLen = strXml.length; + for (var i = 0; i < strLen; ++i) { + bufView[i] = strXml.charCodeAt(i);// Set the ArrayBuffer mode. + } + var that = new xml.XmlPullParser(arrayBuffer); + ``` + + +### parse + +parse\(option: ParseOptions\): void + +Parses XML information. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

option

+

ParseOptions

+

Yes

+

Options for controlling and obtaining the parsed information.

+
+ + +- Example + + ``` + var strXml = + '' + + '' + + ' Happy' + + ' Work' + + ' Play' + + ''; + var arrayBuffer = new ArrayBuffer(strXml.length*2); + var bufView = new Uint8Array(arrayBuffer); + var strLen = strXml.length; + for (var i = 0; i < strLen; ++i) { + bufView[i] = strXml.charCodeAt(i); + } + var that = new xml.XmlPullParser(arrayBuffer); + var arrTag = {}; + arrTag[0] = '132'; + var i = 1; + function func(key, value){ + arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); + i++; + return true; + } + var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} + that.parse(options); + ``` + + +## ParseOptions + +Defines the XML parsing options. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

supportDoctype

+

boolean

+

No

+

Whether to ignore Doctype. The default value is false.

+

ignoreNameSpace

+

boolean

+

No

+

Whether to ignore Namespace. The default value is false.

+

tagValueCallbackFunction

+

(name: string, value: string)=> boolean

+

No

+

Callback used to return tagValue.

+

attributeValueCallbackFunction

+

(name: string, value: string)=> boolean

+

No

+

Callback used to return attributeValue.

+

tokenValueCallbackFunction

+

(eventType: EventType, value: ParseInfo)=> boolean

+

No

+

Callback used to return tokenValue.

+
+ +## ParseInfo + +Provides methods to manage the parsed XML information. + +### getColumnNumber + +getColumnNumber\(\): number + +Obtains the column line number, which starts from 1. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Column number obtained.

+
+ + +### getDepth + +getDepth\(\): number + +Obtains the depth of this element. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Depth obtained.

+
+ + +### getLineNumber + +getLineNumber\(\): number + +Obtains the current line number, starting from 1. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Line number obtained.

+
+ + +### getName + +getName\(\): string + +Obtains the name of this element. + +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Element name obtained.

+
+ + +### getNamespace + +getNamespace\(\): string + +Obtains the namespace of this element. + +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Namespace obtained.

+
+ + +### getPrefix + +getPrefix\(\): string + +Obtains the prefix of this element. + +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Element prefix obtained.

+
+ + +### getText + +getText\(\): string + +Obtains the text of the current event. + +- Return values + + + + + + + + + + +

Type

+

Description

+

string

+

Text content obtained.

+
+ + +### isEmptyElementTag + +isEmptyElementTag\(\): boolean + +Checks whether the current element is empty. + +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

Returns true if the element is empty; returns false otherwise.

+
+ + +### isWhitespace + +isWhitespace\(\): boolean + +Checks whether the current text event contains only whitespace characters. + +- Return values + + + + + + + + + + +

Type

+

Description

+

boolean

+

Returns true if the text event contains only whitespace characters; returns false otherwise.

+
+ + +### getAttributeCount + +getAttributeCount\(\): number + +Obtains the number of attributes for the current start tag. + +- Return values + + + + + + + + + + +

Type

+

Description

+

number

+

Number of attributes obtained.

+
+ + +## EventType + +Enumerates the events. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Value

+

Description

+

START_DOCUMENT

+

0

+

Indicates a start document event.

+

END_DOCUMENT

+

1

+

Indicates an end document event.

+

START_TAG

+

2

+

Indicates a start tag event.

+

END_TAG

+

3

+

Indicates an end tag event.

+

TEXT

+

4

+

Indicates a text event.

+

CDSECT

+

5

+

Indicates a CDATA section event.

+

COMMENT

+

6

+

Indicates an XML comment event.

+

DOCDECL

+

7

+

Indicates an XML document type declaration event.

+

INSTRUCTION

+

8

+

Indicates an XML processing instruction event.

+

ENTITY_REFERENCE

+

9

+

Indicates an entity reference event.

+

WHITESPACE

+

10

+

Indicates a whitespace character event.

+
+ diff --git a/zh-cn/application-dev/background-task-management/Readme-CN.md b/zh-cn/application-dev/background-task-management/Readme-CN.md new file mode 100644 index 0000000000000000000000000000000000000000..36178f390b77fbf8b4ed9abd5309c450f0fed3eb --- /dev/null +++ b/zh-cn/application-dev/background-task-management/Readme-CN.md @@ -0,0 +1,5 @@ +# 后台任务管理 + +- 后台任务 + - [后台任务概述](background-task-overview.md) + - [后台任务开发指导](background-task-dev-guide.md) \ No newline at end of file diff --git a/zh-cn/application-dev/background-task-management/background-task-overview.md b/zh-cn/application-dev/background-task-management/background-task-overview.md index f3cec92c4187b4a63b4ca35f787b37e37c0a71d5..5a4602a62b034aea18a59fffd65aaa331fde53cd 100644 --- a/zh-cn/application-dev/background-task-management/background-task-overview.md +++ b/zh-cn/application-dev/background-task-management/background-task-overview.md @@ -1,4 +1,4 @@ -# 概述 +# 后台任务概述 对于有用户交互的OS来说,资源优先分配给与用户交互的业务进程,换句话说,在支撑OS运行的进程以外,用户能感知到的业务进程优先级最高,所以后台任务管理的范围是用户感知不到的业务进程。 diff --git a/zh-cn/application-dev/database/Readme-CN.md b/zh-cn/application-dev/database/Readme-CN.md index f6341aa680d95dc524fb2e1820f7b08b53ecc69d..c96d684813ae4d444503601e566f5e42061f552e 100644 --- a/zh-cn/application-dev/database/Readme-CN.md +++ b/zh-cn/application-dev/database/Readme-CN.md @@ -1,4 +1,11 @@ -# 分布式数据服务 +# 数据管理 -- [分布式数据服务概述](database-mdds-overview.md) -- [分布式数据服务开发指导](database-mdds-guidelines.md) +- 分布式数据服务 + - [分布式数据服务概述](database-mdds-overview.md) + - [分布式数据服务开发指导](database-mdds-guidelines.md) +- 关系型数据库 + - [关系型数据库概述](database-relational-overview.md) + - [分布式数据服务开发指导](database-relational-guidelines.md) +- 轻量级数据存储 + - [轻量级数据存储概述](database-preference-overview.md) + - [轻量级数据存储开发指导](database-preference-guidelines.md) diff --git a/zh-cn/application-dev/database/database-preference-guidelines.md b/zh-cn/application-dev/database/database-preference-guidelines.md new file mode 100644 index 0000000000000000000000000000000000000000..93ae0313272e6599e0f12ce48cea14e4a47b042f --- /dev/null +++ b/zh-cn/application-dev/database/database-preference-guidelines.md @@ -0,0 +1,161 @@ +# 轻量级数据存储开发指导 + +## 场景介绍 + +轻量级数据存储功能通常用于保存应用的一些常用配置信息,并不适合需要存储大量数据和频繁改变数据的场景。应用的数据保存在文件中,这些文件可以持久化地存储在设备上。需要注意的是,应用访问的实例包含文件所有数据,这些数据会一直加载在设备的内存中,直到应用主动从内存中将其移除前,应用可以通过Storage的API进行数据操作。 + +## 接口说明 + +轻量级存储为应用提供key-value键值型的文件数据处理能力,支持应用对数据进行轻量级存储及查询。数据存储形式为键值对,键的类型为字符串型,值的存储数据类型包括数字型、字符型、布尔型。 + +**创建存储实例** + +读取指定文件,将数据加载到Storage实例,即可创建一个存储实例,用于数据操作。 + +**表1** 轻量级数据存储实例创建接口 + +| 包名 | 接口名 | 描述 | +| ----------------- | ------------------------------------------- | ------------------------------------------- | +| ohos.data.storage | getStorage(path: string): Promise\ | 获取文件对应的Storage单实例,用于数据操作。 | + +**存入数据** + +通过put系列方法,可以增加或修改Storage实例中的数据。 + +**表2** 轻量级数据存入接口 + +| 类名 | 接口名 | 描述 | +| ------- | -------------------------------------------------- | ----------------------------------------------- | +| Storage | put(key: string, value: ValueType): Promise\ | 支持值为number、string、boolean类型的数据存入。 | + +**读取数据** + +通过调用get系列方法,可以读取Storage中的数据。 + +**表3** 轻量级数据读取接口 + +| 类名 | 接口名 | 描述 | +| ------- | ---------------------------------------------------------- | ----------------------------------------------- | +| Storage | get(key: string, defValue: ValueType): Promise\ | 支持获取值为number、string、boolean类型的数据。 | + +**数据持久化** + +通过执行flush方法,应用可以将缓存的数据再次写回文本文件中进行持久化存储。 + +**表4** 轻量级数据持久化接口 + +| 类名 | 接口名 | 描述 | +| ------- | ----------------------- | --------------------------------------- | +| Storage | flush(): Promise\ | 将Storage实例通过异步线程回写入文件中。 | + +**订阅数据变化** + +订阅数据变化需要指定StorageObserver作为回调方法。订阅的key的值发生变更后,当执行flush方法时,StorageObserver被回调。 + +**表5** 轻量级数据变化订阅接口 + +| 类名 | 接口名 | 描述 | +| ------- | ------------------------------------------------------------ | -------------- | +| Storage | on(type: 'change', callback: Callback\): void | 订阅数据变化。 | +| Storage | off(type: 'change', callback: Callback\): void | 注销订阅。 | + +**删除数据文件** + +通过调用以下两种接口,可以删除数据实例或对应的文件。 + +**表6** 轻量级数据存储删除接口 + +| 包名 | 接口名 | 描述 | +| ----------------- | ---------------------------------------------------- | ------------------------------------------------------------ | +| ohos.data.storage | deleteStorage(path: string): Promise\ | 从缓存中移除已加载的Storage对象,同时从设备上删除对应的文件。 | +| ohos.data.storage | removeStorageFromCache(path: string): Promise\ | 仅从缓存中移除已加载的Storage对象,主要用于释放内存。 | + +## 开发步骤 + +1. 准备工作,导入@ohos.data.storage以及相关的模块到开发环境。 + + ``` + import dataStorage from '@ohos.data.storage' + import featureAbility from '@ohos.ability.featureAbility' // 用于获取文件存储路径 + ``` + +2. 获取Storage实例。 + + 读取指定文件,将数据加载到Storage实例,用于数据操作。 + ``` + var context = featureAbility.getContext() + var path = await context.getFilesDir() + let promise = dataStorage.getStorage(path + '/mystore') + ``` + +3. 存入数据。 + + 使用Storage put方法保存数据到缓存的实例中。 + + ``` + promise.then((storage) => { + let getPromise = storage.put('startup', 'auto') // 保存数据到缓存的storage示例中。 + getPromise.then(() => { + console.info("Put the value of startup successfully.") + }).catch((err) => { + console.info("Put the value of startup failed with err: " + err) + }) + }).catch((err) => { + console.info("Get the storage failed") + }) + ``` + +4. 读取数据。 + + 使用Storage get方法读取数据。 + + ``` + promise.then((storage) => { + let getPromise = storage.get('startup', 'default') + getPromise.then((value) => { + console.info("The value of startup is " + value) + }).catch((err) => { + console.info("Get the value of startup failed with err: " + err) + }) + }).catch((err) => { + console.info("Get the storage failed")}) + ``` + +5. 数据持久化。 + + 应用存入数据到Storage实例后,可以通过flush或者flushSync方法将Storage实例回写到文件中。 + + ``` + storage.flush(); + ``` + +6. 订阅数据变化。 + + 应用订阅数据变化需要指定StorageObserver作为回调方法。订阅的key的值发生变更后,当执行flush方法时,StorageObserver被触发回调。不再需要StorageObserver时请注销。 + + ``` + promise.then((storage) => { + var observer = function (key) { + console.info("The key of " + key + " changed.") + } + storage.on('change', observer) + storage.putSync('startup', 'auto') // 修改storage存储数据 + storage.flushSync() // 触发订阅者回调方法 + + storage.off('change', observer) // 注销数据变化订阅 + }).catch((err) => { + console.info("Get the storage failed") + }) + ``` + +7. 删除指定文件。 + + 使用deleteStorage方法从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。删除后,数据及文件将不可恢复。 + + ``` + let promise = dataStorage.deleteStorage(path + '/mystore') + promise.then(() => { + console.info("Deleted successfully.") + }).catch((err) => { + console.info("Deleted failed with err: " + err)}) + ``` \ No newline at end of file diff --git a/zh-cn/application-dev/database/database-preference-overview.md b/zh-cn/application-dev/database/database-preference-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..b906e9423d4b4f988a0d12d66167f0ec6f855047 --- /dev/null +++ b/zh-cn/application-dev/database/database-preference-overview.md @@ -0,0 +1,28 @@ +# 轻量级数据存储概述 + +轻量级数据存储适用于对Key-Value结构的数据进行存取和持久化操作。应用获取某个轻量级存储对象后,该存储对象中的数据将会被缓存在内存中,以便应用获得更快的数据存取速度。应用也可以将缓存的数据再次写回文本文件中进行持久化存储,由于文件读写将产生不可避免的系统资源开销,建议应用减少对持久化文件的读写频率。 + +## 基本概念 + +- **Key-Value数据结构** + + 一种键值结构数据类型。Key是不重复的关键字,Value是数据值。 + +- **非关系型数据库** + + 区别于关系数据库,不保证遵循ACID(Atomic、Consistency、Isolation及Durability)特性,不采用关系模型来组织数据,数据之间无关系。 + +## 运作机制 + +1. 应用通过指定Storage文件将其中的数据加载到Storage实例,系统会通过静态容器将该实例存储在内存中,同一应用或进程中每个文件仅存在一个Storage实例,直到应用主动从内存中移除该实例或者删除该Storage文件。 +2. 应用获取到Storage文件对应的实例后,可以从Storage实例中读取数据,或者将数据存入Storage实例中。通过调用flush或者flushSync方法可以将Storage实例中的数据回写到文件里。 + +**图1** 轻量级数据存储运作机制 + +![zh-cn_image_0000001199139454](figures/zh-cn_image_0000001199139454.png) + +## 约束与限制 + +- 因Storage实例会加载到内存中,建议存储的数据不超过一万条,并及时清理不再使用的实例,以便减少非内存开销。 +- 数据中的key为string类型,要求非空且字符长度不超过80个。 +- 当数据中的value为string类型时,允许为空,字符长度不超过8192个。 \ No newline at end of file diff --git a/zh-cn/application-dev/database/database-relational-guidelines.md b/zh-cn/application-dev/database/database-relational-guidelines.md new file mode 100644 index 0000000000000000000000000000000000000000..127fa0bae8e4a437f27d02262d388d22ff7a1ba5 --- /dev/null +++ b/zh-cn/application-dev/database/database-relational-guidelines.md @@ -0,0 +1,200 @@ +# 关系型数据库开发指导 + +## 场景介绍 + +关系型数据库是在SQLite基础上实现的本地数据操作机制,提供给用户无需编写原生SQL语句就能进行数据增删改查的方法,同时也支持原生SQL语句操作。 + + +## 接口说明 + +**数据库的创建和删除** + +关系型数据库提供了数据库创建方式,以及对应的删除接口,涉及的API如下所示。 + +**表1** 数据库创建和删除API + +| 类名 | 接口名 | 描述 | +| -------- | -------- | -------- | +| dataRdb | getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): void | 获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,结果以callback形式返回。
- config:与此RDB存储相关的数据库配置。
- version:数据库版本。
- callback:指定callback回调函数。返回一个RdbStore。 | +| dataRdb | getRdbStore(config: StoreConfig, version: number): Promise<RdbStore> | 获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,结果以Promise形式返回。
- config:与此RDB存储相关的数据库配置。
- version:数据库版本。 | +| dataRdb | deleteRdbStore(name: string, callback: AsyncCallback<void>): void | 删除数据库,结果以callback形式返回。
- name:数据库名称。
- callback:指定callback回调函数。如果数据库已删除,则为true;否则返回false。 | +| dataRdb | deleteRdbStore(name: string): Promise<void> | 使用指定的数据库文件配置删除数据库,结果以Promise形式返回。
- name:数据库名称。 | + +**数据库的增删改查** + +关系型数据库提供对本地数据增删改查操作的能力,相关API如下所示。 + +- **新增** + 关系型数据库提供了插入数据的接口,通过ValuesBucket输入要存储的数据,通过返回值判断是否插入成功,插入成功时返回最新插入数据所在的行号,失败时则返回-1。 + **表2** 数据库插入API + + | 类名 | 接口名 | 描述 | + | -------- | -------- | -------- | + | RdbStore | insert(name: string, values: ValuesBucket, callback: AsyncCallback<number>):void | 向目标表中插入一行数据,结果以callback形式返回。
- name:指定的目标表名。
- values:表示要插入到表中的数据行。
- callback:指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 | + | RdbStore | insert(name: string, values: ValuesBucket): Promise<number> | 向目标表中插入一行数据,结果以Promise形式返回。
- name:指定的目标表名。
- values:表示要插入到表中的数据行。 | + +- **更新** + 调用更新接口,传入要更新的数据,并通过RdbPredicates指定更新条件。该接口的返回值表示更新操作影响的行数。如果更新失败,则返回0。 + + **表3** 数据库更新API + + | 类名 | 接口名 | 描述 | + | -------- | -------- | -------- | + | RdbStore | update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void | 根据RdbPredicates的指定实例对象更新数据库中的数据,结果以callback形式返回。
- values:以ValuesBucket存储的要更新的数据。
- rdbPredicates:表示RdbPredicates的实例对象指定的更新条件。
- callback:指定的callback回调方法。返回受影响的行数。 | + | RdbStore | update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise | 根据RdbPredicates的指定实例对象更新数据库中的数据,结果以Promise形式返回。
- values:以ValuesBucket存储的要更新的数据。
- rdbPredicates:表示RdbPredicates的实例对象指定的更新条件。 | + +- **删除** + 调用删除接口,通过RdbPredicates指定删除条件。该接口的返回值表示删除的数据行数,可根据此值判断是否删除成功。如果删除失败,则返回0。 + + **表4** 数据库删除API + + | 类名 | 接口名 | 描述 | + | -------- | -------- | -------- | + | RdbStore | delete(rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void | 根据rdbPredicates的指定实例对象从数据库中删除数据,结果以callback形式返回。
- rdbPredicates:RdbPredicates的实例对象指定的删除条件。
- callback:指定callback回调函数。返回受影响的行数。 | + | RdbStore | delete(rdbPredicates: RdbPredicates): Promise | 根据rdbPredicates的指定实例对象从数据库中删除数据,结果以Promise形式返回。
- rdbPredicates:RdbPredicates的实例对象指定的删除条件。 | + +- **查询** + 关系型数据库提供了两种查询数据的方式: + + - 直接调用查询接口。使用该接口,会将包含查询条件的谓词自动拼接成完整的SQL语句进行查询操作,无需用户传入原生的SQL语句。 + - 执行原生的SQL语句进行查询操作。 + + **表5** 数据库查询API + + | 类名 | 接口名 | 描述 | + | -------- | -------- | -------- | + | RdbStore | query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback<ResultSet>): void | 根据指定条件查询数据库中的数据,结果以callback形式返回。
- rdbPredicates:表示RdbPredicates的实例对象指定的查询条件。
- columns:表示要查询的列。如果值为空,则查询应用于所有列。
- callback:指定callback回调函数。如果操作成功,则返回ResultSet对象。 | + | RdbStore | query(rdbPredicates: RdbPredicates, columns: Array): Promise<ResultSet> | 根据指定条件查询数据库中的数据,结果以Promise形式返回。
- rdbPredicates:表示RdbPredicates的实例对象指定的查询条件。
- columns:表示要查询的列。如果值为空,则查询应用于所有列。 | + | RdbStore | querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void | 根据指定SQL语句查询数据库中的数据,结果以callback形式返回。
- sql:指定要查询的SQL语句。
- bindArgs:SQL语句中参数的值。
- callback:指定callback回调函数。如果操作成功,则返回ResultSet对象。 | + | RdbStore | querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> | 根据指定SQL语句查询数据库中的数据,结果以Promise形式返回。
- sql:指定要查询的SQL语句。
- bindArgs:SQL语句中参数的值。 | + +**数据库谓词的使用** + +关系型数据库提供了用于设置数据库操作条件的谓词RdbPredicates,该类确定RDB中条件表达式的值是true还是false。 + +**表6** 数据库谓词API + +| 类名 | 接口名 | 描述 | +| -------- | -------- | -------- | +| RdbPredicates | equalTo(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为ValueType且值等于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | notEqualTo(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为ValueType且值不等于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | beginWrap(): RdbPredicates | 向谓词添加左括号。
- RdbPredicates:返回带有左括号的谓词。 | +| RdbPredicates | endWrap(): RdbPredicates | 向谓词添加右括号。
- RdbPredicates:返回带有右括号的谓词。 | +| RdbPredicates | or(): RdbPredicates | 将或条件添加到谓词中。
- RdbPredicates:返回带有或条件的谓词。 | +| RdbPredicates | and(): RdbPredicates | 向谓词添加和条件。
- RdbPredicates:返回带有和条件的谓词。 | +| RdbPredicates | contains(field: string, value: string): RdbPredicats | 配置谓词以匹配数据字段为String且value包含指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回带有包含条件的谓词。 | +| RdbPredicates | beginsWith(field: string, value: string): RdbPredicates | 配置谓词以匹配数据字段为String且值以指定字符串开头的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | endsWith(field: string, value: string): RdbPredicates | 配置谓词以匹配数据字段为String且值以指定字符串结尾的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | isNull(field: string): RdbPredicates | 配置谓词以匹配值为null的字段。
- field:数据库表中的列名。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | isNotNull(field: string): RdbPredicates | 配置谓词以匹配值不为null的指定字段。
- field:数据库表中的列名。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | like(field: string, value: string): RdbPredicates | 配置谓词以匹配数据字段为String且值类似于指定字符串的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | glob(field: string, value: string): RdbPredicates | 配置RdbPredicates匹配数据字段为String的指定字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | between(field: string, low: ValueType, high: ValueType): RdbPredicates | 将谓词配置为匹配数据字段为ValueType且value在给定范围内的指定字段。
- field:数据库表中的列名。
- low:指示与谓词匹配的最小值。
- high:指示与谓词匹配的最大值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates | 配置RdbPredicates以匹配数据字段为ValueType且value超出给定范围的指定字段。
- field:数据库表中的列名。
- low:指示与谓词匹配的最小值。
- high:指示与谓词匹配的最大值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | greaterThan(field: string, value: ValueType): RdbPredicatesgr | 配置谓词以匹配数据字段为ValueType且值大于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | lessThan(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为valueType且value小于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为ValueType且value大于或等于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为ValueType且value小于或等于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | orderByAsc(field: string): RdbPredicates | 配置谓词以匹配其值按升序排序的列。
- field:数据库表中的列名。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | orderByDesc(field: string): RdbPredicates | 配置谓词以匹配其值按降序排序的列。
- field:数据库表中的列名。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | distinct(): RdbPredicates | 配置谓词以过滤重复记录并仅保留其中一个。
- RdbPredicates:返回可用于过滤重复记录的谓词。 | +| RdbPredicates | limitAs(value: number): RdbPredicates | 设置最大数据记录数的谓词。
- value:最大数据记录数。
- RdbPredicates:返回可用于设置最大数据记录数的谓词。 | +| RdbPredicates | offsetAs(rowOffset: number): RdbPredicates | 配置RdbPredicates以指定返回结果的起始位置。
- rowOffset:返回结果的起始位置,取值为正整数。
- RdbPredicates:返回具有指定返回结果起始位置的谓词。 | +| RdbPredicates | groupBy(fields: Array<string>): RdbPredicates | 配置RdbPredicates按指定列分组查询结果。
- fields:指定分组依赖的列名。
- RdbPredicates:返回分组查询列的谓词。 | +| RdbPredicates | indexedBy(indexName: string): RdbPredicates | 配置RdbPredicates以指定索引列。
- indexName:索引列的名称。
- RdbPredicates:返回具有指定索引列的RdbPredicates。 | +| RdbPredicates | in(field: string, value: Array<ValueType>): RdbPredicates | 配置RdbPredicates以匹配数据字段为ValueType数组且值在给定范围内的指定字段。
- field:数据库表中的列名。
- value:以ValueType型数组形式指定的要匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | +| RdbPredicates | notIn(field: string, value: Array<ValueType>): RdbPredicates | 将RdbPredicates配置为匹配数据字段为ValueType且值超出给定范围的指定字段。
- field:数据库表中的列名。
- value:以ValueType型数组形式指定的要匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | + +**查询结果集的使用** + +关系型数据库提供了查询返回的结果集ResultSet,其指向查询结果中的一行数据,供用户对查询结果进行遍历和访问。ResultSet对外API如下所示。 + +> ![icon-notice.gif](public_sys-resources/icon-notice.gif) **须知:** +> **注:结果集使用完后,请一定要调用close方法显式关闭。** + +**表7** 结果集API + +| 类名 | 接口名 | 描述 | +| -------- | -------- | -------- | +| ResultSet | goTo(offset:number): boolean | 从结果集当前位置移动指定偏移量。 | +| ResultSet | goToRow(position: number): boolean | 将结果集移动到指定位置。 | +| ResultSet | goToNextRow(): boolean | 将结果集向后移动一行。 | +| ResultSet | goToPreviousRow(): boolean | 将结果集向前移动一行。 | +| ResultSet | getColumnIndex(columnName: string): number | 根据指定的列名获取列索引。 | +| ResultSet | getColumnName(columnIndex: number): string | 根据指定的列索引获取列名。 | +| ResultSet | goToFirstRow(): boolean | 判断结果集当前位置是否在第一行。 | +| ResultSet | goToLastRow(): boolean | 判断结果集当前位置是否在最后一行。 | +| ResultSet | getString(columnIndex: number): string | 获取当前行指定列的值,以String类型返回。 | +| ResultSet | getBlob(columnIndex: number): Uint8Array | 获取当前行指定列的值,以字节数组形式返回。 | +| ResultSet | getDouble(columnIndex: number): number | 获取当前行指定列的值,以double型返回。 | +| ResultSet | isColumnNull(columnIndex: number): boolean | 检查当前行中指定列的值是否为null。 | +| ResultSet | close(): void | 关闭结果集。 | + +**数据库更改秘钥** + +用户可以对当前数据库进行加密。 + +数据库的加密仅限于初始使用一个数据库时就进行加密,使用过程中进行秘钥的变更,但不支持取消秘钥。 + +数据库初始时为加密库,则一直为加密库;初始时为未加密库,则一直为未加密库。 + +**表8** 数据库更改秘钥 + +| 类名 | 接口名 | 描述 | +| -------- | -------- | -------- | +| RdbStore | changeEncryptKey(newEncryptKey:Uint8Array, callback: AsyncCallback<number>):void; | 数据库更改秘钥接口,通过callback 可以异步处理返回结果。返回结果0成功,非0失败。 | +| RdbStore | changeEncryptKey(newEncryptKey:Uint8Array): Promise<number>; | 数据库更改秘钥接口,通过await 可以同步处理返回结果。返回结果0成功,非0失败。 | + + +## 开发步骤 + +1. 创建数据库。 + 1. 配置数据库相关信息,包括数据库的名称、存储模式、是否为只读模式等。 + 2. 初始化数据库表结构和相关数据。 + 3. 创建数据库。 + + 示例代码如下: + + ``` + import dataRdb 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 STORE_CONFIG = {name: "rdbstore.db",} + + let rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); + await rdbStore.executeSql(CREATE_TABLE_TEST); + ``` + +2. 插入数据。 + 1. 构造要插入的数据,以ValuesBucket形式存储。 + 2. 调用关系型数据库提供的插入接口。 + + 示例代码如下: + + ``` + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket = {"name": "Tom", "age": 18, "salary": 100.5, "blobType": u8,} + let insertPromise = rdbStore.insert("test", valueBucket) + ``` + +3. 查询数据。 + 1. 构造用于查询的谓词对象,设置查询条件。 + 2. 调用查询接口查询数据。 + 3. 调用结果集接口,返回查询结果。 + + 示例代码如下: + + ``` + let predicates = new dataRdb.RdbPredicates("test"); + predicates.equalTo("name", "Tom") + let resultSet = await rdbStore.query(predicates) + + resultSet.goToFirstRow() + const id = await resultSet.getLong(resultSet.getColumnIndex("id")) + const name = await resultSet.getString(resultSet.getColumnIndex("name")) + const age = await resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) + + resultSet.close() + ``` diff --git a/zh-cn/application-dev/database/database-relational-overview.md b/zh-cn/application-dev/database/database-relational-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..f9a84f85a03efcda86bac16424ecb82bfbe108de --- /dev/null +++ b/zh-cn/application-dev/database/database-relational-overview.md @@ -0,0 +1,41 @@ +# 关系型数据库概述 + +关系型数据库(Relational Database,RDB)是一种基于关系模型来管理数据的数据库。关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制,对外提供了一系列的增、删、改、查等接口,也可以直接运行用户输入的SQL语句来满足复杂的场景需要。 + +## 基本概念 + +- **关系型数据库** + + 基于关系模型来管理数据的数据库,以行和列的形式存储数据。 + +- **谓词** + + 数据库中用来代表数据实体的性质、特征或者数据实体之间关系的词项,主要用来定义数据库的操作条件。 + +- **结果集** + + 指用户查询之后的结果集合,可以对数据进行访问。结果集提供了灵活的数据访问方式,可以更方便的拿到用户想要的数据。 + +- **SQLite数据库** + + 一款遵守ACID的轻型开源关系型数据库管理系统。 + +## 运作机制 + +关系型数据库对外提供通用的操作接口,底层使用SQLite作为持久化存储引擎,支持SQLite具有的所有数据库特性,包括但不限于事务、索引、视图、触发器、外键、参数化查询和预编译SQL语句。 + +**图1** 关系型数据库运作机制 + +![how-rdb-works](figures/how-rdb-works.png) + +## 默认配置 + +- 如果不指定数据库的日志模式,那么系统默认日志方式是WAL(Write Ahead Log)模式。 +- 如果不指定数据库的落盘模式,那么系统默认落盘方式是FULL模式。 +- OpenHarmony数据库使用的共享内存默认大小是2MB。 + +## 约束与限制 + +- 数据库中连接池的最大数量是4个,用以管理用户的读操作。 + +- 为保证数据的准确性,数据库同一时间只能支持一个写操作。 \ No newline at end of file diff --git a/zh-cn/application-dev/database/figures/how-rdb-works.png b/zh-cn/application-dev/database/figures/how-rdb-works.png new file mode 100644 index 0000000000000000000000000000000000000000..e85411eef39281e3213d6b4697a8d32d2cecd9a2 Binary files /dev/null and b/zh-cn/application-dev/database/figures/how-rdb-works.png differ diff --git a/zh-cn/application-dev/database/figures/zh-cn_image_0000001199139454.png b/zh-cn/application-dev/database/figures/zh-cn_image_0000001199139454.png new file mode 100644 index 0000000000000000000000000000000000000000..5a6f6879944d0fda3cc24d7e726c842c74476728 Binary files /dev/null and b/zh-cn/application-dev/database/figures/zh-cn_image_0000001199139454.png differ diff --git a/zh-cn/application-dev/reference/apis/js-apis-hiappevent.md b/zh-cn/application-dev/reference/apis/js-apis-hiappevent.md index e0d5f8e146e5df63023b67a078e0c7d5edcb34a3..aec3024d35bcb5205f7d72e7a8bbb35de7b1453c 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-hiappevent.md +++ b/zh-cn/application-dev/reference/apis/js-apis-hiappevent.md @@ -11,9 +11,9 @@ import hiAppEvent from '@ohos.hiAppEvent'; ``` -## 权限 +## 系统能力 -无 +SystemCapability.HiviewDFX.HiAppEvent ## hiAppEvent.write