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