提交 5b59ac7a 编写于 作者: Z zengyawen

update docs

Signed-off-by: Nzengyawen <zengyawen1@huawei.com>
上级 eb4b61f9
# Agent-Powered Scheduled Reminders
- [Overview](background-agent-scheduled-reminder-overview.md)
- [Development Guidelines](background-agent-scheduled-reminder-guide.md)
# Overview<a name="EN-US_TOPIC_0000001139084594"></a>
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.
# 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
# RDB Overview<a name="EN-US_TOPIC_0000001231030607"></a>
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<a name="section1063573420813"></a>
- **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<a name="section4810552814"></a>
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<a name="fig1826214361535"></a>
![](figures/how-rdb-works.png "how-rdb-works")
## Default Settings<a name="section176091243121218"></a>
- 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 name="section929813398308"></a>
- 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.
# Lightweight Data Store Development<a name="EN-US_TOPIC_0000001230830543"></a>
## When to Use<a name="section13841104521714"></a>
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<a name="section15173156141712"></a>
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
<a name="table17310132152415"></a>
<table><thead align="left"><tr id="row93118212413"><th class="cellrowborder" valign="top" width="17.69%" id="mcps1.2.4.1.1"><p id="p031118214242"><a name="p031118214242"></a><a name="p031118214242"></a>Package Name</p>
</th>
<th class="cellrowborder" valign="top" width="28.249999999999996%" id="mcps1.2.4.1.2"><p id="p19311326245"><a name="p19311326245"></a><a name="p19311326245"></a>Method</p>
</th>
<th class="cellrowborder" valign="top" width="54.059999999999995%" id="mcps1.2.4.1.3"><p id="p1131118252418"><a name="p1131118252418"></a><a name="p1131118252418"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row38631245202910"><td class="cellrowborder" valign="top" width="17.69%" headers="mcps1.2.4.1.1 "><p id="p8365103153013"><a name="p8365103153013"></a><a name="p8365103153013"></a>ohos.data.storage</p>
</td>
<td class="cellrowborder" valign="top" width="28.249999999999996%" headers="mcps1.2.4.1.2 "><p id="p1937481213019"><a name="p1937481213019"></a><a name="p1937481213019"></a>getStorage(path: string): Promise&lt;Storage&gt;;</p>
</td>
<td class="cellrowborder" valign="top" width="54.059999999999995%" headers="mcps1.2.4.1.3 "><p id="p4311132162417"><a name="p4311132162417"></a><a name="p4311132162417"></a>Obtains the <strong id="b193911821194211"><a name="b193911821194211"></a><a name="b193911821194211"></a>Storage</strong> singleton corresponding to a file for data operations.</p>
</td>
</tr>
</tbody>
</table>
**Writing Data**
Call the **put\(\)** method to add or modify data in a **Storage** instance.
**Table 2** API for writing data
<a name="table52021841142013"></a>
<table><thead align="left"><tr id="row2202741122013"><th class="cellrowborder" valign="top" width="19.79%" id="mcps1.2.4.1.1"><p id="p12161443377"><a name="p12161443377"></a><a name="p12161443377"></a>Class</p>
</th>
<th class="cellrowborder" valign="top" width="37%" id="mcps1.2.4.1.2"><p id="p172028414205"><a name="p172028414205"></a><a name="p172028414205"></a>Method</p>
</th>
<th class="cellrowborder" valign="top" width="43.21%" id="mcps1.2.4.1.3"><p id="p162020415205"><a name="p162020415205"></a><a name="p162020415205"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row8203194115202"><td class="cellrowborder" valign="top" width="19.79%" headers="mcps1.2.4.1.1 "><p id="p31644311712"><a name="p31644311712"></a><a name="p31644311712"></a>Storage</p>
</td>
<td class="cellrowborder" valign="top" width="37%" headers="mcps1.2.4.1.2 "><p id="p105961650131617"><a name="p105961650131617"></a><a name="p105961650131617"></a>put(key: string, value: ValueType): Promise&lt;void&gt;;</p>
</td>
<td class="cellrowborder" valign="top" width="43.21%" headers="mcps1.2.4.1.3 "><p id="p127261044489"><a name="p127261044489"></a><a name="p127261044489"></a>Writes data of the number, string, and Boolean types.</p>
</td>
</tr>
</tbody>
</table>
**Reading Data**
Call the **get\(\)** method to read data from a **Storage** instance.
**Table 3** API for reading data
<a name="table182143189350"></a>
<table><thead align="left"><tr id="row173241118123511"><th class="cellrowborder" valign="top" width="18.04%" id="mcps1.2.4.1.1"><p id="p94819229584"><a name="p94819229584"></a><a name="p94819229584"></a>Class</p>
</th>
<th class="cellrowborder" valign="top" width="37.830000000000005%" id="mcps1.2.4.1.2"><p id="p18324181853514"><a name="p18324181853514"></a><a name="p18324181853514"></a>Method</p>
</th>
<th class="cellrowborder" valign="top" width="44.13%" id="mcps1.2.4.1.3"><p id="p11324131814355"><a name="p11324131814355"></a><a name="p11324131814355"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row18325141813350"><td class="cellrowborder" valign="top" width="18.04%" headers="mcps1.2.4.1.1 "><p id="p1448113223583"><a name="p1448113223583"></a><a name="p1448113223583"></a>Storage</p>
</td>
<td class="cellrowborder" valign="top" width="37.830000000000005%" headers="mcps1.2.4.1.2 "><p id="p1335031410172"><a name="p1335031410172"></a><a name="p1335031410172"></a>get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;;</p>
</td>
<td class="cellrowborder" valign="top" width="44.13%" headers="mcps1.2.4.1.3 "><p id="p11862123993920"><a name="p11862123993920"></a><a name="p11862123993920"></a>Reads data of the number, string, and Boolean types.</p>
</td>
</tr>
</tbody>
</table>
**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
<a name="table1290414100219"></a>
<table><thead align="left"><tr id="row690412101627"><th class="cellrowborder" valign="top" width="18.04%" id="mcps1.2.4.1.1"><p id="p1390414101929"><a name="p1390414101929"></a><a name="p1390414101929"></a>Class</p>
</th>
<th class="cellrowborder" valign="top" width="37.830000000000005%" id="mcps1.2.4.1.2"><p id="p59045104215"><a name="p59045104215"></a><a name="p59045104215"></a>Method</p>
</th>
<th class="cellrowborder" valign="top" width="44.13%" id="mcps1.2.4.1.3"><p id="p1190416106210"><a name="p1190416106210"></a><a name="p1190416106210"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row99041710923"><td class="cellrowborder" valign="top" width="18.04%" headers="mcps1.2.4.1.1 "><p id="p7904101018217"><a name="p7904101018217"></a><a name="p7904101018217"></a>Storage</p>
</td>
<td class="cellrowborder" valign="top" width="37.830000000000005%" headers="mcps1.2.4.1.2 "><p id="p1290418101218"><a name="p1290418101218"></a><a name="p1290418101218"></a>flush(): Promise&lt;void&gt;;</p>
</td>
<td class="cellrowborder" valign="top" width="44.13%" headers="mcps1.2.4.1.3 "><p id="p1234935810316"><a name="p1234935810316"></a><a name="p1234935810316"></a>Writes data in the <strong id="b263252724411"><a name="b263252724411"></a><a name="b263252724411"></a>Storage</strong> instance back to its file through an asynchronous thread.</p>
</td>
</tr>
</tbody>
</table>
**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
<a name="table6483954112110"></a>
<table><thead align="left"><tr id="row124847540217"><th class="cellrowborder" valign="top" width="17.849999999999998%" id="mcps1.2.4.1.1"><p id="p1210134212816"><a name="p1210134212816"></a><a name="p1210134212816"></a>Class</p>
</th>
<th class="cellrowborder" valign="top" width="42.34%" id="mcps1.2.4.1.2"><p id="p1848445472111"><a name="p1848445472111"></a><a name="p1848445472111"></a>Method</p>
</th>
<th class="cellrowborder" valign="top" width="39.81%" id="mcps1.2.4.1.3"><p id="p1848475414213"><a name="p1848475414213"></a><a name="p1848475414213"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row2048513546212"><td class="cellrowborder" valign="top" width="17.849999999999998%" headers="mcps1.2.4.1.1 "><p id="p17210342586"><a name="p17210342586"></a><a name="p17210342586"></a>Storage</p>
</td>
<td class="cellrowborder" valign="top" width="42.34%" headers="mcps1.2.4.1.2 "><p id="p124859540219"><a name="p124859540219"></a><a name="p124859540219"></a>on(type: 'change', callback: Callback&lt;StorageObserver&gt;): void;</p>
</td>
<td class="cellrowborder" valign="top" width="39.81%" headers="mcps1.2.4.1.3 "><p id="p1148505452114"><a name="p1148505452114"></a><a name="p1148505452114"></a>Subscribes to data changes.</p>
</td>
</tr>
<tr id="row24851554182111"><td class="cellrowborder" valign="top" width="17.849999999999998%" headers="mcps1.2.4.1.1 "><p id="p914241031014"><a name="p914241031014"></a><a name="p914241031014"></a>Storage</p>
</td>
<td class="cellrowborder" valign="top" width="42.34%" headers="mcps1.2.4.1.2 "><p id="p9929202151011"><a name="p9929202151011"></a><a name="p9929202151011"></a>off(type: 'change', callback: Callback&lt;StorageObserver&gt;): void;</p>
</td>
<td class="cellrowborder" valign="top" width="39.81%" headers="mcps1.2.4.1.3 "><p id="p54853548219"><a name="p54853548219"></a><a name="p54853548219"></a>Unsubscribes from data changes.</p>
</td>
</tr>
</tbody>
</table>
**Deleting Data**
Use the following APIs to delete a **Storage** instance or data file.
**Table 6** APIs for deleting data
<a name="table2445155152418"></a>
<table><thead align="left"><tr id="row164451856244"><th class="cellrowborder" valign="top" width="17.72%" id="mcps1.2.4.1.1"><p id="p8182648181513"><a name="p8182648181513"></a><a name="p8182648181513"></a>Package Name</p>
</th>
<th class="cellrowborder" valign="top" width="43.980000000000004%" id="mcps1.2.4.1.2"><p id="p184461952245"><a name="p184461952245"></a><a name="p184461952245"></a>Method</p>
</th>
<th class="cellrowborder" valign="top" width="38.3%" id="mcps1.2.4.1.3"><p id="p11446652246"><a name="p11446652246"></a><a name="p11446652246"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1644616517249"><td class="cellrowborder" valign="top" width="17.72%" headers="mcps1.2.4.1.1 "><p id="p318244815153"><a name="p318244815153"></a><a name="p318244815153"></a>ohos.data.storage</p>
</td>
<td class="cellrowborder" valign="top" width="43.980000000000004%" headers="mcps1.2.4.1.2 "><p id="p194461457246"><a name="p194461457246"></a><a name="p194461457246"></a>deleteStorage(path: string): Promise&lt;void&gt;;</p>
</td>
<td class="cellrowborder" valign="top" width="38.3%" headers="mcps1.2.4.1.3 "><p id="p19291149141220"><a name="p19291149141220"></a><a name="p19291149141220"></a>Deletes a <strong id="b16577722115210"><a name="b16577722115210"></a><a name="b16577722115210"></a>Storage</strong> instance from the cache and deletes its file from the device.</p>
</td>
</tr>
<tr id="row64461551242"><td class="cellrowborder" valign="top" width="17.72%" headers="mcps1.2.4.1.1 "><p id="p1918314488153"><a name="p1918314488153"></a><a name="p1918314488153"></a>ohos.data.storage</p>
</td>
<td class="cellrowborder" valign="top" width="43.980000000000004%" headers="mcps1.2.4.1.2 "><p id="p134467513248"><a name="p134467513248"></a><a name="p134467513248"></a>removeStorageFromCache(path: string): Promise&lt;void&gt;;</p>
</td>
<td class="cellrowborder" valign="top" width="38.3%" headers="mcps1.2.4.1.3 "><p id="p164461159247"><a name="p164461159247"></a><a name="p164461159247"></a>Deletes a <strong id="b12971117115417"><a name="b12971117115417"></a><a name="b12971117115417"></a>Storage</strong> instance from the cache to release memory.</p>
</td>
</tr>
</tbody>
</table>
## How to Develop<a name="section146940394256"></a>
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)
})
```
# Lightweight Data Store Overview<a name="EN-US_TOPIC_0000001230752103"></a>
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<a name="section1055404171115"></a>
- **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<a name="section682631371115"></a>
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<a name="fig1657785713509"></a>
![](figures/en-us_image_0000001199139454.png)
## Constraints<a name="section17243172883219"></a>
- **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.
......@@ -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)
# Context Module
## Applicable Devices
| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| SmartVision Device|
| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | ------------ |
| Context.getOrCreateLocalDir(callback: AsyncCallback\<string>) | Yes| Yes| Yes| Yes| No| No|
| Context.getOrCreateLocalDir() | Yes| Yes| Yes| Yes| No| No|
| Context.verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback\<number>) | Yes| Yes| Yes| Yes| No| No|
| Context.verifyPermission(permission: string, callback: AsyncCallback\<number>) | Yes| Yes| Yes| Yes| No| No|
| Context.verifyPermission(permission: string, options?: PermissionOptions) | Yes| Yes| Yes| Yes| No| No|
| Context.requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, resultCallback: AsyncCallback\<PermissionRequestResult>) | Yes| Yes| Yes| Yes| No| No|
| Context.getApplicationInfo(callback: AsyncCallback\<ApplicationInfo>) | Yes| Yes| Yes| Yes| No| No|
| Context.getApplicationInfo() | Yes| Yes| Yes| Yes| No| No|
| Context.getBundleName(callback: AsyncCallback\<string>) | Yes| Yes| Yes| Yes| No| No|
| Context.getBundleName() | Yes| Yes| Yes| Yes| No| No|
| Context.getProcessInfo(callback: AsyncCallback\<ProcessInfo>) | Yes| Yes| Yes| Yes| No| No|
| Context.getProcessInfo() | Yes| Yes| Yes| Yes| No| No|
| Context.getElementName(callback: AsyncCallback\<ElementName>) | Yes| Yes| Yes| Yes| No| No|
| Context.getElementName() | Yes| Yes| Yes| Yes| No| No|
| Context.getProcessName(callback: AsyncCallback\<string>) | Yes| Yes| Yes| Yes| No| No|
| Context.getProcessName() | Yes| Yes| Yes| Yes| No| No|
| Context.getCallingBundle(callback: AsyncCallback\<string>) | Yes| Yes| Yes| Yes| No| No|
| Context.getCallingBundle() | Yes| Yes| Yes| Yes| No| No|
## Modules to Import
```js
......
......@@ -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\<void>) | Yes| Yes| Yes| Yes| No|
| CommonEvent.publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\<void>) | Yes| Yes| Yes| Yes| No|
| CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\<CommonEventSubscriber>) | Yes| Yes| Yes| Yes| No|
| CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo) | Yes| Yes| Yes| Yes| No|
| CommonEvent.subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEventData>) | Yes| Yes| Yes| Yes| No|
| CommonEvent.unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>) | Yes| Yes| Yes| Yes| No|
## Required Permissions
| Common Event Macro| Common Event Name| Subscriber Permissions|
......
此差异已折叠。
### 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\<number>) | 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\<void>) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.off(type: 'dataChange', uri: string, callback?: AsyncCallback\<void>) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array\<string>>) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.getFileTypes(uri: string, mimeTypeFilter: string) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.getType(uri: string, callback: AsyncCallback\<string>) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.getType(uri: string) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\<string>) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.normalizeUri(uri: string) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.denormalizeUri(uri: string, callback: AsyncCallback\<string>) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.denormalizeUri(uri: string) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.notifyChange(uri: string, callback: AsyncCallback\<void>) | 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\<number>) | 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<rdb.ValuesBucket>, callback: AsyncCallback\<number>) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>) | 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\<number>) | 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\<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<ResultSet>) | Yes| Yes| Yes| Yes| No| No|
| DataAbilityHelper.query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates) | Yes| Yes| Yes| Yes| No| No|
# DataAbilityHelper Module (JavaScript SDK APIs)
#### Modules to Import
......
# FeatureAbility Module (JavaScript)
#### Applicable Devices
| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| SmartVision Device|
| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | ------------ |
| FeatureAbility.startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>): void | Yes| Yes| Yes| Yes| No| No|
| FeatureAbility.startAbility(parameter: StartAbilityParameter): Promise\<number> | Yes| Yes| Yes| Yes| No| No|
| FeatureAbility.acquireDataAbilityHelper(uri: string): DataAbilityHelper | Yes| Yes| Yes| Yes| No| No|
| FeatureAbility.startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\<AbilityResult>): void | Yes| Yes| Yes| Yes| No| No|
| FeatureAbility.startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult> | Yes| Yes| Yes| Yes| No| No|
| FeatureAbility.terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>): void | Yes| Yes| Yes| Yes| No| No|
| FeatureAbility.terminateSelfWithResult(parameter: AbilityResult): Promise\<void> | Yes| Yes| Yes| Yes| No| No|
| FeatureAbility.hasWindowFocus(callback: AsyncCallback\<boolean>): void | Yes| Yes| Yes| Yes| No| No|
| FeatureAbility.hasWindowFocus(): Promise\<boolean> | Yes| Yes| Yes| Yes| No| No|
| FeatureAbility.getWant(callback: AsyncCallback\<Want>) | 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>): void | Yes| Yes| Yes| Yes| No| No|
| FeatureAbility.terminateSelf(): Promise\<void> | 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>): void | Yes| Yes| Yes| Yes| No| No|
| FeatureAbility.disconnectAbility(connection: number): Promise\<void> | Yes| Yes| Yes| Yes| No| No|
#### Constraints
APIs of the **FeatureAbility** module can be called only by Page abilities.
......
# Notification Module
## Applicable Devices
| API | Phone | Tablet | Smart TV | Wearable |
| ------------------------------------------------------------ | ---- | ---- | ------ | -------- |
| Notification.publish(request: NotificationRequest, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.publish(request: NotificationRequest) | Yes | Yes | Yes | Yes |
| Notification.cancel(id: number, label: string, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.cancel(id:number, label?:string) | Yes | Yes | Yes | Yes |
| Notification.cancel(id: number, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.cancelAll(callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.cancelAll() | Yes | Yes | Yes | Yes |
| Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.addSlot(slot: NotificationSlot) | Yes | Yes | Yes | Yes |
| Notification.addSlot(type: SlotType, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.addSlot(type: SlotType) | Yes | Yes | Yes | Yes |
| Notification.addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.addSlots(slots: Array\<NotificationSlot\>) | Yes | Yes | Yes | Yes |
| Notification.getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>) | Yes | Yes | Yes | Yes |
| Notification.getSlot(slotType: SlotType) | Yes | Yes | Yes | Yes |
| Notification.getSlots(callback: AsyncCallback<Array\<NotificationSlot\>>) | Yes | Yes | Yes | Yes |
| Notification.getSlots() | Yes | Yes | Yes | Yes |
| Notification.removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.removeSlot(slotType: SlotType) | Yes | Yes | Yes | Yes |
| Notification.removeAllSlots(callback: AsyncCallback\<void\>): void | Yes | Yes | Yes | Yes |
| Notification.removeAllSlots(): Promise\<void\> | Yes | Yes | Yes | Yes |
| Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo) | Yes | Yes | Yes | Yes |
| Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.unsubscribe(subscriber: NotificationSubscriber) | Yes | Yes | Yes | Yes |
| Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.enableNotification(bundle: BundleOption, enable: boolean) | Yes | Yes | Yes | Yes |
| Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>) | Yes | Yes | Yes | Yes |
| Notification.isNotificationEnabled(bundle: BundleOption) | Yes | Yes | Yes | Yes |
| Notification.isNotificationEnabled(callback: AsyncCallback\<boolean\>) | Yes | Yes | Yes | Yes |
| Notification.isNotificationEnabled() | Yes | Yes | Yes | Yes |
| Notification.displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.displayBadge(bundle: BundleOption, enable: boolean) | Yes | Yes | Yes | Yes |
| Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>) | Yes | Yes | Yes | Yes |
| Notification.isBadgeDisplayed(bundle: BundleOption) | Yes | Yes | Yes | Yes |
| Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot) | Yes | Yes | Yes | Yes |
| Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<NotificationSlot\>>) | Yes | Yes | Yes | Yes |
| Notification.getSlotsByBundle(bundle: BundleOption) | Yes | Yes | Yes | Yes |
| Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>) | Yes | Yes | Yes | Yes |
| Notification.getSlotNumByBundle(bundle: BundleOption) | Yes | Yes | Yes | Yes |
| Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.remove(bundle: BundleOption, notificationKey: NotificationKey) | Yes | Yes | Yes | Yes |
| Notification.remove(hashCode: string, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.remove(hashCode: string) | Yes | Yes | Yes | Yes |
| Notification.removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.removeAll(callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.removeAll(bundle?: BundleOption) | Yes | Yes | Yes | Yes |
| Notification.getAllActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>) | Yes | Yes | Yes | Yes |
| Notification.getAllActiveNotifications() | Yes | Yes | Yes | Yes |
| Notification.getActiveNotificationCount(callback: AsyncCallback\<number\>) | Yes | Yes | Yes | Yes |
| Notification.getActiveNotificationCount() | Yes | Yes | Yes | Yes |
| Notification.getActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>) | Yes | Yes | Yes | Yes |
| Notification.getActiveNotifications() | Yes | Yes | Yes | Yes |
| Notification.cancelGroup(groupName: string, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.cancelGroup(groupName: string) | Yes | Yes | Yes | Yes |
| Notification.removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.removeGroupByBundle(bundle: BundleOption, groupName: string) | Yes | Yes | Yes | Yes |
| Notification.setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| Notification.setDoNotDisturbDate(date: DoNotDisturbDate) | Yes | Yes | Yes | Yes |
| Notification.getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>) | Yes | Yes | Yes | Yes |
| Notification.getDoNotDisturbDate() | Yes | Yes | Yes | Yes |
| Notification.supportDoNotDisturbMode(callback: AsyncCallback\<boolean\>) | Yes | Yes | Yes | Yes |
| Notification.supportDoNotDisturbMode() | Yes | Yes | Yes | Yes |
| WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>) | Yes | Yes | Yes | Yes |
| WantAgent.getWantAgent(info: WantAgentInfo): Promise\<WantAgent\> | Yes | Yes | Yes | Yes |
| WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>) | Yes | Yes | Yes | Yes |
| WantAgent.getBundleName(agent: WantAgent): Promise\<string\> | Yes | Yes | Yes | Yes |
| WantAgent.getUid(agent: WantAgent, callback: AsyncCallback\<number\>) | Yes | Yes | Yes | Yes |
| WantAgent.getUid(agent: WantAgent): Promise\<number\> | Yes | Yes | Yes | Yes |
| WantAgent.getWant(agent: WantAgent, callback: AsyncCallback\<Want\>) | Yes | Yes | Yes | Yes |
| WantAgent.getWant(agent: WantAgent): Promise\<Want\> | Yes | Yes | Yes | Yes |
| WantAgent.cancel(agent: WantAgent, callback: AsyncCallback\<void\>) | Yes | Yes | Yes | Yes |
| WantAgent.cancel(agent: WantAgent): Promise\<void\> | Yes | Yes | Yes | Yes |
| WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\<CompleteData\>) | Yes | Yes | Yes | Yes |
| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>) | Yes | Yes | Yes | Yes |
| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\> | Yes | Yes | Yes | Yes |
## Required Permissions
......
# ParticleAbility Module
## Applicable Devices
| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| SmartVision Device|
| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | ------------ |
| particleAbility.startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<void>: void | Yes| Yes| Yes| Yes| No| No|
| particleAbility.startAbility(parameter: StartAbilityParameter): Promise\<number> | Yes| Yes| Yes| Yes| No| No|
| particleAbility.terminateSelf(callback: AsyncCallback\<void>): void | Yes| Yes| Yes| Yes| No| No|
| particleAbility.terminateSelf(): Promise\<void> | 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>): void | Yes| Yes| Yes| Yes| No| No|
| particleAbility.disconnectAbility(connection: number): Promise\<void> | Yes| Yes| Yes| Yes| No| No|
## Constraints
The ParticleAbility module is used to perform operations on abilities of the Data and Service types.
......
# Resource Manager<a name="EN-US_TOPIC_0000001200042191"></a>
# Resource Manager<a name="EN-US_TOPIC_0000001192428610"></a>
>![](../../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<a name="s56d19203690d4782bfc74069abb6bd71"></a>
```
......@@ -362,8 +362,6 @@ Enumerates screen density types.
Provides the device configuration.
### Attributes<a name="section254242964810"></a>
<a name="table1459620431636"></a>
<table><thead align="left"><tr id="row25971143435"><th class="cellrowborder" valign="top" width="15.870000000000001%" id="mcps1.1.6.1.1"><p id="p1559716434320"><a name="p1559716434320"></a><a name="p1559716434320"></a>Name</p>
</th>
......@@ -406,8 +404,6 @@ Provides the device configuration.
Provides the device capability.
### Attributes<a name="section2201153419440"></a>
<a name="table16201103444414"></a>
<table><thead align="left"><tr id="row620123444415"><th class="cellrowborder" valign="top" width="15.870000000000001%" id="mcps1.1.6.1.1"><p id="p1620163494418"><a name="p1620163494418"></a><a name="p1620163494418"></a>Name</p>
</th>
......@@ -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<a name="section9779153419548"></a>
getString\(resId: number, callback: AsyncCallback<string\>\): 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
</thead>
<tbody><tr id="row119261820145419"><td class="cellrowborder" valign="top" width="20.05%" headers="mcps1.1.3.1.1 "><p id="p179309445393"><a name="p179309445393"></a><a name="p179309445393"></a>Promise&lt;Array&lt;string&gt;&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="79.95%" headers="mcps1.1.3.1.2 "><p id="p139301144153915"><a name="p139301144153915"></a><a name="p139301144153915"></a>Array of character strings corresponding to the specified resource ID.</p>
<td class="cellrowborder" valign="top" width="79.95%" headers="mcps1.1.3.1.2 "><p id="p139301144153915"><a name="p139301144153915"></a><a name="p139301144153915"></a>Array of strings corresponding to the specified resource ID.</p>
</td>
</tr>
</tbody>
......@@ -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
</tr>
<tr id="row1971112524019"><td class="cellrowborder" valign="top" width="7.901402961808262%" headers="mcps1.1.5.1.1 "><p id="p27111125204017"><a name="p27111125204017"></a><a name="p27111125204017"></a>callback</p>
</td>
<td class="cellrowborder" valign="top" width="25.565081839438818%" headers="mcps1.1.5.1.2 "><p id="p1371152514409"><a name="p1371152514409"></a><a name="p1371152514409"></a>AsyncCallback&lt;Array&lt;Uint8Array&gt;&gt;</p>
<td class="cellrowborder" valign="top" width="25.565081839438818%" headers="mcps1.1.5.1.2 "><p id="p1371152514409"><a name="p1371152514409"></a><a name="p1371152514409"></a>AsyncCallback&lt;Uint8Array&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="6.819953234606392%" headers="mcps1.1.5.1.3 "><p id="p13711625124019"><a name="p13711625124019"></a><a name="p13711625124019"></a>Yes</p>
</td>
......@@ -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
</th>
</tr>
</thead>
<tbody><tr id="row9713142554012"><td class="cellrowborder" valign="top" width="23.02%" headers="mcps1.1.3.1.1 "><p id="p1071352554019"><a name="p1071352554019"></a><a name="p1071352554019"></a>Promise&lt;Array&lt;Uint8Array&gt;&gt;</p>
<tbody><tr id="row9713142554012"><td class="cellrowborder" valign="top" width="23.02%" headers="mcps1.1.3.1.1 "><p id="p1071352554019"><a name="p1071352554019"></a><a name="p1071352554019"></a>Promise&lt;Uint8Array&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="76.98%" headers="mcps1.1.3.1.2 "><p id="p8713192517405"><a name="p8713192517405"></a><a name="p8713192517405"></a>Promise used to return the content of the obtained media file.</p>
</td>
......@@ -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
```
### getRawFile<sup>8+</sup><a name="section95073471466"></a>
getRawFile\(path: string, callback: AsyncCallback<Uint8Array\>\): void
Obtains the content of rawfile in the specified path. This method uses an asynchronous callback to return the result.
- Parameters
<a name="table15072471264"></a>
<table><thead align="left"><tr id="row1550784715616"><th class="cellrowborder" valign="top" width="7.901402961808262%" id="mcps1.1.5.1.1"><p id="p1650720473611"><a name="p1650720473611"></a><a name="p1650720473611"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="25.565081839438818%" id="mcps1.1.5.1.2"><p id="p1850710478614"><a name="p1850710478614"></a><a name="p1850710478614"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="6.819953234606392%" id="mcps1.1.5.1.3"><p id="p7508247962"><a name="p7508247962"></a><a name="p7508247962"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="59.713561964146535%" id="mcps1.1.5.1.4"><p id="p1250816471565"><a name="p1250816471565"></a><a name="p1250816471565"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row205084473617"><td class="cellrowborder" valign="top" width="7.901402961808262%" headers="mcps1.1.5.1.1 "><p id="p12508144716615"><a name="p12508144716615"></a><a name="p12508144716615"></a>path</p>
</td>
<td class="cellrowborder" valign="top" width="25.565081839438818%" headers="mcps1.1.5.1.2 "><p id="p45085471768"><a name="p45085471768"></a><a name="p45085471768"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="6.819953234606392%" headers="mcps1.1.5.1.3 "><p id="p1150834716613"><a name="p1150834716613"></a><a name="p1150834716613"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="59.713561964146535%" headers="mcps1.1.5.1.4 "><p id="p950814719617"><a name="p950814719617"></a><a name="p950814719617"></a>Path of the rawfile.</p>
</td>
</tr>
<tr id="row145082471163"><td class="cellrowborder" valign="top" width="7.901402961808262%" headers="mcps1.1.5.1.1 "><p id="p145081347867"><a name="p145081347867"></a><a name="p145081347867"></a>callback</p>
</td>
<td class="cellrowborder" valign="top" width="25.565081839438818%" headers="mcps1.1.5.1.2 "><p id="p550814471615"><a name="p550814471615"></a><a name="p550814471615"></a>AsyncCallback&lt;Uint8Array&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="6.819953234606392%" headers="mcps1.1.5.1.3 "><p id="p1450884713612"><a name="p1450884713612"></a><a name="p1450884713612"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="59.713561964146535%" headers="mcps1.1.5.1.4 "><p id="p150864719611"><a name="p150864719611"></a><a name="p150864719611"></a> Asynchronous callback used to return the rawfile content, in byte arrays.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
resourceManager.getResourceManager((error, mgr) => {
mgr.getRawFile("test.xml", (error, value) => {
if (error != null) {
console.log(value);
} else {
console.log(value);
}
});
});
```
### getRawFile<sup>8+</sup><a name="section53115315102"></a>
getRawFile\(path: string\): Promise<Uint8Array\>
Obtains the content of the rawfile in the specified path. This method uses a promise to return the result.
- Parameters
<a name="table73111831141015"></a>
<table><thead align="left"><tr id="row1311143131013"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p1631163171011"><a name="p1631163171011"></a><a name="p1631163171011"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="14.729999999999999%" id="mcps1.1.5.1.2"><p id="p431193191013"><a name="p431193191013"></a><a name="p431193191013"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="9.16%" id="mcps1.1.5.1.3"><p id="p131114317106"><a name="p131114317106"></a><a name="p131114317106"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.5.1.4"><p id="p1531211312104"><a name="p1531211312104"></a><a name="p1531211312104"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1331263131011"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p1531223111011"><a name="p1531223111011"></a><a name="p1531223111011"></a>path</p>
</td>
<td class="cellrowborder" valign="top" width="14.729999999999999%" headers="mcps1.1.5.1.2 "><p id="p173121931151016"><a name="p173121931151016"></a><a name="p173121931151016"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="9.16%" headers="mcps1.1.5.1.3 "><p id="p12312173118102"><a name="p12312173118102"></a><a name="p12312173118102"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p13312163141013"><a name="p13312163141013"></a><a name="p13312163141013"></a>Path of the rawfile.</p>
</td>
</tr>
</tbody>
</table>
- Return values
<a name="table6312113112103"></a>
<table><thead align="left"><tr id="row12312231101015"><th class="cellrowborder" valign="top" width="34.339999999999996%" id="mcps1.1.3.1.1"><p id="p19312173112109"><a name="p19312173112109"></a><a name="p19312173112109"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="65.66%" id="mcps1.1.3.1.2"><p id="p1431223161016"><a name="p1431223161016"></a><a name="p1431223161016"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row12312431151011"><td class="cellrowborder" valign="top" width="34.339999999999996%" headers="mcps1.1.3.1.1 "><p id="p14312113119102"><a name="p14312113119102"></a><a name="p14312113119102"></a>Promise&lt;Uint8Array&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="65.66%" headers="mcps1.1.3.1.2 "><p id="p43128317109"><a name="p43128317109"></a><a name="p43128317109"></a> Promise used to return the rawfile content, in byte arrays.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
resourceManager.getResourceManager((error, mgr) => {
mgr.getRawFile("test.xml").then(value => {
console.log(value);
}).catch(error => {
console.log("getrawfile promise " + error);
});
});
```
......@@ -3,30 +3,6 @@
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>The APIs of this module are supported since API version 7.
## Applicable Devices<a name="section16881239114912"></a>
<a name="table857714145377"></a>
<table><thead align="left"><tr id="row55778146373"><th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.1"><p id="p7577141417376"><a name="p7577141417376"></a><a name="p7577141417376"></a>Phone</p>
</th>
<th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.2"><p id="p487719816463"><a name="p487719816463"></a><a name="p487719816463"></a>Tablet</p>
</th>
<th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.3"><p id="p135771614203720"><a name="p135771614203720"></a><a name="p135771614203720"></a>Smart TV</p>
</th>
<th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.4"><p id="p25772014133712"><a name="p25772014133712"></a><a name="p25772014133712"></a>Wearable</p>
</th>
</tr>
</thead>
<tbody><tr id="row8578151423715"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.1 "><p id="p65782014203718"><a name="p65782014203718"></a><a name="p65782014203718"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.2 "><p id="p148771182469"><a name="p148771182469"></a><a name="p148771182469"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.3 "><p id="p45783141377"><a name="p45783141377"></a><a name="p45783141377"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.4 "><p id="p11578161443718"><a name="p11578161443718"></a><a name="p11578161443718"></a>Yes</p>
</td>
</tr>
</tbody>
</table>
## Modules to Import<a name="s56d19203690d4782bfc74069abb6bd71"></a>
......
此差异已折叠。
......@@ -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<a name="section16881239114912"></a>
<a name="table857714145377"></a>
<table><thead align="left"><tr id="row55778146373"><th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.1"><p id="p7577141417376"><a name="p7577141417376"></a><a name="p7577141417376"></a>Phone</p>
</th>
<th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.2"><p id="p487719816463"><a name="p487719816463"></a><a name="p487719816463"></a>Tablet</p>
</th>
<th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.3"><p id="p135771614203720"><a name="p135771614203720"></a><a name="p135771614203720"></a>Smart TV</p>
</th>
<th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.4"><p id="p25772014133712"><a name="p25772014133712"></a><a name="p25772014133712"></a>Wearable</p>
</th>
</tr>
</thead>
<tbody><tr id="row8578151423715"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.1 "><p id="p65782014203718"><a name="p65782014203718"></a><a name="p65782014203718"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.2 "><p id="p148771182469"><a name="p148771182469"></a><a name="p148771182469"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.3 "><p id="p45783141377"><a name="p45783141377"></a><a name="p45783141377"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.4 "><p id="p11578161443718"><a name="p11578161443718"></a><a name="p11578161443718"></a>No</p>
</td>
</tr>
</tbody>
</table>
## Modules to Import<a name="s56d19203690d4782bfc74069abb6bd71"></a>
......
# Worker Startup<a name="EN-US_TOPIC_0000001172830331"></a>
>![](../../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<a name="s56d19203690d4782bfc74069abb6bd71"></a>
......@@ -131,13 +131,13 @@ A constructor used to create a worker instance.
- Return values
<a name="table362855181117"></a>
<table><thead align="left"><tr id="row1462255191114"><th class="cellrowborder" valign="top" width="20.990000000000002%" id="mcps1.1.3.1.1"><p id="p1621355121115"><a name="p1621355121115"></a><a name="p1621355121115"></a>Name</p>
<table><thead align="left"><tr id="row1462255191114"><th class="cellrowborder" valign="top" width="20.990000000000002%" id="mcps1.1.3.1.1"><p id="p1621355121115"><a name="p1621355121115"></a><a name="p1621355121115"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="79.01%" id="mcps1.1.3.1.2"><p id="p16295571119"><a name="p16295571119"></a><a name="p16295571119"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row116275516110"><td class="cellrowborder" valign="top" width="20.990000000000002%" headers="mcps1.1.3.1.1 "><p id="p76295515112"><a name="p76295515112"></a><a name="p76295515112"></a>worker</p>
<tbody><tr id="row116275516110"><td class="cellrowborder" valign="top" width="20.990000000000002%" headers="mcps1.1.3.1.1 "><p id="p76295515112"><a name="p76295515112"></a><a name="p76295515112"></a>Worker</p>
</td>
<td class="cellrowborder" valign="top" width="79.01%" headers="mcps1.1.3.1.2 "><p id="p362195531112"><a name="p362195531112"></a><a name="p362195531112"></a>Returns the worker instance created; returns <strong id="b49535319421"><a name="b49535319421"></a><a name="b49535319421"></a>undefined</strong> if the worker instance fails to be created.</p>
</td>
......@@ -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
<a name="table4536208105515"></a>
<table><thead align="left"><tr id="row25360810551"><th class="cellrowborder" valign="top" width="20.990000000000002%" id="mcps1.1.3.1.1"><p id="p2536685552"><a name="p2536685552"></a><a name="p2536685552"></a>Name</p>
<table><thead align="left"><tr id="row25360810551"><th class="cellrowborder" valign="top" width="20.990000000000002%" id="mcps1.1.3.1.1"><p id="p2536685552"><a name="p2536685552"></a><a name="p2536685552"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="79.01%" id="mcps1.1.3.1.2"><p id="p185371287554"><a name="p185371287554"></a><a name="p185371287554"></a>Description</p>
</th>
......@@ -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
<a name="t3e93239d9b134b80957bcdd4acb05291"></a>
<table><thead align="left"><tr id="recc81d9f995d44aa87ba9d714b756569"><th class="cellrowborder" valign="top" width="21.84%" id="mcps1.1.3.1.1"><p id="aa3137ce511d140fba6cc93513a7a91e3"><a name="aa3137ce511d140fba6cc93513a7a91e3"></a><a name="aa3137ce511d140fba6cc93513a7a91e3"></a>Name</p>
<table><thead align="left"><tr id="recc81d9f995d44aa87ba9d714b756569"><th class="cellrowborder" valign="top" width="21.84%" id="mcps1.1.3.1.1"><p id="aa3137ce511d140fba6cc93513a7a91e3"><a name="aa3137ce511d140fba6cc93513a7a91e3"></a><a name="aa3137ce511d140fba6cc93513a7a91e3"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="78.16%" id="mcps1.1.3.1.2"><p id="a4ba8ead9ee7b48298d9a6ed10659f13b"><a name="a4ba8ead9ee7b48298d9a6ed10659f13b"></a><a name="a4ba8ead9ee7b48298d9a6ed10659f13b"></a>Description</p>
</th>
......@@ -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
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册