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