1# @ohos.contact (Contacts) 2 3The **contact** module provides contact management functions, such as adding, deleting, and updating contacts. 4 5>**NOTE** 6> 7>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. 8 9 10## Modules to Import 11 12``` 13import { contact } from '@kit.ContactsKit'; 14``` 15 16## contact.addContact<sup>10+</sup> 17 18addContact(context: Context, contact: Contact, callback: AsyncCallback<number>): void 19 20Adds a contact. This API uses an asynchronous callback to return the result. 21 22**Atomic service API**: This API can be used in atomic services since API version 12. 23 24**Permission required**: ohos.permission.WRITE_CONTACTS 25 26**System capability**: SystemCapability.Applications.ContactsData 27 28**Parameters** 29 30| Name | Type | Mandatory| Description | 31| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 32| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 33| contact | [Contact](#contact) | Yes | Contact information. | 34| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, the ID of the added contact is returned. If the operation fails, an error code is returned. | 35 36**Error codes** 37 38| ID| Error Message | 39| -------- | ------------------ | 40| 201 | Permission denied. | 41| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 42 43**Example** 44 45```js 46 import { BusinessError } from '@kit.BasicServicesKit'; 47 // Obtain the context. 48 let context = getContext(this) as Context; 49 contact.addContact( 50 context, 51 { 52 name: { 53 fullName: 'xxx' 54 }, 55 phoneNumbers: [{ 56 phoneNumber: '138xxxxxxxx' 57 }] 58 }, (err: BusinessError, data) => { 59 if (err) { 60 console.error(`Failed to add Contact. Code:${err.code}, message: ${err.message}`); 61 return; 62 } 63 console.info(`Succeeded in adding Contact. data: ${JSON.stringify(data)}`); 64 }); 65``` 66 67## contact.addContact<sup>(deprecated)7+</sup> 68 69addContact(contact:Contact, callback:AsyncCallback<number>): void 70 71Adds a contact. This API uses an asynchronous callback to return the result. 72 73> **NOTE** 74> 75> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [addContact](#contactaddcontact10). 76 77**Permission required**: ohos.permission.WRITE_CONTACTS 78 79**System capability**: SystemCapability.Applications.ContactsData 80 81**Parameters** 82 83| Name | Type | Mandatory| Description | 84| -------- | --------------------------- | ---- | -------------------------------------------------------- | 85| contact | [Contact](#contact) | Yes | Contact information. | 86| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, the ID of the added contact is returned. If the operation fails, an error code is returned.| 87 88**Example** 89 90 ```js 91 import { BusinessError } from '@kit.BasicServicesKit'; 92 contact.addContact({ 93 name: { 94 fullName: 'xxx' 95 }, 96 phoneNumbers: [{ 97 phoneNumber: '138xxxxxxxx' 98 }] 99 }, (err: BusinessError, data) => { 100 if (err) { 101 console.error(`Failed to add Contact. Code: ${err.code}, message: ${err.message}`); 102 return; 103 } 104 console.info(`Succeeded in adding Contact. data: ${JSON.stringify(data)}`); 105 }); 106 ``` 107 108## contact.addContact<sup>10+</sup> 109 110addContact(context: Context, contact: Contact): Promise<number> 111 112Adds a contact. This API uses a promise to return the result. 113 114**Atomic service API**: This API can be used in atomic services since API version 12. 115 116**Permission required**: ohos.permission.WRITE_CONTACTS 117 118**System capability**: SystemCapability.Applications.ContactsData 119 120**Parameters** 121 122| Name | Type | Mandatory| Description | 123| ------- | ------------------- | ---- | ------------------------------------------------------------ | 124| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 125| contact | [Contact](#contact) | Yes | Contact information. | 126 127**Return Value** 128 129| Type | Description | 130| --------------------- | --------------------------------- | 131| Promise<number> | Promise used to return the result, which is the ID of the added contact.| 132 133**Error codes** 134 135| ID| Error Message | 136| -------- | ------------------ | 137| 201 | Permission denied. | 138| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 139 140**Example** 141 142```js 143 import { BusinessError } from '@kit.BasicServicesKit'; 144 // Obtain the context. 145 let context = getContext(this) as Context; 146 let promise = contact.addContact( 147 context, 148 { 149 name: { 150 fullName: 'xxx' 151 }, 152 phoneNumbers: [{ 153 phoneNumber: '138xxxxxxxx' 154 }] 155 }); 156 promise.then((data) => { 157 console.info(`Succeeded in adding Contact. data: ${JSON.stringify(data)}`); 158 }).catch((err: BusinessError) => { 159 console.error(`Failed to add Contact. Code: ${err.code}, message: ${err.message}`); 160 }); 161``` 162 163## contact.addContact<sup>(deprecated)7+</sup> 164 165addContact(contact: Contact): Promise<number> 166 167Adds a contact. This API uses a promise to return the result. 168 169> **NOTE** 170> 171> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [addContact](#contactaddcontact10-1). 172 173**Permission required**: ohos.permission.WRITE_CONTACTS 174 175**System capability**: SystemCapability.Applications.ContactsData 176 177**Parameters** 178 179| Name | Type | Mandatory| Description | 180| ------- | ------------------- | ---- | ------------ | 181| contact | [Contact](#contact) | Yes | Contact information.| 182 183**Return Value** 184 185| Type | Description | 186| --------------------- | --------------------------------- | 187| Promise<number> | Promise used to return the result, which is the ID of the added contact.| 188 189**Example** 190 191 ```js 192 import { BusinessError } from '@kit.BasicServicesKit'; 193 let promise = contact.addContact({ 194 name: { 195 fullName: 'xxx' 196 }, 197 phoneNumbers: [{ 198 phoneNumber: '138xxxxxxxx' 199 }] 200 }); 201 promise.then((data) => { 202 console.info(`Succeeded in adding Contact. data: ${JSON.stringify(data)}`); 203 }).catch((err: BusinessError) => { 204 console.error(`Failed to add Contact. Code: ${err.code}, message: ${err.message}`); 205 }); 206 ``` 207 208## contact.deleteContact<sup>10+</sup> 209 210deleteContact(context: Context, key: string, callback: AsyncCallback<void>): void 211 212Deletes a contact based on the specified contact key. This API uses an asynchronous callback to return the result. 213 214**Permission required**: ohos.permission.WRITE_CONTACTS 215 216**System capability**: SystemCapability.Applications.ContactsData 217 218**Parameters** 219 220| Name | Type | Mandatory| Description | 221| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 222| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 223| key | string | Yes | Unique query key of a contact. One contact corresponds to one key. | 224| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the ID of the deleted contact is returned. If the operation fails, an error code is returned. | 225 226**Error codes** 227 228| ID| Error Message | 229| -------- | ------------------ | 230| 201 | Permission denied. | 231| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 232 233**Example** 234 235```js 236 import { BusinessError } from '@kit.BasicServicesKit'; 237 // Obtain the context. 238 let context = getContext(this) as Context; 239 contact.deleteContact(context, 'xxx', (err: BusinessError) => { 240 if (err) { 241 console.error(`Failed to delete Contact. Code: ${err.code}, message: ${err.message}`); 242 return; 243 } 244 console.info('Succeeded in deleting Contact.'); 245 }); 246``` 247 248## contact.deleteContact<sup>(deprecated)7+</sup> 249 250deleteContact(key: string, callback: AsyncCallback<void>): void 251 252Deletes a contact based on the specified contact key. This API uses an asynchronous callback to return the result. 253 254> **NOTE** 255> 256> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [deleteContact](#contactdeletecontact10). 257 258**Permission required**: ohos.permission.WRITE_CONTACTS 259 260**System capability**: SystemCapability.Applications.ContactsData 261 262**Parameters** 263 264| Name | Type | Mandatory| Description | 265| -------- | ------------------------- | ---- | ------------------------------------ | 266| key | string | Yes | Unique query key of a contact. One contact corresponds to one key.| 267| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the ID of the deleted contact is returned. If the operation fails, an error code is returned.| 268 269**Example** 270 271 ```js 272 import { BusinessError } from '@kit.BasicServicesKit'; 273 contact.deleteContact('xxx', (err: BusinessError) => { 274 if (err) { 275 console.error(`Failed to delete Contact. Code: ${err.code}, message: ${err.message}`); 276 return; 277 } 278 console.info('Succeeded in deleting Contact.'); 279 }); 280 ``` 281 282 283## contact.deleteContact<sup>10+</sup> 284 285deleteContact(context: Context, key: string): Promise<void> 286 287Deletes a contact based on the specified contact key. This API uses a promise to return the result. 288 289**Permission required**: ohos.permission.WRITE_CONTACTS 290 291**System capability**: SystemCapability.Applications.ContactsData 292 293**Parameters** 294 295| Name | Type | Mandatory| Description | 296| ------- | ------- | ---- | ------------------------------------------------------------ | 297| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 298| key | string | Yes | Unique query key of a contact. One contact corresponds to one key. | 299 300**Return Value** 301 302| Type | Description | 303| ------------------- | -------------------------------------- | 304| Promise<void> | Promise that returns no value.| 305 306**Error codes** 307 308| ID| Error Message | 309| -------- | ------------------ | 310| 201 | Permission denied. | 311| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 312 313**Example** 314 315 ```js 316 import { BusinessError } from '@kit.BasicServicesKit'; 317 // Obtain the context. 318 let context = getContext(this) as Context; 319 let promise = contact.deleteContact(context, 'xxx'); 320 promise.then(() => { 321 console.info(`Succeeded in deleting Contact.`); 322 }).catch((err: BusinessError) => { 323 console.error(`Failed to delete Contact. Code: ${err.code}, message: ${err.message}`); 324 }); 325 ``` 326 327## contact.deleteContact<sup>(deprecated)7+</sup> 328 329deleteContact(key: string): Promise<void> 330 331Deletes a contact based on the specified contact key. This API uses a promise to return the result. 332 333> **NOTE** 334> 335> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [deleteContact](#contactdeletecontact10-1). 336 337**Permission required**: ohos.permission.WRITE_CONTACTS 338 339**System capability**: SystemCapability.Applications.ContactsData 340 341**Parameters** 342 343| Name| Type | Mandatory| Description | 344| ------ | ------ | ---- | -------------------------------------- | 345| key | string | Yes | Unique query key of a contact. One contact corresponds to one key.| 346 347**Return Value** 348 349| Type | Description | 350| ------------------- | -------------------------------------- | 351| Promise<void> | Promise that returns no value.| 352 353**Example** 354 355 ```js 356 import { BusinessError } from '@kit.BasicServicesKit'; 357 let promise = contact.deleteContact('xxx'); 358 promise.then(() => { 359 console.info(`Succeeded in deleting Contact.`); 360 }).catch((err: BusinessError) => { 361 console.error(`Failed to delete Contact. Code: ${err.code}, message: ${err.message}`); 362 }); 363 ``` 364 365 366## contact.updateContact<sup>10+</sup> 367 368updateContact(context: Context, contact: Contact, callback: AsyncCallback<void>): void 369 370Updates a contact based on the specified contact information. This API uses an asynchronous callback to return the result. 371 372**Required permissions**: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS 373 374**System capability**: SystemCapability.Applications.ContactsData 375 376**Parameters** 377 378| Name | Type | Mandatory| Description | 379| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 380| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 381| contact | [Contact](#contact) | Yes | Contact information. Contact ID, which is mandatory. | 382| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the ID of the updated contact is returned. If the operation fails, an error code is returned. | 383 384**Error codes** 385 386| ID| Error Message | 387| -------- | ------------------ | 388| 201 | Permission denied. | 389| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 390 391**Example** 392 393 ```js 394 import { BusinessError } from '@kit.BasicServicesKit'; 395 // Obtain the context. 396 let context = getContext(this) as Context; 397 contact.updateContact(context, { 398 id: 1, 399 name: { 400 fullName: 'xxx' 401 }, 402 phoneNumbers: [{ 403 phoneNumber: '138xxxxxxxx' 404 }] 405 }, (err: BusinessError) => { 406 if (err) { 407 console.error(`Failed to update Contact. Code: ${err.code}, message: ${err.message}`); 408 return; 409 } 410 console.info('Succeeded in updating Contact.'); 411 }); 412 ``` 413 414## contact.updateContact<sup>(deprecated)7+</sup> 415 416updateContact(contact: Contact, callback: AsyncCallback<void>): void 417 418Updates a contact based on the specified contact information. This API uses an asynchronous callback to return the result. 419 420> **NOTE** 421> 422> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [updateContact](#contactupdatecontact10). 423 424**Required permissions**: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS 425 426**System capability**: SystemCapability.Applications.ContactsData 427 428**Parameters** 429 430| Name | Type | Mandatory| Description | 431| -------- | ------------------------- | ---- | ------------------------------------ | 432| contact | [Contact](#contact) | Yes | Contact information. Contact ID, which is mandatory. | 433| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the ID of the updated contact is returned. If the operation fails, an error code is returned.| 434 435**Example** 436 437 ```js 438 import { BusinessError } from '@kit.BasicServicesKit'; 439 contact.updateContact({ 440 id: 1, 441 name: { 442 fullName: 'xxx' 443 }, 444 phoneNumbers: [{ 445 phoneNumber: '138xxxxxxxx' 446 }] 447 }, (err: BusinessError) => { 448 if (err) { 449 console.error(`Failed to update Contact. Code: ${err.code}, message: ${err.message}`); 450 return; 451 } 452 console.info('Succeeded in updating Contact.'); 453 }); 454 ``` 455 456 457## contact.updateContact<sup>10+</sup> 458 459updateContact(context: Context, contact: Contact, attrs: ContactAttributes, callback: AsyncCallback<void>): void 460 461Updates a contact based on the specified contact information. This API uses an asynchronous callback to return the result. 462 463**Required permissions**: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS 464 465**System capability**: SystemCapability.Applications.ContactsData 466 467**Parameters** 468 469| Name | Type | Mandatory| Description | 470| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 471| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 472| contact | [Contact](#contact) | Yes | Contact information. Contact ID, which is mandatory. | 473| attrs | [ContactAttributes](#contactattributes) | No | List of contact attributes. | 474| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the ID of the updated contact is returned. If the operation fails, an error code is returned. | 475 476**Error codes** 477 478| ID| Error Message | 479| -------- | ------------------ | 480| 201 | Permission denied. | 481| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 482 483**Example** 484 485 ```js 486 import { BusinessError } from '@kit.BasicServicesKit'; 487 // Obtain the context. 488 let context = getContext(this) as Context; 489 contact.updateContact(context, { 490 id: 1, 491 name: { 492 fullName: 'xxx' 493 }, 494 phoneNumbers: [{ 495 phoneNumber: '138xxxxxxxx' 496 }] 497 }, { 498 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 499 }, (err: BusinessError) => { 500 if (err) { 501 console.error(`Failed to update Contact. Code: ${err.code}, message: ${err.message}`); 502 return; 503 } 504 console.info('Succeeded in updating Contact.'); 505 }); 506 ``` 507 508## contact.updateContact<sup>(deprecated)7+</sup> 509 510updateContact(contact: Contact, attrs: ContactAttributes, callback: AsyncCallback<void>): void 511 512Updates a contact based on the specified contact information. This API uses an asynchronous callback to return the result. 513 514> **NOTE** 515> 516> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [updateContact](#contactupdatecontact10-1). 517 518**Required permissions**: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS 519 520**System capability**: SystemCapability.Applications.ContactsData 521 522**Parameters** 523 524| Name | Type | Mandatory| Description | 525| -------- | --------------------------------------- | ---- | ------------------------------------ | 526| contact | [Contact](#contact) | Yes | Contact information. Contact ID, which is mandatory. | 527| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 528| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the ID of the updated contact is returned. If the operation fails, an error code is returned.| 529 530**Example** 531 532 ```js 533 import { BusinessError } from '@kit.BasicServicesKit'; 534 contact.updateContact({ 535 id: 1, 536 name: { 537 fullName: 'xxx' 538 }, 539 phoneNumbers: [{ 540 phoneNumber: '138xxxxxxxx' 541 }] 542 }, { 543 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 544 }, (err: BusinessError) => { 545 if (err) { 546 console.error(`Failed to update Contact. Code: ${err.code}, message: ${err.message}`); 547 return; 548 } 549 console.info('Succeeded in updating Contact.'); 550 }); 551 ``` 552 553 554## contact.updateContact<sup>10+</sup> 555 556updateContact(context: Context, contact: Contact, attrs?: ContactAttributes): Promise<void> 557 558Updates a contact based on the specified contact information and attributes. This API uses a promise to return the result. 559 560**Required permissions**: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS 561 562**System capability**: SystemCapability.Applications.ContactsData 563 564**Parameters** 565 566| Name | Type | Mandatory| Description | 567| ------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 568| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 569| contact | [Contact](#contact) | Yes | Contact information. Contact ID, which is mandatory. | 570| attrs | [ContactAttributes](#contactattributes) | No | List of contact attributes. | 571 572**Return Value** 573 574| Type | Description | 575| ------------------- | -------------------------------------- | 576| Promise<void> | Promise that returns no value.| 577 578**Error codes** 579 580| ID| Error Message | 581| -------- | ------------------ | 582| 201 | Permission denied. | 583| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 584 585**Example** 586 587```js 588 import { BusinessError } from '@kit.BasicServicesKit'; 589 // Obtain the context. 590 let context = getContext(this) as Context; 591 let promise = contact.updateContact(context, { 592 id: 1, 593 name: { 594 fullName: 'xxx' 595 }, 596 phoneNumbers: [{ 597 phoneNumber: '138xxxxxxxx' 598 }] 599 }, { 600 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 601 }); 602 promise.then(() => { 603 console.info('Succeeded in updating Contact.'); 604 }).catch((err: BusinessError) => { 605 console.error(`Failed to update Contact. Code: ${err.code}, message: ${err.message}`); 606 }); 607``` 608 609## contact.updateContact<sup>(deprecated)7+</sup> 610 611updateContact(contact: Contact, attrs?: ContactAttributes): Promise<void> 612 613Updates a contact based on the specified contact information and attributes. This API uses a promise to return the result. 614 615> **NOTE** 616> 617> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [updateContact](#contactupdatecontact10-2). 618 619**Required permissions**: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS 620 621**System capability**: SystemCapability.Applications.ContactsData 622 623**Parameters** 624 625| Name | Type | Mandatory| Description | 626| ------- | --------------------------------------- | ---- | ------------------ | 627| contact | [Contact](#contact) | Yes | Contact information. Contact ID, which is mandatory. | 628| attrs | [ContactAttributes](#contactattributes) | No | List of contact attributes.| 629 630**Return Value** 631| Type | Description | 632| ------------------- | -------------------------------------- | 633| Promise<void> | Promise that returns no value.| 634 635**Example** 636 637 ```js 638 import { BusinessError } from '@kit.BasicServicesKit'; 639 let promise = contact.updateContact({ 640 id: 1, 641 name: { 642 fullName: 'xxx' 643 }, 644 phoneNumbers: [{ 645 phoneNumber: '138xxxxxxxx' 646 }] 647 }, { 648 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 649 }); 650 promise.then(() => { 651 console.info('Succeeded in updating Contact.'); 652 }).catch((err: BusinessError) => { 653 console.error(`Failed to update Contact. Code: ${err.code}, message: ${err.message}`); 654 }); 655 ``` 656 657 658## contact.isLocalContact<sup>10+</sup> 659 660isLocalContact(context: Context, id: number, callback: AsyncCallback<boolean>): void 661 662Checks whether the ID of this contact is in the local address book. This API uses an asynchronous callback to return the result. 663 664**Permission required**: ohos.permission.READ_CONTACTS 665 666**System capability**: SystemCapability.Applications.ContactsData 667 668**Parameters** 669 670| Name | Type | Mandatory| Description | 671| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 672| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 673| id | number | Yes | Contact ID. Each contact corresponds to one ID. | 674| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, a Boolean value is returned. The value **true** indicates that the contact ID is in the local phonebook, and the value **false** indicates the opposite. If the operation fails, an error code is returned.| 675 676**Error codes** 677 678| ID| Error Message | 679| -------- | ------------------ | 680| 201 | Permission denied. | 681| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 682 683**Example** 684 685 ```js 686 import { BusinessError } from '@kit.BasicServicesKit'; 687 // Obtain the context. 688 let context = getContext(this) as Context; 689 contact.isLocalContact(context, /*id*/1, (err: BusinessError, data) => { 690 if (err) { 691 console.error(`Failed to isLocalContact. Code: ${err.code}, message: ${err.message}`); 692 return; 693 } 694 console.info(`Succeeded in isLocalContact.`); 695 }); 696 ``` 697 698## contact.isLocalContact<sup>(deprecated)7+</sup> 699 700isLocalContact(id: number, callback: AsyncCallback<boolean>): void 701 702Checks whether the ID of this contact is in the local address book. This API uses an asynchronous callback to return the result. 703 704> **NOTE** 705> 706> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [isLocalContact](#contactislocalcontact10). 707 708**Permission required**: ohos.permission.READ_CONTACTS 709 710**System capability**: SystemCapability.Applications.ContactsData 711 712**Parameters** 713 714| Name | Type | Mandatory| Description | 715| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 716| id | number | Yes | Contact ID. Each contact corresponds to one ID. | 717| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, a Boolean value is returned. The value **true** indicates that the contact ID is in the local phonebook, and the value **false** indicates the opposite. If the operation fails, an error code is returned.| 718 719**Example** 720 721 ```js 722 import { BusinessError } from '@kit.BasicServicesKit'; 723 contact.isLocalContact(/*id*/1, (err: BusinessError, data) => { 724 if (err) { 725 console.error(`Failed to isLocalContact. Code: ${err.code}, message: ${err.message}`); 726 return; 727 } 728 console.info(`Succeeded in isLocalContact.`); 729 }); 730 ``` 731 732## contact.isLocalContact<sup>10+</sup> 733 734isLocalContact(context: Context, id: number): Promise<boolean> 735 736Checks whether the ID of this contact is in the local address book. This API uses a promise to return the result. 737 738**Permission required**: ohos.permission.READ_CONTACTS 739 740**System capability**: SystemCapability.Applications.ContactsData 741 742**Parameters** 743 744| Name | Type | Mandatory| Description | 745| ------- | ------- | ---- | ------------------------------------------------------------ | 746| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 747| id | number | Yes | Contact ID. Each contact corresponds to one ID. | 748 749**Return Value** 750 751| Type | Description | 752| ---------------------- | ------------------------------------------------------------ | 753| Promise<boolean> | Promise used to return the result. The value **true** indicates that the contact ID is in the local phonebook, and the value **false** indicates the opposite.| 754 755**Error codes** 756 757| ID| Error Message | 758| -------- | ------------------ | 759| 201 | Permission denied. | 760| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 761 762**Example** 763 764```js 765 import { BusinessError } from '@kit.BasicServicesKit'; 766 // Obtain the context. 767 let context = getContext(this) as Context; 768 let promise = contact.isLocalContact(context, /*id*/1); 769 promise.then((data) => { 770 console.info(`Succeeded in isLocalContact. data->${JSON.stringify(data)}`); 771 }).catch((err: BusinessError) => { 772 console.error(`Failed to isLocalContact. Code: ${err.code}, message: ${err.message}`); 773 }); 774``` 775 776## contact.isLocalContact<sup>(deprecated)7+</sup> 777 778isLocalContact(id: number): Promise<boolean> 779 780Checks whether the ID of this contact is in the local address book. This API uses a promise to return the result. 781 782> **NOTE** 783> 784> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [isLocalContact](#contactislocalcontact10-1). 785 786**Permission required**: ohos.permission.READ_CONTACTS 787 788**System capability**: SystemCapability.Applications.ContactsData 789 790**Parameters** 791 792| Name| Type | Mandatory| Description | 793| ------ | ------ | ---- | ------------------------------------------ | 794| id | number | Yes | Contact ID. Each contact corresponds to one ID.| 795 796**Return Value** 797 798| Type | Description | 799| ---------------------- | ------------------------------------------------------------ | 800| Promise<boolean> | Promise used to return the result. The value **true** indicates that the contact ID is in the local phonebook, and the value **false** indicates the opposite.| 801 802**Example** 803 804 ```js 805 import { BusinessError } from '@kit.BasicServicesKit'; 806 let promise = contact.isLocalContact(/*id*/1); 807 promise.then((data) => { 808 console.info(`Succeeded in isLocalContact. data->${JSON.stringify(data)}`); 809 }).catch((err: BusinessError) => { 810 console.error(`Failed to isLocalContact. Code: ${err.code}, message: ${err.message}`); 811 }); 812 ``` 813 814## contact.isMyCard<sup>10+</sup> 815 816isMyCard(context: Context, id: number, callback: AsyncCallback<boolean>): void 817 818Checks whether a contact is included in my card. This API uses an asynchronous callback to return the result. 819 820**Permission required**: ohos.permission.READ_CONTACTS 821 822**System capability**: SystemCapability.Applications.ContactsData 823 824**Parameters** 825 826| Name | Type | Mandatory| Description | 827| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 828| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 829| id | number | Yes | Contact ID. | 830| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, a Boolean value is returned. The value **true** indicates that the contact is included in my card, and the value **false** indicates the opposite. If the operation fails, an error code is returned.| 831 832**Error codes** 833 834| ID| Error Message | 835| -------- | ------------------ | 836| 201 | Permission denied. | 837| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 838 839**Example** 840 841```js 842 import { BusinessError } from '@kit.BasicServicesKit'; 843 // Obtain the context. 844 let context = getContext(this) as Context; 845 contact.isMyCard(context, /*id*/1, (err: BusinessError, data) => { 846 if (err) { 847 console.error(`Failed to isMyCard. Code: ${err.code}, message: ${err.message}`); 848 return; 849 } 850 console.info(`Succeeded in isMyCard. data->${JSON.stringify(data)}`); 851 }); 852``` 853 854## contact.isMyCard<sup>(deprecated)7+</sup> 855 856isMyCard(id: number, callback: AsyncCallback<boolean>): void 857 858Checks whether a contact is included in my card. This API uses an asynchronous callback to return the result. 859 860> **NOTE** 861> 862> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [isMyCard](#contactismycard10). 863 864**Permission required**: ohos.permission.READ_CONTACTS 865 866**System capability**: SystemCapability.Applications.ContactsData 867 868**Parameters** 869 870| Name | Type | Mandatory| Description | 871| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 872| id | number | Yes | Contact ID. | 873| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, a Boolean value is returned. The value **true** indicates that the contact is included in my card, and the value **false** indicates the opposite. If the operation fails, an error code is returned.| 874 875**Example** 876 877 ```js 878 import { BusinessError } from '@kit.BasicServicesKit'; 879 contact.isMyCard(/*id*/1, (err: BusinessError, data) => { 880 if (err) { 881 console.error(`Failed to isMyCard. Code: ${err.code}, message: ${err.message}`); 882 return; 883 } 884 console.info(`Succeeded in isMyCard. data->${JSON.stringify(data)}`); 885 }); 886 ``` 887 888 889## contact.isMyCard<sup>10+</sup> 890 891isMyCard(context: Context, id: number): Promise<boolean> 892 893Checks whether a contact is included in my card. This API uses a promise to return the result. 894 895**Permission required**: ohos.permission.READ_CONTACTS 896 897**System capability**: SystemCapability.Applications.ContactsData 898 899**Parameters** 900 901| Name | Type | Mandatory| Description | 902| ------- | ------- | ---- | ------------------------------------------------------------ | 903| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 904| id | number | Yes | Contact ID. | 905 906**Return Value** 907 908| Type | Description | 909| ---------------------- | ---------------------------------------------------------- | 910| 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.| 911 912**Error codes** 913 914| ID| Error Message | 915| -------- | ------------------ | 916| 201 | Permission denied. | 917| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 918 919**Example** 920 921```js 922 import { BusinessError } from '@kit.BasicServicesKit'; 923 // Obtain the context. 924 let context = getContext(this) as Context; 925 let promise = contact.isMyCard(context, /*id*/1); 926 promise.then((data) => { 927 console.info(`Succeeded in isMyCard. data->${JSON.stringify(data)}`); 928 }).catch((err: BusinessError) => { 929 console.error(`Failed to isMyCard. Code: ${err.code}, message: ${err.message}`); 930 }); 931``` 932 933## contact.isMyCard<sup>(deprecated)7+</sup> 934 935isMyCard(id: number): Promise<boolean> 936 937Checks whether a contact is included in my card. This API uses a promise to return the result. 938 939> **NOTE** 940> 941> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [isMyCard](#contactismycard10-1). 942 943**Permission required**: ohos.permission.READ_CONTACTS 944 945**System capability**: SystemCapability.Applications.ContactsData 946 947**Parameters** 948 949| Name| Type | Mandatory| Description | 950| ------ | ------ | ---- | -------------------- | 951| id | number | Yes | Contact ID.| 952 953**Return Value** 954 955| Type | Description | 956| ---------------------- | ---------------------------------------------------------- | 957| 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.| 958 959**Example** 960 961 ```js 962 import { BusinessError } from '@kit.BasicServicesKit'; 963 let promise = contact.isMyCard(/*id*/1); 964 promise.then((data) => { 965 console.info(`Succeeded in isMyCard. data->${JSON.stringify(data)}`); 966 }).catch((err: BusinessError) => { 967 console.error(`Failed to isMyCard. Code: ${err.code}, message: ${err.message}`); 968 }); 969 ``` 970 971## contact.queryMyCard<sup>10+</sup> 972 973queryMyCard(context: Context, callback: AsyncCallback<Contact>): void 974 975Queries my card. This API uses an asynchronous callback to return the result. 976 977**Permission required**: ohos.permission.READ_CONTACTS 978 979**System capability**: SystemCapability.Applications.ContactsData 980 981**Parameters** 982 983| Name | Type | Mandatory| Description | 984| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 985| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 986| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, information about my card is returned. If the operation fails, an error code is returned. | 987 988**Error codes** 989 990| ID| Error Message | 991| -------- | ------------------ | 992| 201 | Permission denied. | 993| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 994 995**Example** 996 997```js 998 import { BusinessError } from '@kit.BasicServicesKit'; 999 // Obtain the context. 1000 let context = getContext(this) as Context; 1001 contact.queryMyCard(context, (err: BusinessError, data) => { 1002 if (err) { 1003 console.error(`Failed to query My Card. Code: ${err.code}, message: ${err.message}`); 1004 return; 1005 } 1006 console.info(`Succeeded in querying My Card. data->${JSON.stringify(data)}`); 1007 }); 1008``` 1009 1010## contact.queryMyCard<sup>(deprecated)7+</sup> 1011 1012queryMyCard(callback: AsyncCallback<Contact>): void 1013 1014Queries my card. This API uses an asynchronous callback to return the result. 1015 1016> **NOTE** 1017> 1018> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryMyCard](#contactquerymycard10). 1019 1020**Permission required**: ohos.permission.READ_CONTACTS 1021 1022**System capability**: SystemCapability.Applications.ContactsData 1023 1024**Parameters** 1025 1026| Name | Type | Mandatory| Description | 1027| -------- | ---------------------------------------- | ---- | -------------------------------------------------------- | 1028| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, information about my card is returned. If the operation fails, an error code is returned.| 1029 1030**Example** 1031 1032 ```js 1033 import { BusinessError } from '@kit.BasicServicesKit'; 1034 contact.queryMyCard((err: BusinessError, data) => { 1035 if (err) { 1036 console.error(`Failed to query My Card. Code: ${err.code}, message: ${err.message}`); 1037 return; 1038 } 1039 console.info(`Succeeded in querying My Card. data->${JSON.stringify(data)}`); 1040 }); 1041 ``` 1042 1043## contact.queryMyCard<sup>10+</sup> 1044 1045queryMyCard(context: Context, attrs: ContactAttributes, callback: AsyncCallback<Contact>): void 1046 1047Queries my card. This API uses an asynchronous callback to return the result. 1048 1049**Permission required**: ohos.permission.READ_CONTACTS 1050 1051**System capability**: SystemCapability.Applications.ContactsData 1052 1053**Parameters** 1054 1055| Name | Type | Mandatory| Description | 1056| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 1057| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 1058| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 1059| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, information about my card is returned. If the operation fails, an error code is returned. | 1060 1061**Error codes** 1062 1063| ID| Error Message | 1064| -------- | ------------------ | 1065| 201 | Permission denied. | 1066| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1067 1068**Example** 1069 1070```js 1071 import { BusinessError } from '@kit.BasicServicesKit'; 1072 // Obtain the context. 1073 let context = getContext(this) as Context; 1074 contact.queryMyCard(context, { 1075 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 1076 }, (err: BusinessError, data) => { 1077 if (err) { 1078 console.error(`Failed to query My Card. Code: ${err.code}, message: ${err.message}`); 1079 return; 1080 } 1081 console.info(`Succeeded in querying My Card. data->${JSON.stringify(data)}`); 1082 }); 1083``` 1084 1085## contact.queryMyCard<sup>(deprecated)7+</sup> 1086 1087queryMyCard(attrs: ContactAttributes, callback: AsyncCallback<Contact>): void 1088 1089Queries my card. This API uses an asynchronous callback to return the result. 1090 1091> **NOTE** 1092> 1093> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryMyCard](#contactquerymycard10-1). 1094 1095**Permission required**: ohos.permission.READ_CONTACTS 1096 1097**System capability**: SystemCapability.Applications.ContactsData 1098 1099**Parameters** 1100 1101| Name | Type | Mandatory| Description | 1102| -------- | ---------------------------------------- | ---- | -------------------------------------------------------- | 1103| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 1104| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, information about my card is returned. If the operation fails, an error code is returned.| 1105 1106**Example** 1107 1108 ```js 1109 import { BusinessError } from '@kit.BasicServicesKit'; 1110 contact.queryMyCard({ 1111 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 1112 }, (err: BusinessError, data) => { 1113 if (err) { 1114 console.error(`Failed to query My Card. Code: ${err.code}, message: ${err.message}`); 1115 return; 1116 } 1117 console.info(`Succeeded in querying My Card. data->${JSON.stringify(data)}`); 1118 }); 1119 ``` 1120 1121## contact.queryMyCard<sup>10+</sup> 1122 1123queryMyCard(context: Context, attrs?: ContactAttributes): Promise<Contact> 1124 1125Queries my card based on the specified contact attributes. This API uses a promise to return the result. 1126 1127**Permission required**: ohos.permission.READ_CONTACTS 1128 1129**System capability**: SystemCapability.Applications.ContactsData 1130 1131**Parameters** 1132 1133| Name | Type | Mandatory| Description | 1134| ------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 1135| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 1136| attrs | [ContactAttributes](#contactattributes) | No | List of contact attributes. | 1137 1138**Return Value** 1139 1140| Type | Description | 1141| ---------------------------------- | --------------------------------------- | 1142| Promise<[Contact](#contact)> | Promise used to return the result, which is a contact in my card.| 1143 1144**Error codes** 1145 1146| ID| Error Message | 1147| -------- | ------------------ | 1148| 201 | Permission denied. | 1149| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1150 1151**Example** 1152 1153```js 1154 import { BusinessError } from '@kit.BasicServicesKit'; 1155 // Obtain the context. 1156 let context = getContext(this) as Context; 1157 let promise = contact.queryMyCard(context, { 1158 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 1159 }); 1160 promise.then((data) => { 1161 console.info(`Succeeded in querying My Card. data->${JSON.stringify(data)}`); 1162 }).catch((err: BusinessError) => { 1163 console.error(`Failed to query My Card. Code: ${err.code}, message: ${err.message}`); 1164 }); 1165``` 1166 1167## contact.queryMyCard<sup>(deprecated)7+</sup> 1168 1169queryMyCard(attrs?: ContactAttributes): Promise<Contact> 1170 1171Queries my card based on the specified contact attributes. This API uses a promise to return the result. 1172 1173> **NOTE** 1174> 1175> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryMyCard](#contactquerymycard10-2). 1176 1177**Permission required**: ohos.permission.READ_CONTACTS 1178 1179**System capability**: SystemCapability.Applications.ContactsData 1180 1181**Parameters** 1182 1183| Name| Type | Mandatory| Description | 1184| ------ | --------------------------------------- | ---- | ------------------ | 1185| attrs | [ContactAttributes](#contactattributes) | No | List of contact attributes.| 1186 1187**Return Value** 1188| Type | Description | 1189| ---------------------------------- | --------------------------------------- | 1190| Promise<[Contact](#contact)> | Promise used to return the result, which is a contact in my card.| 1191 1192**Example** 1193 1194 ```js 1195 import { BusinessError } from '@kit.BasicServicesKit'; 1196 let promise = contact.queryMyCard({ 1197 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 1198 }); 1199 promise.then((data) => { 1200 console.info(`Succeeded in querying My Card. data->${JSON.stringify(data)}`); 1201 }).catch((err: BusinessError) => { 1202 console.error(`Failed to query My Card. Code: ${err.code}, message: ${err.message}`); 1203 }); 1204 ``` 1205 1206 1207## contact.selectContact<sup>(deprecated)7+</sup> 1208 1209selectContact(callback: AsyncCallback<Array<Contact>>): void 1210 1211Selects a contact. This API uses an asynchronous callback to return the result. 1212 1213> **NOTE** 1214> 1215> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [selectContacts](#contactselectcontacts10). 1216 1217**System capability**: SystemCapability.Applications.Contacts 1218 1219**Parameters** 1220 1221| Name | Type | Mandatory| Description | 1222| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 1223| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of selected contacts is returned. If the operation fails, an error code is returned.| 1224 1225**Example** 1226 1227 ```js 1228 import { BusinessError } from '@kit.BasicServicesKit'; 1229 contact.selectContact((err: BusinessError, data) => { 1230 if (err) { 1231 console.error(`Failed to select Contact. Code: ${err.code}, message: ${err.message}`); 1232 return; 1233 } 1234 console.info(`Succeeded in selecting Contact. data->${JSON.stringify(data)}`); 1235 }); 1236 ``` 1237 1238 1239## contact.selectContact<sup>(deprecated)7+</sup> 1240 1241selectContact(): Promise<Array<Contact>> 1242 1243Selects a contact. This API uses a promise to return the result. 1244 1245> **NOTE** 1246> 1247> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [selectContacts](#contactselectcontacts10-1). 1248 1249**System capability**: SystemCapability.Applications.Contacts 1250 1251**Return Value** 1252 1253| Type | Description | 1254| ----------------------------------------------- | --------------------------------------- | 1255| Promise<Array<[Contact](#contact)>> | Promise used to return the result, which is an array of selected contacts.| 1256 1257**Example** 1258 1259 ```js 1260 import { BusinessError } from '@kit.BasicServicesKit'; 1261 let promise = contact.selectContact(); 1262 promise.then((data) => { 1263 console.info(`Succeeded in selecting Contact. data->${JSON.stringify(data)}`); 1264 }).catch((err: BusinessError) => { 1265 console.error(`Failed to select Contact. Code: ${err.code}, message: ${err.message}`); 1266 }); 1267 ``` 1268 1269## contact.selectContacts<sup>10+</sup> 1270 1271selectContacts(callback: AsyncCallback<Array<Contact>>): void 1272 1273Selects a contact. This API uses an asynchronous callback to return the result. 1274 1275**Atomic service API**: This API can be used in atomic services since API version 11. 1276 1277**System capability**: SystemCapability.Applications.Contacts 1278 1279**Parameters** 1280 1281| Name | Type | Mandatory| Description | 1282| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 1283| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of selected contacts is returned. If the operation fails, an error code is returned.| 1284 1285**Error codes** 1286 1287| ID| Error Message | 1288| -------- | ------------------ | 1289| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1290 1291**Example** 1292 1293 ```js 1294 import { BusinessError } from '@kit.BasicServicesKit'; 1295 contact.selectContacts((err: BusinessError, data) => { 1296 if (err) { 1297 console.error(`Failed to select Contacts. Code: ${err.code}, message: ${err.message}`); 1298 return; 1299 } 1300 console.info(`Succeeded in selecting Contacts. data->${JSON.stringify(data)}`); 1301 }); 1302 ``` 1303 1304## contact.selectContacts<sup>10+</sup> 1305 1306selectContacts(): Promise<Array<Contact>> 1307 1308Selects a contact. This API uses a promise to return the result. 1309 1310**Atomic service API**: This API can be used in atomic services since API version 11. 1311 1312**System capability**: SystemCapability.Applications.Contacts 1313 1314**Return Value** 1315 1316| Type | Description | 1317| ----------------------------------------------- | --------------------------------------- | 1318| Promise<Array<[Contact](#contact)>> | Promise used to return the result, which is an array of selected contacts.| 1319 1320 1321**Example** 1322 1323 ```js 1324 import { BusinessError } from '@kit.BasicServicesKit'; 1325 let promise = contact.selectContacts(); 1326 promise.then((data) => { 1327 console.info(`Succeeded in selecting Contacts. data->${JSON.stringify(data)}`); 1328 }).catch((err: BusinessError) => { 1329 console.error(`Failed to select Contacts. Code: ${err.code}, message: ${err.message}`); 1330 }); 1331 ``` 1332 1333## contact.selectContacts<sup>10+</sup> 1334 1335selectContacts(options: ContactSelectionOptions, callback: AsyncCallback<Array<Contact>>): void 1336 1337Selects a contact. This API uses an asynchronous callback to return the result. 1338 1339**Atomic service API**: This API can be used in atomic services since API version 11. 1340 1341**System capability**: SystemCapability.Applications.Contacts 1342 1343**Parameters** 1344 1345| Name | Type | Mandatory| Description | 1346| -------- | ----------------------------------------------------- | ---- | ------------------------------------ | 1347| options | [ContactSelectionOptions](#contactselectionoptions10) | Yes | Contact selection options.| 1348| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of selected contacts is returned. If the operation fails, an error code is returned.| 1349 1350**Error codes** 1351 1352| ID| Error Message | 1353| -------- | ------------------ | 1354| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1355 1356**Example** 1357 1358 ```js 1359 import { BusinessError } from '@kit.BasicServicesKit'; 1360 contact.selectContacts({ 1361 isMultiSelect:false 1362 }, (err: BusinessError, data) => { 1363 if (err) { 1364 console.error(`Failed to select Contacts. Code: ${err.code}, message: ${err.message}`); 1365 return; 1366 } 1367 console.info(`Succeeded in selecting Contacts. data->${JSON.stringify(data)}`); 1368 }); 1369 ``` 1370 1371## contact.selectContacts<sup>10+</sup> 1372 1373selectContacts(options: ContactSelectionOptions): Promise<Array<Contact>> 1374 1375Selects a contact. This API uses a promise to return the result. 1376 1377**Atomic service API**: This API can be used in atomic services since API version 11. 1378 1379**System capability**: SystemCapability.Applications.Contacts 1380 1381**Parameters** 1382 1383| Name | Type | Mandatory| Description | 1384| -------- | ----------------------------------------------------- | ---- | ------------------------------------ | 1385| options | [ContactSelectionOptions](#contactselectionoptions10) | Yes | Contact selection options.| 1386 1387**Return Value** 1388 1389| Type | Description | 1390| ----------------------------------------------- | --------------------------------------- | 1391| Promise<Array<[Contact](#contact)>> | Promise used to return the result, which is an array of selected contacts.| 1392 1393**Error codes** 1394 1395| ID| Error Message | 1396| -------- | ------------------ | 1397| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1398 1399**Example** 1400 1401 ```js 1402 import { BusinessError } from '@kit.BasicServicesKit'; 1403 let promise = contact.selectContacts({isMultiSelect:false}); 1404 promise.then((data) => { 1405 console.info(`Succeeded in selecting Contacts. data->${JSON.stringify(data)}`); 1406 }).catch((err: BusinessError) => { 1407 console.error(`Failed to select Contacts. Code: ${err.code}, message: ${err.message}`); 1408 }); 1409 ``` 1410 1411## contact.queryContact<sup>10+</sup> 1412 1413queryContact(context: Context, key: string, callback: AsyncCallback<Contact>): void 1414 1415Queries a contact based on the specified key. This API uses an asynchronous callback to return the result. 1416 1417**Permission required**: ohos.permission.READ_CONTACTS 1418 1419**System capability**: SystemCapability.Applications.ContactsData 1420 1421**Parameters** 1422 1423| Name | Type | Mandatory| Description | 1424| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 1425| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 1426| key | string | Yes | Contact key. Each contact corresponds to one key. | 1427| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, the queried contact is returned. If the operation fails, an error code is returned. | 1428 1429**Error codes** 1430 1431| ID| Error Message | 1432| -------- | ------------------ | 1433| 201 | Permission denied. | 1434| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1435 1436**Example** 1437 1438 ```js 1439 import { BusinessError } from '@kit.BasicServicesKit'; 1440 // Obtain the context. 1441 let context = getContext(this) as Context; 1442 contact.queryContact(context, 'xxx', (err: BusinessError, data) => { 1443 if (err) { 1444 console.error(`Failed to query Contact. Code: ${err.code}, message: ${err.message}`); 1445 return; 1446 } 1447 console.info(`Succeeded in querying Contact. data->${JSON.stringify(data)}`); 1448 }); 1449 ``` 1450 1451## contact.queryContact<sup>(deprecated)7+</sup> 1452 1453queryContact(key: string, callback: AsyncCallback<Contact>): void 1454 1455Queries a contact based on the specified key. This API uses an asynchronous callback to return the result. 1456 1457> **NOTE** 1458> 1459> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContact](#contactquerycontact10). 1460 1461**Permission required**: ohos.permission.READ_CONTACTS 1462 1463**System capability**: SystemCapability.Applications.ContactsData 1464 1465**Parameters** 1466 1467| Name | Type | Mandatory| Description | 1468| -------- | ---------------------------------------- | ---- | ---------------------------------------------------------- | 1469| key | string | Yes | Contact key. Each contact corresponds to one key. | 1470| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, the queried contact is returned. If the operation fails, an error code is returned.| 1471 1472**Example** 1473 1474 ```js 1475 import { BusinessError } from '@kit.BasicServicesKit'; 1476 contact.queryContact('xxx', (err: BusinessError, data) => { 1477 if (err) { 1478 console.error(`Failed to query Contact. Code: ${err.code}, message: ${err.message}`); 1479 return; 1480 } 1481 console.info(`Succeeded in querying Contact. data->${JSON.stringify(data)}`); 1482 }); 1483 ``` 1484 1485 1486## contact.queryContact<sup>10+</sup> 1487 1488queryContact(context: Context, key: string, holder: Holder, callback: AsyncCallback<Contact>): void 1489 1490Queries a contact based on the specified key and holder. This API uses an asynchronous callback to return the result. 1491 1492**Permission required**: ohos.permission.READ_CONTACTS 1493 1494**System capability**: SystemCapability.Applications.ContactsData 1495 1496**Parameters** 1497 1498| Name | Type | Mandatory| Description | 1499| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 1500| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 1501| key | string | Yes | Contact key. Each contact corresponds to one key. | 1502| holder | [Holder](#holder) | No | Application that creates the contacts. | 1503| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, the queried contact is returned. If the operation fails, an error code is returned. | 1504 1505**Error codes** 1506 1507| ID| Error Message | 1508| -------- | ------------------ | 1509| 201 | Permission denied. | 1510| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1511 1512**Example** 1513 1514 ```js 1515 import { BusinessError } from '@kit.BasicServicesKit'; 1516 // Obtain the context. 1517 let context = getContext(this) as Context; 1518 contact.queryContact(context, 'xxx', { 1519 holderId: 1, 1520 bundleName: "", 1521 displayName: "" 1522 }, (err: BusinessError, data) => { 1523 if (err) { 1524 console.error(`Failed to query Contact. Code: ${err.code}, message: ${err.message}`); 1525 return; 1526 } 1527 console.info(`Succeeded in querying Contact. data->${JSON.stringify(data)}`); 1528 }); 1529 ``` 1530 1531## contact.queryContact<sup>(deprecated)7+</sup> 1532 1533queryContact(key: string, holder: Holder, callback: AsyncCallback<Contact>): void 1534 1535Queries a contact based on the specified key and holder. This API uses an asynchronous callback to return the result. 1536 1537> **NOTE** 1538> 1539> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContact](#contactquerycontact10-1). 1540 1541**Permission required**: ohos.permission.READ_CONTACTS 1542 1543**System capability**: SystemCapability.Applications.ContactsData 1544 1545**Parameters** 1546 1547| Name | Type | Mandatory| Description | 1548| -------- | ---------------------------------------- | ---- | ---------------------------------------------------------- | 1549| key | string | Yes | Contact key. Each contact corresponds to one key. | 1550| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 1551| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, the queried contact is returned. If the operation fails, an error code is returned.| 1552 1553**Example** 1554 1555 ```js 1556 import { BusinessError } from '@kit.BasicServicesKit'; 1557 contact.queryContact('xxx', { 1558 holderId: 1, 1559 bundleName: "", 1560 displayName: "" 1561 }, (err: BusinessError, data) => { 1562 if (err) { 1563 console.error(`Failed to query Contact. Code: ${err.code}, message: ${err.message}`); 1564 return; 1565 } 1566 console.info(`Succeeded in querying Contact. data->${JSON.stringify(data)}`); 1567 }); 1568 ``` 1569 1570## contact.queryContact<sup>10+</sup> 1571 1572queryContact(context: Context, key: string, attrs: ContactAttributes, callback: AsyncCallback<Contact>): void 1573 1574Queries a contact based on the specified key and attributes. This API uses an asynchronous callback to return the result. 1575 1576**Permission required**: ohos.permission.READ_CONTACTS 1577 1578**System capability**: SystemCapability.Applications.ContactsData 1579 1580**Parameters** 1581 1582| Name | Type | Mandatory| Description | 1583| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 1584| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 1585| key | string | Yes | Contact key. Each contact corresponds to one key. | 1586| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 1587| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, the queried contact is returned. If the operation fails, an error code is returned. | 1588 1589**Error codes** 1590 1591| ID| Error Message | 1592| -------- | ------------------ | 1593| 201 | Permission denied. | 1594| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1595 1596**Example** 1597 1598 ```js 1599 import { BusinessError } from '@kit.BasicServicesKit'; 1600 // Obtain the context. 1601 let context = getContext(this) as Context; 1602 contact.queryContact(context, 'xxx', { 1603 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 1604 }, (err: BusinessError, data) => { 1605 if (err) { 1606 console.error(`Failed to query Contact. Code: ${err.code}, message: ${err.message}`); 1607 return; 1608 } 1609 console.info(`Succeeded in querying Contact. data->${JSON.stringify(data)}`); 1610 }); 1611 ``` 1612 1613## contact.queryContact<sup>(deprecated)7+</sup> 1614 1615queryContact(key: string, attrs: ContactAttributes, callback: AsyncCallback<Contact>): void 1616 1617Queries a contact based on the specified key and attributes. This API uses an asynchronous callback to return the result. 1618 1619> **NOTE** 1620> 1621> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContact](#contactquerycontact10-2). 1622 1623**Permission required**: ohos.permission.READ_CONTACTS 1624 1625**System capability**: SystemCapability.Applications.ContactsData 1626 1627**Parameters** 1628 1629| Name | Type | Mandatory| Description | 1630| -------- | ---------------------------------------- | ---- | ---------------------------------------------------------- | 1631| key | string | Yes | Contact key. Each contact corresponds to one key. | 1632| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 1633| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, the queried contact is returned. If the operation fails, an error code is returned.| 1634 1635**Example** 1636 1637 ```js 1638 import { BusinessError } from '@kit.BasicServicesKit'; 1639 contact.queryContact('xxx', { 1640 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 1641 }, (err: BusinessError, data) => { 1642 if (err) { 1643 console.error(`Failed to query Contact. Code: ${err.code}, message: ${err.message}`); 1644 return; 1645 } 1646 console.info(`Succeeded in querying Contact. data->${JSON.stringify(data)}`); 1647 }); 1648 ``` 1649 1650## contact.queryContact<sup>10+</sup> 1651 1652queryContact(context: Context, key: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Contact>): void 1653 1654Queries a contact based on the specified key, holder, and attributes. This API uses an asynchronous callback to return the result. 1655 1656**Permission required**: ohos.permission.READ_CONTACTS 1657 1658**System capability**: SystemCapability.Applications.ContactsData 1659 1660**Parameters** 1661 1662| Name | Type | Mandatory| Description | 1663| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 1664| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 1665| key | string | Yes | Contact key. Each contact corresponds to one key. | 1666| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 1667| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 1668| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, the queried contact is returned. If the operation fails, an error code is returned. | 1669 1670**Error codes** 1671 1672| ID| Error Message | 1673| -------- | ------------------ | 1674| 201 | Permission denied. | 1675| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1676 1677**Example** 1678 1679```js 1680 import { BusinessError } from '@kit.BasicServicesKit'; 1681 // Obtain the context. 1682 let context = getContext(this) as Context; 1683 contact.queryContact(context, 'xxx', { 1684 holderId: 1, 1685 bundleName: "", 1686 displayName: "" 1687 }, { 1688 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 1689 }, (err: BusinessError, data) => { 1690 if (err) { 1691 console.error(`Failed to query Contact. Code: ${err.code}, message: ${err.message}`); 1692 return; 1693 } 1694 console.info(`Succeeded in querying Contact. data->${JSON.stringify(data)}`); 1695 }); 1696``` 1697 1698## contact.queryContact<sup>(deprecated)7+</sup> 1699 1700queryContact(key: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Contact>): void 1701 1702Queries a contact based on the specified key, holder, and attributes. This API uses an asynchronous callback to return the result. 1703 1704> **NOTE** 1705> 1706> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContact](#contactquerycontact10-3). 1707 1708**Permission required**: ohos.permission.READ_CONTACTS 1709 1710**System capability**: SystemCapability.Applications.ContactsData 1711 1712**Parameters** 1713 1714| Name | Type | Mandatory| Description | 1715| -------- | ---------------------------------------- | ---- | ---------------------------------------------------------- | 1716| key | string | Yes | Contact key. Each contact corresponds to one key. | 1717| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 1718| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 1719| callback | AsyncCallback<[Contact](#contact)> | Yes | Callback used to return the result. If the operation is successful, the queried contact is returned. If the operation fails, an error code is returned.| 1720 1721**Example** 1722 1723 ```js 1724 import { BusinessError } from '@kit.BasicServicesKit'; 1725 contact.queryContact('xxx', { 1726 holderId: 1, 1727 bundleName: "", 1728 displayName: "" 1729 }, { 1730 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 1731 }, (err: BusinessError, data) => { 1732 if (err) { 1733 console.error(`Failed to query Contact. Code: ${err.code}, message: ${err.message}`); 1734 return; 1735 } 1736 console.info(`Succeeded in querying Contact. data->${JSON.stringify(data)}`); 1737 }); 1738 ``` 1739 1740 1741## contact.queryContact<sup>10+</sup> 1742 1743queryContact(context: Context, key: string, holder?: Holder, attrs?: ContactAttributes): Promise<Contact> 1744 1745Queries a contact based on the specified key, holder, and attributes. This API uses a promise to return the result. 1746 1747**Permission required**: ohos.permission.READ_CONTACTS 1748 1749**System capability**: SystemCapability.Applications.ContactsData 1750 1751**Parameters** 1752 1753| Name | Type | Mandatory| Description | 1754| ------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 1755| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 1756| key | string | Yes | Contact key. Each contact corresponds to one key. | 1757| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for contact filtering by default. | 1758| attrs | [ContactAttributes](#contactattributes) | No | Contact attribute list. If this parameter is not specified, all contact attributes are queried by default. | 1759 1760**Return Value** 1761| Type | Description | 1762| ---------------------------------- | ------------------------------------- | 1763| Promise<[Contact](#contact)> | Promise used to return the result, which is thequeried contact.| 1764 1765**Error codes** 1766 1767| ID| Error Message | 1768| -------- | ------------------ | 1769| 201 | Permission denied. | 1770| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1771 1772**Example** 1773 1774 ```js 1775 import { BusinessError } from '@kit.BasicServicesKit'; 1776 // Obtain the context. 1777 let context = getContext(this) as Context; 1778 let promise = contact.queryContact(context, 'xxx', { 1779 holderId: 1, 1780 bundleName: "", 1781 displayName: "" 1782 }, { 1783 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 1784 }); 1785 promise.then((data) => { 1786 console.info(`Succeeded in querying Contact. data->${JSON.stringify(data)}`); 1787 }).catch((err: BusinessError) => { 1788 console.error(`Failed to query Contact. Code: ${err.code}, message: ${err.message}`); 1789 }); 1790 ``` 1791 1792## contact.queryContact<sup>(deprecated)7+</sup> 1793 1794queryContact(key: string, holder?: Holder, attrs?: ContactAttributes): Promise<Contact> 1795 1796Queries a contact based on the specified key, holder, and attributes. This API uses a promise to return the result. 1797 1798> **NOTE** 1799> 1800> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContact](#contactquerycontact10-4). 1801 1802**Permission required**: ohos.permission.READ_CONTACTS 1803 1804**System capability**: SystemCapability.Applications.ContactsData 1805 1806**Parameters** 1807 1808| Name| Type | Mandatory| Description | 1809| ------ | --------------------------------------- | ---- | -------------------------------------- | 1810| key | string | Yes | Contact key. Each contact corresponds to one key.| 1811| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for contact filtering by default. | 1812| attrs | [ContactAttributes](#contactattributes) | No | Contact attribute list. If this parameter is not specified, all contact attributes are queried by default. | 1813 1814**Return Value** 1815| Type | Description | 1816| ---------------------------------- | ------------------------------------- | 1817| Promise<[Contact](#contact)> | Promise used to return the result, which is thequeried contact.| 1818 1819**Example** 1820 1821 ```js 1822 import { BusinessError } from '@kit.BasicServicesKit'; 1823 let promise = contact.queryContact('xxx', { 1824 holderId: 1, 1825 bundleName: "", 1826 displayName: "" 1827 }, { 1828 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 1829 }); 1830 promise.then((data) => { 1831 console.info(`Succeeded in querying Contact. data->${JSON.stringify(data)}`); 1832 }).catch((err: BusinessError) => { 1833 console.error(`Failed to query Contact. Code: ${err.code}, message: ${err.message}`); 1834 }); 1835 ``` 1836 1837## contact.queryContacts<sup>10+</sup> 1838 1839queryContacts(context: Context, callback: AsyncCallback<Array<Contact>>): void 1840 1841Queries all contacts. This API uses an asynchronous callback to return the result. 1842 1843**Permission required**: ohos.permission.READ_CONTACTS 1844 1845**System capability**: SystemCapability.Applications.ContactsData 1846 1847**Parameters** 1848 1849| Name | Type | Mandatory| Description | 1850| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 1851| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 1852| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 1853 1854**Error codes** 1855 1856| ID| Error Message | 1857| -------- | ------------------ | 1858| 201 | Permission denied. | 1859| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1860 1861**Example** 1862 1863 ```js 1864 import { BusinessError } from '@kit.BasicServicesKit'; 1865 // Obtain the context. 1866 let context = getContext(this) as Context; 1867 contact.queryContacts(context, (err: BusinessError, data) => { 1868 if (err) { 1869 console.error(`Failed to query Contacts. Code: ${err.code}, message: ${err.message}`); 1870 return; 1871 } 1872 console.info(`Succeeded in querying Contacts. data->${JSON.stringify(data)}`); 1873 }); 1874 ``` 1875 1876## contact.queryContacts<sup>(deprecated)7+</sup> 1877 1878queryContacts(callback: AsyncCallback<Array<Contact>>): void 1879 1880Queries all contacts. This API uses an asynchronous callback to return the result. 1881 1882> **NOTE** 1883> 1884> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContacts](#contactquerycontacts10). 1885 1886**Permission required**: ohos.permission.READ_CONTACTS 1887 1888**System capability**: SystemCapability.Applications.ContactsData 1889 1890**Parameters** 1891 1892| Name | Type | Mandatory| Description | 1893| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 1894| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 1895 1896**Example** 1897 1898 ```js 1899 import { BusinessError } from '@kit.BasicServicesKit'; 1900 contact.queryContacts((err: BusinessError, data) => { 1901 if (err) { 1902 console.error(`Failed to query Contacts. Code: ${err.code}, message: ${err.message}`); 1903 return; 1904 } 1905 console.info(`Succeeded in querying Contacts. data->${JSON.stringify(data)}`); 1906 }); 1907 ``` 1908 1909## contact.queryContacts<sup>10+</sup> 1910 1911queryContacts(context: Context, holder: Holder, callback: AsyncCallback<Array<Contact>>): void 1912 1913Queries contacts based on the specified holder. This API uses an asynchronous callback to return the result. 1914 1915**Permission required**: ohos.permission.READ_CONTACTS 1916 1917**System capability**: SystemCapability.Applications.ContactsData 1918 1919**Parameters** 1920 1921| Name | Type | Mandatory| Description | 1922| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 1923| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 1924| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 1925| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 1926 1927**Error codes** 1928 1929| ID| Error Message | 1930| -------- | ------------------ | 1931| 201 | Permission denied. | 1932| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 1933 1934**Example** 1935 1936 ```js 1937 import { BusinessError } from '@kit.BasicServicesKit'; 1938 // Obtain the context. 1939 let context = getContext(this) as Context; 1940 contact.queryContacts(context, { 1941 holderId: 1, 1942 bundleName: "", 1943 displayName: "" 1944 }, (err: BusinessError, data) => { 1945 if (err) { 1946 console.error(`Failed to query Contacts. Code: ${err.code}, message: ${err.message}`); 1947 return; 1948 } 1949 console.info(`Succeeded in querying Contacts. data->${JSON.stringify(data)}`); 1950 }); 1951 ``` 1952 1953## contact.queryContacts<sup>(deprecated)7+</sup> 1954 1955queryContacts(holder: Holder, callback: AsyncCallback<Array<Contact>>): void 1956 1957Queries contacts based on the specified holder. This API uses an asynchronous callback to return the result. 1958 1959> **NOTE** 1960> 1961> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContacts](#contactquerycontacts10-1). 1962 1963**Permission required**: ohos.permission.READ_CONTACTS 1964 1965**System capability**: SystemCapability.Applications.ContactsData 1966 1967**Parameters** 1968 1969| Name | Type | Mandatory| Description | 1970| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 1971| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 1972| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 1973 1974**Example** 1975 1976 ```js 1977 import { BusinessError } from '@kit.BasicServicesKit'; 1978 contact.queryContacts({ 1979 holderId: 1, 1980 bundleName: "", 1981 displayName: "" 1982 }, (err: BusinessError, data) => { 1983 if (err) { 1984 console.error(`Failed to query Contacts. Code: ${err.code}, message: ${err.message}`); 1985 return; 1986 } 1987 console.info(`Succeeded in querying Contacts. data->${JSON.stringify(data)}`); 1988 }); 1989 ``` 1990 1991## contact.queryContacts<sup>10+</sup> 1992 1993queryContacts(context: Context, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 1994 1995Queries contacts based on the specified attributes. This API uses an asynchronous callback to return the result. 1996 1997**Permission required**: ohos.permission.READ_CONTACTS 1998 1999**System capability**: SystemCapability.Applications.ContactsData 2000 2001**Parameters** 2002 2003| Name | Type | Mandatory| Description | 2004| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2005| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2006| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2007| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2008 2009**Error codes** 2010 2011| ID| Error Message | 2012| -------- | ------------------ | 2013| 201 | Permission denied. | 2014| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2015 2016**Example** 2017 2018 ```js 2019 import { BusinessError } from '@kit.BasicServicesKit'; 2020 // Obtain the context. 2021 let context = getContext(this) as Context; 2022 contact.queryContacts(context, { 2023 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2024 }, (err: BusinessError, data) => { 2025 if (err) { 2026 console.error(`Failed to query Contacts. Code: ${err.code}, message: ${err.message}`); 2027 return; 2028 } 2029 console.info(`Succeeded in querying Contacts. data->${JSON.stringify(data)}`); 2030 }); 2031 ``` 2032 2033## contact.queryContacts<sup>(deprecated)7+</sup> 2034 2035queryContacts(attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 2036 2037Queries contacts based on the specified attributes. This API uses an asynchronous callback to return the result. 2038 2039> **NOTE** 2040> 2041> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContacts](#contactquerycontacts10-2). 2042 2043**Permission required**: ohos.permission.READ_CONTACTS 2044 2045**System capability**: SystemCapability.Applications.ContactsData 2046 2047**Parameters** 2048 2049| Name | Type | Mandatory| Description | 2050| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2051| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2052| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2053 2054**Example** 2055 2056 ```js 2057 import { BusinessError } from '@kit.BasicServicesKit'; 2058 contact.queryContacts({ 2059 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2060 }, (err: BusinessError, data) => { 2061 if (err) { 2062 console.error(`Failed to query Contacts. Code: ${err.code}, message: ${err.message}`); 2063 return; 2064 } 2065 console.info(`Succeeded in querying Contacts. data->${JSON.stringify(data)}`); 2066 }); 2067 ``` 2068 2069## contact.queryContacts<sup>10+</sup> 2070 2071queryContacts(context: Context, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 2072 2073Queries contacts based on the specified holder and attributes. This API uses an asynchronous callback to return the result. 2074 2075**Permission required**: ohos.permission.READ_CONTACTS 2076 2077**System capability**: SystemCapability.Applications.ContactsData 2078 2079**Parameters** 2080 2081| Name | Type | Mandatory| Description | 2082| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2083| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2084| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 2085| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2086| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2087 2088**Error codes** 2089 2090| ID| Error Message | 2091| -------- | ------------------ | 2092| 201 | Permission denied. | 2093| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2094 2095**Example** 2096 2097 ```js 2098 import { BusinessError } from '@kit.BasicServicesKit'; 2099 // Obtain the context. 2100 let context = getContext(this) as Context; 2101 contact.queryContacts(context, { 2102 holderId: 1, 2103 bundleName: "", 2104 displayName: "" 2105 }, { 2106 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2107 }, (err: BusinessError, data) => { 2108 if (err) { 2109 console.error(`Failed to query Contacts. Code: ${err.code}, message: ${err.message}`); 2110 return; 2111 } 2112 console.info(`Succeeded in querying Contacts. data->${JSON.stringify(data)}`); 2113 }); 2114 ``` 2115 2116## contact.queryContacts<sup>(deprecated)7+</sup> 2117 2118queryContacts(holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 2119 2120Queries contacts based on the specified holder and attributes. This API uses an asynchronous callback to return the result. 2121 2122> **NOTE** 2123> 2124> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContacts](#contactquerycontacts10-3). 2125 2126**Permission required**: ohos.permission.READ_CONTACTS 2127 2128**System capability**: SystemCapability.Applications.ContactsData 2129 2130**Parameters** 2131 2132| Name | Type | Mandatory| Description | 2133| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2134| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 2135| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2136| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2137 2138**Example** 2139 2140 ```js 2141 import { BusinessError } from '@kit.BasicServicesKit'; 2142 contact.queryContacts({ 2143 holderId: 1, 2144 bundleName: "", 2145 displayName: "" 2146 }, { 2147 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2148 }, (err: BusinessError, data) => { 2149 if (err) { 2150 console.error(`Failed to query Contacts. Code: ${err.code}, message: ${err.message}`); 2151 return; 2152 } 2153 console.info(`Succeeded in querying Contacts. data->${JSON.stringify(data)}`); 2154 }); 2155 ``` 2156 2157## contact.queryContacts<sup>10+</sup> 2158 2159queryContacts(context: Context, holder?: Holder, attrs?: ContactAttributes): Promise<Array<Contact>> 2160 2161Queries contacts based on the specified holder and attributes. This API uses a promise to return the result. 2162 2163**Permission required**: ohos.permission.READ_CONTACTS 2164 2165**System capability**: SystemCapability.Applications.ContactsData 2166 2167**Parameters** 2168 2169| Name | Type | Mandatory| Description | 2170| ------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 2171| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2172| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for contact filtering by default. | 2173| attrs | [ContactAttributes](#contactattributes) | No | Contact attribute list. If this parameter is not specified, all contact attributes are queried by default. | 2174 2175**Return Value** 2176| Type | Description | 2177| ----------------------------------------------- | ----------------------------------------- | 2178| Promise<Array<[Contact](#contact)>> | Promise used to return the result, which is an array of queried contacts.| 2179 2180**Error codes** 2181 2182| ID| Error Message | 2183| -------- | ------------------ | 2184| 201 | Permission denied. | 2185| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2186 2187**Example** 2188 2189 ```js 2190 import { BusinessError } from '@kit.BasicServicesKit'; 2191 // Obtain the context. 2192 let context = getContext(this) as Context; 2193 let promise = contact.queryContacts(context, { 2194 holderId: 1, 2195 bundleName: "", 2196 displayName: "" 2197 }, { 2198 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2199 }); 2200 promise.then((data) => { 2201 console.info(`Succeeded in querying Contacts. data: ${JSON.stringify(data)}`); 2202 }).catch((err: BusinessError) => { 2203 console.error(`Failed to query Contacts. Code: ${err.code}, message: ${err.message}`); 2204 }); 2205 ``` 2206 2207## contact.queryContacts<sup>(deprecated)7+</sup> 2208 2209queryContacts(holder?: Holder, attrs?: ContactAttributes): Promise<Array<Contact>> 2210 2211Queries contacts based on the specified holder and attributes. This API uses a promise to return the result. 2212 2213> **NOTE** 2214> 2215> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContacts](#contactquerycontacts10-4). 2216 2217**Permission required**: ohos.permission.READ_CONTACTS 2218 2219**System capability**: SystemCapability.Applications.ContactsData 2220 2221**Parameters** 2222 2223| Name| Type | Mandatory| Description | 2224| ------ | --------------------------------------- | ---- | ---------------------- | 2225| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for contact filtering by default.| 2226| attrs | [ContactAttributes](#contactattributes) | No | Contact attribute list. If this parameter is not specified, all contact attributes are queried by default. | 2227 2228**Return Value** 2229 2230| Type | Description | 2231| ----------------------------------------------- | ----------------------------------------- | 2232| Promise<Array<[Contact](#contact)>> | Promise used to return the result, which is an array of queried contacts.| 2233 2234**Example** 2235 2236```js 2237 import { BusinessError } from '@kit.BasicServicesKit'; 2238 let promise = contact.queryContacts({ 2239 holderId: 1, 2240 bundleName: "", 2241 displayName: "" 2242 }, { 2243 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2244 }); 2245 promise.then((data) => { 2246 console.info(`Succeeded in querying Contacts. data->${JSON.stringify(data)}`); 2247 }).catch((err: BusinessError) => { 2248 console.error(`Failed to query Contacts. Code: ${err.code}, message: ${err.message}`); 2249 }); 2250``` 2251 2252## contact.queryContactsByPhoneNumber<sup>10+</sup> 2253 2254queryContactsByPhoneNumber(context: Context, phoneNumber: string, callback: AsyncCallback<Array<Contact>>): void 2255 2256Queries contacts based on the specified phone number. This API uses an asynchronous callback to return the result. 2257 2258**Permission required**: ohos.permission.READ_CONTACTS 2259 2260**System capability**: SystemCapability.Applications.ContactsData 2261 2262**Parameters** 2263 2264| Name | Type | Mandatory| Description | 2265| ----------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2266| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2267| phoneNumber | string | Yes | Phone number of the contacts. | 2268| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2269 2270**Error codes** 2271 2272| ID| Error Message | 2273| -------- | ------------------ | 2274| 201 | Permission denied. | 2275| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2276 2277**Example** 2278 2279 ```js 2280 import { BusinessError } from '@kit.BasicServicesKit'; 2281 // Obtain the context. 2282 let context = getContext(this) as Context; 2283 contact.queryContactsByPhoneNumber(context, '138xxxxxxxx', (err: BusinessError, data) => { 2284 if (err) { 2285 console.error(`Failed to query Contacts By PhoneNumber. Code: ${err.code}, message: ${err.message}`); 2286 return; 2287 } 2288 console.info(`Succeeded in querying Contacts By PhoneNumber. data->${JSON.stringify(data)}`); 2289 }); 2290 ``` 2291 2292## contact.queryContactsByPhoneNumber<sup>(deprecated)7+</sup> 2293 2294queryContactsByPhoneNumber(phoneNumber: string, callback: AsyncCallback<Array<Contact>>): void 2295 2296Queries contacts based on the specified phone number. This API uses an asynchronous callback to return the result. 2297 2298> **NOTE** 2299> 2300> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContactsByPhoneNumber](#contactquerycontactsbyphonenumber10). 2301 2302**Permission required**: ohos.permission.READ_CONTACTS 2303 2304**System capability**: SystemCapability.Applications.ContactsData 2305 2306**Parameters** 2307 2308| Name | Type | Mandatory| Description | 2309| ----------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2310| phoneNumber | string | Yes | Phone number of the contacts. | 2311| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2312 2313**Example** 2314 2315 ```js 2316 import { BusinessError } from '@kit.BasicServicesKit'; 2317 contact.queryContactsByPhoneNumber('138xxxxxxxx', (err: BusinessError, data) => { 2318 if (err) { 2319 console.error(`Failed to query Contacts By PhoneNumber. Code: ${err.code}, message: ${err.message}`); 2320 return; 2321 } 2322 console.info(`Succeeded in querying Contacts By PhoneNumber. data->${JSON.stringify(data)}`); 2323 }); 2324 ``` 2325 2326 2327## contact.queryContactsByPhoneNumber<sup>10+</sup> 2328 2329queryContactsByPhoneNumber(context: Context, phoneNumber: string, holder: Holder, callback: AsyncCallback<Array<Contact>>): void 2330 2331Queries contacts based on the specified phone number and holder. This API uses an asynchronous callback to return the result. 2332 2333**Permission required**: ohos.permission.READ_CONTACTS 2334 2335**System capability**: SystemCapability.Applications.ContactsData 2336 2337**Parameters** 2338 2339| Name | Type | Mandatory| Description | 2340| ----------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2341| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2342| phoneNumber | string | Yes | Phone number of the contacts. | 2343| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 2344| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2345 2346**Error codes** 2347 2348| ID| Error Message | 2349| -------- | ------------------ | 2350| 201 | Permission denied. | 2351| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2352 2353**Example** 2354 2355 ```js 2356 import { BusinessError } from '@kit.BasicServicesKit'; 2357 // Obtain the context. 2358 let context = getContext(this) as Context; 2359 contact.queryContactsByPhoneNumber(context, '138xxxxxxxx', { 2360 holderId: 1, 2361 bundleName: "", 2362 displayName: "" 2363 }, (err: BusinessError, data) => { 2364 if (err) { 2365 console.error(`Failed to query Contacts By PhoneNumber. Code: ${err.code}, message: ${err.message}`); 2366 return; 2367 } 2368 console.info(`Succeeded in querying Contacts By PhoneNumber. data->${JSON.stringify(data)}`); 2369 }); 2370 ``` 2371 2372## contact.queryContactsByPhoneNumber<sup>(deprecated)7+</sup> 2373 2374queryContactsByPhoneNumber(phoneNumber: string, holder: Holder, callback: AsyncCallback<Array<Contact>>): void 2375 2376Queries contacts based on the specified phone number and holder. This API uses an asynchronous callback to return the result. 2377 2378> **NOTE** 2379> 2380> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContactsByPhoneNumber](#contactquerycontactsbyphonenumber10-1). 2381 2382**Permission required**: ohos.permission.READ_CONTACTS 2383 2384**System capability**: SystemCapability.Applications.ContactsData 2385 2386**Parameters** 2387 2388| Name | Type | Mandatory| Description | 2389| ----------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2390| phoneNumber | string | Yes | Phone number of the contacts. | 2391| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 2392| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2393 2394**Example** 2395 2396 ```js 2397 import { BusinessError } from '@kit.BasicServicesKit'; 2398 contact.queryContactsByPhoneNumber('138xxxxxxxx', { 2399 holderId: 1, 2400 bundleName: "", 2401 displayName: "" 2402 }, (err: BusinessError, data) => { 2403 if (err) { 2404 console.error(`Failed to query Contacts By PhoneNumber. Code: ${err.code}, message: ${err.message}`); 2405 return; 2406 } 2407 console.info(`Succeeded in querying Contacts By PhoneNumber. data->${JSON.stringify(data)}`); 2408 }); 2409 ``` 2410 2411## contact.queryContactsByPhoneNumber<sup>10+</sup> 2412 2413queryContactsByPhoneNumber(context: Context, phoneNumber: string, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 2414 2415Queries contacts based on the specified phone number and attributes. This API uses an asynchronous callback to return the result. 2416 2417**Permission required**: ohos.permission.READ_CONTACTS 2418 2419**System capability**: SystemCapability.Applications.ContactsData 2420 2421**Parameters** 2422 2423| Name | Type | Mandatory| Description | 2424| ----------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2425| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2426| phoneNumber | string | Yes | Phone number of the contacts. | 2427| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2428| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2429 2430**Error codes** 2431 2432| ID| Error Message | 2433| -------- | ------------------ | 2434| 201 | Permission denied. | 2435| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2436 2437**Example** 2438 2439 ```js 2440 import { BusinessError } from '@kit.BasicServicesKit'; 2441 // Obtain the context. 2442 let context = getContext(this) as Context; 2443 contact.queryContactsByPhoneNumber(context, '138xxxxxxxx', { 2444 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2445 }, (err: BusinessError, data) => { 2446 if (err) { 2447 console.error(`Failed to query Contacts By PhoneNumber. Code: ${err.code}, message: ${err.message}`); 2448 return; 2449 } 2450 console.info(`Succeeded in querying Contacts By PhoneNumber. data->${JSON.stringify(data)}`); 2451 }); 2452 ``` 2453 2454## contact.queryContactsByPhoneNumber<sup>(deprecated)7+</sup> 2455 2456queryContactsByPhoneNumber(phoneNumber: string, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 2457 2458Queries contacts based on the specified phone number and attributes. This API uses an asynchronous callback to return the result. 2459 2460> **NOTE** 2461> 2462> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContactsByPhoneNumber](#contactquerycontactsbyphonenumber10-2). 2463 2464**Permission required**: ohos.permission.READ_CONTACTS 2465 2466**System capability**: SystemCapability.Applications.ContactsData 2467 2468**Parameters** 2469 2470| Name | Type | Mandatory| Description | 2471| ----------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2472| phoneNumber | string | Yes | Phone number of the contacts. | 2473| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2474| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2475 2476**Example** 2477 2478 ```js 2479 import { BusinessError } from '@kit.BasicServicesKit'; 2480 contact.queryContactsByPhoneNumber('138xxxxxxxx', { 2481 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2482 }, (err: BusinessError, data) => { 2483 if (err) { 2484 console.error(`Failed to query Contacts By PhoneNumber. Code: ${err.code}, message: ${err.message}`); 2485 return; 2486 } 2487 console.info(`Succeeded in querying Contacts By PhoneNumber. data->${JSON.stringify(data)}`); 2488 }); 2489 ``` 2490 2491## contact.queryContactsByPhoneNumber<sup>10+</sup> 2492 2493queryContactsByPhoneNumber(context: Context, phoneNumber: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 2494 2495Queries contacts based on the specified phone number, holder, and attributes. This API uses an asynchronous callback to return the result. 2496 2497**Permission required**: ohos.permission.READ_CONTACTS 2498 2499**System capability**: SystemCapability.Applications.ContactsData 2500 2501**Parameters** 2502 2503| Name | Type | Mandatory| Description | 2504| ----------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2505| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2506| phoneNumber | string | Yes | Phone number of the contacts. | 2507| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 2508| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2509| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2510 2511**Error codes** 2512 2513| ID| Error Message | 2514| -------- | ------------------ | 2515| 201 | Permission denied. | 2516| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2517 2518**Example** 2519 2520 ```js 2521 import { BusinessError } from '@kit.BasicServicesKit'; 2522 // Obtain the context. 2523 let context = getContext(this) as Context; 2524 contact.queryContactsByPhoneNumber(context, '138xxxxxxxx', { 2525 holderId: 1, 2526 bundleName: "", 2527 displayName: "" 2528 }, { 2529 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2530 }, (err: BusinessError, data) => { 2531 if (err) { 2532 console.error(`Failed to query Contacts By PhoneNumber. Code: ${err.code}, message: ${err.message}`); 2533 return; 2534 } 2535 console.info(`Succeeded in querying Contacts By PhoneNumber. data->${JSON.stringify(data)}`); 2536 }); 2537 ``` 2538 2539## contact.queryContactsByPhoneNumber<sup>(deprecated)7+</sup> 2540 2541queryContactsByPhoneNumber(phoneNumber: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 2542 2543Queries contacts based on the specified phone number, holder, and attributes. This API uses an asynchronous callback to return the result. 2544 2545> **NOTE** 2546> 2547> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContactsByPhoneNumber](#contactquerycontactsbyphonenumber10-3). 2548 2549**Permission required**: ohos.permission.READ_CONTACTS 2550 2551**System capability**: SystemCapability.Applications.ContactsData 2552 2553**Parameters** 2554 2555| Name | Type | Mandatory| Description | 2556| ----------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2557| phoneNumber | string | Yes | Phone number of the contacts. | 2558| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 2559| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2560| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2561 2562**Example** 2563 2564 ```js 2565 import { BusinessError } from '@kit.BasicServicesKit'; 2566 contact.queryContactsByPhoneNumber('138xxxxxxxx', { 2567 holderId: 1, 2568 bundleName: "", 2569 displayName: "" 2570 }, { 2571 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2572 }, (err: BusinessError, data) => { 2573 if (err) { 2574 console.error(`Failed to query Contacts By PhoneNumber. Code: ${err.code}, message: ${err.message}`); 2575 return; 2576 } 2577 console.info(`Succeeded in querying Contacts By PhoneNumber. data->${JSON.stringify(data)}`); 2578 }); 2579 ``` 2580 2581## contact.queryContactsByPhoneNumber<sup>10+</sup> 2582 2583queryContactsByPhoneNumber(context: Context, phoneNumber: string, holder?: Holder, attrs?: ContactAttributes): Promise<Array<Contact>> 2584 2585Queries contacts based on the specified phone number, holder, and attributes. This API uses a promise to return the result. 2586 2587**Permission required**: ohos.permission.READ_CONTACTS 2588 2589**System capability**: SystemCapability.Applications.ContactsData 2590 2591**Parameters** 2592 2593| Name | Type | Mandatory| Description | 2594| ----------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 2595| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2596| phoneNumber | string | Yes | Phone number of the contacts. | 2597| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for contact filtering by default. | 2598| attrs | [ContactAttributes](#contactattributes) | No | Contact attribute list. If this parameter is not specified, all contact attributes are queried by default. | 2599 2600**Return Value** 2601 2602| Type | Description | 2603| ----------------------------------------------- | ----------------------------------------- | 2604| Promise<Array<[Contact](#contact)>> | Promise used to return the result, which is an array of queried contacts.| 2605 2606**Error codes** 2607 2608| ID| Error Message | 2609| -------- | ------------------ | 2610| 201 | Permission denied. | 2611| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2612 2613**Example** 2614 2615 ```js 2616 import { BusinessError } from '@kit.BasicServicesKit'; 2617 // Obtain the context. 2618 let context = getContext(this) as Context; 2619 let promise = contact.queryContactsByPhoneNumber(context, '138xxxxxxxx', { 2620 holderId: 1, 2621 bundleName: "", 2622 displayName: "" 2623 }, { 2624 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2625 }); 2626 promise.then((data) => { 2627 console.info(`Succeeded in querying Contacts By PhoneNumber. data->${JSON.stringify(data)}`); 2628 }).catch((err: BusinessError) => { 2629 console.error(`Failed to query Contacts By PhoneNumber. Code: ${err.code}, message: ${err.message}`); 2630 }); 2631 ``` 2632 2633## contact.queryContactsByPhoneNumber<sup>(deprecated)7+</sup> 2634 2635queryContactsByPhoneNumber(phoneNumber: string, holder?: Holder, attrs?: ContactAttributes): Promise<Array<Contact>> 2636 2637Queries contacts based on the specified phone number, holder, and attributes. This API uses a promise to return the result. 2638 2639> **NOTE** 2640> 2641> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContactsByPhoneNumber](#contactquerycontactsbyphonenumber10-4). 2642 2643**Permission required**: ohos.permission.READ_CONTACTS 2644 2645**System capability**: SystemCapability.Applications.ContactsData 2646 2647**Parameters** 2648 2649| Name | Type | Mandatory| Description | 2650| ----------- | --------------------------------------- | ---- | ---------------------- | 2651| phoneNumber | string | Yes | Phone number of the contacts. | 2652| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for contact filtering by default.| 2653| attrs | [ContactAttributes](#contactattributes) | No | Contact attribute list. If this parameter is not specified, all contact attributes are queried by default. | 2654 2655**Return Value** 2656 2657| Type | Description | 2658| ----------------------------------------------- | ----------------------------------------- | 2659| Promise<Array<[Contact](#contact)>> | Promise used to return the result, which is an array of queried contacts.| 2660 2661**Example** 2662 2663 ```js 2664 import { BusinessError } from '@kit.BasicServicesKit'; 2665 let promise = contact.queryContactsByPhoneNumber('138xxxxxxxx', { 2666 holderId: 1, 2667 bundleName: "", 2668 displayName: "" 2669 }, { 2670 attributes: [contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE] 2671 }); 2672 promise.then((data) => { 2673 console.info(`Succeeded in querying Contacts By PhoneNumber. data->${JSON.stringify(data)}`); 2674 }).catch((err: BusinessError) => { 2675 console.error(`Failed to query Contacts By PhoneNumber. Code: ${err.code}, message: ${err.message}`); 2676 }); 2677 ``` 2678 2679## contact.queryContactsByEmail<sup>10+</sup> 2680 2681queryContactsByEmail(context: Context, email: string, callback: AsyncCallback<Array<Contact>>): void 2682 2683Queries contacts based on the specified email address. This API uses an asynchronous callback to return the result. 2684 2685**Permission required**: ohos.permission.READ_CONTACTS 2686 2687**System capability**: SystemCapability.Applications.ContactsData 2688 2689**Parameters** 2690 2691| Name | Type | Mandatory| Description | 2692| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2693| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2694| email | string | Yes | Email address of the contact. | 2695| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2696 2697**Error codes** 2698 2699| ID| Error Message | 2700| -------- | ------------------ | 2701| 201 | Permission denied. | 2702| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2703 2704**Example** 2705 2706 ```js 2707 import { BusinessError } from '@kit.BasicServicesKit'; 2708 // Obtain the context. 2709 let context = getContext(this) as Context; 2710 contact.queryContactsByEmail(context, 'xxx@email.com', (err: BusinessError, data) => { 2711 if (err) { 2712 console.error(`Failed to query Contacts By Email. Code: ${err.code}, message: ${err.message}`); 2713 return; 2714 } 2715 console.info(`Succeeded in querying Contacts By Email. data->${JSON.stringify(data)}`); 2716 }); 2717 ``` 2718 2719## contact.queryContactsByEmail<sup>(deprecated)7+</sup> 2720 2721queryContactsByEmail(email: string, callback: AsyncCallback<Array<Contact>>): void 2722 2723Queries contacts based on the specified email address. This API uses an asynchronous callback to return the result. 2724 2725> **NOTE** 2726> 2727> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContactsByEmail](#contactquerycontactsbyemail10). 2728 2729**Permission required**: ohos.permission.READ_CONTACTS 2730 2731**System capability**: SystemCapability.Applications.ContactsData 2732 2733**Parameters** 2734 2735| Name | Type | Mandatory| Description | 2736| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2737| email | string | Yes | Email address of the contact. | 2738| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2739 2740**Example** 2741 2742 ```js 2743 import { BusinessError } from '@kit.BasicServicesKit'; 2744 contact.queryContactsByEmail('xxx@email.com', (err: BusinessError, data) => { 2745 if (err) { 2746 console.error(`Failed to query Contacts By Email. Code: ${err.code}, message: ${err.message}`); 2747 return; 2748 } 2749 console.info(`Succeeded in querying Contacts By Email. data->${JSON.stringify(data)}`); 2750 }); 2751 ``` 2752 2753## contact.queryContactsByEmail<sup>10+</sup> 2754 2755queryContactsByEmail(context: Context, email: string, holder: Holder, callback: AsyncCallback<Array<Contact>>): void 2756 2757Queries a contact based on the specified email and holder. This API uses an asynchronous callback to return the result. 2758 2759**Permission required**: ohos.permission.READ_CONTACTS 2760 2761**System capability**: SystemCapability.Applications.ContactsData 2762 2763**Parameters** 2764 2765| Name | Type | Mandatory| Description | 2766| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2767| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2768| email | string | Yes | Email address of the contact. | 2769| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 2770| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2771 2772**Error codes** 2773 2774| ID| Error Message | 2775| -------- | ------------------ | 2776| 201 | Permission denied. | 2777| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2778 2779**Example** 2780 2781 ```js 2782 import { BusinessError } from '@kit.BasicServicesKit'; 2783 // Obtain the context. 2784 let context = getContext(this) as Context; 2785 contact.queryContactsByEmail(context, 'xxx@email.com', { 2786 holderId: 1, 2787 bundleName: "", 2788 displayName: "" 2789 }, (err: BusinessError, data) => { 2790 if (err) { 2791 console.error(`Failed to query Contacts By Email. Code: ${err.code}, message: ${err.message}`); 2792 return; 2793 } 2794 console.info(`Succeeded in querying Contacts By Email. data->${JSON.stringify(data)}`); 2795 }); 2796 ``` 2797 2798## contact.queryContactsByEmail<sup>(deprecated)7+</sup> 2799 2800queryContactsByEmail(email: string, holder: Holder, callback: AsyncCallback<Array<Contact>>): void 2801 2802Queries a contact based on the specified email and holder. This API uses an asynchronous callback to return the result. 2803 2804> **NOTE** 2805> 2806> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContactsByEmail](#contactquerycontactsbyemail10-1). 2807 2808**Permission required**: ohos.permission.READ_CONTACTS 2809 2810**System capability**: SystemCapability.Applications.ContactsData 2811 2812**Parameters** 2813 2814| Name | Type | Mandatory| Description | 2815| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2816| email | string | Yes | Email address of the contact. | 2817| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 2818| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2819 2820**Example** 2821 2822 ```js 2823 import { BusinessError } from '@kit.BasicServicesKit'; 2824 contact.queryContactsByEmail('xxx@email.com', { 2825 holderId: 1, 2826 bundleName: "", 2827 displayName: "" 2828 }, (err: BusinessError, data) => { 2829 if (err) { 2830 console.error(`Failed to query Contacts By Email. Code: ${err.code}, message: ${err.message}`); 2831 return; 2832 } 2833 console.info(`Succeeded in querying Contacts By Email. data->${JSON.stringify(data)}`); 2834 }); 2835 ``` 2836 2837## contact.queryContactsByEmail<sup>10+</sup> 2838 2839queryContactsByEmail(context: Context, email: string, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 2840 2841Queries a contact based on the specified email and attributes. This API uses an asynchronous callback to return the result. 2842 2843**Permission required**: ohos.permission.READ_CONTACTS 2844 2845**System capability**: SystemCapability.Applications.ContactsData 2846 2847**Parameters** 2848 2849| Name | Type | Mandatory| Description | 2850| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2851| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2852| email | string | Yes | Email address of the contact. | 2853| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2854| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2855 2856**Error codes** 2857 2858| ID| Error Message | 2859| -------- | ------------------ | 2860| 201 | Permission denied. | 2861| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2862 2863**Example** 2864 2865 ```js 2866 import { BusinessError } from '@kit.BasicServicesKit'; 2867 // Obtain the context. 2868 let context = getContext(this) as Context; 2869 contact.queryContactsByEmail(context, 'xxx@email.com', { 2870 attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME] 2871 }, (err: BusinessError, data) => { 2872 if (err) { 2873 console.error(`Failed to query Contacts By Email. Code: ${err.code}, message: ${err.message}`); 2874 return; 2875 } 2876 console.info(`Succeeded in querying Contacts By Email. data->${JSON.stringify(data)}`); 2877 }); 2878 ``` 2879 2880## contact.queryContactsByEmail<sup>(deprecated)7+</sup> 2881 2882queryContactsByEmail(email: string, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 2883 2884Queries a contact based on the specified email and attributes. This API uses an asynchronous callback to return the result. 2885 2886> **NOTE** 2887> 2888> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContactsByEmail](#contactquerycontactsbyemail10-2). 2889 2890**Permission required**: ohos.permission.READ_CONTACTS 2891 2892**System capability**: SystemCapability.Applications.ContactsData 2893 2894**Parameters** 2895 2896| Name | Type | Mandatory| Description | 2897| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2898| email | string | Yes | Email address of the contact. | 2899| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2900| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2901 2902**Example** 2903 2904 ```js 2905 import { BusinessError } from '@kit.BasicServicesKit'; 2906 contact.queryContactsByEmail('xxx@email.com', { 2907 attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME] 2908 }, (err: BusinessError, data) => { 2909 if (err) { 2910 console.error(`Failed to query Contacts By Email. Code: ${err.code}, message: ${err.message}`); 2911 return; 2912 } 2913 console.info(`Succeeded in querying Contacts By Email. data->${JSON.stringify(data)}`); 2914 }); 2915 ``` 2916 2917## contact.queryContactsByEmail<sup>10+</sup> 2918 2919queryContactsByEmail(context: Context, email: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 2920 2921Queries a contact based on the specified email, holder, and attributes. This API uses an asynchronous callback to return the result. 2922 2923**Permission required**: ohos.permission.READ_CONTACTS 2924 2925**System capability**: SystemCapability.Applications.ContactsData 2926 2927**Parameters** 2928 2929| Name | Type | Mandatory| Description | 2930| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2931| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 2932| email | string | Yes | Email address of the contact. | 2933| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 2934| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2935| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2936 2937**Error codes** 2938 2939| ID| Error Message | 2940| -------- | ------------------ | 2941| 201 | Permission denied. | 2942| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 2943 2944**Example** 2945 2946 ```js 2947 import { BusinessError } from '@kit.BasicServicesKit'; 2948 // Obtain the context. 2949 let context = getContext(this) as Context; 2950 contact.queryContactsByEmail(context, 'xxx@email.com', { 2951 holderId: 1, 2952 bundleName: "", 2953 displayName: "" 2954 }, { 2955 attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME] 2956 }, (err: BusinessError, data) => { 2957 if (err) { 2958 console.error(`Failed to query Contacts By Email. Code: ${err.code}, message: ${err.message}`); 2959 return; 2960 } 2961 console.info(`Succeeded in querying Contacts By Email. data->${JSON.stringify(data)}`); 2962 }); 2963 ``` 2964 2965## contact.queryContactsByEmail<sup>(deprecated)7+</sup> 2966 2967queryContactsByEmail(email: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback<Array<Contact>>): void 2968 2969Queries a contact based on the specified email, holder, and attributes. This API uses an asynchronous callback to return the result. 2970 2971> **NOTE** 2972> 2973> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContactsByEmail](#contactquerycontactsbyemail10-3). 2974 2975**Permission required**: ohos.permission.READ_CONTACTS 2976 2977**System capability**: SystemCapability.Applications.ContactsData 2978 2979**Parameters** 2980 2981| Name | Type | Mandatory| Description | 2982| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2983| email | string | Yes | Email address of the contact. | 2984| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 2985| attrs | [ContactAttributes](#contactattributes) | Yes | List of contact attributes. | 2986| callback | AsyncCallback<Array<[Contact](#contact)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried contacts is returned. If the operation fails, an error code is returned.| 2987 2988**Example** 2989 2990 ```js 2991 import { BusinessError } from '@kit.BasicServicesKit'; 2992 contact.queryContactsByEmail('xxx@email.com', { 2993 holderId: 1, 2994 bundleName: "", 2995 displayName: "" 2996 }, { 2997 attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME] 2998 }, (err: BusinessError, data) => { 2999 if (err) { 3000 console.error(`Failed to query Contacts By Email. Code: ${err.code}, message: ${err.message}`); 3001 return; 3002 } 3003 console.info(`Succeeded in querying Contacts By Email. data->${JSON.stringify(data)}`); 3004 }); 3005 ``` 3006 3007## contact.queryContactsByEmail<sup>10+</sup> 3008 3009queryContactsByEmail(context: Context, email: string, holder?: Holder, attrs?: ContactAttributes): Promise<Array<Contact>> 3010 3011Queries a contact based on the specified email, holder, and attributes. This API uses a promise to return the result. 3012 3013**Permission required**: ohos.permission.READ_CONTACTS 3014 3015**System capability**: SystemCapability.Applications.ContactsData 3016 3017**Parameters** 3018 3019| Name | Type | Mandatory| Description | 3020| ------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 3021| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 3022| email | string | Yes | Email address of the contact. | 3023| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for contact filtering by default. | 3024| attrs | [ContactAttributes](#contactattributes) | No | Contact attribute list. If this parameter is not specified, all contact attributes are queried by default. | 3025 3026**Return Value** 3027 3028| Type | Description | 3029| ----------------------------------------------- | ----------------------------------------- | 3030| Promise<Array<[Contact](#contact)>> | Promise used to return the result, which is an array of queried contacts.| 3031 3032**Error codes** 3033 3034| ID| Error Message | 3035| -------- | ------------------ | 3036| 201 | Permission denied. | 3037| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 3038 3039**Example** 3040 3041 ```js 3042 import { BusinessError } from '@kit.BasicServicesKit'; 3043 // Obtain the context. 3044 let context = getContext(this) as Context; 3045 let promise = contact.queryContactsByEmail(context, 'xxx@email.com', { 3046 holderId: 1, 3047 bundleName: "", 3048 displayName: "" 3049 }, { 3050 attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME] 3051 }); 3052 promise.then((data) => { 3053 console.info(`Succeeded in querying Contacts By Email. data->${JSON.stringify(data)}`); 3054 }).catch((err: BusinessError) => { 3055 console.error(`Failed to query Contacts By Email. Code: ${err.code}, message: ${err.message}`); 3056 }); 3057 ``` 3058 3059## contact.queryContactsByEmail<sup>(deprecated)7+</sup> 3060 3061queryContactsByEmail(email: string, holder?: Holder, attrs?: ContactAttributes): Promise<Array<Contact>> 3062 3063Queries a contact based on the specified email, holder, and attributes. This API uses a promise to return the result. 3064 3065> **NOTE** 3066> 3067> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryContactsByEmail](#contactquerycontactsbyemail10-4). 3068 3069**Permission required**: ohos.permission.READ_CONTACTS 3070 3071**System capability**: SystemCapability.Applications.ContactsData 3072 3073**Parameters** 3074 3075| Name| Type | Mandatory| Description | 3076| ------ | --------------------------------------- | ---- | ---------------------- | 3077| email | string | Yes | Email address of the contact. | 3078| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for contact filtering by default.| 3079| attrs | [ContactAttributes](#contactattributes) | No | Contact attribute list. If this parameter is not specified, all contact attributes are queried by default. | 3080 3081**Return Value** 3082 3083| Type | Description | 3084| ----------------------------------------------- | ----------------------------------------- | 3085| Promise<Array<[Contact](#contact)>> | Promise used to return the result, which is an array of queried contacts.| 3086 3087**Example** 3088 3089 ```js 3090 import { BusinessError } from '@kit.BasicServicesKit'; 3091 let promise = contact.queryContactsByEmail('xxx@email.com', { 3092 holderId: 1, 3093 bundleName: "", 3094 displayName: "" 3095 }, { 3096 attributes: [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME] 3097 }); 3098 promise.then((data) => { 3099 console.info(`Succeeded in querying Contacts By Email. data->${JSON.stringify(data)}`); 3100 }).catch((err: BusinessError) => { 3101 console.error(`Failed to query Contacts By Email. Code: ${err.code}, message: ${err.message}`); 3102 }); 3103 ``` 3104 3105## contact.queryGroups<sup>10+</sup> 3106 3107queryGroups(context: Context, callback: AsyncCallback<Array<Group>>): void 3108 3109Queries all groups of this contact. This API uses an asynchronous callback to return the result. 3110 3111**Permission required**: ohos.permission.READ_CONTACTS 3112 3113**System capability**: SystemCapability.Applications.ContactsData 3114 3115**Parameters** 3116 3117| Name | Type | Mandatory| Description | 3118| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | 3119| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 3120| callback | AsyncCallback<Array<[Group](#group)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried groups is returned. If the operation fails, an error code is returned.| 3121 3122**Error codes** 3123 3124| ID| Error Message | 3125| -------- | ------------------ | 3126| 201 | Permission denied. | 3127| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 3128 3129**Example** 3130 3131 ```js 3132 import { BusinessError } from '@kit.BasicServicesKit'; 3133 // Obtain the context. 3134 let context = getContext(this) as Context; 3135 contact.queryGroups(context, (err: BusinessError, data) => { 3136 if (err) { 3137 console.error(`Failed to query Groups. Code: ${err.code}, message: ${err.message}`); 3138 return; 3139 } 3140 console.info(`Succeeded in querying Groups. data->${JSON.stringify(data)}`); 3141 }); 3142 ``` 3143 3144## contact.queryGroups<sup>(deprecated)7+</sup> 3145 3146queryGroups(callback: AsyncCallback<Array<Group>>): void 3147 3148Queries all groups of this contact. This API uses an asynchronous callback to return the result. 3149 3150> **NOTE** 3151> 3152> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryGroups](#contactquerygroups10). 3153 3154**Permission required**: ohos.permission.READ_CONTACTS 3155 3156**System capability**: SystemCapability.Applications.ContactsData 3157 3158**Parameters** 3159 3160| Name | Type | Mandatory| Description | 3161| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | 3162| callback | AsyncCallback<Array<[Group](#group)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried groups is returned. If the operation fails, an error code is returned.| 3163 3164**Example** 3165 3166 ```js 3167 import { BusinessError } from '@kit.BasicServicesKit'; 3168 contact.queryGroups((err: BusinessError, data) => { 3169 if (err) { 3170 console.error(`Failed to query Groups. Code: ${err.code}, message: ${err.message}`); 3171 return; 3172 } 3173 console.info(`Succeeded in querying Groups.. data->${JSON.stringify(data)}`); 3174 }); 3175 ``` 3176 3177## contact.queryGroups<sup>10+</sup> 3178 3179queryGroups(context: Context, holder: Holder, callback: AsyncCallback<Array<Group>>): void 3180 3181Queries all groups of this contact based on the specified holder. This API uses an asynchronous callback to return the result. 3182 3183**Permission required**: ohos.permission.READ_CONTACTS 3184 3185**System capability**: SystemCapability.Applications.ContactsData 3186 3187**Parameters** 3188 3189| Name | Type | Mandatory| Description | 3190| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | 3191| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 3192| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 3193| callback | AsyncCallback<Array<[Group](#group)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried groups is returned. If the operation fails, an error code is returned.| 3194 3195**Error codes** 3196 3197| ID| Error Message | 3198| -------- | ------------------ | 3199| 201 | Permission denied. | 3200| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 3201 3202**Example** 3203 3204 ```js 3205 import { BusinessError } from '@kit.BasicServicesKit'; 3206 // Obtain the context. 3207 let context = getContext(this) as Context; 3208 contact.queryGroups(context, { 3209 holderId: 1, 3210 bundleName: "", 3211 displayName: "" 3212 }, (err: BusinessError, data) => { 3213 if (err) { 3214 console.error(`Failed to query Groups. Code: ${err.code}, message: ${err.message}`); 3215 return; 3216 } 3217 console.info(`Succeeded in querying Groups. data->${JSON.stringify(data)}`); 3218 }); 3219 ``` 3220 3221## contact.queryGroups<sup>(deprecated)7+</sup> 3222 3223queryGroups(holder: Holder, callback: AsyncCallback<Array<Group>>): void 3224 3225Queries all groups of this contact based on the specified holder. This API uses an asynchronous callback to return the result. 3226 3227> **NOTE** 3228> 3229> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryGroups](#contactquerygroups10-1). 3230 3231**Permission required**: ohos.permission.READ_CONTACTS 3232 3233**System capability**: SystemCapability.Applications.ContactsData 3234 3235**Parameters** 3236 3237| Name | Type | Mandatory| Description | 3238| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | 3239| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 3240| callback | AsyncCallback<Array<[Group](#group)>> | Yes | Callback used to return the result. If the operation is successful, an array of queried groups is returned. If the operation fails, an error code is returned.| 3241 3242**Example** 3243 3244 ```js 3245 import { BusinessError } from '@kit.BasicServicesKit'; 3246 contact.queryGroups({ 3247 holderId: 1, 3248 bundleName: "", 3249 displayName: "" 3250 }, (err: BusinessError, data) => { 3251 if (err) { 3252 console.error(`Failed to query Groups. Code: ${err.code}, message: ${err.message}`); 3253 return; 3254 } 3255 console.info(`Succeeded in querying Groups. data->${JSON.stringify(data)}`); 3256 }); 3257 ``` 3258 3259## contact.queryGroups<sup>10+</sup> 3260 3261queryGroups(context: Context, holder?: Holder): Promise<Array<Group>> 3262 3263Queries all groups of this contact based on the specified holder. This API uses a promise to return the result. 3264 3265**Permission required**: ohos.permission.READ_CONTACTS 3266 3267**System capability**: SystemCapability.Applications.ContactsData 3268 3269**Parameters** 3270 3271| Name | Type | Mandatory| Description | 3272| ------- | ----------------- | ---- | ------------------------------------------------------------ | 3273| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 3274| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for group filtering by default. | 3275 3276**Return Value** 3277 3278| Type | Description | 3279| ------------------------------------------- | --------------------------------------- | 3280| Promise<Array<[Group](#group)>> | Promise used to return the result, which is an array of groups.| 3281 3282**Error codes** 3283 3284| ID| Error Message | 3285| -------- | ------------------ | 3286| 201 | Permission denied. | 3287| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 3288 3289**Example** 3290 3291 ```js 3292 import { BusinessError } from '@kit.BasicServicesKit'; 3293 // Obtain the context. 3294 let context = getContext(this) as Context; 3295 let promise = contact.queryGroups(context, { 3296 holderId: 1, 3297 bundleName: "", 3298 displayName: "" 3299 }); 3300 promise.then((data) => { 3301 console.info(`Succeeded in querying Groups. data->${JSON.stringify(data)}`); 3302 }).catch((err: BusinessError) => { 3303 console.error(`Failed to query Groups. Code: ${err.code}, message: ${err.message}`); 3304 }); 3305 ``` 3306 3307## contact.queryGroups<sup>(deprecated)7+</sup> 3308 3309queryGroups(holder?: Holder): Promise<Array<Group>> 3310 3311Queries all groups of this contact based on the specified holder. This API uses a promise to return the result. 3312 3313> **NOTE** 3314> 3315> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryGroups](#contactquerygroups10-2). 3316 3317**Permission required**: ohos.permission.READ_CONTACTS 3318 3319**System capability**: SystemCapability.Applications.ContactsData 3320 3321**Parameters** 3322 3323| Name| Type | Mandatory| Description | 3324| ------ | ----------------- | ---- | ---------------------- | 3325| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for group filtering by default.| 3326 3327**Return Value** 3328 3329| Type | Description | 3330| ------------------------------------------- | --------------------------------------- | 3331| Promise<Array<[Group](#group)>> | Promise used to return the result, which is an array of groups.| 3332 3333**Example** 3334 3335 ```js 3336 import { BusinessError } from '@kit.BasicServicesKit'; 3337 let promise = contact.queryGroups({ 3338 holderId: 1, 3339 bundleName: "", 3340 displayName: "" 3341 }); 3342 promise.then((data) => { 3343 console.info(`Succeeded in querying Groups. data->${JSON.stringify(data)}`); 3344 }).catch((err: BusinessError) => { 3345 console.error(`Failed to query Groups. Code: ${err.code}, message: ${err.message}`); 3346 }); 3347 ``` 3348 3349## contact.queryHolders<sup>10+</sup> 3350 3351queryHolders(context: Context, callback: AsyncCallback<Array<Holder>>): void 3352 3353Queries all applications that have created contacts. This API uses an asynchronous callback to return the result. 3354 3355**Permission required**: ohos.permission.READ_CONTACTS 3356 3357**System capability**: SystemCapability.Applications.ContactsData 3358 3359**Parameters** 3360 3361| Name | Type | Mandatory| Description | 3362| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ | 3363| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 3364| callback | AsyncCallback<Array<[Holder](#holder)>> | Yes | Callback used to return the result. If the operation is successful, an array of the queried applications is returned. If the operation fails, an error code is returned.| 3365 3366**Error codes** 3367 3368| ID| Error Message | 3369| -------- | ------------------ | 3370| 201 | Permission denied. | 3371| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 3372 3373**Example** 3374 3375 ```js 3376 import { BusinessError } from '@kit.BasicServicesKit'; 3377 // Obtain the context. 3378 let context = getContext(this) as Context; 3379 contact.queryHolders(context, (err: BusinessError, data) => { 3380 if (err) { 3381 console.error(`Failed to query Holders. Code: ${err.code}, message: ${err.message}`); 3382 return; 3383 } 3384 console.info(`Succeeded in querying Holders. data->${JSON.stringify(data)}`); 3385 }); 3386 ``` 3387 3388## contact.queryHolders<sup>(deprecated)7+</sup> 3389 3390queryHolders(callback: AsyncCallback<Array<Holder>>): void 3391 3392Queries all applications that have created contacts. This API uses an asynchronous callback to return the result. 3393 3394> **NOTE** 3395> 3396> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryHolders](#contactqueryholders10). 3397 3398**Permission required**: ohos.permission.READ_CONTACTS 3399 3400**System capability**: SystemCapability.Applications.ContactsData 3401 3402**Parameters** 3403 3404| Name | Type | Mandatory| Description | 3405| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ | 3406| callback | AsyncCallback<Array<[Holder](#holder)>> | Yes | Callback used to return the result. If the operation is successful, an array of the queried applications is returned. If the operation fails, an error code is returned.| 3407 3408**Example** 3409 3410 ```js 3411 import { BusinessError } from '@kit.BasicServicesKit'; 3412 contact.queryHolders((err: BusinessError, data) => { 3413 if (err) { 3414 console.error(`Failed to query Holders. Code: ${err.code}, message: ${err.message}`); 3415 return; 3416 } 3417 console.info(`Succeeded in querying Holders. data->${JSON.stringify(data)}`); 3418 }); 3419 ``` 3420 3421## contact.queryHolders<sup>10+</sup> 3422 3423queryHolders(context: Context): Promise<Array<Holder>> 3424 3425Queries all applications that have created contacts. This API uses a promise to return the result. 3426 3427**Permission required**: ohos.permission.READ_CONTACTS 3428 3429**System capability**: SystemCapability.Applications.ContactsData 3430 3431**Parameters** 3432 3433| Name | Type | Mandatory| Description | 3434| ------- | ------- | ---- | ------------------------------------------------------------ | 3435| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 3436 3437**Return Value** 3438 3439| Type | Description | 3440| --------------------------------------------- | ------------------------------------------------------- | 3441| Promise<Array<[Holder](#holder)>> | Promise used to return the result, which is an array of queried applications.| 3442 3443**Error codes** 3444 3445| ID| Error Message | 3446| -------- | ------------------ | 3447| 201 | Permission denied. | 3448| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. | 3449 3450**Example** 3451 3452 ```js 3453 import { BusinessError } from '@kit.BasicServicesKit'; 3454 // Obtain the context. 3455 let context = getContext(this) as Context; 3456 let promise = contact.queryHolders(context); 3457 promise.then((data) => { 3458 console.info(`Succeeded in querying Holders. data->${JSON.stringify(data)}`); 3459 }).catch((err: BusinessError) => { 3460 console.error(`Failed to query Holders. Code: ${err.code}, message: ${err.message}`); 3461 }); 3462 ``` 3463 3464## contact.queryHolders<sup>(deprecated)7+</sup> 3465 3466queryHolders(): Promise<Array<Holder>> 3467 3468Queries all applications that have created contacts. This API uses a promise to return the result. 3469 3470> **NOTE** 3471> 3472> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryHolders](#contactqueryholders10-1). 3473 3474**Permission required**: ohos.permission.READ_CONTACTS 3475 3476**System capability**: SystemCapability.Applications.ContactsData 3477 3478**Return Value** 3479 3480| Type | Description | 3481| --------------------------------------------- | ------------------------------------------------------- | 3482| Promise<Array<[Holder](#holder)>> | Promise used to return the result, which is an array of queried applications.| 3483 3484**Example** 3485 3486 ```js 3487 import { BusinessError } from '@kit.BasicServicesKit'; 3488 let promise = contact.queryHolders(); 3489 promise.then((data) => { 3490 console.info(`Succeeded in querying Holders. data->${JSON.stringify(data)}`); 3491 }).catch((err: BusinessError) => { 3492 console.error(`Failed to query Holders. Code: ${err.code}, message: ${err.message}`); 3493 }); 3494 ``` 3495 3496## contact.queryKey<sup>10+</sup> 3497 3498queryKey(context: Context, id: number, callback: AsyncCallback<string>): void 3499 3500Queries the key of a contact based on the specified contact ID. This API uses an asynchronous callback to return the result. 3501 3502**Permission required**: ohos.permission.READ_CONTACTS 3503 3504**System capability**: SystemCapability.Applications.ContactsData 3505 3506**Parameters** 3507 3508| Name | Type | Mandatory| Description | 3509| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 3510| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 3511| id | number | Yes | Contact ID. | 3512| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, the key of the queried contact is returned. If the operation fails, an error code is returned.| 3513 3514**Error codes** 3515 3516| ID| Error Message | 3517| -------- | ------------------ | 3518| 201 | Permission denied. | 3519| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3520 3521**Example** 3522 3523 ```js 3524 import { BusinessError } from '@kit.BasicServicesKit'; 3525 // Obtain the context. 3526 let context = getContext(this) as Context; 3527 contact.queryKey(context, /*id*/1, (err: BusinessError, data) => { 3528 if (err) { 3529 console.error(`Failed to query Key. Code: ${err.code}, message: ${err.message}`); 3530 return; 3531 } 3532 console.info(`Succeeded in querying Key. data->${JSON.stringify(data)}`); 3533 }); 3534 ``` 3535 3536## contact.queryKey<sup>(deprecated)7+</sup> 3537 3538queryKey(id: number, callback: AsyncCallback<string>): void 3539 3540Queries the key of a contact based on the specified contact ID. This API uses an asynchronous callback to return the result. 3541 3542> **NOTE** 3543> 3544> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryKey](#contactquerykey10). 3545 3546**Permission required**: ohos.permission.READ_CONTACTS 3547 3548**System capability**: SystemCapability.Applications.ContactsData 3549 3550**Parameters** 3551 3552| Name | Type | Mandatory| Description | 3553| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 3554| id | number | Yes | Contact ID. | 3555| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, the key of the queried contact is returned. If the operation fails, an error code is returned.| 3556 3557**Example** 3558 3559 ```js 3560 import { BusinessError } from '@kit.BasicServicesKit'; 3561 contact.queryKey(/*id*/1, (err: BusinessError, data) => { 3562 if (err) { 3563 console.error(`Failed to query Key. Code: ${err.code}, message: ${err.message}`); 3564 return; 3565 } 3566 console.info(`Succeeded in querying Key. data->${JSON.stringify(data)}`); 3567 }); 3568 ``` 3569 3570## contact.queryKey<sup>10+</sup> 3571 3572queryKey(context: Context, id: number, holder: Holder, callback: AsyncCallback<string>): void 3573 3574Queries the key of a contact based on the specified contact ID and holder. This API uses an asynchronous callback to return the result. 3575 3576**Permission required**: ohos.permission.READ_CONTACTS 3577 3578**System capability**: SystemCapability.Applications.ContactsData 3579 3580**Parameters** 3581 3582| Name | Type | Mandatory| Description | 3583| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 3584| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 3585| id | number | Yes | Contact ID. | 3586| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 3587| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, the key of the queried contact is returned. If the operation fails, an error code is returned.| 3588 3589**Error codes** 3590 3591| ID| Error Message | 3592| -------- | ------------------ | 3593| 201 | Permission denied. | 3594| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3595 3596**Example** 3597 3598 ```js 3599 import { BusinessError } from '@kit.BasicServicesKit'; 3600 // Obtain the context. 3601 let context = getContext(this) as Context; 3602 contact.queryKey(context, /*id*/1, { 3603 holderId: 1, 3604 bundleName: "", 3605 displayName: "" 3606 }, (err: BusinessError, data) => { 3607 if (err) { 3608 console.error(`Failed to query Key. Code: ${err.code}, message: ${err.message}`); 3609 return; 3610 } 3611 console.info(`Succeeded in querying Key. data->${JSON.stringify(data)}`); 3612 }); 3613 ``` 3614 3615## contact.queryKey<sup>(deprecated)7+</sup> 3616 3617queryKey(id: number, holder: Holder, callback: AsyncCallback<string>): void 3618 3619Queries the key of a contact based on the specified contact ID and holder. This API uses an asynchronous callback to return the result. 3620 3621> **NOTE** 3622> 3623> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryKey](#contactquerykey10-1). 3624 3625**Permission required**: ohos.permission.READ_CONTACTS 3626 3627**System capability**: SystemCapability.Applications.ContactsData 3628 3629**Parameters** 3630 3631| Name | Type | Mandatory| Description | 3632| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 3633| id | number | Yes | Contact ID. | 3634| holder | [Holder](#holder) | Yes | Application that creates the contacts. | 3635| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, the key of the queried contact is returned. If the operation fails, an error code is returned.| 3636 3637**Example** 3638 3639 ```js 3640 import { BusinessError } from '@kit.BasicServicesKit'; 3641 contact.queryKey(/*id*/1, { 3642 holderId: 1, 3643 bundleName: "", 3644 displayName: "" 3645 }, (err: BusinessError, data) => { 3646 if (err) { 3647 console.error(`Failed to query Key. Code: ${err.code}, message: ${err.message}`); 3648 return; 3649 } 3650 console.info(`Succeeded in querying Key. data->${JSON.stringify(data)}`); 3651 }); 3652 ``` 3653 3654## contact.queryKey<sup>10+</sup> 3655 3656queryKey(context: Context, id: number, holder?: Holder): Promise<string> 3657 3658Queries the key of a contact based on the specified contact ID and holder. This API uses a promise to return the result. 3659 3660**Permission required**: ohos.permission.READ_CONTACTS 3661 3662**System capability**: SystemCapability.Applications.ContactsData 3663 3664**Parameters** 3665 3666| Name | Type | Mandatory| Description | 3667| ------- | ----------------- | ---- | ------------------------------------------------------------ | 3668| context | Context | Yes | Application context. For the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 3669| id | number | Yes | Contact ID. | 3670| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for contact filtering by default. | 3671 3672**Return Value** 3673 3674| Type | Description | 3675| --------------------- | ------------------------------------------ | 3676| Promise<string> | Promise used to return the result, which is the key of the queried contact.| 3677 3678**Error codes** 3679 3680| ID| Error Message | 3681| -------- | ------------------ | 3682| 201 | Permission denied. | 3683| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3684 3685**Example** 3686 3687 ```js 3688 import { BusinessError } from '@kit.BasicServicesKit'; 3689 // Obtain the context. 3690 let context = getContext(this) as Context; 3691 let promise = contact.queryKey(context, /*id*/1, { 3692 holderId: 1, 3693 bundleName: "", 3694 displayName: "" 3695 }); 3696 promise.then((data) => { 3697 console.info(`Succeeded in querying Key. data->${JSON.stringify(data)}`); 3698 }).catch((err: BusinessError) => { 3699 console.error(`Failed to query Key. Code: ${err.code}, message: ${err.message}`); 3700 }); 3701 ``` 3702 3703## contact.queryKey<sup>(deprecated)7+</sup> 3704 3705queryKey(id: number, holder?: Holder): Promise<string> 3706 3707Queries the key of a contact based on the specified contact ID and holder. This API uses a promise to return the result. 3708 3709> **NOTE** 3710> 3711> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [queryKey](#contactquerykey10-2). 3712 3713**Permission required**: ohos.permission.READ_CONTACTS 3714 3715**System capability**: SystemCapability.Applications.ContactsData 3716 3717**Parameters** 3718 3719| Name| Type | Mandatory| Description | 3720| ------ | ----------------- | ---- | ---------------------- | 3721| id | number | Yes | Contact ID. | 3722| holder | [Holder](#holder) | No | Application information for a contact. If this parameter is not specified, it is not used for contact filtering by default.| 3723 3724**Return Value** 3725 3726| Type | Description | 3727| --------------------- | ------------------------------------------ | 3728| Promise<string> | Promise used to return the result, which is the key of the queried contact.| 3729 3730**Example** 3731 3732 ```js 3733 import { BusinessError } from '@kit.BasicServicesKit'; 3734 let promise = contact.queryKey(/*id*/1, { 3735 holderId: 1, 3736 bundleName: "", 3737 displayName: "" 3738 }); 3739 promise.then((data) => { 3740 console.info(`Succeeded in querying Key. data->${JSON.stringify(data)}`); 3741 }).catch((err: BusinessError) => { 3742 console.error(`Failed to query Key. Code: ${err.code}, message: ${err.message}`); 3743 }); 3744 ``` 3745 3746## ContactSelectionOptions<sup>10+</sup> 3747 3748Defines the contact selection options. 3749 3750**Atomic service API**: This API can be used in atomic services since API version 11. 3751 3752**System capability**: SystemCapability.Applications.Contacts 3753 3754| Name | Type | Mandatory | Description | 3755| --------------------------------- | ------------------------------------- | ---- | ---------------- | 3756| isMultiSelect <sup>10+</sup> | boolean | No | Whether multiple contacts can be selected. | 3757 3758 3759 3760## Contact 3761 3762Defines a contact. 3763 3764**Atomic service API**: This API can be used in atomic services since API version 11. 3765 3766**System capability**: SystemCapability.Applications.ContactsData 3767 3768### Constant 3769 3770| Name | Value |Read-Only | Description | 3771| ------------------ | ---- | ---- | ---------------- | 3772| INVALID_CONTACT_ID | -1 |Yes | Default contact ID.| 3773 3774 3775### Attributes 3776 3777| Name | Type | Readable| Writable| Description | 3778| ----------------- | --------------------------------------- | ---- | ---- | -------------------------------------- | 3779| id | number | Yes | No | Contact ID. | 3780| key | string | Yes | No | Contact key. | 3781| contactAttributes | [ContactAttributes](#contactattributes) | Yes | Yes | List of contact attributes. | 3782| emails | [Email](#email)[] | Yes | Yes | List of email addresses of the contact. | 3783| events | [Event](#event)[] | Yes | Yes | List of important dates such as birthdays and anniversaries of the contact.| 3784| groups | [Group](#group)[] | Yes | Yes | List of groups of the contact. | 3785| imAddresses | [ImAddress](#imaddress)[] | Yes | Yes | List of instant message addresses of the contact. | 3786| phoneNumbers | [PhoneNumber](#phonenumber)[] | Yes | Yes | List of phone numbers of the contact. | 3787| portrait | [Portrait](#portrait) | Yes | Yes | Contact portrait. | 3788| postalAddresses | [PostalAddress](#postaladdress)[] | Yes | Yes | List of postal addresses of the contact. | 3789| relations | [Relation](#relation)[] | Yes | Yes | List of relationships with the contact. | 3790| sipAddresses | [SipAddress](#sipaddress)[] | Yes | Yes | List of Session Initiation Protocol (SIP) addresses of the contact. | 3791| websites | [Website](#website)[] | Yes | Yes | List of websites of the contact. | 3792| name | [Name](#name) | Yes | Yes | Contact name. | 3793| nickName | [NickName](#nickname) | Yes | Yes | Contact nickname. | 3794| note | [Note](#note) | Yes | Yes | Contact notes. | 3795| organization | [Organization](#organization) | Yes | Yes | Organization of the contact. | 3796 3797 3798**Example** 3799 3800Create contact data in JSON format: 3801 3802 3803```js 3804let myContact: contact.Contact = { 3805 phoneNumbers: [{ 3806 phoneNumber: "138xxxxxxxx" 3807 }], 3808 name: { 3809 fullName: "fullName", 3810 namePrefix: "namePrefix" 3811 }, 3812 nickName: { 3813 nickName: "nickName" 3814 } 3815}; 3816``` 3817 3818 3819 3820## ContactAttributes 3821 3822Provides a list of contact attributes, which are generally used as arguments. 3823If **null** is passed, all attributes are queried by default. 3824 3825**Atomic service API**: This API can be used in atomic services since API version 11. 3826 3827**System capability**: SystemCapability.Applications.ContactsData 3828 3829| Name | Type | Readable| Writable| Description | 3830| ---------- | ------------------------- | ---- | ---- | ---------------- | 3831| attributes | [Attribute](#attribute)[] | Yes | Yes | List of contact attributes.| 3832 3833 3834**Example** 3835 3836Create contact data in JSON format: 3837 3838 3839```js 3840let contactAttributes: contact.ContactAttributes = { 3841 attributes: [ 3842 contact.Attribute.ATTR_EMAIL, 3843 contact.Attribute.ATTR_NAME, 3844 contact.Attribute.ATTR_PHONE 3845 ] 3846}; 3847``` 3848 3849 3850## Attribute 3851 3852Enumerates contact attributes. 3853 3854**Atomic service API**: This API can be used in atomic services since API version 11. 3855 3856**System capability**: SystemCapability.Applications.ContactsData 3857 3858| Name | Description | 3859| --------------------- | ---------------------------------- | 3860| ATTR_CONTACT_EVENT | Important dates such as birthday and anniversaries of the contact.| 3861| ATTR_EMAIL | Email address of the contact. | 3862| ATTR_GROUP_MEMBERSHIP | Groups of the contact. | 3863| ATTR_IM | IM addresses of the contact. | 3864| ATTR_NAME | Contact name. | 3865| ATTR_NICKNAME | Contact nickname. | 3866| ATTR_NOTE | Contact notes. | 3867| ATTR_ORGANIZATION | Organization of the contact. | 3868| ATTR_PHONE | Phone number of the contacts. | 3869| ATTR_PORTRAIT | Contact portrait. | 3870| ATTR_POSTAL_ADDRESS | Postal address of the contact. | 3871| ATTR_RELATION | Relationship with the contact. | 3872| ATTR_SIP_ADDRESS | SIP addresses of the contact. | 3873| ATTR_WEBSITE | Website that stores the contact information. | 3874 3875 3876**Example** 3877 3878Create contact data in JSON format: 3879 3880```js 3881let attributes = [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE]; 3882``` 3883 3884 3885## Email 3886 3887Defines a contact's email. 3888 3889**Atomic service API**: This API can be used in atomic services since API version 11. 3890 3891**System capability**: SystemCapability.Applications.ContactsData 3892 3893### Constant 3894 3895| Name | Value | Description | 3896| ---------------- | ---- | ---------------- | 3897| CUSTOM_LABEL | 0 | Custom mailbox type.| 3898| EMAIL_HOME | 1 | Home mailbox. | 3899| EMAIL_WORK | 2 | Work mailbox. | 3900| EMAIL_OTHER | 3 | Other mailbox. | 3901| INVALID_LABEL_ID | -1 | Invalid mailbox. | 3902 3903 3904### Attributes 3905 3906| Name | Type | Readable| Writable| Description | 3907| ----------- | -------- | ---- | ---- | ---------------- | 3908| email | string | Yes | Yes | Email addresses | 3909| labelName | string | Yes | Yes | Name of the mailbox type.| 3910| displayName | string | Yes | Yes | Displayed name of the mailbox.| 3911| labelId | number | Yes | Yes | Mailbox type. | 3912 3913 3914**Example** 3915 3916 Create contact data in JSON format: 3917 3918```js 3919let email: contact.Email = { 3920 email: "xxx@email.com", 3921 displayName: "displayName" 3922} 3923``` 3924 3925 3926 Or, create data by configuring an **Email** object. 3927 3928```js 3929let email = new contact.Email(); 3930email.email = "xxx@email.com"; 3931``` 3932 3933 3934## Holder 3935 3936Defines an application that creates the contact. 3937 3938**System capability**: SystemCapability.Applications.ContactsData 3939 3940| Name | Type | Readable| Writable| Mandatory| Description | 3941| ----------- | ------ | ---- | ---- | ---- | ------------ | 3942| bundleName | string | Yes | No | Yes | Bundle name. The value is **com.ohos.contacts**.| 3943| displayName | string | Yes | No | No | Application name. | 3944| holderId | number | Yes | Yes | No | Application ID. | 3945 3946 3947**Example** 3948 3949 Create contact data in JSON format: 3950 3951```js 3952let holder: contact.Holder = { 3953 bundleName: "com.ohos.contacts", 3954 displayName: "displayName", 3955 holderId: 1 3956}; 3957``` 3958 3959 3960## Event 3961 3962Defines a contact's event. 3963 3964**Atomic service API**: This API can be used in atomic services since API version 11. 3965 3966**System capability**: SystemCapability.Applications.ContactsData 3967 3968### Constant 3969 3970| Name | Value | Description | 3971| ----------------- | ---- | ------------------ | 3972| CUSTOM_LABEL | 0 | Custom event. | 3973| EVENT_ANNIVERSARY | 1 | Anniversary event.| 3974| EVENT_OTHER | 2 | Other event. | 3975| EVENT_BIRTHDAY | 3 | Birthday event. | 3976| INVALID_LABEL_ID | -1 | Invalid event. | 3977 3978 3979### Attributes 3980 3981| Name | Type | Readable| Writable| Description | 3982| --------- | -------- | ---- | ---- | -------------- | 3983| eventDate | string | Yes | Yes | Event date. | 3984| labelName | string | Yes | Yes | Event type.| 3985| labelId | number | Yes | Yes | Event type ID. | 3986 3987 3988**Example** 3989 3990 Create contact data in JSON format: 3991 3992```js 3993let event: contact.Event = { 3994 eventDate: "xxxxxx" 3995}; 3996``` 3997 3998 Or, create data by configuring an **Event** object. 3999 4000```js 4001let event = new contact.Event(); 4002event.eventDate = "xxxxxx"; 4003``` 4004 4005 4006## Group 4007 4008Defines a contact group. 4009 4010**Atomic service API**: This API can be used in atomic services since API version 11. 4011 4012**System capability**: SystemCapability.Applications.ContactsData 4013 4014| Name | Type | Readable| Writable| Description | 4015| ------- | -------- | ---- | ---- | ------------------ | 4016| groupId | number | Yes | Yes | ID of a contact group. | 4017| title | string | Yes | Yes | Name of a contact group.| 4018 4019 4020**Example** 4021 4022 Create contact data in JSON format: 4023 4024```js 4025let group: contact.Group = { 4026 groupId: 1, 4027 title: "title" 4028}; 4029``` 4030 4031 4032## ImAddress 4033 4034Enumerates IM addresses. 4035 4036**Atomic service API**: This API can be used in atomic services since API version 11. 4037 4038**System capability**: SystemCapability.Applications.ContactsData 4039 4040### Constant 4041 4042| Name | Value | Description | 4043| ---------------- | ---- | -------------------- | 4044| CUSTOM_LABEL | -1 | Custom IM| 4045| IM_AIM | 0 | AIM | 4046| IM_MSN | 1 | MSN | 4047| IM_YAHOO | 2 | Yahoo | 4048| IM_SKYPE | 3 | Skype | 4049| IM_QQ | 4 | QQ | 4050| IM_ICQ | 6 | ICQ | 4051| IM_JABBER | 7 | JABBER| 4052| INVALID_LABEL_ID | -2 | Invalid IM| 4053 4054 4055### Attributes 4056 4057| Name | Type | Readable| Writable| Description | 4058| --------- | -------- | ---- | ---- | ------------------ | 4059| imAddress | string | Yes | Yes | IM address. | 4060| labelName | string | Yes | Yes | IM name.| 4061| labelId | number | Yes | Yes | IM ID. | 4062 4063 4064**Example** 4065 4066 Create contact data in JSON format: 4067 4068```js 4069let imAddress: contact.ImAddress = { 4070 imAddress: "imAddress", 4071 labelName: "labelName" 4072}; 4073``` 4074 4075 4076 Or, create data by configuring an **ImAddress** object. 4077 4078```js 4079let imAddress = new contact.ImAddress(); 4080imAddress.imAddress = "imAddress"; 4081``` 4082 4083 4084## Name 4085 4086Defines a contact's name. 4087 4088**Atomic service API**: This API can be used in atomic services since API version 11. 4089 4090**System capability**: SystemCapability.Applications.ContactsData 4091 4092| Name | Type | Readable| Writable| Description | 4093| ------------------ | -------- | ---- | ---- | --------------------------- | 4094| familyName | string | Yes | Yes | Family name. | 4095| familyNamePhonetic | string | Yes | Yes | Family name in pinyin. | 4096| fullName | string | Yes | Yes | Full name of the contact. | 4097| givenName | string | Yes | Yes | Given name of the contact.| 4098| givenNamePhonetic | string | Yes | Yes | Given name of the contact in pinyin. | 4099| middleName | string | Yes | Yes | Middle name of the contact. | 4100| middleNamePhonetic | string | Yes | Yes | Middle name of the contact in pinyin. | 4101| namePrefix | string | Yes | Yes | Prefix of the contact name. | 4102| nameSuffix | string | Yes | Yes | Suffix of the contact name. | 4103 4104 4105**Example** 4106 4107 Create contact data in JSON format: 4108 4109```js 4110let name: contact.Name = { 4111 familyName: "familyName", 4112 fullName: "fullName" 4113}; 4114``` 4115 4116 4117## NickName 4118 4119Defines a contact's nickname. 4120 4121**Atomic service API**: This API can be used in atomic services since API version 11. 4122 4123**System capability**: SystemCapability.Applications.ContactsData 4124 4125| Name | Type | Readable| Writable| Description | 4126| -------- | -------- | ---- | ---- | -------------- | 4127| nickName | string | Yes | Yes | Contact nickname.| 4128 4129 4130**Example** 4131 4132 Create contact data in JSON format: 4133 4134```js 4135let nickName: contact.NickName = { 4136 nickName: "nickName" 4137}; 4138``` 4139 4140## Note 4141 4142Defines a contact's note. 4143 4144**Atomic service API**: This API can be used in atomic services since API version 11. 4145 4146**System capability**: SystemCapability.Applications.ContactsData 4147 4148| Name | Type | Readable| Writable| Description | 4149| ----------- | -------- | ---- | ---- | ------------------ | 4150| noteContent | string | Yes | Yes | Notes of the contact.| 4151 4152 4153**Example** 4154 4155 Create contact data in JSON format: 4156 4157```js 4158let note: contact.Note = { 4159 noteContent: "noteContent" 4160}; 4161``` 4162 4163 4164## Organization 4165 4166Defines a contact's organization. 4167 4168**Atomic service API**: This API can be used in atomic services since API version 11. 4169 4170**System capability**: SystemCapability.Applications.ContactsData 4171 4172| Name | Type | Readable| Writable| Description | 4173| ----- | -------- | ---- | ---- | ---------- | 4174| name | string | Yes | Yes | Organization name.| 4175| title | string | Yes | Yes | Job title.| 4176 4177 4178**Example** 4179 4180 Create contact data in JSON format: 4181 4182```js 4183let organization: contact.Organization = { 4184 name: "name", 4185 title: "title" 4186}; 4187``` 4188 4189 4190## PhoneNumber 4191 4192Defines a contact's phone number. 4193 4194**Atomic service API**: This API can be used in atomic services since API version 11. 4195 4196**System capability**: SystemCapability.Applications.ContactsData 4197 4198### Constant 4199 4200| Name | Value | Description | 4201| ---------------- | ---- | ------------------------------------------------ | 4202| CUSTOM_LABEL | 0 | Custom phone type. | 4203| NUM_HOME | 1 | Home phone. | 4204| NUM_MOBILE | 2 | Mobile phone. | 4205| NUM_WORK | 3 | Work phone. | 4206| NUM_FAX_WORK | 4 | Work fax. | 4207| NUM_FAX_HOME | 5 | Family fax. | 4208| NUM_PAGER | 6 | Pager. | 4209| NUM_OTHER | 7 | Other phone type. | 4210| NUM_CALLBACK | 8 | Callback phone. | 4211| NUM_CAR | 9 | Car phone. | 4212| NUM_COMPANY_MAIN | 10 | Company phone. | 4213| NUM_ISDN | 11 | Integrated Services Digital Network (ISDN) phone. | 4214| NUM_MAIN | 12 | Main phone. | 4215| NUM_OTHER_FAX | 13 | Other fax phone. | 4216| NUM_RADIO | 14 | Wireless phone. | 4217| NUM_TELEX | 15 | Telex phone. | 4218| NUM_TTY_TDD | 16 | Teletypewriter (TTY) or Test Driven Development (TDD) phone.| 4219| NUM_WORK_MOBILE | 17 | Work mobile phone. | 4220| NUM_WORK_PAGER | 18 | Work pager. | 4221| NUM_ASSISTANT | 19 | Assistant phone. | 4222| NUM_MMS | 20 | MMS phone. | 4223| INVALID_LABEL_ID | -1 | Invalid phone type. | 4224 4225 4226### Attributes 4227 4228| Name | Type | Readable| Writable| Description | 4229| ----------- | -------- | ---- | ---- | ------------------ | 4230| labelName | string | Yes | Yes | Phone number type.| 4231| phoneNumber | string | Yes | Yes | Phone number. | 4232| labelId | number | Yes | Yes | Phone number ID. | 4233 4234 4235**Example** 4236 4237 Create contact data in JSON format: 4238 4239```js 4240let phoneNumber: contact.PhoneNumber = { 4241 phoneNumber: "138xxxxxxxx", 4242 labelId: contact.PhoneNumber.NUM_HOME 4243}; 4244``` 4245 4246 Or, create data by configuring a new **PhoneNumber** object. 4247 4248```js 4249let phoneNumber = new contact.PhoneNumber(); 4250phoneNumber.phoneNumber = "138xxxxxxxx"; 4251``` 4252 4253 4254## Portrait 4255 4256Defines a contact's portrait. 4257 4258**Atomic service API**: This API can be used in atomic services since API version 11. 4259 4260**System capability**: SystemCapability.Applications.ContactsData 4261 4262| Name| Type | Readable| Writable| Description | 4263| ---- | -------- | ---- | ---- | -------------- | 4264| uri | string | Yes | Yes | Contact portrait.| 4265 4266 4267**Example** 4268 4269 Create contact data in JSON format: 4270 4271```js 4272let portrait: contact.Portrait = { 4273 uri: "uri" 4274}; 4275``` 4276 4277 4278## PostalAddress 4279 4280Defines a contact's postal address. 4281 4282**Atomic service API**: This API can be used in atomic services since API version 11. 4283 4284**System capability**: SystemCapability.Applications.ContactsData 4285 4286### Constant 4287 4288| Name | Value | Description | 4289| ---------------- | ---- | -------------------- | 4290| CUSTOM_LABEL | 0 | Custom postal address type.| 4291| ADDR_HOME | 1 | Home address. | 4292| ADDR_WORK | 2 | Work address. | 4293| ADDR_OTHER | 3 | Other addresses. | 4294| INVALID_LABEL_ID | -1 | Invalid address type. | 4295 4296 4297### Attributes 4298 4299| Name | Type | Readable| Writable| Description | 4300| ------------- | -------- | ---- | ---- | -------------------------- | 4301| city | string | Yes | Yes | City where the contact is located. | 4302| country | string | Yes | Yes | Country/Region where the contact is located. | 4303| labelName | string | Yes | Yes | Postal address type. | 4304| neighborhood | string | Yes | Yes | Neighbor of the contact. | 4305| pobox | string | Yes | Yes | Email of the contact. | 4306| postalAddress | string | Yes | Yes | Postal address of the contact. | 4307| postcode | string | Yes | Yes | Postal code of the region where the contact is located.| 4308| region | string | Yes | Yes | Area where the contact is located. | 4309| street | string | Yes | Yes | Street where the contact resides. | 4310| labelId | number | Yes | Yes | Postal address type. | 4311 4312 4313**Example** 4314 4315 Create contact data in JSON format: 4316 4317```js 4318let postalAddress: contact.PostalAddress = { 4319 city: "city", 4320 postalAddress: "postalAddress" 4321}; 4322``` 4323 4324 Or, create data by configuring a new **PostalAddress** object. 4325 4326```js 4327let postalAddress = new contact.PostalAddress(); 4328postalAddress.city = "city"; 4329postalAddress.postalAddress = "postalAddress"; 4330``` 4331 4332 4333## Relation 4334 4335Defines a contact's relationship. 4336 4337**Atomic service API**: This API can be used in atomic services since API version 11. 4338 4339**System capability**: SystemCapability.Applications.ContactsData 4340 4341### Constant 4342 4343| Name | Value | Description | 4344| ------------------------- | ---- | ------------------ | 4345| CUSTOM_LABEL | 0 | Custom relationship. | 4346| RELATION_ASSISTANT | 1 | Assistant. | 4347| RELATION_BROTHER | 2 | Sibling. | 4348| RELATION_CHILD | 3 | Child. | 4349| RELATION_DOMESTIC_PARTNER | 4 | Domestic partner.| 4350| RELATION_FATHER | 5 | Father. | 4351| RELATION_FRIEND | 6 | Friend. | 4352| RELATION_MANAGER | 7 | Manager. | 4353| RELATION_MOTHER | 8 | Mother. | 4354| RELATION_PARENT | 9 | Parent. | 4355| RELATION_PARTNER | 10 | Partner.| 4356| RELATION_REFERRED_BY | 11 | Referrer. | 4357| RELATION_RELATIVE | 12 | Relative. | 4358| RELATION_SISTER | 13 | Sister. | 4359| RELATION_SPOUSE | 14 | Spouse. | 4360| INVALID_LABEL_ID | -1 | Invalid relationship. | 4361 4362 4363### Attributes 4364 4365| Name | Type | Readable| Writable| Description | 4366| ------------ | -------- | ---- | ---- | -------------- | 4367| labelName | string | Yes | Yes | Relationship type.| 4368| relationName | string | Yes | Yes | Relationship name. | 4369| labelId | number | Yes | Yes | Relationship ID. | 4370 4371 4372**Example** 4373 4374 Create contact data in JSON format: 4375 4376```js 4377let relation: contact.Relation = { 4378 relationName: "relationName", 4379 labelId: contact.Relation.RELATION_ASSISTANT 4380}; 4381``` 4382 4383 Or, create data by configuring a new **Relation** object. 4384 4385```js 4386let relation = new contact.Relation(); 4387relation.relationName = "relationName"; 4388relation.labelId = contact.Relation.RELATION_ASSISTANT; 4389``` 4390 4391 4392## SipAddress 4393 4394Defines a contact's SIP address. 4395 4396**Atomic service API**: This API can be used in atomic services since API version 11. 4397 4398**System capability**: SystemCapability.Applications.ContactsData 4399 4400### Constant 4401 4402| Name | Value | Description | 4403| ---------------- | ---- | ----------------------------------- | 4404| CUSTOM_LABEL | 0 | Custom SIP address.| 4405| SIP_HOME | 1 | Home SIP address. | 4406| SIP_WORK | 2 | Work SIP address. | 4407| SIP_OTHER | 3 | Other SIP address. | 4408| INVALID_LABEL_ID | -1 | Invalid SIP address. | 4409 4410 4411### Attributes 4412 4413| Name | Type | Readable| Writable| Description | 4414| ---------- | -------- | ---- | ---- | --------------------------------- | 4415| labelName | string | Yes | Yes | SIP address type.| 4416| sipAddress | string | Yes | Yes | SIP address. | 4417| labelId | number | Yes | Yes | SIP address ID. | 4418 4419**Example** 4420 4421 Create contact data in JSON format: 4422 4423```js 4424let sipAddress: contact.SipAddress = { 4425 sipAddress: "sipAddress" 4426}; 4427``` 4428 4429 Or, create data by configuring a new **SipAddress** object. 4430 4431```js 4432let sipAddress = new contact.SipAddress(); 4433sipAddress.sipAddress = "sipAddress"; 4434``` 4435 4436 4437## Website 4438 4439Defines a contact's website. 4440 4441**Atomic service API**: This API can be used in atomic services since API version 11. 4442 4443**System capability**: SystemCapability.Applications.ContactsData 4444 4445| Name | Type | Readable| Writable| Description | 4446| ------- | -------- | ---- | ---- | ------------------ | 4447| website | string | Yes | Yes | Website of the contact.| 4448 4449 4450**Example** 4451 4452 Create contact data in JSON format: 4453 4454```js 4455let website: contact.Website = { 4456 website: "website" 4457}; 4458``` 4459