未验证 提交 8d874f4b 编写于 作者: O openharmony_ci 提交者: Gitee

!1461 update docs

Merge pull request !1461 from zengyawen/master
......@@ -8,8 +8,13 @@
- [JavaScript-based Web-like Development Paradigm](ui/ui-arkui-js.md)
- [TypeScript-based Declarative Development Paradigm](ui/ui-arkui-ts.md)
- [Agent-Powered Scheduled Reminders ](background-agent-scheduled-reminder/Readme-EN.md)
- [Background Task Management ](background-task-management/Readme-EN.md)
- [Media](media/Readme-EN.md)
- [Security](security/Readme-EN.md)
- [IPC & RPC](connectivity/ipc-rpc.md)
- [Data Management](database/Readme-EN.md)
- [USB Service](usb/Readme-EN.md)
- [DFX](dfx/Readme-EN.md)
- [Development References](reference/Readme-EN.md)
- [JavaScript-based Web-like Development Paradigm](reference/arkui-js/Readme-EN.md)
......
# 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.
# Background Task Management
- [Background Task Management Overview](background-task-overview.md)
- [Background Task Management Development](background-task-dev-guide.md)
\ No newline at end of file
# 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.
# Media
- [Audio](audio.md)
- Audio
- [Audio Overview](audio-overview.md)
- [Audio Playback Development](audio-playback.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)
# 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>
......
此差异已折叠。
......@@ -8,10 +8,12 @@
- 方舟开发框架(ArkUI)
- [基于JS扩展的类Web开发范式](ui/ui-arkui-js.md)
- [基于TS扩展的声明式开发范式](ui/ui-arkui-ts.md)
- [后台代理提醒](background-agent-scheduled-reminder/Readme-CN.md)
- [后台任务管理](background-task-management/Readme-CN.md)
- [媒体](media/Readme-CN.md)
- [安全](security/Readme-CN.md)
- [IPC与RPC通信](connectivity/ipc-rpc.md)
- [分布式数据服务](database/Readme-CN.md)
- [数据管理](database/Readme-CN.md)
- [USB服务](usb/Readme-CN.md)
- [DFX](dfx/Readme-CN.md)
- [开发参考](reference/Readme-CN.md)
......
# 后台任务管理
- 后台任务
- [后台任务概述](background-task-overview.md)
- [后台任务开发指导](background-task-dev-guide.md)
\ No newline at end of file
# 概述
# 后台任务概述
对于有用户交互的OS来说,资源优先分配给与用户交互的业务进程,换句话说,在支撑OS运行的进程以外,用户能感知到的业务进程优先级最高,所以后台任务管理的范围是用户感知不到的业务进程。
......
# 分布式数据服务
# 数据管理
- [分布式数据服务概述](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)
# 轻量级数据存储开发指导
## 场景介绍
轻量级数据存储功能通常用于保存应用的一些常用配置信息,并不适合需要存储大量数据和频繁改变数据的场景。应用的数据保存在文件中,这些文件可以持久化地存储在设备上。需要注意的是,应用访问的实例包含文件所有数据,这些数据会一直加载在设备的内存中,直到应用主动从内存中将其移除前,应用可以通过Storage的API进行数据操作。
## 接口说明
轻量级存储为应用提供key-value键值型的文件数据处理能力,支持应用对数据进行轻量级存储及查询。数据存储形式为键值对,键的类型为字符串型,值的存储数据类型包括数字型、字符型、布尔型。
**创建存储实例**
读取指定文件,将数据加载到Storage实例,即可创建一个存储实例,用于数据操作。
**表1** 轻量级数据存储实例创建接口
| 包名 | 接口名 | 描述 |
| ----------------- | ------------------------------------------- | ------------------------------------------- |
| ohos.data.storage | getStorage(path: string): Promise\<Storage> | 获取文件对应的Storage单实例,用于数据操作。 |
**存入数据**
通过put系列方法,可以增加或修改Storage实例中的数据。
**表2** 轻量级数据存入接口
| 类名 | 接口名 | 描述 |
| ------- | -------------------------------------------------- | ----------------------------------------------- |
| Storage | put(key: string, value: ValueType): Promise\<void> | 支持值为number、string、boolean类型的数据存入。 |
**读取数据**
通过调用get系列方法,可以读取Storage中的数据。
**表3** 轻量级数据读取接口
| 类名 | 接口名 | 描述 |
| ------- | ---------------------------------------------------------- | ----------------------------------------------- |
| Storage | get(key: string, defValue: ValueType): Promise\<ValueType> | 支持获取值为number、string、boolean类型的数据。 |
**数据持久化**
通过执行flush方法,应用可以将缓存的数据再次写回文本文件中进行持久化存储。
**表4** 轻量级数据持久化接口
| 类名 | 接口名 | 描述 |
| ------- | ----------------------- | --------------------------------------- |
| Storage | flush(): Promise\<void> | 将Storage实例通过异步线程回写入文件中。 |
**订阅数据变化**
订阅数据变化需要指定StorageObserver作为回调方法。订阅的key的值发生变更后,当执行flush方法时,StorageObserver被回调。
**表5** 轻量级数据变化订阅接口
| 类名 | 接口名 | 描述 |
| ------- | ------------------------------------------------------------ | -------------- |
| Storage | on(type: 'change', callback: Callback\<StorageObserver>): void | 订阅数据变化。 |
| Storage | off(type: 'change', callback: Callback\<StorageObserver>): void | 注销订阅。 |
**删除数据文件**
通过调用以下两种接口,可以删除数据实例或对应的文件。
**表6** 轻量级数据存储删除接口
| 包名 | 接口名 | 描述 |
| ----------------- | ---------------------------------------------------- | ------------------------------------------------------------ |
| ohos.data.storage | deleteStorage(path: string): Promise\<void> | 从缓存中移除已加载的Storage对象,同时从设备上删除对应的文件。 |
| ohos.data.storage | removeStorageFromCache(path: string): Promise\<void> | 仅从缓存中移除已加载的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
# 轻量级数据存储概述
轻量级数据存储适用于对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
......@@ -11,9 +11,9 @@ import hiAppEvent from '@ohos.hiAppEvent';
```
## 权限
## 系统能力
SystemCapability.HiviewDFX.HiAppEvent
## hiAppEvent.write
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册