提交 a999e60e 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 c77d9a92
...@@ -13,7 +13,7 @@ The **DataShare** module allows an application to manage its own data and share ...@@ -13,7 +13,7 @@ The **DataShare** module allows an application to manage its own data and share
|query?(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;Object&gt;): void|Queries data from the database.| |query?(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;Object&gt;): void|Queries data from the database.|
|delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback&lt;number&gt;): void|Deletes data from the database.| |delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback&lt;number&gt;): void|Deletes data from the database.|
For details about the data provider APIs, see [DataShareExtensionAbility](../reference/apis/js-apis-application-DataShareExtensionAbility.md). For details about the data provider APIs, see [DataShareExtensionAbility](../reference/apis/js-apis-application-dataShareExtensionAbility.md).
**Table 2** APIs of the data consumer **Table 2** APIs of the data consumer
...@@ -34,11 +34,52 @@ There are two roles in **DataShare**: ...@@ -34,11 +34,52 @@ There are two roles in **DataShare**:
- Data provider: adds, deletes, modifies, and queries data, opens files, and shares data. - Data provider: adds, deletes, modifies, and queries data, opens files, and shares data.
- Data consumer: accesses the data provided by the provider using **DataShareHelper**. - Data consumer: accesses the data provided by the provider using **DataShareHelper**.
Examples are given below.
### Data Provider Application Development (Only for System Applications) ### Data Provider Application Development (Only for System Applications)
1. Import dependencies. [DataShareExtensionAbility](../reference/apis/js-apis-application-dataShareExtensionAbility.md) provides the following APIs. You can override these APIs as required.
- **onCreate**
Called by the server to initialize service logic when the **DataShare** client connects to the **DataShareExtensionAbility** server. This method can be overridden as required.
- **insert**
Inserts data. This API is called when the client requests to insert data.
- **update**
Updates data. This API is called when the client requests to update data.
- **delete**
Deletes data. This API is called when the client requests to delete data.
- **query**
Queries data. This API is called when the client requests to query data.
- **batchInsert**
Batch inserts data. This API is called when the client requests to batch insert data.
- **normalizeUri**
Converts the URI provided by the client to the URI used by the server.
- **denormalizeUri**
Converts the URI used by the server to the initial URI passed by the client.
Before implementing a **DataShare** service, you need to create a **DataShareExtensionAbility** object in the DevEco Studio project as follows:
1. In the **ets** directory of the **Module** project, right-click and choose **New > Directory** to create a directory named **DataShareAbility**.
2. Right-click the **DataShareAbility** directory, and choose **New > TypeScript File** to create a file named **DataShareAbility.ts**.
3. In the **DataShareAbility.ts** file, import the **DataShareExtensionAbility** dependency package. You can override the service implementation as required. For example, if the data provider provides only the services for inserting, deleting, and querying data, you can override **insert()**, **delete()**, and **query()** only.
4. Import dependencies.
```ts ```ts
import Extension from '@ohos.application.DataShareExtensionAbility'; import Extension from '@ohos.application.DataShareExtensionAbility';
...@@ -47,9 +88,9 @@ Examples are given below. ...@@ -47,9 +88,9 @@ Examples are given below.
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
``` ```
2. Override **DataShareExtensionAbility** APIs based on actual requirements. For example, if the data provider provides only data query, override only **query()**. 5. Override **DataShareExtensionAbility** APIs based on actual requirements. For example, if the data provider provides only data query, override only **query()**.
3. Implement the data provider services. For example, implement data storage of the data provider by using a database, reading and writing files, or accessing the network. 6. Implement the data provider services. For example, implement data storage of the data provider by using a database, reading and writing files, or accessing the network.
```ts ```ts
const DB_NAME = "DB00.db"; const DB_NAME = "DB00.db";
...@@ -66,7 +107,7 @@ Examples are given below. ...@@ -66,7 +107,7 @@ Examples are given below.
// Override onCreate(). // Override onCreate().
onCreate(want, callback) { onCreate(want, callback) {
result = this.context.cacheDir + '/datashare.txt' result = this.context.cacheDir + '/datashare.txt';
// Create an RDB store. // Create an RDB store.
rdb.getRdbStore(this.context, { rdb.getRdbStore(this.context, {
name: DB_NAME, name: DB_NAME,
...@@ -76,7 +117,9 @@ Examples are given below. ...@@ -76,7 +117,9 @@ Examples are given below.
rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) { rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) {
console.log('DataShareExtAbility onCreate, executeSql done err:' + JSON.stringify(err)); console.log('DataShareExtAbility onCreate, executeSql done err:' + JSON.stringify(err));
}); });
if (callback) {
callback(); callback();
}
}); });
} }
...@@ -103,7 +146,7 @@ Examples are given below. ...@@ -103,7 +146,7 @@ Examples are given below.
}; };
``` ```
4. Define **DataShareExtensionAbility** in **module.json5**. 7. Define **DataShareExtensionAbility** in **module.json5**.
| Field| Description | | Field| Description |
| ------------ | ------------------------------------------------------------ | | ------------ | ------------------------------------------------------------ |
...@@ -133,7 +176,7 @@ Examples are given below. ...@@ -133,7 +176,7 @@ Examples are given below.
1. Import dependencies. 1. Import dependencies.
```ts ```ts
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
import dataShare from '@ohos.data.dataShare'; import dataShare from '@ohos.data.dataShare';
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
``` ```
...@@ -151,7 +194,7 @@ Examples are given below. ...@@ -151,7 +194,7 @@ Examples are given below.
let dsHelper; let dsHelper;
let abilityContext; let abilityContext;
export default class MainAbility extends Ability { export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
abilityContext = this.context; abilityContext = this.context;
dataShare.createDataShareHelper(abilityContext, dseUri, (err, data)=>{ dataShare.createDataShareHelper(abilityContext, dseUri, (err, data)=>{
...@@ -168,7 +211,7 @@ Examples are given below. ...@@ -168,7 +211,7 @@ Examples are given below.
let valuesBucket = { "name": "ZhangSan", "age": 21, "isStudent": false, "Binary": new Uint8Array([1, 2, 3]) }; let valuesBucket = { "name": "ZhangSan", "age": 21, "isStudent": false, "Binary": new Uint8Array([1, 2, 3]) };
let updateBucket = { "name": "LiSi", "age": 18, "isStudent": true, "Binary": new Uint8Array([1, 2, 3]) }; let updateBucket = { "name": "LiSi", "age": 18, "isStudent": true, "Binary": new Uint8Array([1, 2, 3]) };
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
let valArray = new Array("*"); let valArray = ['*'];
// Insert a piece of data. // Insert a piece of data.
dsHelper.insert(dseUri, valuesBucket, (err, data) => { dsHelper.insert(dseUri, valuesBucket, (err, data) => {
console.log("dsHelper insert result: " + data); console.log("dsHelper insert result: " + data);
...@@ -186,4 +229,3 @@ Examples are given below. ...@@ -186,4 +229,3 @@ Examples are given below.
console.log("dsHelper delete result: " + data); console.log("dsHelper delete result: " + data);
}); });
``` ```
...@@ -14,12 +14,12 @@ For details about the APIs, see [Distributed KV Store](../reference/apis/js-apis ...@@ -14,12 +14,12 @@ For details about the APIs, see [Distributed KV Store](../reference/apis/js-apis
| API | Description | | API | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ | | ------------------------------------------------------------ | ------------------------------------------------------------ |
| createKVManager(config: KVManagerConfig, callback: AsyncCallback&lt;KVManager&gt;): void<br>createKVManager(config: KVManagerConfig): Promise&lt;KVManager> | Creates a **KvManager** object for database management. | | createKVManager(config: KVManagerConfig, callback: AsyncCallback&lt;KVManager&gt;): void<br>createKVManager(config: KVManagerConfig): Promise&lt;KVManager> | Creates a **KvManager** object for database management. |
| getKVStore&lt;TextendsKVStore&gt;(storeId: string, options: Options, callback: AsyncCallback&lt;T&gt;): void<br>getKVStore&lt;TextendsKVStore&gt;(storeId: string, options: Options): Promise&lt;T&gt; | Creates and obtains a KV store.| | getKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options, callback: AsyncCallback&lt;T&gt;): void<br>getKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options): Promise&lt;T&gt; | Creates and obtains a KV store.|
| put(key: string, value: Uint8Array\|string\|number\|boolean, callback: AsyncCallback&lt;void&gt;): void<br>put(key: string, value: Uint8Array\|string\|number\|boolean): Promise&lt;void> | Inserts and updates data. | | put(key: string, value: Uint8Array\|string\|number\|boolean, callback: AsyncCallback&lt;void&gt;): void<br>put(key: string, value: Uint8Array\|string\|number\|boolean): Promise&lt;void> | Inserts and updates data. |
| delete(key: string, callback: AsyncCallback&lt;void&gt;): void<br>delete(key: string): Promise&lt;void> | Deletes data. | | delete(key: string, callback: AsyncCallback&lt;void&gt;): void<br>delete(key: string): Promise&lt;void> | Deletes data. |
| get(key: string, callback: AsyncCallback&lt;Uint8Array\|string\|boolean\|number&gt;): void<br>get(key: string): Promise&lt;Uint8Array\|string\|boolean\|number> | Queries data. | | get(key: string, callback: AsyncCallback&lt;Uint8Array\|string\|boolean\|number&gt;): void<br>get(key: string): Promise&lt;Uint8Array\|string\|boolean\|number> | Obtains data. |
| on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;ChangeNotification&gt;): void<br>on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string,number]&gt;&gt;): void | Subscribes to data changes in the KV store. | | on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;ChangeNotification&gt;): void<br>on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string,number]&gt;&gt;): void | Subscribes to data changes in the KV store. |
| sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void | Triggers database synchronization in manual mode. | | sync(deviceIdList: string[], mode: SyncMode, delayMs?: number): void | Triggers database synchronization in manual mode. |
## How to Develop ## How to Develop
...@@ -61,29 +61,29 @@ The following uses a single KV store as an example to describe the development p ...@@ -61,29 +61,29 @@ The following uses a single KV store as an example to describe the development p
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666).then((data) => { context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666).then((data) => {
console.info('success: ${data}'); console.info('success: ${data}');
}).catch((error) => { }).catch((error) => {
console.info('failed: ${error}'); console.error('failed: ${error}');
}) })
} }
grantPermission(); grantPermission();
// Stage model // Stage model
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null; let context = null;
function grantPermission() { class EntryAbility extends UIAbility {
class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
let context = this.context; let context = this.context;
} }
} }
function grantPermission() {
let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC']; let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC'];
context.requestPermissionsFromUser(permissions).then((data) => { context.requestPermissionsFromUser(permissions).then((data) => {
console.log('success: ${data}'); console.log('success: ${data}');
}).catch((error) => { }).catch((error) => {
console.log('failed: ${error}'); console.error('failed: ${error}');
}); });
} }
...@@ -103,9 +103,9 @@ The following uses a single KV store as an example to describe the development p ...@@ -103,9 +103,9 @@ The following uses a single KV store as an example to describe the development p
let context = featureAbility.getContext(); let context = featureAbility.getContext();
// Obtain the context of the stage model. // Obtain the context of the stage model.
import AbilityStage from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null; let context = null;
class MainAbility extends AbilityStage{ class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context; context = this.context;
} }
...@@ -119,7 +119,7 @@ The following uses a single KV store as an example to describe the development p ...@@ -119,7 +119,7 @@ The following uses a single KV store as an example to describe the development p
} }
distributedKVStore.createKVManager(kvManagerConfig, function (err, manager) { distributedKVStore.createKVManager(kvManagerConfig, function (err, manager) {
if (err) { if (err) {
console.error(`Failed to create KVManager.code is ${err.code},message is ${err.message}`); console.error(`Failed to createKVManager.code is ${err.code},message is ${err.message}`);
return; return;
} }
console.log('Created KVManager successfully'); console.log('Created KVManager successfully');
......
...@@ -113,10 +113,10 @@ You can use the following APIs to delete a **Preferences** instance or data file ...@@ -113,10 +113,10 @@ You can use the following APIs to delete a **Preferences** instance or data file
```ts ```ts
// Obtain the context. // Obtain the context.
import Ability from '@ohos.application.Ability' import UIAbility from '@ohos.app.ability.UIAbility'
let context = null; let context = null;
let preferences = null; let preferences = null;
export default class MainAbility extends Ability { export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context; context = this.context;
} }
...@@ -159,7 +159,7 @@ You can use the following APIs to delete a **Preferences** instance or data file ...@@ -159,7 +159,7 @@ You can use the following APIs to delete a **Preferences** instance or data file
5. Store data persistently. 5. Store data persistently.
Use **flush()** to flush data from the **Preferences** instance to its file. Use **preferences.flush()** to flush data from the **Preferences** instance to its file.
```js ```js
preferences.flush(); preferences.flush();
...@@ -200,6 +200,6 @@ You can use the following APIs to delete a **Preferences** instance or data file ...@@ -200,6 +200,6 @@ You can use the following APIs to delete a **Preferences** instance or data file
proDelete.then(() => { proDelete.then(() => {
console.info("Deleted data successfully."); console.info("Deleted data successfully.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to delete data. Cause: " + err); console.info("Failed to delete. Cause: " + err);
}) })
``` ```
# @ohos.data.dataShare (DataShare) # @ohos.data.dataShare (Data Sharing)
The **DataShare** module allows an application to manage its own data and share data with other applications on the same device. The **DataShare** module allows an application to manage its own data and share data with other applications on the same device.
...@@ -37,18 +37,12 @@ Example: ...@@ -37,18 +37,12 @@ Example:
**com.samples.datasharetest.DataShare** is the data share identifier, and **DB00/TBL00** is the resource path. **com.samples.datasharetest.DataShare** is the data share identifier, and **DB00/TBL00** is the resource path.
## dataShare.createDataShareHelper ## dataShare.createDataShareHelper
createDataShareHelper(context: Context, uri: string, callback: AsyncCallback&lt;DataShareHelper&gt;): void createDataShareHelper(context: Context, uri: string, callback: AsyncCallback&lt;DataShareHelper&gt;): void
Creates a **DataShareHelper** instance. This API uses an asynchronous callback to return the result. Creates a **DataShareHelper** instance. This API uses an asynchronous callback to return the result.
Observe the following when using this API:
- If an application running in the background needs to call this API to access **DataShareExtension**, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
- If **visible** of the target **DataShareExtension** is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
- For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer
**Parameters** **Parameters**
...@@ -70,7 +64,7 @@ For details about the error codes, see [DataShare Error Codes](../errorcodes/err ...@@ -70,7 +64,7 @@ For details about the error codes, see [DataShare Error Codes](../errorcodes/err
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let dataShareHelper; let dataShareHelper;
...@@ -94,11 +88,6 @@ createDataShareHelper(context: Context, uri: string): Promise&lt;DataShareHelper ...@@ -94,11 +88,6 @@ createDataShareHelper(context: Context, uri: string): Promise&lt;DataShareHelper
Creates a **DataShareHelper** instance. This API uses a promise to return the result. Creates a **DataShareHelper** instance. This API uses a promise to return the result.
Observe the following when using this API:
- If an application running in the background needs to call this API to access **DataShareExtension**, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission.
- If **visible** of the target **DataShareExtension** is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission.
- For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md).
**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer
**Parameters** **Parameters**
...@@ -125,7 +114,7 @@ For details about the error codes, see [DataShare Error Codes](../errorcodes/err ...@@ -125,7 +114,7 @@ For details about the error codes, see [DataShare Error Codes](../errorcodes/err
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let dataShareHelper; let dataShareHelper;
...@@ -164,8 +153,7 @@ Subscribes to changes of the specified data. After an observer is registered, th ...@@ -164,8 +153,7 @@ Subscribes to changes of the specified data. After an observer is registered, th
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
function onCallback() { function onCallback() {
console.info("**** Observer on callback ****"); console.info("**** Observer on callback ****");
} }
...@@ -187,13 +175,12 @@ Unsubscribes from the changes of the specified data. This API uses an asynchrono ...@@ -187,13 +175,12 @@ Unsubscribes from the changes of the specified data. This API uses an asynchrono
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------------ |
| type | string | Yes | Event type to unsubscribe from. The value is **dataChange**, which indicates data change events.| | type | string | Yes | Event type to unsubscribe from. The value is **dataChange**, which indicates data change events.|
| uri | string | Yes | URI of the data.| | uri | string | Yes | URI of the data.|
| callback | AsyncCallback&lt;void&gt; | No | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | No | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
function offCallback() { function offCallback() {
console.info("**** Observer off callback ****"); console.info("**** Observer off callback ****");
} }
...@@ -220,8 +207,7 @@ Inserts a single data record into the database. This API uses an asynchronous ca ...@@ -220,8 +207,7 @@ Inserts a single data record into the database. This API uses an asynchronous ca
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
const valueBucket = { const valueBucket = {
"name": "rose", "name": "rose",
...@@ -265,8 +251,7 @@ Inserts a single data record into the database. This API uses a promise to retur ...@@ -265,8 +251,7 @@ Inserts a single data record into the database. This API uses a promise to retur
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
const valueBucket = { const valueBucket = {
"name": "rose1", "name": "rose1",
...@@ -303,8 +288,8 @@ Deletes one or more data records from the database. This API uses an asynchronou ...@@ -303,8 +288,8 @@ Deletes one or more data records from the database. This API uses an asynchronou
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let da = new dataSharePredicates.DataSharePredicates(); let da = new dataSharePredicates.DataSharePredicates();
...@@ -346,8 +331,8 @@ Deletes one or more data records from the database. This API uses a promise to r ...@@ -346,8 +331,8 @@ Deletes one or more data records from the database. This API uses a promise to r
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let da = new dataSharePredicates.DataSharePredicates(); let da = new dataSharePredicates.DataSharePredicates();
...@@ -383,8 +368,8 @@ Queries data in the database. This API uses an asynchronous callback to return t ...@@ -383,8 +368,8 @@ Queries data in the database. This API uses an asynchronous callback to return t
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let columns = ["*"]; let columns = ["*"];
...@@ -428,8 +413,8 @@ Queries data in the database. This API uses a promise to return the result. ...@@ -428,8 +413,8 @@ Queries data in the database. This API uses a promise to return the result.
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let columns = ["*"]; let columns = ["*"];
...@@ -466,8 +451,8 @@ Updates data in the database. This API uses an asynchronous callback to return t ...@@ -466,8 +451,8 @@ Updates data in the database. This API uses an asynchronous callback to return t
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let da = new dataSharePredicates.DataSharePredicates(); let da = new dataSharePredicates.DataSharePredicates();
...@@ -516,8 +501,8 @@ Updates data in the database. This API uses a promise to return the result. ...@@ -516,8 +501,8 @@ Updates data in the database. This API uses a promise to return the result.
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let da = new dataSharePredicates.DataSharePredicates(); let da = new dataSharePredicates.DataSharePredicates();
...@@ -558,8 +543,7 @@ Batch inserts data into the database. This API uses an asynchronous callback to ...@@ -558,8 +543,7 @@ Batch inserts data into the database. This API uses an asynchronous callback to
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,}, let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,},
{"name": "roe12", "age": 21, "salary": 20.5,}, {"name": "roe12", "age": 21, "salary": 20.5,},
...@@ -601,8 +585,7 @@ Batch inserts data into the database. This API uses a promise to return the resu ...@@ -601,8 +585,7 @@ Batch inserts data into the database. This API uses a promise to return the resu
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,}, let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,},
{"name": "roe12", "age": 21, "salary": 20.5,}, {"name": "roe12", "age": 21, "salary": 20.5,},
...@@ -636,8 +619,7 @@ Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the lo ...@@ -636,8 +619,7 @@ Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the lo
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.normalizeUri(uri, (err, data) => { dataShareHelper.normalizeUri(uri, (err, data) => {
if (err != undefined) { if (err != undefined) {
...@@ -671,8 +653,7 @@ Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the lo ...@@ -671,8 +653,7 @@ Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the lo
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.normalizeUri(uri).then((data) => { dataShareHelper.normalizeUri(uri).then((data) => {
console.log("normalizeUri = " + data); console.log("normalizeUri = " + data);
...@@ -699,8 +680,7 @@ Denormalizes a URI. This API uses an asynchronous callback to return the result. ...@@ -699,8 +680,7 @@ Denormalizes a URI. This API uses an asynchronous callback to return the result.
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.denormalizeUri(uri, (err, data) => { dataShareHelper.denormalizeUri(uri, (err, data) => {
if (err != undefined) { if (err != undefined) {
...@@ -734,8 +714,7 @@ Denormalizes a URI. This API uses a promise to return the result. ...@@ -734,8 +714,7 @@ Denormalizes a URI. This API uses a promise to return the result.
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.denormalizeUri(uri).then((data) => { dataShareHelper.denormalizeUri(uri).then((data) => {
console.log("denormalizeUri = " + data); console.log("denormalizeUri = " + data);
...@@ -762,8 +741,7 @@ Notifies the registered observer of data changes. This API uses an asynchronous ...@@ -762,8 +741,7 @@ Notifies the registered observer of data changes. This API uses an asynchronous
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.notifyChange(uri, () => { dataShareHelper.notifyChange(uri, () => {
console.log("***** notifyChange *****"); console.log("***** notifyChange *****");
...@@ -793,8 +771,7 @@ Notifies the registered observer of data changes. This API uses a promise to ret ...@@ -793,8 +771,7 @@ Notifies the registered observer of data changes. This API uses a promise to ret
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility'
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.notifyChange(uri); dataShareHelper.notifyChange(uri);
``` ```
...@@ -38,7 +38,7 @@ Obtains a **Preferences** instance. This API uses an asynchronous callback to re ...@@ -38,7 +38,7 @@ Obtains a **Preferences** instance. This API uses an asynchronous callback to re
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
| name | string | Yes | Name of the **Preferences** instance.| | name | string | Yes | Name of the **Preferences** instance.|
| callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **object** is the **Preferences** instance obtained. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **object** is the **Preferences** instance obtained. Otherwise, **err** is an error code.|
...@@ -69,9 +69,9 @@ Stage model: ...@@ -69,9 +69,9 @@ Stage model:
```ts ```ts
// Obtain the context. // Obtain the context.
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null; let context = null;
class MainAbility extends Ability{ class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context; context = this.context;
} }
...@@ -103,7 +103,7 @@ Obtains a **Preferences** instance. This API uses a promise to return the result ...@@ -103,7 +103,7 @@ Obtains a **Preferences** instance. This API uses a promise to return the result
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | ----------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
| name | string | Yes | Name of the **Preferences** instance.| | name | string | Yes | Name of the **Preferences** instance.|
**Return value** **Return value**
...@@ -139,9 +139,9 @@ Stage model: ...@@ -139,9 +139,9 @@ Stage model:
```ts ```ts
// Obtain the context. // Obtain the context.
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null; let context = null;
class MainAbility extends Ability{ class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context; context = this.context;
} }
...@@ -177,7 +177,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi ...@@ -177,7 +177,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- | | -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
| name | string | Yes | Name of the **Preferences** instance to delete. | | name | string | Yes | Name of the **Preferences** instance to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
...@@ -215,9 +215,9 @@ Stage model: ...@@ -215,9 +215,9 @@ Stage model:
```ts ```ts
// Obtain the context. // Obtain the context.
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null; let context = null;
class MainAbility extends Ability{ class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context; context = this.context;
} }
...@@ -252,7 +252,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi ...@@ -252,7 +252,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | ----------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
| name | string | Yes | Name of the **Preferences** instance to delete.| | name | string | Yes | Name of the **Preferences** instance to delete.|
**Return value** **Return value**
...@@ -294,9 +294,9 @@ Stage model: ...@@ -294,9 +294,9 @@ Stage model:
```ts ```ts
// Obtain the context. // Obtain the context.
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null; let context = null;
class MainAbility extends Ability{ class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context; context = this.context;
} }
...@@ -328,7 +328,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi ...@@ -328,7 +328,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- | | -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
| name | string | Yes | Name of the **Preferences** instance to remove. | | name | string | Yes | Name of the **Preferences** instance to remove. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
...@@ -358,9 +358,9 @@ Stage model: ...@@ -358,9 +358,9 @@ Stage model:
```ts ```ts
// Obtain the context. // Obtain the context.
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null; let context = null;
class MainAbility extends Ability{ class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context; context = this.context;
} }
...@@ -394,7 +394,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi ...@@ -394,7 +394,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | ----------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
| name | string | Yes | Name of the **Preferences** instance to remove.| | name | string | Yes | Name of the **Preferences** instance to remove.|
**Return value** **Return value**
...@@ -428,9 +428,9 @@ Stage model: ...@@ -428,9 +428,9 @@ Stage model:
```ts ```ts
// Obtain the context. // Obtain the context.
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null; let context = null;
class MainAbility extends Ability{ class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context; context = this.context;
} }
...@@ -662,7 +662,7 @@ try { ...@@ -662,7 +662,7 @@ try {
has(key: string, callback: AsyncCallback&lt;boolean&gt;): void has(key: string, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses an asynchronous callback to return the result.. Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -698,7 +698,7 @@ try { ...@@ -698,7 +698,7 @@ try {
has(key: string): Promise&lt;boolean&gt; has(key: string): Promise&lt;boolean&gt;
Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses a promise to return the result.. Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -987,7 +987,7 @@ Unsubscribes from data changes. ...@@ -987,7 +987,7 @@ Unsubscribes from data changes.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------- | ---- | ------------------------------------------ | | -------- | -------------------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Event type to unsubscribe from. The value **change** indicates data change events. | | type | string | Yes | Event type to unsubscribe from. The value **change** indicates data change events. |
| callback | Callback&lt;{ key : string }&gt; | No | Callback to unregister. If this parameter is left blank, the callbacks used to subscribing to all data changes will be unregistered.| | callback | Callback&lt;{ key : string }&gt; | No | Callback to unregister. If this parameter is left blank, all callbacks for data changes will be unregistered. |
**Example** **Example**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册