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