share-device-data-across-apps-overview.md 3.0 KB
Newer Older
1
# Cross-Application Data Sharing Overview
A
Annie_wang 已提交
2 3 4

## Function

5
The application data on a device, such as the Contacts, short message service (SMS), and Gallery data, always needs to be shared with other applications. However, certain data, such as the accounts and passwords, cannot be shared. Certain data, such as SMS messages, can be accessed but not modified by other applications. The **DataShare**  module provides a secure and easy-to-use mechanism for sharing data of an application with other applications on the same device.
A
Annie_wang 已提交
6

7
## Basic Concepts
A
Annie_wang 已提交
8

9
Before developing cross-application data sharing on a device, understand the following concepts:
A
Annie_wang 已提交
10

11
- Data provider: an application that provides data and implements related services. It is also called the data producer or server.
A
Annie_wang 已提交
12

13
- Data consumer: an application that accesses the data or services provided by the data provider. It is also called the client.
A
Annie_wang 已提交
14

15
- **ValuesBucket**: a set of data to be inserted. It can be one or more data records in KV pairs. In each KV pair, the key must be of the string type, and the value can be a number, a string, a Boolean value, or an unsigned integer array.
A
Annie_wang 已提交
16

17
- **ResultSet**: a set of query results. It provides flexible modes for obtaining various data.
A
Annie_wang 已提交
18

19
- **Predicates**: an object that specifies the conditions for updating, deleting, or querying data in a database.
A
Annie_wang 已提交
20 21


22
## Implementation
A
Annie_wang 已提交
23

24
The data provider can directly use **DataShare** to share data with other applications without complex encapsulation. The data consumer only needs to use a set of APIs to access the data, because the **DataShare** access mode does not vary with the data provisioning mode. This greatly reduces the learning time and development difficulty.
A
Annie_wang 已提交
25

26
The cross-application data sharing can be implemented in either of the following ways:
A
Annie_wang 已提交
27

28
- **DataShareExtensionAbility**
A
Annie_wang 已提交
29

30
  You can implement an ExtensionAbility with a callback in the HAP. When the data consumer calls an API, the ExtensionAbility of the data provider will be automatically started to invoke the registered callback.
A
Annie_wang 已提交
31

32
  This method is recommended when the cross-application data access involves service operations other than mere addition, deletion, modification, and query of data in databases.
A
Annie_wang 已提交
33

34 35 36 37 38
- Silent access

  You can configure database access rules in the HAP. When the data consumer calls an API, the system ability automatically obtains the access rules in the HAP and returns data without starting the data provider.

  This method is recommended when the cross-application data access involves only the operations for adding, deleting, modifying, and querying data in databases.
A
Annie_wang 已提交
39 40 41 42


## Constraints

43
- **DataShare** is subject to the limitations on the database used by the data provider. The supported data models, length of the keys and values, and maximum number of databases that can be accessed at a time by each application vary with the database in use.
A
Annie_wang 已提交
44

45
- The payloads of **ValuesBucket**, **Predicates**, and **ResultSet** are restricted by inter-process communication (IPC).
A
Annie_wang 已提交
46 47

- Currently, **dataShare** supports development based on the stage model only.