js-apis-contact.md 74.1 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.contact (Contacts)
S
shawn_he 已提交
2

S
shawn_he 已提交
3 4
The **contact** module provides contact management functions, such as adding, deleting, and updating contacts.

S
shawn_he 已提交
5 6 7 8 9 10 11
>**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

S
shawn_he 已提交
12
```
S
shawn_he 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26
import contact from '@ohos.contact';
```

## contact.addContact

addContact(contact:Contact, callback:AsyncCallback<number>): void

Adds a contact. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.WRITE_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
27

S
shawn_he 已提交
28 29 30 31 32 33 34
| Name  | Type                       | Mandatory| Description                          |
| -------- | --------------------------- | ---- | ------------------------------ |
| contact  | [Contact](#contact)         | Yes  | Contact information.                  |
| callback | AsyncCallback<number> | Yes  | Callback used to return the contact ID.|

**Example**

S
shawn_he 已提交
35
  ```js
S
shawn_he 已提交
36
  contact.addContact({
S
shawn_he 已提交
37
      name: {fullName: 'xxx'},
S
shawn_he 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
      phoneNumbers: [{phoneNumber: '138xxxxxxxx'}]
  }, (err, data) => {
      if (err) {
          console.log(`addContact callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`addContact callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.addContact

addContact(contact: Contact): Promise<number>

Adds a contact. This API uses a promise to return the result.

**Permission required**: ohos.permission.WRITE_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
60

S
shawn_he 已提交
61 62 63 64 65
| Name | Type               | Mandatory| Description        |
| ------- | ------------------- | ---- | ------------ |
| contact | [Contact](#contact) | Yes  | Contact information.|

**Return Value**
S
shawn_he 已提交
66

S
shawn_he 已提交
67 68 69 70 71 72
| Type                 | Description                                       |
| --------------------- | ------------------------------------------- |
| Promise<number> | Promise used to return the contact ID.|

**Example**

S
shawn_he 已提交
73
  ```js
S
shawn_he 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  let promise = contact.addContact({
      name: {fullName: 'xxx'},
      phoneNumbers: [{phoneNumber: '138xxxxxxxx'}]
  });
  promise.then((data) => {
      console.log(`addContact success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`addContact fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.deleteContact

deleteContact(key: string, callback: AsyncCallback<void>): void

Deletes a contact based on the specified contact key. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.WRITE_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
97

S
shawn_he 已提交
98 99 100 101 102 103 104
| Name  | Type                     | Mandatory| Description                                |
| -------- | ------------------------- | ---- | ------------------------------------ |
| key      | string                    | Yes  | Contact key. Each contact corresponds to one key.|
| callback | AsyncCallback<void> | Yes  | Callback used to return the result.    |

**Example**

S
shawn_he 已提交
105
  ```js
S
shawn_he 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
  contact.deleteContact('xxx', (err) => {
      if (err) {
          console.log(`deleteContact callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log('deleteContact success');
  });
  ```


## contact.deleteContact

deleteContact(key: string): Promise<void>

Deletes a contact based on the specified contact key. This API uses a promise to return the result.

**Permission required**: ohos.permission.WRITE_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
127

S
shawn_he 已提交
128 129 130 131 132
| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
| key    | string | Yes  | Contact key. Each contact corresponds to one key.|

**Return Value**
S
shawn_he 已提交
133

S
shawn_he 已提交
134 135 136 137 138 139
| Type               | Description                                         |
| ------------------- | --------------------------------------------- |
| Promise<void> | Promise used to return the result.|

**Example**

S
shawn_he 已提交
140
  ```js
S
shawn_he 已提交
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
  let promise = contact.deleteContact('xxx');
  promise.then(() => {
      console.log(`deleteContact success`);
  }).catch((err) => {
      console.error(`deleteContact fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.updateContact

updateContact(contact: Contact, callback: AsyncCallback<void>): void

Updates a contact based on the specified contact information. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.WRITE_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
161

S
shawn_he 已提交
162 163 164 165 166 167 168
| Name  | Type                     | Mandatory| Description                                |
| -------- | ------------------------- | ---- | ------------------------------------ |
| contact  | [Contact](#contact)       | Yes  | Contact information.                        |
| callback | AsyncCallback<void> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
169
  ```js
S
shawn_he 已提交
170
  contact.updateContact({
S
shawn_he 已提交
171
      id: 1,
S
shawn_he 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
      name: {fullName: 'xxx'},
      phoneNumbers: [{phoneNumber: '138xxxxxxxx'}]
  }, (err) => {
      if (err) {
          console.log('updateContact callback: err->${JSON.stringify(err)}');
          return;
      }
      console.log('updateContact success');
  });
  ```


## contact.updateContact

updateContact(contact: Contact, attrs: ContactAttributes, callback: AsyncCallback<void>): void

S
shawn_he 已提交
188
Updates a contact based on the specified contact information. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
189 190 191 192 193 194

**Permission required**: ohos.permission.WRITE_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
195

S
shawn_he 已提交
196 197 198 199 200 201 202 203
| Name  | Type                                   | Mandatory| Description                                |
| -------- | --------------------------------------- | ---- | ------------------------------------ |
| contact  | [Contact](#contact)                     | Yes  | Contact information.                        |
| attrs    | [ContactAttributes](#contactattributes) | Yes  | List of contact attributes.                  |
| callback | AsyncCallback<void>               | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
204
  ```js
S
shawn_he 已提交
205
  contact.updateContact({
S
shawn_he 已提交
206
      id: 1,
S
shawn_he 已提交
207
      name: {fullName: 'xxx'},
S
shawn_he 已提交
208
      phoneNumbers: [{phoneNumber: '138xxxxxxxx'}]
S
shawn_he 已提交
209 210
  }, {
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
  }, (err) => {
      if (err) {
          console.log('updateContact callback: err->${JSON.stringify(err)}');
          return;
      }
      console.log('updateContact success');
  });
  ```


## contact.updateContact

updateContact(contact: Contact, attrs?: ContactAttributes): Promise<void>

Updates a contact based on the specified contact information and attributes. This API uses a promise to return the result.

**Permission required**: ohos.permission.WRITE_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
232

S
shawn_he 已提交
233 234 235 236 237 238 239 240 241 242 243 244
| Name | Type                                   | Mandatory| Description              |
| ------- | --------------------------------------- | ---- | ------------------ |
| contact | [Contact](#contact)                     | Yes  | Contact information.      |
| attrs   | [ContactAttributes](#contactattributes) | No  | List of contact attributes.|

**Return Value**
| Type               | Description                                             |
| ------------------- | ------------------------------------------------- |
| Promise<void> | Promise used to return the result.|

**Example**

S
shawn_he 已提交
245
  ```js
S
shawn_he 已提交
246
  let promise = contact.updateContact({
S
shawn_he 已提交
247
      id: 1,
S
shawn_he 已提交
248
      name: {fullName: 'xxx'},
S
shawn_he 已提交
249 250
      phoneNumbers: [{phoneNumber: '138xxxxxxxx'}]
  }, {
S
shawn_he 已提交
251
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
  });
  promise.then(() => {
      console.log('updateContact success');
  }).catch((err) => {
      console.error(`updateContact fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.isLocalContact

isLocalContact(id: number, callback: AsyncCallback<boolean>): void

Checks whether the ID of this contact is in the local address book. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
272

S
shawn_he 已提交
273 274 275 276 277 278 279
| Name  | Type                        | Mandatory| Description                                                        |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| id       | number                       | Yes  | Contact ID. Each contact corresponds to one ID.                  |
| callback | AsyncCallback<boolean> | Yes  | Callback used to return a boolean value. The value **true** indicates that the contact ID is in the local address book, and the value **false** indicates the opposite.|

**Example**

S
shawn_he 已提交
280
  ```js
S
shawn_he 已提交
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
  contact.isLocalContact(/*id*/1, (err, data) => {
      if (err) {
          console.log(`isLocalContact callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`isLocalContact callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.isLocalContact

isLocalContact(id: number): Promise<boolean>

Checks whether the ID of this contact is in the local address book. This API uses a promise to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
302

S
shawn_he 已提交
303 304 305 306 307
| Name| Type  | Mandatory| Description                                      |
| ------ | ------ | ---- | ------------------------------------------ |
| id     | number | Yes  | Contact ID. Each contact corresponds to one ID.|

**Return Value**
S
shawn_he 已提交
308

S
shawn_he 已提交
309 310 311 312 313 314
| Type                  | Description                                                        |
| ---------------------- | ------------------------------------------------------------ |
| Promise<boolean> | Promise used to return the result. The value **true** indicates that the contact ID is in the local address book, and the value **false** indicates the opposite.|

**Example**

S
shawn_he 已提交
315
  ```js
S
shawn_he 已提交
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
  let promise = contact.isLocalContact(/*id*/1);
  promise.then((data) => {
      console.log(`isLocalContact success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`isLocalContact fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.isMyCard

isMyCard(id: number, callback: AsyncCallback<boolean>): void

Checks whether a contact is included in my card. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
336

S
shawn_he 已提交
337 338 339 340 341 342 343
| Name  | Type                        | Mandatory| Description                                                        |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| id       | number                       | Yes  | Contact ID.                                        |
| callback | AsyncCallback<boolean> | Yes  | Callback used to return the result. The value **true** indicates that the contact is included in my card, and the value **false** indicates the opposite.|

**Example**

S
shawn_he 已提交
344
  ```js
S
shawn_he 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
  contact.isMyCard(/*id*/1, (err, data) => {
      if (err) {
          console.log(`isMyCard callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`isMyCard callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.isMyCard

isMyCard(id: number): Promise<boolean>

Checks whether a contact is included in my card. This API uses a promise to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
366

S
shawn_he 已提交
367 368 369 370 371
| Name| Type  | Mandatory| Description                |
| ------ | ------ | ---- | -------------------- |
| id     | number | Yes  | Contact ID.|

**Return Value**
S
shawn_he 已提交
372

S
shawn_he 已提交
373 374 375 376 377 378
| Type                  | Description                                                        |
| ---------------------- | ------------------------------------------------------------ |
| Promise<boolean> | Promise used to return the result. The value **true** indicates that the contact is included in my card, and the value **false** indicates the opposite.|

**Example**

S
shawn_he 已提交
379
  ```js
S
shawn_he 已提交
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
  let promise = contact.isMyCard(/*id*/1);
  promise.then((data) => {
      console.log(`isMyCard success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`isMyCard fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.queryMyCard

queryMyCard(callback: AsyncCallback<Contact>): void

Queries my card. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
400

S
shawn_he 已提交
401 402 403 404 405 406
| Name  | Type                                    | Mandatory| Description                          |
| -------- | ---------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback<[Contact](#contact)> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
407
  ```js
S
shawn_he 已提交
408 409 410 411 412 413 414 415 416 417 418 419 420 421
  contact.queryMyCard((err, data) => {
      if (err) {
          console.log(`queryMyCard callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryMyCard callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryMyCard

queryMyCard(attrs: ContactAttributes, callback: AsyncCallback<Contact>): void

S
shawn_he 已提交
422
Queries my card. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
423 424 425 426 427 428

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
429

S
shawn_he 已提交
430 431 432 433 434 435 436
| Name  | Type                                    | Mandatory| Description                          |
| -------- | ---------------------------------------- | ---- | ------------------------------ |
| attrs    | [ContactAttributes](#contactattributes)  | Yes  | List of contact attributes.            |
| callback | AsyncCallback<[Contact](#contact)> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
437
  ```js
S
shawn_he 已提交
438
  contact.queryMyCard({
S
shawn_he 已提交
439
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
440 441 442 443 444 445 446 447 448 449 450 451 452 453
  }, (err, data) => {
      if (err) {
          console.log(`queryMyCard callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryMyCard callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryMyCard

queryMyCard(attrs?: ContactAttributes): Promise<Contact>

S
shawn_he 已提交
454
Queries my card based on the specified contact attributes. This API uses a promise to return the result.
S
shawn_he 已提交
455 456 457 458 459 460

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
461

S
shawn_he 已提交
462 463 464 465 466 467 468 469 470 471 472
| Name| Type                                   | Mandatory| Description              |
| ------ | --------------------------------------- | ---- | ------------------ |
| attrs  | [ContactAttributes](#contactattributes) | No  | List of contact attributes.|

**Return Value**
| Type                              | Description                                       |
| ---------------------------------- | ------------------------------------------- |
| Promise<[Contact](#contact)> | Promise used to return the result.|

**Example**

S
shawn_he 已提交
473
  ```js
S
shawn_he 已提交
474
  let promise = contact.queryMyCard({
S
shawn_he 已提交
475
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
  });
  promise.then((data) => {
      console.log(`queryMyCard success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`queryMyCard fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.selectContact

selectContact(callback: AsyncCallback<Array<Contact>>): void

Selects a contact. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
491
**System capability**: SystemCapability.Applications.Contacts
S
shawn_he 已提交
492 493

**Parameters**
S
shawn_he 已提交
494

S
shawn_he 已提交
495 496 497 498 499 500
| Name  | Type                                                 | Mandatory| Description                                |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
501
  ```js
S
shawn_he 已提交
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
  contact.selectContact((err, data) => {
      if (err) {
          console.log(`selectContact callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`selectContact callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.selectContact

selectContact(): Promise<Array<Contact>>

Selects a contact. This API uses a promise to return the result.

S
shawn_he 已提交
518
**System capability**: SystemCapability.Applications.Contacts
S
shawn_he 已提交
519 520

**Return Value**
S
shawn_he 已提交
521

S
shawn_he 已提交
522 523 524 525 526 527
| Type                                           | Description                                             |
| ----------------------------------------------- | ------------------------------------------------- |
| Promise<Array<[Contact](#contact)>> | Promise used to return the result.|

**Example**

S
shawn_he 已提交
528
  ```js
S
shawn_he 已提交
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
  let promise = contact.selectContact();
  promise.then((data) => {
      console.log(`selectContact success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`selectContact fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.queryContact

queryContact(key: string,  callback: AsyncCallback<Contact>): void

Queries a contact based on the specified key. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
549

S
shawn_he 已提交
550 551 552 553 554 555 556
| Name  | Type                                    | Mandatory| Description                                  |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| key      | string                                   | Yes  | Contact key. Each contact corresponds to one key.|
| callback | AsyncCallback<[Contact](#contact)> | Yes  | Callback used to return the result.      |

**Example**

S
shawn_he 已提交
557
  ```js
S
shawn_he 已提交
558 559 560 561 562 563 564 565 566 567 568 569 570 571
  contact.queryContact('xxx', (err, data) => {
      if (err) {
          console.log(`queryContact callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContact callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContact

queryContact(key: string, holder: Holder, callback: AsyncCallback<Contact>): void

S
shawn_he 已提交
572
Queries a contact based on the specified key. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
573 574 575 576 577 578

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
579

S
shawn_he 已提交
580 581 582 583 584 585 586 587
| Name  | Type                                    | Mandatory| Description                                  |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| key      | string                                   | Yes  | Contact key. Each contact corresponds to one key.|
| holder   | [Holder](#holder)                        | Yes  | Application that creates the contacts.                |
| callback | AsyncCallback<[Contact](#contact)> | Yes  | Callback used to return the result.      |

**Example**

S
shawn_he 已提交
588
  ```js
S
shawn_he 已提交
589
  contact.queryContact('xxx', {
S
shawn_he 已提交
590 591 592
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
593 594 595 596 597 598 599 600 601 602 603 604 605 606
  }, (err, data) => {
      if (err) {
          console.log(`queryContact callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContact callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContact

queryContact(key: string,  attrs: ContactAttributes, callback: AsyncCallback<Contact>): void

S
shawn_he 已提交
607
Queries a contact based on the specified key. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
608 609 610 611 612 613

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
614

S
shawn_he 已提交
615 616 617 618 619 620 621 622
| Name  | Type                                    | Mandatory| Description                                  |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| key      | string                                   | Yes  | Contact key. Each contact corresponds to one key.|
| attrs    | [ContactAttributes](#contactattributes)  | Yes  | List of contact attributes.                    |
| callback | AsyncCallback<[Contact](#contact)> | Yes  | Callback used to return the result.      |

**Example**

S
shawn_he 已提交
623
  ```js
S
shawn_he 已提交
624
  contact.queryContact('xxx', {
S
shawn_he 已提交
625
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
626 627 628 629 630 631 632 633 634 635 636 637 638 639
  }, (err, data) => {
      if (err) {
          console.log(`queryContact callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContact callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContact

queryContact(key: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Contact>): void

S
shawn_he 已提交
640
Queries a contact based on the specified key. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
641 642 643 644 645 646

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
647

S
shawn_he 已提交
648 649 650 651 652 653 654 655 656
| Name  | Type                                    | Mandatory| Description                                  |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| key      | string                                   | Yes  | Contact key. Each contact corresponds to one key.|
| holder   | [Holder](#holder)                        | Yes  | Application that creates the contacts.                |
| attrs    | [ContactAttributes](#contactattributes)  | Yes  | List of contact attributes.                    |
| callback | AsyncCallback<[Contact](#contact)> | Yes  | Callback used to return the result.      |

**Example**

S
shawn_he 已提交
657
  ```js
S
shawn_he 已提交
658
  contact.queryContact('xxx', {
S
shawn_he 已提交
659 660 661
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
662
  }, {
S
shawn_he 已提交
663
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
  }, (err, data) => {
      if (err) {
          console.log(`queryContact callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContact callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContact

queryContact(key: string, holder?: Holder, attrs?: ContactAttributes): Promise<Contact>

Queries contacts based on the specified key, application, and attributes. This API uses a promise to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
685

S
shawn_he 已提交
686 687 688 689 690 691 692 693 694 695 696 697 698
| Name| Type                                   | Mandatory| Description                                  |
| ------ | --------------------------------------- | ---- | -------------------------------------- |
| key    | string                                  | Yes  | Contact key. Each contact corresponds to one key.|
| holder | [Holder](#holder)                       | No  | Application that creates the contacts.                |
| attrs  | [ContactAttributes](#contactattributes) | No  | List of contact attributes.                    |

**Return Value**
| Type                              | Description                                           |
| ---------------------------------- | ----------------------------------------------- |
| Promise<[Contact](#contact)> | Promise used to return the result.|

**Example**

S
shawn_he 已提交
699
  ```js
S
shawn_he 已提交
700
  let promise = contact.queryContact('xxx', {
S
shawn_he 已提交
701 702 703
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
704
  }, {
S
shawn_he 已提交
705
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
  });
  promise.then((data) => {
      console.log(`queryContact success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`queryContact fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.queryContacts

queryContacts(callback: AsyncCallback<Array<Contact>>): void

Queries all contacts. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
726

S
shawn_he 已提交
727 728 729 730 731 732
| Name  | Type                                                 | Mandatory| Description                                  |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
733
  ```js
S
shawn_he 已提交
734 735 736 737 738 739 740 741 742 743 744 745 746 747
  contact.queryContacts((err, data) => {
      if (err) {
          console.log(`queryContacts callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContacts callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContacts

queryContacts(holder: Holder, callback: AsyncCallback<Array<Contact>>): void

S
shawn_he 已提交
748
Queries all contacts. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
749 750 751 752 753 754

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
755

S
shawn_he 已提交
756 757 758 759 760 761 762
| Name  | Type                                                 | Mandatory| Description                                  |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| holder   | [Holder](#holder)                                     | Yes  | Application that creates the contacts.                |
| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
763
  ```js
S
shawn_he 已提交
764
  contact.queryContacts({
S
shawn_he 已提交
765 766 767
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
768 769 770 771 772 773 774 775 776 777 778 779 780 781
  }, (err, data) => {
      if (err) {
          console.log(`queryContacts callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContacts callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContacts

queryContacts(attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void

S
shawn_he 已提交
782
Queries all contacts. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
783 784 785 786 787 788

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
789

S
shawn_he 已提交
790 791 792 793 794 795 796
| Name  | Type                                                 | Mandatory| Description                                  |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| attrs    | [ContactAttributes](#contactattributes)               | Yes  | List of contact attributes.                    |
| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
797
  ```js
S
shawn_he 已提交
798
  contact.queryContacts({
S
shawn_he 已提交
799
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
800 801 802 803 804 805 806 807 808 809 810 811 812 813
  }, (err, data) => {
      if (err) {
          console.log(`queryContacts callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContacts callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContacts

queryContacts(holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void

S
shawn_he 已提交
814
Queries all contacts. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
815 816 817 818 819 820

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
821

S
shawn_he 已提交
822 823 824 825 826 827 828 829
| Name  | Type                                                 | Mandatory| Description                                  |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| holder   | [Holder](#holder)                                     | Yes  | Application that creates the contacts.                |
| attrs    | [ContactAttributes](#contactattributes)               | Yes  | List of contact attributes.                    |
| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
830
  ```js
S
shawn_he 已提交
831
  contact.queryContacts({
S
shawn_he 已提交
832 833 834
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
835
  }, {
S
shawn_he 已提交
836
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
  }, (err, data) => {
      if (err) {
          console.log(`queryContacts callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContacts callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContacts

queryContacts(holder?: Holder, attrs?: ContactAttributes): Promise<Array<Contact>>

Queries all contacts based on the specified application and attributes. This API uses a promise to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
858

S
shawn_he 已提交
859 860 861 862 863 864 865 866 867 868 869 870
| Name| Type                                   | Mandatory| Description                  |
| ------ | --------------------------------------- | ---- | ---------------------- |
| holder | [Holder](#holder)                       | No  | Application that creates the contacts.|
| attrs  | [ContactAttributes](#contactattributes) | No  | List of contact attributes.    |

**Return Value**
| Type                                           | Description                                               |
| ----------------------------------------------- | --------------------------------------------------- |
| Promise<Array<[Contact](#contact)>> | Promise used to return the result.|

**Example**

S
shawn_he 已提交
871
  ```js
S
shawn_he 已提交
872
  let promise = contact.queryContacts({
S
shawn_he 已提交
873 874 875
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
876
  }, {
S
shawn_he 已提交
877
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
  });
  promise.then((data) => {
      console.log(`queryContacts success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`queryContacts fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.queryContactsByPhoneNumber

queryContactsByPhoneNumber(phoneNumber: string, callback: AsyncCallback<Array<Contact>>): void

Queries contacts based on the specified phone number. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
898

S
shawn_he 已提交
899 900 901 902 903 904 905
| Name     | Type                                                 | Mandatory| Description                                  |
| ----------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| phoneNumber | string                                                | Yes  | Phone number of the contacts.                    |
| callback    | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
906
  ```js
S
shawn_he 已提交
907 908 909 910 911 912 913 914 915 916 917 918 919 920
  contact.queryContactsByPhoneNumber('138xxxxxxxx', (err, data) => {
      if (err) {
          console.log(`queryContactsByPhoneNumber callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContactsByPhoneNumber callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContactsByPhoneNumber

queryContactsByPhoneNumber(phoneNumber: string, holder: Holder, callback: AsyncCallback<Array<Contact>>): void

S
shawn_he 已提交
921
Queries contacts based on the specified phone number. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
922 923 924 925 926 927

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
928

S
shawn_he 已提交
929 930 931 932 933 934 935 936
| Name     | Type                                                 | Mandatory| Description                                  |
| ----------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| phoneNumber | string                                                | Yes  | Phone number of the contacts.                    |
| holder      | [Holder](#holder)                                     | Yes  | Application that creates the contacts.                |
| callback    | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
937
  ```js
S
shawn_he 已提交
938
  contact.queryContactsByPhoneNumber('138xxxxxxxx', {
S
shawn_he 已提交
939 940 941
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
942 943 944 945 946 947 948 949 950 951 952 953 954 955
  }, (err, data) => {
      if (err) {
          console.log(`queryContactsByPhoneNumber callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContactsByPhoneNumber callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContactsByPhoneNumber

queryContactsByPhoneNumber(phoneNumber: string, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void

S
shawn_he 已提交
956
Queries contacts based on the specified phone number. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
957 958 959 960 961 962

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
963

S
shawn_he 已提交
964 965 966 967 968 969 970 971
| Name     | Type                                                 | Mandatory| Description                                  |
| ----------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| phoneNumber | string                                                | Yes  | Phone number of the contacts.                    |
| attrs       | [ContactAttributes](#contactattributes)               | Yes  | List of contact attributes.                    |
| callback    | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
972
  ```js
S
shawn_he 已提交
973
  contact.queryContactsByPhoneNumber('138xxxxxxxx', {
S
shawn_he 已提交
974
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
975 976 977 978 979 980 981 982 983 984 985 986 987 988
  }, (err, data) => {
      if (err) {
          console.log(`queryContactsByPhoneNumber callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContactsByPhoneNumber callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContactsByPhoneNumber

queryContactsByPhoneNumber(phoneNumber: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void

S
shawn_he 已提交
989
Queries contacts based on the specified phone number. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
990 991 992 993 994 995

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
996

S
shawn_he 已提交
997 998 999 1000 1001 1002 1003 1004 1005
| Name     | Type                                                 | Mandatory| Description                                  |
| ----------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| phoneNumber | string                                                | Yes  | Phone number of the contacts.                    |
| holder      | [Holder](#holder)                                     | Yes  | Application that creates the contacts.                |
| attrs       | [ContactAttributes](#contactattributes)               | Yes  | List of contact attributes.                    |
| callback    | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
1006
  ```js
S
shawn_he 已提交
1007
  contact.queryContactsByPhoneNumber('138xxxxxxxx', {
S
shawn_he 已提交
1008 1009 1010
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
1011
  }, {
S
shawn_he 已提交
1012
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
  }, (err, data) => {
      if (err) {
          console.log(`queryContactsByPhoneNumber callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContactsByPhoneNumber callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContactsByPhoneNumber

queryContactsByPhoneNumber(phoneNumber: string, holder?: Holder, attrs?: ContactAttributes): Promise<Array<Contact>>

Queries contacts based on the specified phone number, application, and attributes. This API uses a promise to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1034

S
shawn_he 已提交
1035 1036 1037 1038 1039 1040 1041
| Name     | Type                                   | Mandatory| Description                  |
| ----------- | --------------------------------------- | ---- | ---------------------- |
| phoneNumber | string                                  | Yes  | Phone number of the contacts.    |
| holder      | [Holder](#holder)                       | No  | Application that creates the contacts.|
| attrs       | [ContactAttributes](#contactattributes) | No  | List of contact attributes.    |

**Return Value**
S
shawn_he 已提交
1042

S
shawn_he 已提交
1043 1044 1045 1046 1047 1048
| Type                                           | Description                                               |
| ----------------------------------------------- | --------------------------------------------------- |
| Promise<Array<[Contact](#contact)>> | Promise used to return the result.|

**Example**

S
shawn_he 已提交
1049
  ```js
S
shawn_he 已提交
1050
  let promise = contact.queryContactsByPhoneNumber('138xxxxxxxx', {
S
shawn_he 已提交
1051 1052 1053
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
1054
  }, {
S
shawn_he 已提交
1055
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
  });
  promise.then((data) => {
      console.log(`queryContactsByPhoneNumber success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`queryContactsByPhoneNumber fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.queryContactsByEmail

queryContactsByEmail(email: string, callback: AsyncCallback<Array<Contact>>): void

Queries contacts based on the specified email address. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1076

S
shawn_he 已提交
1077 1078 1079 1080 1081 1082 1083
| Name  | Type                                                 | Mandatory| Description                                  |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| email    | string                                                | Yes  | Email address of the contact.                    |
| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
1084
  ```js
S
shawn_he 已提交
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
  contact.queryContactsByEmail('xxx@email.com', (err, data) => {
      if (err) {
          console.log(`queryContactsByEmail callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContactsByEmail callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContactsByEmail

queryContactsByEmail(email: string, holder: Holder, callback: AsyncCallback<Array<Contact>>): void

S
shawn_he 已提交
1099
Queries contacts based on the specified email address. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
1100 1101 1102 1103 1104 1105

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1106

S
shawn_he 已提交
1107 1108 1109 1110 1111 1112 1113 1114
| Name  | Type                                                 | Mandatory| Description                                  |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| email    | string                                                | Yes  | Email address of the contact.                    |
| holder   | [Holder](#holder)                                     | Yes  | Application that creates the contacts.                |
| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
1115
  ```js
S
shawn_he 已提交
1116
  contact.queryContactsByEmail('xxx@email.com', {
S
shawn_he 已提交
1117
      holderId: 0,
S
shawn_he 已提交
1118 1119
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
  }, (err, data) => {
      if (err) {
          console.log(`queryContactsByEmail callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContactsByEmail callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContactsByEmail

queryContactsByEmail(email: string, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void

S
shawn_he 已提交
1134
Queries contacts based on the specified email address. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
1135 1136 1137 1138 1139 1140

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1141

S
shawn_he 已提交
1142 1143 1144 1145 1146 1147 1148 1149
| Name  | Type                                                 | Mandatory| Description                                |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------ |
| email    | string                                                | Yes  | Email address of the contact.                  |
| attrs    | [ContactAttributes](#contactattributes)               | Yes  | List of contact attributes.                  |
| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
1150
  ```js
S
shawn_he 已提交
1151
  contact.queryContactsByEmail('xxx@email.com', {
S
shawn_he 已提交
1152
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
  }, (err, data) => {
      if (err) {
          console.log(`queryContactsByEmail callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContactsByEmail callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContactsByEmail

queryContactsByEmail(email: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void

S
shawn_he 已提交
1167
Queries contacts based on the specified email address. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
1168 1169 1170 1171 1172 1173

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1174

S
shawn_he 已提交
1175 1176 1177 1178 1179 1180 1181 1182 1183
| Name  | Type                                                 | Mandatory| Description                                |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------ |
| email    | string                                                | Yes  | Email address of the contact.                  |
| holder   | [Holder](#holder)                                     | Yes  | Application that creates the contacts.              |
| attrs    | [ContactAttributes](#contactattributes)               | Yes  | List of contact attributes.                  |
| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
1184
  ```js
S
shawn_he 已提交
1185
  contact.queryContactsByEmail('xxx@email.com', {
S
shawn_he 已提交
1186 1187 1188
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
1189
  }, {
S
shawn_he 已提交
1190
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
  }, (err, data) => {
      if (err) {
          console.log(`queryContactsByEmail callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryContactsByEmail callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryContactsByEmail

queryContactsByEmail(email: string, holder?: Holder, attrs?: ContactAttributes): Promise<Array<Contact>>

Queries contacts based on the specified email address, application, and attributes. This API uses a promise to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1212

S
shawn_he 已提交
1213 1214 1215 1216 1217 1218 1219
| Name| Type                                   | Mandatory| Description                  |
| ------ | --------------------------------------- | ---- | ---------------------- |
| email  | string                                  | Yes  | Email address of the contact.    |
| holder | [Holder](#holder)                       | No  | Application that creates the contacts.|
| attrs  | [ContactAttributes](#contactattributes) | No  | List of contact attributes.    |

**Return Value**
S
shawn_he 已提交
1220

S
shawn_he 已提交
1221 1222 1223 1224 1225 1226
| Type                                           | Description                                               |
| ----------------------------------------------- | --------------------------------------------------- |
| Promise<Array<[Contact](#contact)>> | Promise used to return the result.|

**Example**

S
shawn_he 已提交
1227
  ```js
S
shawn_he 已提交
1228
  let promise = contact.queryContactsByEmail('xxx@email.com', {
S
shawn_he 已提交
1229 1230 1231
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
1232
  }, {
S
shawn_he 已提交
1233
      attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME]
S
shawn_he 已提交
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
  });
  promise.then((data) => {
      console.log(`queryContactsByEmail success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`queryContactsByEmail fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.queryGroups

queryGroups(callback: AsyncCallback<Array<Group>>): void

Queries all groups of this contact. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1254

S
shawn_he 已提交
1255 1256 1257 1258 1259 1260
| Name  | Type                                             | Mandatory| Description                                |
| -------- | ------------------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback<Array<[Group](#group)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
1261
  ```js
S
shawn_he 已提交
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
  contact.queryGroups((err, data) => {
      if (err) {
          console.log(`queryGroups callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryGroups callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryGroups

queryGroups(holder: Holder, callback: AsyncCallback<Array<Group>>): void

S
shawn_he 已提交
1276
Queries all groups of this contact. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
1277 1278 1279 1280 1281 1282

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1283

S
shawn_he 已提交
1284 1285 1286 1287 1288 1289 1290
| Name  | Type                                             | Mandatory| Description                                |
| -------- | ------------------------------------------------- | ---- | ------------------------------------ |
| holder   | Holder                                            | Yes  | Application that creates the contacts.              |
| callback | AsyncCallback<Array<[Group](#group)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
1291
  ```js
S
shawn_he 已提交
1292
  contact.queryGroups({
S
shawn_he 已提交
1293 1294 1295
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316
  }, (err, data) => {
      if (err) {
          console.log(`queryGroups callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryGroups callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryGroups

queryGroups(holder?: Holder): Promise<Array<Group>>

Queries all groups of this contact based on the specified application. This API uses a promise to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1317

S
shawn_he 已提交
1318 1319 1320 1321 1322
| Name| Type             | Mandatory| Description                  |
| ------ | ----------------- | ---- | ---------------------- |
| holder | [Holder](#holder) | No  | Application that creates the contacts.|

**Return Value**
S
shawn_he 已提交
1323

S
shawn_he 已提交
1324 1325 1326 1327 1328 1329
| Type                                       | Description                                             |
| ------------------------------------------- | ------------------------------------------------- |
| Promise<Array<[Group](#group)>> | Promise used to return the result.|

**Example**

S
shawn_he 已提交
1330
  ```js
S
shawn_he 已提交
1331
  let promise = contact.queryGroups({
S
shawn_he 已提交
1332 1333 1334
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
  });
  promise.then((data) => {
      console.log(`queryGroups success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`queryGroups fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.queryHolders

queryHolders(callback: AsyncCallback<Array<Holder>>): void

Queries all applications that have created contacts. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1355

S
shawn_he 已提交
1356 1357 1358 1359 1360 1361
| Name  | Type                                               | Mandatory| Description                                                |
| -------- | --------------------------------------------------- | ---- | ---------------------------------------------------- |
| callback | AsyncCallback<Array<[Holder](#holder)>> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
1362
  ```js
S
shawn_he 已提交
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383
  contact.queryHolders((err, data) => {
      if (err) {
          console.log(`queryHolders callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryHolders callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryHolders

queryHolders(): Promise<Array<Holder>>

Queries all applications that have created contacts. This API uses a promise to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Return Value**
S
shawn_he 已提交
1384

S
shawn_he 已提交
1385 1386 1387 1388 1389 1390
| Type                                         | Description                                                        |
| --------------------------------------------- | ------------------------------------------------------------ |
| Promise<Array<[Holder](#holder)>> | Promise used to return the result.|

**Example**

S
shawn_he 已提交
1391
  ```js
S
shawn_he 已提交
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
  let promise = contact.queryHolders();
  promise.then((data) => {
      console.log(`queryHolders success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`queryHolders fail: err->${JSON.stringify(err)}`);
  });
  ```


## contact.queryKey

queryKey(id: number, callback: AsyncCallback<string>): void

Queries the key of a contact based on the specified contact ID. This API uses an asynchronous callback to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1412

S
shawn_he 已提交
1413 1414 1415 1416 1417 1418 1419
| Name  | Type                       | Mandatory| Description                                   |
| -------- | --------------------------- | ---- | --------------------------------------- |
| id       | number                      | Yes  | Contact ID.                   |
| callback | AsyncCallback<string> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
1420
  ```js
S
shawn_he 已提交
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
  contact.queryKey(/*id*/1, (err, data) => {
      if (err) {
          console.log(`queryKey callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryKey callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryKey

queryKey(id: number, holder: Holder, callback: AsyncCallback<string>): void

S
shawn_he 已提交
1435
Queries the key of a contact based on the specified contact ID. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
1436 1437 1438 1439 1440 1441

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1442

S
shawn_he 已提交
1443 1444 1445 1446 1447 1448 1449 1450
| Name  | Type                       | Mandatory| Description                                   |
| -------- | --------------------------- | ---- | --------------------------------------- |
| id       | number                      | Yes  | Contact ID.                   |
| holder   | [Holder](#holder)           | Yes  | Application that creates the contacts.                 |
| callback | AsyncCallback<string> | Yes  | Callback used to return the result.|

**Example**

S
shawn_he 已提交
1451
  ```js
S
shawn_he 已提交
1452
  contact.queryKey(/*id*/1, {
S
shawn_he 已提交
1453 1454 1455
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476
  }, (err, data) => {
      if (err) {
          console.log(`queryKey callback: err->${JSON.stringify(err)}`);
          return;
      }
      console.log(`queryKey callback: success data->${JSON.stringify(data)}`);
  });
  ```


## contact.queryKey

queryKey(id: number, holder?: Holder): Promise<string>

Queries the key of a contact based on the specified contact ID and application. This API uses a promise to return the result.

**Permission required**: ohos.permission.READ_CONTACTS

**System capability**: SystemCapability.Applications.ContactsData

**Parameters**
S
shawn_he 已提交
1477

S
shawn_he 已提交
1478 1479 1480 1481 1482 1483
| Name| Type             | Mandatory| Description                  |
| ------ | ----------------- | ---- | ---------------------- |
| id     | number            | Yes  | Contact ID.  |
| holder | [Holder](#holder) | No  | Application that creates the contacts.|

**Return Value**
S
shawn_he 已提交
1484

S
shawn_he 已提交
1485 1486 1487 1488 1489 1490
| Type                 | Description                                                |
| --------------------- | ---------------------------------------------------- |
| Promise<string> | Promise used to return the result.|

**Example**

S
shawn_he 已提交
1491
  ```js
S
shawn_he 已提交
1492
  let promise = contact.queryKey(/*id*/1, {
S
shawn_he 已提交
1493 1494 1495
      holderId: 0,
      bundleName: "",
      displayName: ""
S
shawn_he 已提交
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
  });
  promise.then((data) => {
      console.log(`queryKey success: data->${JSON.stringify(data)}`);
  }).catch((err) => {
      console.error(`queryKey fail: err->${JSON.stringify(err)}`);
  });
  ```


## Contact

Defines a contact.

**System capability**: SystemCapability.Applications.ContactsData

### Constant

| Name              | Value  | Description            |
| ------------------ | ---- | ---------------- |
| INVALID_CONTACT_ID | -1   | Default contact ID.|


### Attributes

S
shawn_he 已提交
1520
|       Name       |                   Type                 | Readable| Writable| Description                                  |
S
shawn_he 已提交
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545
| ----------------- | --------------------------------------- | ---- | ---- | -------------------------------------- |
| id                | number                                  | Yes  | No  | Contact ID.                          |
| key               | string                                  | Yes  | No  | Contact key.                         |
| contactAttributes | [ContactAttributes](#contactattributes) | Yes  | Yes  | List of contact attributes.                    |
| emails            | [Email](#email)[]                       | Yes  | Yes  | List of email addresses of the contact.                |
| events            | [Event](#event)[]                       | Yes  | Yes  | List of important dates such as birthdays and anniversaries of the contact.|
| groups            | [Group](#group)[]                       | Yes  | Yes  | List of groups of the contact.                    |
| imAddresses       | [ImAddress](#imaddress)[]               | Yes  | Yes  | List of instant message addresses of the contact.            |
| phoneNumbers      | [PhoneNumber](#phonenumber)[]           | Yes  | Yes  | List of phone numbers of the contact.                |
| portrait          | [Portrait](#portrait)                   | Yes  | Yes  | Contact portrait.                        |
| postalAddresses   | [PostalAddress](#postaladdress)[]       | Yes  | Yes  | List of postal addresses of the contact.                |
| relations         | [Relation](#relation)[]                 | Yes  | Yes  | List of relationships with the contact.                    |
| sipAddresses      | [SipAddress](#sipaddress)[]             | Yes  | Yes  | List of Session Initiation Protocol (SIP) addresses of the contact. |
| websites          | [Website](#website)[]                   | Yes  | Yes  | List of websites of the contact.                    |
| name              | [Name](#name)                           | Yes  | Yes  | Contact name.                        |
| nickName          | [NickName](#nickname)                   | Yes  | Yes  | Contact nickname.                        |
| note              | [Note](#note)                           | Yes  | Yes  | Contact notes.                        |
| organization      | [Organization](#organization)           | Yes  | Yes  | Organization of the contact.                    |


**Example**

Create contact data in JSON format:


S
shawn_he 已提交
1546
```js
S
shawn_he 已提交
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
let myContact = {
    phoneNumbers: [{
        phoneNumber: "138xxxxxxxx"
    }],
    name: {
        fullName: "fullName",
        namePrefix: "namePrefix"
    },
    nickName: {
        nickName: "nickName"
    }
};
```


  Or, create data by configuring a new Contact object.

S
shawn_he 已提交
1564
```js
S
shawn_he 已提交
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581
let myContact = new contact.Contact();
let name = new contact.Name();
name.fullName = "fullName";
let phoneNumber = new contact.PhoneNumber();
phoneNumber.phoneNumber = "138xxxxxxxx";
myContact.name = name;
myContact.phoneNumbers = [phoneNumber];
```


## ContactAttributes

Provides a list of contact attributes, which are generally used as arguments. 
If **null** is passed, all attributes are queried by default.

**System capability**: SystemCapability.Applications.ContactsData

S
shawn_he 已提交
1582
| Name      |            Type          | Readable| Writable| Description            |
S
shawn_he 已提交
1583 1584 1585 1586 1587 1588 1589 1590 1591
| ---------- | ------------------------- | ---- | ---- | ---------------- |
| attributes | [Attribute](#attribute)[] | Yes  | Yes  | List of contact attributes.|


**Example**

Create contact data in JSON format:


S
shawn_he 已提交
1592
```js
S
shawn_he 已提交
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604
let contactAttributes = {
    attributes: [
        contact.Attribute.ATTR_EMAIL,
        contact.Attribute.ATTR_NAME,
        contact.Attribute.ATTR_PHONE
    ]
};
```

Or, create data by configuring a **ContactAttributes** object.


S
shawn_he 已提交
1605
```js
S
shawn_he 已提交
1606
let contactAttributes = new contact.ContactAttributes();
S
shawn_he 已提交
1607
contactAttributes.attributes = [contact.Attribute.ATTR_EMAIL];
S
shawn_he 已提交
1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638
```


## Attribute

Enumerates contact attributes.

**System capability**: SystemCapability.Applications.ContactsData

| Name                 | Description                              |
| --------------------- | ---------------------------------- |
| ATTR_CONTACT_EVENT    | Important dates such as birthday and anniversaries of the contact.|
| ATTR_EMAIL            | Email address of the contact.                |
| ATTR_GROUP_MEMBERSHIP | Groups of the contact.                    |
| ATTR_IM               | IM addresses of the contact.            |
| ATTR_NAME             | Contact name.                    |
| ATTR_NICKNAME         | Contact nickname.                    |
| ATTR_NOTE             | Contact notes.                    |
| ATTR_ORGANIZATION     | Organization of the contact.                |
| ATTR_PHONE            | Phone number of the contacts.                |
| ATTR_PORTRAIT         | Contact portrait.                    |
| ATTR_POSTAL_ADDRESS   | Postal address of the contact.                |
| ATTR_RELATION         | Relationship with the contact.                    |
| ATTR_SIP_ADDRESS      | SIP addresses of the contact. |
| ATTR_WEBSITE          | Website that stores the contact information.                    |


**Example**

Create contact data in JSON format:

S
shawn_he 已提交
1639
```js
S
shawn_he 已提交
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
let attributes = [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE];
```


## Email

Defines a contact's email.

**System capability**: SystemCapability.Applications.ContactsData

### Constant

| Name            | Value  | Description            |
| ---------------- | ---- | ---------------- |
| CUSTOM_LABEL     | 0    | Custom mailbox type.|
| EMAIL_HOME       | 1    | Home mailbox.  |
| EMAIL_WORK       | 2    | Work mailbox.  |
| EMAIL_OTHER      | 3    | Other mailbox.  |
| INVALID_LABEL_ID | -1   | Invalid mailbox.  |


### Attributes

S
shawn_he 已提交
1663
| Name       |   Type  | Readable| Writable| Description            |
S
shawn_he 已提交
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674
| ----------- | -------- | ---- | ---- | ---------------- |
| email       | string   | Yes  | Yes  | Email addresses      |
| labelName   | string   | Yes  | Yes  | Name of the mailbox type.|
| displayName | string   | Yes  | Yes  | Displayed name of the mailbox.|
| labelId     | number   | Yes  | Yes  | Mailbox type.    |


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
1675
```js
S
shawn_he 已提交
1676 1677 1678 1679 1680 1681 1682 1683 1684
let email = {
    email: "xxx@email.com",
    displayName: "displayName"
}
```


  Or, create data by configuring an **Email** object.

S
shawn_he 已提交
1685
```js
S
shawn_he 已提交
1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696
let email = new contact.Email();
email.email = "xxx@email.com";
```


## Holder

Defines an application that creates the contact.

**System capability**: SystemCapability.Applications.ContactsData

S
shawn_he 已提交
1697 1698 1699 1700 1701
| Name       | Type  | Readable| Writable| Description        |
| ----------- | ------ | ---- | ---- | ------------ |
| bundleName  | string | Yes  | No  | Bundle name.|
| displayName | string | Yes  | No  | Application name.  |
| holderId    | number | Yes  | Yes  | Application ID.    |
S
shawn_he 已提交
1702 1703 1704 1705 1706 1707


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
1708
```js
S
shawn_he 已提交
1709 1710 1711 1712 1713 1714 1715
let holder = {
  holderId: 0
};
```

  Or, create data by configuring a **Holder** object.

S
shawn_he 已提交
1716
```js
S
shawn_he 已提交
1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
let holder = new contact.Holder();
holder.holderId = 0;
```


## Event

Defines a contact's event.

**System capability**: SystemCapability.Applications.ContactsData

### Constant

| Name             | Value  | Description              |
| ----------------- | ---- | ------------------ |
| CUSTOM_LABEL      | 0    | Custom event.  |
| EVENT_ANNIVERSARY | 1    | Anniversary event.|
| EVENT_OTHER       | 2    | Other event.    |
| EVENT_BIRTHDAY    | 3    | Birthday event.    |
| INVALID_LABEL_ID  | -1   | Invalid event.    |


### Attributes

S
shawn_he 已提交
1741
|    Name  |   Type  | Readable| Writable| Description          |
S
shawn_he 已提交
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751
| --------- | -------- | ---- | ---- | -------------- |
| eventDate | string   | Yes  | Yes  | Event date.  |
| labelName | string   | Yes  | Yes  | Event type.|
| labelId   | number   | Yes  | Yes  | Event type ID.    |


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
1752
```js
S
shawn_he 已提交
1753 1754 1755 1756 1757 1758 1759
let event = {
    eventDate: "xxxxxx"
};
```

  Or, create data by configuring an **Event** object.

S
shawn_he 已提交
1760
```js
S
shawn_he 已提交
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771
let event = new contact.Event();
event.eventDate = "xxxxxx";
```


## Group

Defines a contact group.

**System capability**: SystemCapability.Applications.ContactsData

S
shawn_he 已提交
1772
| Name   |   Type  | Readable| Writable| Description              |
S
shawn_he 已提交
1773 1774 1775 1776 1777 1778 1779 1780 1781
| ------- | -------- | ---- | ---- | ------------------ |
| groupId | number   | Yes  | Yes  | ID of a contact group.  |
| title   | string   | Yes  | Yes  | Name of a contact group.|


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
1782
```js
S
shawn_he 已提交
1783 1784 1785 1786 1787 1788 1789 1790
let group = {
    groupId: 1,
    title: "title"
};
```

  Or, create data by configuring a **Group** object.

S
shawn_he 已提交
1791
```js
S
shawn_he 已提交
1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819
let group = new contact.Group();
group.title = "title";
```


## ImAddress

Enumerates IM addresses.

**System capability**: SystemCapability.Applications.ContactsData

### Constant

| Name            | Value  | Description                |
| ---------------- | ---- | -------------------- |
| CUSTOM_LABEL     | -1   | Custom IM|
| IM_AIM           | 0    | AIM   |
| IM_MSN           | 1    | MSN   |
| IM_YAHOO         | 2    | Yahoo |
| IM_SKYPE         | 3    | Skype |
| IM_QQ            | 4    | QQ    |
| IM_ICQ           | 6    | ICQ   |
| IM_JABBER        | 7    | JABBER|
| INVALID_LABEL_ID | -2   | Invalid IM|


### Attributes

S
shawn_he 已提交
1820
| Name     |   Type  | Readable| Writable| Description              |
S
shawn_he 已提交
1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
| --------- | -------- | ---- | ---- | ------------------ |
| imAddress | string   | Yes  | Yes  | IM address.    |
| labelName | string   | Yes  | Yes  | IM name.|
| labelId   | number   | Yes  | Yes  | IM ID.    |


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
1831
```js
S
shawn_he 已提交
1832 1833 1834 1835 1836 1837 1838 1839 1840
let imAddress = {
    imAddress: "imAddress",
    labelName: "labelName"
};
```


  Or, create data by configuring an **ImAddress** object.

S
shawn_he 已提交
1841
```js
S
shawn_he 已提交
1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
let imAddress = new contact.ImAddress();
imAddress.imAddress = "imAddress";
```


## Name

Defines a contact's name.

**System capability**: SystemCapability.Applications.ContactsData

S
shawn_he 已提交
1853
| Name              |   Type  | Readable| Writable| Description                       |
S
shawn_he 已提交
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869
| ------------------ | -------- | ---- | ---- | --------------------------- |
| familyName         | string   | Yes  | Yes  | Family name.         |
| familyNamePhonetic | string   | Yes  | Yes  | Family name in pinyin.     |
| fullName           | string   | Yes  | Yes  | Full name of the contact.             |
| givenName          | string   | Yes  | Yes  | Given name of the contact.|
| givenNamePhonetic  | string   | Yes  | Yes  | Given name of the contact in pinyin.         |
| middleName         | string   | Yes  | Yes  | Middle name of the contact.           |
| middleNamePhonetic | string   | Yes  | Yes  | Middle name of the contact in pinyin.       |
| namePrefix         | string   | Yes  | Yes  | Prefix of the contact name.         |
| nameSuffix         | string   | Yes  | Yes  | Suffix of the contact name.         |


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
1870
```js
S
shawn_he 已提交
1871 1872 1873 1874 1875 1876 1877 1878
let name = {
    familyName: "familyName",
    fullName: "fullName"
};
```

  Or, create data by configuring a **Name** object.

S
shawn_he 已提交
1879
```js
S
shawn_he 已提交
1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891
let name = new contact.Name();
name.familyName = "familyName";
name.fullName = "fullName";
```


## NickName

Defines a contact's nickname.

**System capability**: SystemCapability.Applications.ContactsData

S
shawn_he 已提交
1892
| Name    |   Type  | Readable| Writable| Description          |
S
shawn_he 已提交
1893 1894 1895 1896 1897 1898 1899 1900
| -------- | -------- | ---- | ---- | -------------- |
| nickName | string   | Yes  | Yes  | Contact nickname.|


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
1901
```js
S
shawn_he 已提交
1902 1903 1904 1905 1906 1907 1908
let nickName = {
    nickName: "nickName"
};
```

  Or, create data by configuring a **NickName** object.

S
shawn_he 已提交
1909
```js
S
shawn_he 已提交
1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920
let nickName = new contact.NickName();
nickName.nickName = "nickName";
```


## Note

Defines a contact's note.

**System capability**: SystemCapability.Applications.ContactsData

S
shawn_he 已提交
1921
| Name       |   Type  | Readable| Writable| Description              |
S
shawn_he 已提交
1922 1923 1924 1925 1926 1927 1928 1929
| ----------- | -------- | ---- | ---- | ------------------ |
| noteContent | string   | Yes  | Yes  | Notes of the contact.|


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
1930
```js
S
shawn_he 已提交
1931 1932 1933 1934 1935 1936 1937
let note = {
    noteContent: "noteContent"
};
```

  Or, create data by configuring a **Note** object.

S
shawn_he 已提交
1938
```js
S
shawn_he 已提交
1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
let note = new contact.Note();
note.noteContent = "noteContent";
```


## Organization

Defines a contact's organization.

**System capability**: SystemCapability.Applications.ContactsData

S
shawn_he 已提交
1950
| Name |   Type  | Readable| Writable| Description      |
S
shawn_he 已提交
1951 1952 1953 1954 1955 1956 1957 1958 1959
| ----- | -------- | ---- | ---- | ---------- |
| name  | string   | Yes  | Yes  | Organization name.|
| title | string   | Yes  | Yes  | Organization title.|


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
1960
```js
S
shawn_he 已提交
1961 1962 1963 1964 1965 1966 1967 1968
let organization = {
    name: "name",
    title: "title"
};
```

  Or, create data by configuring an **Organization** object.

S
shawn_he 已提交
1969
```js
S
shawn_he 已提交
1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
let organization = new contact.Organization();
organization.name = "name";
organization.title = "title";
```


## PhoneNumber

Defines a contact's phone number.

**System capability**: SystemCapability.Applications.ContactsData

### Constant

| Name            | Value  | Description                                            |
| ---------------- | ---- | ------------------------------------------------ |
| CUSTOM_LABEL     | 0    | Custom phone type.                                |
| NUM_HOME         | 1    | Home phone.                                  |
| NUM_MOBILE       | 2    | Mobile phone.                                  |
| NUM_WORK         | 3    | Work phone.                                  |
| NUM_FAX_WORK     | 4    | Work fax.                              |
| NUM_FAX_HOME     | 5    | Family fax.                              |
| NUM_PAGER        | 6    | Pager.                                |
| NUM_OTHER        | 7    | Other phone type.                                  |
| NUM_CALLBACK     | 8    | Callback phone.                                  |
| NUM_CAR          | 9    | Car phone.                                  |
| NUM_COMPANY_MAIN | 10   | Company phone.                                  |
| NUM_ISDN         | 11   | Integrated Services Digital Network (ISDN) phone.                |
| NUM_MAIN         | 12   | Main phone.                                    |
| NUM_OTHER_FAX    | 13   | Other fax phone.                                  |
| NUM_RADIO        | 14   | Wireless phone.                                  |
| NUM_TELEX        | 15   | Telex phone.                                  |
| NUM_TTY_TDD      | 16   | Teletypewriter (TTY) or Test Driven Development (TDD) phone.|
| NUM_WORK_MOBILE  | 17   | Work mobile phone.                              |
| NUM_WORK_PAGER   | 18   | Work pager.                            |
| NUM_ASSISTANT    | 19   | Assistant phone.                                  |
| NUM_MMS          | 20   | MMS phone.                                  |
| INVALID_LABEL_ID | -1   | Invalid phone type.                                  |


### Attributes

S
shawn_he 已提交
2012
| Name       |   Type  | Readable| Writable| Description              |
S
shawn_he 已提交
2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
| ----------- | -------- | ---- | ---- | ------------------ |
| labelName   | string   | Yes  | Yes  | Phone number type.|
| phoneNumber | string   | Yes  | Yes  | Phone number.        |
| labelId     | number   | Yes  | Yes  | Phone number ID.    |


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
2023
```js
S
shawn_he 已提交
2024 2025 2026 2027 2028 2029 2030 2031
let phoneNumber = {
    phoneNumber: "138xxxxxxxx",
    labelId: contact.PhoneNumber.NUM_HOME
};
```

  Or, create data by configuring a new **PhoneNumber** object.

S
shawn_he 已提交
2032
```js
S
shawn_he 已提交
2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043
let phoneNumber = new contact.PhoneNumber();
phoneNumber.phoneNumber = "138xxxxxxxx";
```


## Portrait

Defines a contact's portrait.

**System capability**: SystemCapability.Applications.ContactsData

S
shawn_he 已提交
2044
| Name|   Type  | Readable| Writable| Description          |
S
shawn_he 已提交
2045 2046 2047 2048 2049 2050 2051 2052
| ---- | -------- | ---- | ---- | -------------- |
| uri  | string   | Yes  | Yes  | Contact portrait.|


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
2053
```js
S
shawn_he 已提交
2054 2055 2056 2057 2058 2059 2060
let portrait = {
    uri: "uri"
};
```

  Or, create data by configuring a new **Portrait** object.

S
shawn_he 已提交
2061
```js
S
shawn_he 已提交
2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085
let portrait = new contact.Portrait();
portrait.uri = "uri";
```


## PostalAddress

Defines a contact's postal address.

**System capability**: SystemCapability.Applications.ContactsData

### Constant

| Name            | Value  | Description                |
| ---------------- | ---- | -------------------- |
| CUSTOM_LABEL     | 0    | Custom postal address type.|
| ADDR_HOME        | 1    | Home address.      |
| ADDR_WORK        | 2    | Work address.      |
| ADDR_OTHER       | 3    | Other addresses.      |
| INVALID_LABEL_ID | -1   | Invalid address type.      |


### Attributes

S
shawn_he 已提交
2086
| Name         |   Type  | Readable| Writable| Description                      |
S
shawn_he 已提交
2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103
| ------------- | -------- | ---- | ---- | -------------------------- |
| city          | string   | Yes  | Yes  | City where the contact is located.        |
| country       | string   | Yes  | Yes  | Country/Region where the contact is located.        |
| labelName     | string   | Yes  | Yes  | Postal address type.        |
| neighborhood  | string   | Yes  | Yes  | Neighbor of the contact.            |
| pobox         | string   | Yes  | Yes  | Email of the contact.            |
| postalAddress | string   | Yes  | Yes  | Postal address of the contact.        |
| postcode      | string   | Yes  | Yes  | Postal code of the region where the contact is located.|
| region        | string   | Yes  | Yes  | Area where the contact is located.        |
| street        | string   | Yes  | Yes  | Street where the contact resides.        |
| labelId       | number   | Yes  | Yes  | Postal address ID.            |


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
2104
```js
S
shawn_he 已提交
2105 2106 2107 2108 2109 2110 2111
let postalAddress = {
    city: "city"
};
```

  Or, create data by configuring a new **PostalAddress** object.

S
shawn_he 已提交
2112
```js
S
shawn_he 已提交
2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147
let postalAddress = new contact.PostalAddress();
postalAddress.city = "city";
```


## Relation

Defines a contact's relationship.

**System capability**: SystemCapability.Applications.ContactsData

### Constant

| Name                     | Value  | Description              |
| ------------------------- | ---- | ------------------ |
| CUSTOM_LABEL              | 0    | Custom relationship.  |
| RELATION_ASSISTANT        | 1    | Assistant.    |
| RELATION_BROTHER          | 2    | Sibling.    |
| RELATION_CHILD            | 3    | Child.    |
| RELATION_DOMESTIC_PARTNER | 4    | Domestic partner.|
| RELATION_FATHER           | 5    | Father.    |
| RELATION_FRIEND           | 6    | Friend.    |
| RELATION_MANAGER          | 7    | Manager.  |
| RELATION_MOTHER           | 8    | Mother.    |
| RELATION_PARENT           | 9    | Parent.    |
| RELATION_PARTNER          | 10   | Partner.|
| RELATION_REFERRED_BY      | 11   | Referrer.  |
| RELATION_RELATIVE         | 12   | Relative.    |
| RELATION_SISTER           | 13   | Sister.    |
| RELATION_SPOUSE           | 14   | Spouse.    |
| INVALID_LABEL_ID          | -1   | Invalid relationship.  |


### Attributes

S
shawn_he 已提交
2148
| Name        |   Type  | Readable| Writable| Description          |
S
shawn_he 已提交
2149 2150 2151 2152 2153 2154 2155 2156 2157 2158
| ------------ | -------- | ---- | ---- | -------------- |
| labelName    | string   | Yes  | Yes  | Relationship type.|
| relationName | string   | Yes  | Yes  | Relationship name.    |
| labelId      | number   | Yes  | Yes  | Relationship ID.    |


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
2159
```js
S
shawn_he 已提交
2160 2161 2162 2163 2164 2165 2166 2167
let relation = {
    relationName: "relationName",
    labelId: contact.Relation.RELATION_ASSISTANT
};
```

  Or, create data by configuring a new **Relation** object.

S
shawn_he 已提交
2168
```js
S
shawn_he 已提交
2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193
let relation = new contact.Relation();
relation.relationName = "relationName";
relation.labelId = contact.Relation.RELATION_ASSISTANT;
```


## SipAddress

Defines a contact's SIP address.

**System capability**: SystemCapability.Applications.ContactsData

### Constant

| Name            | Value  | Description                               |
| ---------------- | ---- | ----------------------------------- |
| CUSTOM_LABEL     | 0    | Custom SIP address.|
| SIP_HOME         | 1    | Home SIP address.  |
| SIP_WORK         | 2    | Work SIP address.  |
| SIP_OTHER        | 3    | Other SIP address.  |
| INVALID_LABEL_ID | -1   | Invalid SIP address.  |


### Attributes

S
shawn_he 已提交
2194
| Name      |   Type  | Readable| Writable| Description                             |
S
shawn_he 已提交
2195 2196 2197 2198 2199 2200 2201 2202 2203
| ---------- | -------- | ---- | ---- | --------------------------------- |
| labelName  | string   | Yes  | Yes  | SIP address type.|
| sipAddress | string   | Yes  | Yes  | SIP address.        |
| labelId    | number   | Yes  | Yes  | SIP address ID.    |

**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
2204
```js
S
shawn_he 已提交
2205 2206 2207 2208 2209 2210 2211
var sipAddress = {
    sipAddress: "sipAddress"
};
```

  Or, create data by configuring a new **SipAddress** object.

S
shawn_he 已提交
2212
```js
S
shawn_he 已提交
2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223
let sipAddress = new contact.SipAddress();
sipAddress.sipAddress = "sipAddress";
```


## Website

Defines a contact's website.

**System capability**: SystemCapability.Applications.ContactsData

S
shawn_he 已提交
2224
| Name   |   Type  | Readable| Writable| Description              |
S
shawn_he 已提交
2225 2226 2227 2228 2229 2230 2231 2232
| ------- | -------- | ---- | ---- | ------------------ |
| website | string   | Yes  | Yes  | Website of the contact.|


**Example**

  Create contact data in JSON format:

S
shawn_he 已提交
2233
```js
S
shawn_he 已提交
2234 2235 2236 2237 2238 2239 2240
let website = {
    website: "website"
};
```

  Or, create data by configuring a new **Website** object.

S
shawn_he 已提交
2241
```js
S
shawn_he 已提交
2242 2243
let website = new contact.Website();
website.website = "website";
S
shawn_he 已提交
2244
```