README.md
1# applications_contactsdata<a name="ZH-CN_TOPIC_0000001122925147"></a>
2
3- [Introduction](#section1166054159366)
4- [Image architecture](#section1619419895966)
5- [Directory Structure](#section161941989596)
6- [Repositories Involved](#section1371113476307)
7
8## Introduction<a name="section1166054159366"></a>
9
10The contact database application is an indispensable information management applicationS for every user to manage the contact database.
11Its content is very important for user managers, so the contact database should be able to provide sufficient information and quick
12query means for each user's management, which greatly helps users to reasonably manage the contact database information.
13
14## Image architecture<a name="section1619419895966"></a>
15
16![](figures/Image_architecture.png)
17
18## Directory Structure<a name="section161941989596"></a>
19
20```
21/foundation/contactsdataability/
22├── ability
23│ ├── account #Account Management
24│ ├── common #Public Methods
25│ ├── datadisasterrecovery #Data Corruption Recovery
26│ ├── merge #Contacts Merge
27│ └── sinicization #Chinese Characters to Pinyin Related
28├── contacts #NAPI
29├── dataBusiness
30│ ├── calllog #Call Records
31│ ├── contacts #Contacts Person
32│ ├── quicksearch #Quick Search
33│ └── voicemail #Voicemail
34├── test #Test Catalog
35├── BUILD.gn
36└── ohos.build
37```
38
39## Repositories Involved<a name="section1371113476307"></a>
40
41system applications
42
43applications_contactsdata
README_zh.md
1# 联系人数据库子系统
2# applications_contactsdata
3
4- [简介](#section1166054159366)
5- [架构图](#section1619419895966)
6- [目录](#section161941989596)
7- [相关仓](#section1371113476307)
8
9## 简介<a name="section1166054159366"></a>
10
11联系人数据库应用是每一个用户管理联系人数据库的不可缺少的一个信息管理应用,
12它的内容对于用户管理者来说是至关重要的,所以联系人数据库应该能够为每一个
13用户的管理提供充足的信息和快捷查询手段,大大方便用户合理的管理联系人数据库信息。
14
15## 架构图<a name="section1619419895966"></a>
16
17![](figures/Image_architecture_zh.png)
18
19## 目录<a name="section161941989596"></a>
20
21```
22/foundation/contactsdataability/
23├── ability
24│ ├── account #账户管理
25│ ├── common #公共方法:log,utils等
26│ ├── datadisasterrecovery #数据损坏恢复
27│ ├── merge #联系人合并
28│ └── sinicization #汉字转拼音相关
29├── contacts #NAPI
30├── dataBusiness
31│ ├── calllog #通话记录
32│ ├── contacts #联系人
33│ ├── quicksearch #快速检索
34│ └── voicemail #语音信箱
35├── test #测试目录
36├── BUILD.gn
37└── ohos.build
38```
39## 使用说明
40
41### 概述
42
43提供联系人数据和通话记录以及语音信箱增、删、改、查、等接口。
44接口参数主要有string类型的uri和对象类型的value、DataSharePredicates
45
46使用功能接口前,需要导入相关模块。
47
48```js
49import dataShare from '@ohos.data.dataShare';
50```
51### 通话记录
52
53#### dataShareHelper.insert(uri: string, value: ValuesBucket)
54
55- 接口说明
56
57 通话记录插入
58
59- insert参数描述
60
61 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
62 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
63 | uri | 只读 | string | 是 | 具体操作的uri |
64 | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
65
66返回值为 通话记录id
67
68更新示例
69```js
70import dataShare from '@ohos.data.dataShare';
71var calllogData = "datashare:///com.ohos.calllogability";
72var calllogUri = "datashare:///com.ohos.calllogability/calls/calllog";
73var value = {"phone_number" : "xxxxx","display_name" : "xxx"};
74// 获取dataShareHelper
75let dataShareHelper = dataShare.createDataShareHelper(calllogData);
76// 调用insert方法
77dataShareHelper.insert(calllogUri, value).then((data) => {
78 console.info("calllogId = " + data);
79});
80```
81#### dataShareHelper.update(uri: string, condition: DataSharePredicates, value: ValuesBucket)
82
83- 接口说明
84
85 通话记录修改
86
87- update参数描述
88
89 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
90 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
91 | uri | 只读 | string | 是 | 具体操作的uri |
92 | condition | 只读 | DataSharePredicates | 是 | 更新条件 |
93 | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
94
95返回值为 成功为0否则为-1
96
97修改示例
98```js
99import dataShare from '@ohos.data.dataShare';
100var calllogData = "datashare:///com.ohos.calllogability";
101var calllogUri = "datashare:///com.ohos.calllogability/calls/calllog";
102var value = {"phone_number" : "xxxxx","display_name" : "xxx"};
103// 获取dataShareHelper
104let dataShareHelper = dataShare.createDataShareHelper(calllogData);
105// 条件参数
106let condition = new dataShare.DataSharePredicates();
107condition.equalTo("id", "xxx");
108// 调用update方法
109dataShareHelper.update(calllogUri, value, condition).then((data) => {
110 console.info("resultCode = " + data);
111});
112```
113
114#### dataShareHelper.delete(uri: string, condition: DataSharePredicates)
115
116- 接口说明
117
118 通话记录删除
119
120- delete参数描述
121
122 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
123 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
124 | uri | 只读 | string | 是 | 具体操作的uri |
125 | condition | 只读 | DataSharePredicates | 是 | 删除条件 |
126
127返回值为 成功为0否则为-1
128
129删除示例
130```js
131import dataShare from '@ohos.data.dataShare';
132var calllogData = "datashare:///com.ohos.calllogability";
133var calllogUri = "datashare:///com.ohos.calllogability/calls/calllog";
134// 获取dataShareHelper
135let dataShareHelper = dataShare.createDataShareHelper(calllogData);
136// 条件参数
137let condition = new dataShare.DataSharePredicates();
138condition.equalTo("id", "xxx");
139// 调用delete方法
140dataShareHelper.delete(calllogUri, condition).then((data) => {
141 console.info("deleteCode = " + data);
142});
143```
144
145#### dataShareHelper.query(uri: string, condition: DataSharePredicates, resultColumns: array)
146
147- 接口说明
148
149 通话记录查询
150
151- 查询参数描述
152
153 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
154 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
155 | uri | 只读 | string | 是 | 具体操作的uri |
156 | condition | 只读 | DataSharePredicates | 是 | 查询条件 |
157 | resultColumns | 只读 | array | 是 | 需要查询的列字段名称 |
158
159返回值为 ResultSet 查询结果集
160
161查询示例
162```js
163import dataShare from '@ohos.data.dataShare';
164var calllogData = "datashare:///com.ohos.calllogability";
165var calllogUri = "datashare:///com.ohos.calllogability/calls/calllog";
166// 获取dataShareHelper
167let dataShareHelper = dataShare.createDataShareHelper(calllogData);
168// 条件参数
169let condition = new dataShare.DataSharePredicates();
170condition.equalTo("id", "xxx");
171var resultColumns = [ "id", "display_name", "phone_number"];
172// 调用query方法
173dataShareHelper.query(calllogUri, resultColumns, condition).then((resultSet) => {
174 if (resultSet.goToFirstRow()) {
175 do {
176 var displayName = resultSet.getString(resultSet.getColumnIndex("display_name"));
177 var id = resultSet.getLong(resultSet.getColumnIndex("id"));
178 var phoneNumber = resultSet.getString(resultSet.getColumnIndex("phone_number"));
179 } while (resultSet.goToNextRow());
180 }
181 resultSet.close();
182});
183```
184返回值为 ResultSet 查询结果集
185
186### 语音信箱
187
188#### dataShareHelper.insert(uri: string, value: ValuesBucket)
189
190- 接口说明
191
192 语音信箱插入
193
194- insert参数描述
195
196 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
197 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
198 | uri | 只读 | string | 是 | 具体操作的uri |
199 | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
200
201返回值为 语音信箱表id
202
203更新示例
204```js
205import dataShare from '@ohos.data.dataShare';
206var voicemailData = "datashare:///com.ohos.voicemailability";
207var voicemailUri = "datashare:///com.ohos.voicemailability/calls/voicemail";
208var value = {"phone_number" : "xxxxx","display_name" : "xxx"};
209// 获取dataShareHelper
210let dataShareHelper = dataShare.createDataShareHelper(voicemailData);
211// 调用insert方法
212dataShareHelper.insert(voicemailUri, value).then((data) => {
213 console.info("calllogId = " + data);
214});
215```
216#### dataShareHelper.update(uri: string, condition:DataSharePredicates, value: ValuesBucket)
217
218- 接口说明
219
220 语音信箱修改
221
222- update参数描述
223
224 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
225 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
226 | uri | 只读 | string | 是 | 具体操作的uri |
227 | condition | 只读 | DataSharePredicates | 是 | 更新条件 |
228 | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
229
230返回值为 成功为0否则为-1
231
232修改示例
233```js
234import dataShare from '@ohos.data.dataShare';
235var voicemailData = "datashare:///com.ohos.voicemailability";
236var voicemailUri = "datashare:///com.ohos.voicemailability/calls/voicemail";
237var value = {"phone_number" : "xxxxx","display_name" : "xxx"};
238// 获取dataShareHelper
239let dataShareHelper = dataShare.createDataShareHelper(voicemailData);
240// 条件参数
241let condition = new dataShare.DataSharePredicates();
242condition.equalTo("id", "xxx");
243// 调用update方法
244dataShareHelper.update(voicemailUri, value, condition).then((data) => {
245 console.info("resultCode = " + data);
246});
247```
248
249#### dataShareHelper.delete(uri: string, condition: DataSharePredicates)
250
251- 接口说明
252
253 语音信箱删除
254
255- delete参数描述
256
257 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
258 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
259 | uri | 只读 | string | 是 | 具体操作的uri |
260 | condition | 只读 | DataSharePredicates | 是 | 删除条件 |
261
262返回值为 成功为0否则为-1
263
264删除示例
265```js
266import dataShare from '@ohos.data.dataShare';
267var voicemailData = "datashare:///com.ohos.voicemailability";
268var voicemailUri = "datashare:///com.ohos.voicemailability/calls/voicemail";
269// 获取dataShareHelper
270let dataShareHelper = dataShare.createDataShareHelper(voicemailData);
271// 条件参数
272let condition = new dataShare.DataSharePredicates();
273condition.equalTo("id", "xxx");
274// 调用delete方法
275dataShareHelper.delete(voicemailUri, condition).then((data) => {
276 console.info("deleteCode = " + data);
277});
278```
279
280#### dataShareHelper.query(uri: string, condition: DataSharePredicates, resultColumns:array)
281
282- 接口说明
283
284 语音信箱查询
285
286- 查询参数描述
287
288 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
289 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
290 | uri | 只读 | string | 是 | 具体操作的uri |
291 | condition | 只读 | DataSharePredicates | 是 | 查询条件 |
292 | resultColumns | 只读 | array | 是 | 需要查询的列字段名称 |
293
294返回值为 ResultSet 查询结果集
295
296查询示例
297```js
298import dataShare from '@ohos.data.dataShare';
299var voicemailData = "datashare:///com.ohos.voicemailability";
300var voicemailUri = "datashare:///com.ohos.voicemailability/calls/voicemail";
301// 获取dataShareHelper
302let dataShareHelper = dataShare.createDataShareHelper(voicemailData);
303// 条件参数
304let condition = new dataShare.DataSharePredicates();
305condition.equalTo("id", "xxx");
306var resultColumns = [ "id", "display_name", "phone_number"];
307// 调用query方法
308dataShareHelper.query(voicemailUri, resultColumns, condition).then((resultSet) => {
309 if (resultSet.goToFirstRow()) {
310 do {
311 var displayName = resultSet.getString(resultSet.getColumnIndex("display_name"));
312 var id = resultSet.getLong(resultSet.getColumnIndex("id"));
313 var phoneNumber = resultSet.getString(resultSet.getColumnIndex("phone_number"));
314 } while (resultSet.goToNextRow());
315 }
316 resultSet.close();
317});
318```
319
320### 联系人
321
322#### dataShareHelper.insert(uri: string, value: ValuesBucket)
323
324- 接口说明
325
326 联系人插入
327
328- insert参数描述
329
330 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
331 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
332 | uri | 只读 | string | 是 | 具体操作的uri |
333 | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
334
335返回值为 联系人数据表id
336
337更新示例
338```js
339import dataShare from '@ohos.data.dataShare';
340var contactsData = "datashare:///com.ohos.contactsdataability";
341var rawContactUri = "datashare:///com.ohos.contactsdataability/contacts/raw_contact";
342var contactDataUri = "datashare:///com.ohos.contactsdataability/contacts/contact_data";
343var value = {"display_name" : "xxx"};
344// 获取dataShareHelper
345let dataShareHelper = dataShare.createDataShareHelper(contactsData);
346// 调用insert方法
347dataShareHelper.insert(rawContactUri, value).then((rawContactId) => {
348 console.info("rawContactId = " + rawContactId);
349 // 联系人详细信息插入
350 var contactDataValues = {
351 "raw_contact_id" : rawContactId,
352 "content_type" : "name",
353 "detail_info" : "xxxxxxx"
354 };
355 dataShareHelper.insert(contactDataUri, contactDataValues).then((contactDataId) => {
356 console.info("rawContactId = " + contactDataId);
357 };
358});
359```
360#### dataShareHelper.update(uri: string, condition: DataSharePredicates, value: ValuesBucket)
361
362- 接口说明
363
364 联系人修改
365
366- update参数描述
367
368 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
369 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
370 | uri | 只读 | string | 是 | 具体操作的uri |
371 | condition | 只读 | DataSharePredicates | 是 | 更新条件 |
372 | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
373
374返回值为 成功为0否则为-1
375
376修改示例
377```js
378import dataShare from '@ohos.data.dataShare';
379var contactsData = "datashare:///com.ohos.contactsdataability";
380var rawContactUri = "datashare:///com.ohos.contactsdataability/contacts/raw_contact";
381var contactDataUri = "datashare:///com.ohos.contactsdataability/contacts/contact_data";
382var value = {"display_name" : "xxx"};
383// 获取dataShareHelper
384let dataShareHelper = dataShare.createDataShareHelper(contactsData);
385// 条件参数
386let condition = new dataShare.DataSharePredicates();
387condition.equalTo("id", "xxx");
388// 调用update方法
389dataShareHelper.update(rawContactUri, value, condition).then((data) => {
390 console.info("resultCode = " + data);
391});
392```
393
394#### dataShareHelper.delete(uri: string, condition: DataSharePredicates)
395
396- 接口说明
397
398 联系人删除
399
400- delete参数描述
401
402 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
403 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
404 | uri | 只读 | string | 是 | 具体操作的uri |
405 | condition | 只读 | DataSharePredicates | 是 | 删除条件 |
406
407返回值为 成功为0否则为-1
408
409删除示例
410```js
411import dataShare from '@ohos.data.dataShare';
412var contactsData = "datashare:///com.ohos.contactsdataability";
413var rawContactUri = "datashare:///com.ohos.contactsdataability/contacts/raw_contact";
414var contactDataUri = "datashare:///com.ohos.contactsdataability/contacts/contact_data";
415// 获取dataShareHelper
416let dataShareHelper = dataShare.createDataShareHelper(contactsData);
417// 条件参数
418let condition = new dataShare.DataSharePredicates();
419condition.equalTo("id", "xxx");
420// 调用delete方法
421dataShareHelper.delete(contactDataUri, condition).then((data) => {
422 console.info("deleteCode = " + data);
423});
424```
425#### dataShareHelper.query(uri: string, condition: DataSharePredicates, resultColumns: array)
426
427- 接口说明
428
429 联系人查询
430
431- 查询参数描述
432
433 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
434 | -------- | -------- | ---------------------- | ---- | ------------------------------ |
435 | uri | 只读 | string | 是 | 具体操作的uri |
436 | condition | 只读 | DataSharePredicates | 是 | 查询条件 |
437 | resultColumns | 只读 | array | 是 | 需要查询的列字段名称 |
438
439返回值为 ResultSet 查询结果集
440
441查询示例
442```js
443import dataShare from '@ohos.data.dataShare';
444var contactsData = "datashare:///com.ohos.contactsdataability";
445var rawContactUri = "datashare:///com.ohos.contactsdataability/contacts/raw_contact";
446// 获取dataShareHelper
447let dataShareHelper = dataShare.createDataShareHelper(contactsData);
448// 条件参数
449let condition = new dataShare.DataSharePredicates();
450condition.equalTo("id", "xxx");
451var resultColumns = [ "id", "display_name"];
452// 调用query方法
453dataShareHelper.query(rawContactUri, resultColumns, condition).then((resultSet) => {
454 if (resultSet.goToFirstRow()) {
455 do {
456 var displayName = resultSet.getString(resultSet.getColumnIndex("display_name"));
457 } while (resultSet.goToNextRow());
458 }
459 resultSet.close();
460});
461```
462| 系统公共uri |
463| --------------------------------------------------------- |
464| datashare:///com.ohos.contactsdataability |
465| datashare:///com.ohos.contactsdataability/contacts/contact |
466| datashare:///com.ohos.contactsdataability/contacts/raw_contact |
467| datashare:///com.ohos.contactsdataability/contacts/contact_data |
468| datashare:///com.ohos.contactsdataability/contacts/raw_contact/query_merge_list|
469| datashare:///com.ohos.contactsdataability/contacts/raw_contact/split_contact |
470| datashare:///com.ohos.contactsdataability/contacts/raw_contact/manual_merge |
471| datashare:///com.ohos.contactsdataability/contacts/raw_contact/auto_merge |
472| datashare:///com.ohos.contactsdataability/contacts/contact_type |
473| datashare:///com.ohos.contactsdataability/contacts/groups |
474| datashare:///com.ohos.contactsdataability/contacts/photo_files |
475| datashare:///com.ohos.contactsdataability/contacts/contact_blocklist |
476| datashare:///com.ohos.contactsdataability/contacts/deleted_raw_contact |
477| datashare:///com.ohos.contactsdataability/contacts/search_contact |
478| datashare:///com.ohos.contactsdataability/contacts/deleted_raw_contact |
479| datashare:///com.ohos.contactsdataability/contacts/deleted_raw_contact_record |
480| datashare:///com.ohos.contactsdataability/contacts/backup |
481| datashare:///com.ohos.contactsdataability/contacts/recover |
482| datashare:///com.ohos.contactsdataability/profile/contact |
483| datashare:///com.ohos.contactsdataability/profile/raw_contact |
484| datashare:///com.ohos.contactsdataability/profile/contact_data |
485| datashare:///com.ohos.contactsdataability/profile/raw_contact/query_merge_list |
486| datashare:///com.ohos.contactsdataability/profile/raw_contact/split_contact |
487| datashare:///com.ohos.contactsdataability/profile/raw_contact/manual_merge |
488| datashare:///com.ohos.contactsdataability/profile/raw_contact/auto_merge |
489| datashare:///com.ohos.contactsdataability/profile/contact_type |
490| datashare:///com.ohos.contactsdataability/profile/groups |
491| datashare:///com.ohos.contactsdataability/profile/photo_files |
492| datashare:///com.ohos.contactsdataability/profile/contact_blocklist |
493| datashare:///com.ohos.contactsdataability/profile/deleted_raw_contact |
494| datashare:///com.ohos.contactsdataability/profile/search_contact |
495| datashare:///com.ohos.contactsdataability/profile/deleted_raw_contact |
496| datashare:///com.ohos.contactsdataability/profile/deleted_raw_contact_record |
497| datashare:///com.ohos.contactsdataability/profile/backup |
498| datashare:///com.ohos.contactsdataability/profile/recover |
499| datashare:///com.ohos.calllogability |
500| datashare:///com.ohos.calllogability/calls/calllog |
501| datashare:///com.ohos.voicemailability |
502| datashare:///com.ohos.voicemailability/calls/voicemail |
503## 相关仓<a name="section1371113476307"></a>
504
505系统应用
506
507applications_contactsdata