1# @ohos.telephony.sim (SIM Management) 2 3The **sim** module provides basic SIM card management functions. You can obtain the name, number, ISO country code, home PLMN ID, service provider name, SIM card status, type, installation status, activation status, and lock status of the SIM card in the specified slot. Besides, you can set the name, number, and lock status of the SIM card, activate or deactivate the SIM card, and change the PIN or unlock the PIN or PUK of the SIM card. 4 5>**NOTE** 6> 7>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9 10## Modules to Import 11 12```ts 13import sim from '@ohos.telephony.sim'; 14``` 15 16## sim.isSimActive<sup>7+</sup> 17 18isSimActive\(slotId: number, callback: AsyncCallback\<boolean\>\): void 19 20Checks whether the SIM card in the specified slot is activated. This API uses an asynchronous callback to return the result. 21 22**System capability**: SystemCapability.Telephony.CoreService 23 24**Parameters** 25 26| Name | Type | Mandatory| Description | 27| -------- | --------------------------- | ---- | -------------------------------------- | 28| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 29| callback | AsyncCallback<boolean> | Yes | Callback used to return the result, which is a Boolean value indicating whether the SIM card in the specified slot is activated. The value **true** means yes and the value **false** means no. | 30 31**Example** 32 33```ts 34import { BusinessError } from '@ohos.base'; 35import sim from '@ohos.telephony.sim'; 36 37sim.isSimActive(0, (err: BusinessError, data: boolean) => { 38 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 39}); 40``` 41 42 43## sim.isSimActive<sup>7+</sup> 44 45isSimActive\(slotId: number\): Promise\<boolean\> 46 47Checks whether the SIM card in the specified slot is activated. This API uses a promise to return the result. 48 49**System capability**: SystemCapability.Telephony.CoreService 50 51**Parameters** 52 53| Name| Type | Mandatory| Description | 54| ------ | ------ | ---- | -------------------------------------- | 55| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 56 57**Return value** 58 59| Type | Description | 60| --------------------- | ---------------------------------- | 61| Promise<boolean> | Promise used to return the result. The value **true** indicates that the SIM card in the specified slot is activated, and the value **false** indicates the opposite.| 62 63**Example** 64 65```ts 66import { BusinessError } from '@ohos.base'; 67import sim from '@ohos.telephony.sim'; 68 69sim.isSimActive(0).then((data: boolean) => { 70 console.log(`isSimActive success, promise: data->${JSON.stringify(data)}`); 71}).catch((err: BusinessError) => { 72 console.error(`isSimActive failed, promise: err->${JSON.stringify(err)}`); 73}); 74``` 75 76## sim.isSimActiveSync<sup>10+</sup> 77 78isSimActiveSync\(slotId: number\): boolean 79 80Checks whether the SIM card in the specified slot is activated. 81 82**System capability**: SystemCapability.Telephony.CoreService 83 84**Parameters** 85 86| Name| Type | Mandatory| Description | 87| ------ | ------ | ---- | -------------------------------------- | 88| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 89 90**Return value** 91 92| Type | Description | 93| --------------------- | ---------------------------------- | 94| boolean | Boolean value indicating whether the SIM card in the specified slot is activated. The value **true** means yes and the value **false** means no.| 95 96**Example** 97 98```ts 99import sim from '@ohos.telephony.sim'; 100 101let isSimActive: boolean = sim.isSimActiveSync(0); 102console.log(`the sim is active:` + isSimActive); 103``` 104 105## sim.isOperatorSimCard<sup>11+</sup> 106 107isOperatorSimCard\(slotId: number, operator: OperatorSimCard\): boolean 108 109Checks whether the SIM card in the specified slot is provided by a specified carrier. 110 111**System API**: This is a system API. 112 113**System capability**: SystemCapability.Telephony.CoreService 114 115**Parameters** 116 117| Name | Type | Mandatory| Description | 118| ------ | --------------------------------------- | ---- | --------------------------------- | 119| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 120| operator | [OperatorSimCard](#operatorsimcard11) | Yes | Carrier name. (Currently, only SIM cards of China Telecom are supported.)| 121 122**Return value** 123 124| Type | Description | 125| --------------------- | ---------------------------------- | 126| boolean | Boolean value indicating whether the SIM card in the specified slot is provided by a specified carrier. The value **true** means yes and the value **false** means no.| 127 128**Error codes** 129 130For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 131 132| ID| Error Message | 133| -------- | -------------------------------------------- | 134| 202 | Non-system applications use system APIs. | 135| 401 | Parameter error. | 136| 8300001 | Invalid parameter value. | 137| 8300002 | Operation failed. Cannot connect to service. | 138| 8300003 | System internal error. | 139| 8300004 | Do not have sim card. | 140| 8300999 | Unknown error code. | 141 142**Example** 143 144```ts 145import sim from '@ohos.telephony.sim'; 146 147let slotId : number = 0; 148let operator : sim.OperatorSimCard = sim.OperatorSimCard.CHINA_TELECOM_CARD; 149try { 150 let isOperatorSimCard: boolean = sim.isOperatorSimCard(slotId, operator); 151 console.log(`is operator sim card: ` + isOperatorSimCard); 152} catch (err) { 153 console.error("isOperatorSimCard err: " + JSON.stringify(err)); 154} 155``` 156 157## sim.getDefaultVoiceSlotId<sup>7+</sup> 158 159getDefaultVoiceSlotId\(callback: AsyncCallback\<number\>\): void 160 161Obtains the default slot ID of the SIM card that provides voice services. This API uses an asynchronous callback to return the result. 162 163**System capability**: SystemCapability.Telephony.CoreService 164 165**Parameters** 166 167| Name | Type | Mandatory| Description | 168| -------- | --------------------------- | ---- | ---------- | 169| callback | AsyncCallback<number> | Yes | Callback used to return the result.<br>- **0**: card slot 1<br>- **1**: card slot 2<br>- **-1**: card slot not set or service not unavailable| 170 171**Example** 172 173```ts 174import { BusinessError } from '@ohos.base'; 175import sim from '@ohos.telephony.sim'; 176 177sim.getDefaultVoiceSlotId((err: BusinessError, data: number) => { 178 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 179}); 180``` 181 182## sim.getDefaultVoiceSlotId<sup>7+</sup> 183 184getDefaultVoiceSlotId\(\): Promise\<number\> 185 186Obtains the default slot ID of the SIM card that provides voice services. This API uses a promise to return the result. 187 188**System capability**: SystemCapability.Telephony.CoreService 189 190**Return value** 191 192| Type | Description | 193| ----------------- | --------------------------------------- | 194| Promise\<number\> | Promise used to return the result.<br>- **0**: card slot 1<br>- **1**: card slot 2<br>- **-1**: card slot not set or service not unavailable| 195 196**Example** 197 198```ts 199import { BusinessError } from '@ohos.base'; 200import sim from '@ohos.telephony.sim'; 201 202sim.getDefaultVoiceSlotId().then((data: number) => { 203 console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`); 204}).catch((err: BusinessError) => { 205 console.error(`getDefaultVoiceSlotId failed, promise: err->${JSON.stringify(err)}`); 206}); 207``` 208 209## sim.hasOperatorPrivileges<sup>7+</sup> 210 211hasOperatorPrivileges\(slotId: number, callback: AsyncCallback\<boolean\>\): void 212 213Checks whether the application (caller) has been granted the operator permission. This API uses an asynchronous callback to return the result. 214 215**System capability**: SystemCapability.Telephony.CoreService 216 217**Parameters** 218 219| Name | Type | Mandatory| Description | 220| -------- | ------------------------ | ---- | ---------------------------------------- | 221| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 222| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result. | 223 224**Error codes** 225 226For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 227 228| ID| Error Message | 229| -------- | -------------------------------------------- | 230| 401 | Parameter error. | 231| 8300001 | Invalid parameter value. | 232| 8300002 | Operation failed. Cannot connect to service. | 233| 8300003 | System internal error. | 234| 8300999 | Unknown error code. | 235 236**Example** 237 238```ts 239import { BusinessError } from '@ohos.base'; 240import sim from '@ohos.telephony.sim'; 241 242sim.hasOperatorPrivileges(0, (err: BusinessError, data: boolean) => { 243 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 244}); 245``` 246 247## sim.hasOperatorPrivileges<sup>7+</sup> 248 249hasOperatorPrivileges\(slotId: number\): Promise\<boolean\> 250 251Checks whether the application (caller) has been granted the operator permission. This API uses a promise to return the result. 252 253**System capability**: SystemCapability.Telephony.CoreService 254 255**Parameters** 256 257| Name| Type | Mandatory| Description | 258| ------ | ------ | ---- | ---------------------------------------- | 259| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 260 261**Return value** 262 263| Type | Description | 264| :----------------- | :---------------------------------------------------------- | 265| Promise\<boolean\> | Promise used to return the result. The value **true** indicates that the application (caller) has been granted the carrier permission, and the value **false** indicates the opposite.| 266 267**Error codes** 268 269For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 270 271| ID| Error Message | 272| -------- | -------------------------------------------- | 273| 401 | Parameter error. | 274| 8300001 | Invalid parameter value. | 275| 8300002 | Operation failed. Cannot connect to service. | 276| 8300003 | System internal error. | 277| 8300999 | Unknown error code. | 278 279**Example** 280 281```ts 282import { BusinessError } from '@ohos.base'; 283import sim from '@ohos.telephony.sim'; 284 285sim.hasOperatorPrivileges(0).then((data: boolean) => { 286 console.log(`hasOperatorPrivileges success, promise: data->${JSON.stringify(data)}`); 287}).catch((err: BusinessError) => { 288 console.error(`hasOperatorPrivileges failed, promise: err->${JSON.stringify(err)}`); 289}); 290``` 291 292## sim.getISOCountryCodeForSim 293 294getISOCountryCodeForSim\(slotId: number, callback: AsyncCallback\<string\>\): void 295 296Obtains the ISO country code of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 297 298**System capability**: SystemCapability.Telephony.CoreService 299 300**Parameters** 301 302| Name | Type | Mandatory| Description | 303| -------- | ----------------------- | ---- | ---------------------------------------- | 304| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 305| callback | AsyncCallback\<string\> | Yes | Callback used to return the result, which is an ISO country code, for example, **CN** (China).| 306 307**Error codes** 308 309For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 310 311| ID| Error Message | 312| -------- | -------------------------------------------- | 313| 401 | Parameter error. | 314| 8300001 | Invalid parameter value. | 315| 8300002 | Operation failed. Cannot connect to service. | 316| 8300003 | System internal error. | 317| 8300004 | Do not have sim card. | 318| 8300999 | Unknown error code. | 319 320**Example** 321 322```ts 323import { BusinessError } from '@ohos.base'; 324import sim from '@ohos.telephony.sim'; 325 326sim.getISOCountryCodeForSim(0, (err: BusinessError, data: string) => { 327 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 328}); 329``` 330 331 332## sim.getISOCountryCodeForSim 333 334getISOCountryCodeForSim\(slotId: number\): Promise\<string\> 335 336Obtains the ISO country code of the SIM card in the specified slot. This API uses a promise to return the result. 337 338**System capability**: SystemCapability.Telephony.CoreService 339 340**Parameters** 341 342| Name| Type | Mandatory| Description | 343| ------ | ------ | ---- | -------------------------------------- | 344| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 345 346**Return value** 347 348| Type | Description | 349| ----------------- | ------------------------------------------------------------ | 350| Promise\<string\> | Promise used to return the result, which is an ISO country code, for example, **CN** (China).| 351 352**Error codes** 353 354For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 355 356| ID| Error Message | 357| -------- | -------------------------------------------- | 358| 401 | Parameter error. | 359| 8300001 | Invalid parameter value. | 360| 8300002 | Operation failed. Cannot connect to service. | 361| 8300003 | System internal error. | 362| 8300004 | Do not have sim card. | 363| 8300999 | Unknown error code. | 364 365**Example** 366 367```ts 368import { BusinessError } from '@ohos.base'; 369import sim from '@ohos.telephony.sim'; 370 371sim.getISOCountryCodeForSim(0).then((data: string) => { 372 console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`); 373}).catch((err: BusinessError) => { 374 console.error(`getISOCountryCodeForSim failed, promise: err->${JSON.stringify(err)}`); 375}); 376``` 377 378## sim.getISOCountryCodeForSimSync<sup>10+</sup> 379 380getISOCountryCodeForSimSync\(slotId: number\): string 381 382Obtains the ISO country code of the SIM card in the specified slot. 383 384**System capability**: SystemCapability.Telephony.CoreService 385 386**Parameters** 387 388| Name| Type | Mandatory| Description | 389| ------ | ------ | ---- | -------------------------------------- | 390| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 391 392**Return value** 393 394| Type | Description | 395| ----------------- | ------------------------------------------------------------ | 396| string | ISO country code of the SIM card in the specified slot, for example, **CN** (China).| 397 398 399**Example** 400 401```ts 402import sim from '@ohos.telephony.sim'; 403 404let countryCode: string = sim.getISOCountryCodeForSimSync(0); 405console.log(`the country ISO is:` + countryCode); 406``` 407 408 409## sim.getSimOperatorNumeric 410 411getSimOperatorNumeric\(slotId: number, callback: AsyncCallback\<string\>\): void 412 413Obtains the home public land mobile network (PLMN) ID of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 414 415**System capability**: SystemCapability.Telephony.CoreService 416 417**Parameters** 418 419| Name | Type | Mandatory| Description | 420| -------- | ----------------------- | ---- | -------------------------------------- | 421| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 422| callback | AsyncCallback\<string\> | Yes | Callback used to return the result. | 423 424**Error codes** 425 426For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 427 428| ID| Error Message | 429| -------- | -------------------------------------------- | 430| 401 | Parameter error. | 431| 8300001 | Invalid parameter value. | 432| 8300002 | Operation failed. Cannot connect to service. | 433| 8300003 | System internal error. | 434| 8300004 | Do not have sim card. | 435| 8300999 | Unknown error code. | 436 437**Example** 438 439```ts 440import { BusinessError } from '@ohos.base'; 441import sim from '@ohos.telephony.sim'; 442 443sim.getSimOperatorNumeric(0, (err: BusinessError, data: string) => { 444 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 445}); 446``` 447 448 449## sim.getSimOperatorNumeric 450 451getSimOperatorNumeric\(slotId: number\): Promise\<string\> 452 453Obtains the home PLMN ID of the SIM card in the specified slot. This API uses a promise to return the result. 454 455**System capability**: SystemCapability.Telephony.CoreService 456 457**Parameters** 458 459| Name| Type | Mandatory| Description | 460| ------ | ------ | ---- | -------------------------------------- | 461| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 462 463**Return value** 464 465| Type | Description | 466| ----------------- | ------------------------------------------------ | 467| Promise\<string\> | Promise used to return the result.| 468 469**Error codes** 470 471For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 472 473| ID| Error Message | 474| -------- | -------------------------------------------- | 475| 401 | Parameter error. | 476| 8300001 | Invalid parameter value. | 477| 8300002 | Operation failed. Cannot connect to service. | 478| 8300003 | System internal error. | 479| 8300004 | Do not have sim card. | 480| 8300999 | Unknown error code. | 481 482**Example** 483 484```ts 485import { BusinessError } from '@ohos.base'; 486import sim from '@ohos.telephony.sim'; 487 488sim.getSimOperatorNumeric(0).then((data: string) => { 489 console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`); 490}).catch((err: BusinessError) => { 491 console.error(`getSimOperatorNumeric failed, promise: err->${JSON.stringify(err)}`); 492}); 493``` 494 495## sim.getSimOperatorNumericSync<sup>10+</sup> 496 497getSimOperatorNumericSync\(slotId: number\): string 498 499Obtains the home PLMN ID of the SIM card in the specified slot. 500 501**System capability**: SystemCapability.Telephony.CoreService 502 503**Parameters** 504 505| Name| Type | Mandatory| Description | 506| ------ | ------ | ---- | -------------------------------------- | 507| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 508 509**Return value** 510 511| Type | Description | 512| ----------------- | ------------------------------------------------ | 513| string | Home PLMN number of the SIM card in the specified slot.| 514 515 516**Example** 517 518```ts 519import sim from '@ohos.telephony.sim'; 520 521let numeric: string = sim.getSimOperatorNumericSync(0); 522console.log(`the sim operator numeric is:` + numeric); 523``` 524 525 526## sim.getSimSpn 527 528getSimSpn\(slotId: number, callback: AsyncCallback\<string\>\): void 529 530Obtains the service provider name (SPN) of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 531 532**System capability**: SystemCapability.Telephony.CoreService 533 534**Parameters** 535 536| Name | Type | Mandatory| Description | 537| -------- | ----------------------- | ---- | -------------------------------------- | 538| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 539| callback | AsyncCallback\<string\> | Yes | Callback used to return the result. | 540 541**Error codes** 542 543For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 544 545| ID| Error Message | 546| -------- | -------------------------------------------- | 547| 401 | Parameter error. | 548| 8300001 | Invalid parameter value. | 549| 8300002 | Operation failed. Cannot connect to service. | 550| 8300003 | System internal error. | 551| 8300004 | Do not have sim card. | 552| 8300999 | Unknown error code. | 553 554**Example** 555 556```ts 557import { BusinessError } from '@ohos.base'; 558import sim from '@ohos.telephony.sim'; 559 560sim.getSimSpn(0, (err: BusinessError, data: string) => { 561 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 562}); 563``` 564 565 566## sim.getSimSpn 567 568getSimSpn\(slotId: number\): Promise\<string\> 569 570Obtains the SPN of the SIM card in the specified slot. This API uses a promise to return the result. 571 572**System capability**: SystemCapability.Telephony.CoreService 573 574**Parameters** 575 576| Name| Type | Mandatory| Description | 577| ------ | ------ | ---- | -------------------------------------- | 578| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 579 580**Return value** 581 582| Type | Description | 583| ----------------- | ----------------------------------------- | 584| Promise\<string\> | Promise used to return the result.| 585 586**Error codes** 587 588For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 589 590| ID| Error Message | 591| -------- | -------------------------------------------- | 592| 401 | Parameter error. | 593| 8300001 | Invalid parameter value. | 594| 8300002 | Operation failed. Cannot connect to service. | 595| 8300003 | System internal error. | 596| 8300004 | Do not have sim card. | 597| 8300999 | Unknown error code. | 598 599**Example** 600 601```ts 602import { BusinessError } from '@ohos.base'; 603import sim from '@ohos.telephony.sim'; 604 605sim.getSimSpn(0).then((data: string) => { 606 console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`); 607}).catch((err: BusinessError) => { 608 console.error(`getSimSpn failed, promise: err->${JSON.stringify(err)}`); 609}); 610``` 611 612## sim.getSimSpnSync<sup>10+</sup> 613 614getSimSpnSync\(slotId: number\): string 615 616Obtains the SPN of the SIM card in the specified slot. 617 618**System capability**: SystemCapability.Telephony.CoreService 619 620**Parameters** 621 622| Name| Type | Mandatory| Description | 623| ------ | ------ | ---- | -------------------------------------- | 624| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 625 626**Return value** 627 628| Type | Description | 629| ----------------- | ----------------------------------------- | 630| string | SPN of the SIM card in the specified slot.| 631 632 633**Example** 634 635```ts 636import sim from '@ohos.telephony.sim'; 637 638let spn: string = sim.getSimSpnSync(0); 639console.log(`the sim card spn is:` + spn); 640``` 641 642 643## sim.getSimState 644 645getSimState\(slotId: number, callback: AsyncCallback\<SimState\>\): void 646 647Obtains the state of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 648 649**System capability**: SystemCapability.Telephony.CoreService 650 651**Parameters** 652 653| Name | Type | Mandatory| Description | 654| -------- | -------------------------------------- | ---- | -------------------------------------- | 655| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 656| callback | AsyncCallback\<[SimState](#simstate)\> | Yes | Callback used to return the result. For details, see [SimState](#simstate). | 657 658**Error codes** 659 660For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 661 662| ID| Error Message | 663| -------- | -------------------------------------------- | 664| 401 | Parameter error. | 665| 8300001 | Invalid parameter value. | 666| 8300002 | Operation failed. Cannot connect to service. | 667| 8300003 | System internal error. | 668| 8300999 | Unknown error code. | 669 670**Example** 671 672```ts 673import { BusinessError } from '@ohos.base'; 674import sim from '@ohos.telephony.sim'; 675 676sim.getSimState(0, (err: BusinessError, data: sim.SimState) => { 677 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 678}); 679``` 680 681 682## sim.getSimState 683 684getSimState\(slotId: number\): Promise\<SimState\> 685 686Obtains the state of the SIM card in the specified slot. This API uses a promise to return the result. 687 688**System capability**: SystemCapability.Telephony.CoreService 689 690**Parameters** 691 692| Name| Type | Mandatory| Description | 693| ------ | ------ | ---- | -------------------------------------- | 694| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 695 696**Return value** 697 698| Type | Description | 699| -------------------------------- | ------------------------------------------ | 700| Promise\<[SimState](#simstate)\> | Promise used to return the result.| 701 702**Error codes** 703 704For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 705 706| ID| Error Message | 707| -------- | -------------------------------------------- | 708| 401 | Parameter error. | 709| 8300001 | Invalid parameter value. | 710| 8300002 | Operation failed. Cannot connect to service. | 711| 8300003 | System internal error. | 712| 8300999 | Unknown error code. | 713 714**Example** 715 716```ts 717import { BusinessError } from '@ohos.base'; 718import sim from '@ohos.telephony.sim'; 719 720sim.getSimState(0).then((data: sim.SimState) => { 721 console.log(`getSimState success, promise: data->${JSON.stringify(data)}`); 722}).catch((err: BusinessError) => { 723 console.error(`getSimState failed, promise: err->${JSON.stringify(err)}`); 724}); 725``` 726 727## sim.getSimStateSync<sup>10+</sup> 728 729getSimStateSync\(slotId: number\): SimState 730 731Obtains the state of the SIM card in the specified slot. 732 733**System capability**: SystemCapability.Telephony.CoreService 734 735**Parameters** 736 737| Name| Type | Mandatory| Description | 738| ------ | ------ | ---- | -------------------------------------- | 739| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 740 741**Return value** 742 743| Type | Description | 744| ---------------------------- | ------------------------------------------ | 745| [SimState](#simstate) | State of the SIM card in the specified slot.| 746 747 748**Example** 749 750```ts 751import sim from '@ohos.telephony.sim'; 752 753let simState: sim.SimState = sim.getSimStateSync(0); 754console.log(`The sim state is:` + simState); 755``` 756 757## sim.getCardType<sup>7+</sup> 758 759getCardType\(slotId: number, callback: AsyncCallback\<CardType\>\): void 760 761Obtains the type of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 762 763**System capability**: SystemCapability.Telephony.CoreService 764 765**Parameters** 766 767| Name | Type | Mandatory| Description | 768| -------- | ----------------------- | ---- | -------------------------------------- | 769| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 770| callback | AsyncCallback\<[CardType](#cardtype7)\> | Yes | Callback used to return the result. | 771 772**Error codes** 773 774For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 775 776| ID| Error Message | 777| -------- | -------------------------------------------- | 778| 401 | Parameter error. | 779| 8300001 | Invalid parameter value. | 780| 8300002 | Operation failed. Cannot connect to service. | 781| 8300003 | System internal error. | 782| 8300004 | Do not have sim card. | 783| 8300999 | Unknown error code. | 784 785**Example** 786 787```ts 788import { BusinessError } from '@ohos.base'; 789import sim from '@ohos.telephony.sim'; 790 791sim.getCardType(0, (err: BusinessError, data: sim.CardType) => { 792 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 793}); 794``` 795 796 797## sim.getCardType<sup>7+</sup> 798 799getCardType\(slotId: number\): Promise\<CardType\> 800 801Obtains the type of the SIM card in the specified slot. This API uses a promise to return the result. 802 803**System capability**: SystemCapability.Telephony.CoreService 804 805**Parameters** 806 807| Name| Type | Mandatory| Description | 808| ------ | ------ | ---- | -------------------------------------- | 809| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 810 811**Return value** 812 813| Type | Description | 814| ----------------- | ------------------------------------------------------------ | 815| Promise\<[CardType](#cardtype7)\> | Promise used to return the result.| 816 817**Error codes** 818 819For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 820 821| ID| Error Message | 822| -------- | -------------------------------------------- | 823| 401 | Parameter error. | 824| 8300001 | Invalid parameter value. | 825| 8300002 | Operation failed. Cannot connect to service. | 826| 8300003 | System internal error. | 827| 8300004 | Do not have sim card. | 828| 8300999 | Unknown error code. | 829 830**Example** 831 832```ts 833import { BusinessError } from '@ohos.base'; 834import sim from '@ohos.telephony.sim'; 835 836sim.getCardType(0).then((data: sim.CardType) => { 837 console.log(`getCardType success, promise: data->${JSON.stringify(data)}`); 838}).catch((err: BusinessError) => { 839 console.error(`getCardType failed, promise: err->${JSON.stringify(err)}`); 840}); 841``` 842 843## sim.getCardTypeSync<sup>10+</sup> 844 845getCardTypeSync\(slotId: number\): CardType 846 847Obtains the type of the SIM card in the specified slot. 848 849**System capability**: SystemCapability.Telephony.CoreService 850 851**Parameters** 852 853| Name| Type | Mandatory| Description | 854| ------ | ------ | ---- | -------------------------------------- | 855| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 856 857**Return value** 858 859| Type | Description | 860| ----------------- | ------------------------------------------------------------ | 861| [CardType](#cardtype7) | Type of the SIM card in the specified slot.| 862 863 864**Example** 865 866```ts 867import sim from '@ohos.telephony.sim'; 868 869let cardType: sim.CardType = sim.getCardTypeSync(0); 870console.log(`the card type is:` + cardType); 871``` 872 873 874## sim.hasSimCard<sup>7+</sup> 875 876hasSimCard\(slotId: number, callback: AsyncCallback\<boolean\>\): void 877 878Checks whether the SIM card in the specified slot is installed. This API uses an asynchronous callback to return the result. 879 880**System capability**: SystemCapability.Telephony.CoreService 881 882**Parameters** 883 884| Name | Type | Mandatory| Description | 885| -------- | --------------------------- | ---- | -------------------------------------- | 886| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 887| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** indicates that the SIM card in the specified slot is installed, and the value **false** indicates the opposite. | 888 889**Error codes** 890 891For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 892 893| ID| Error Message | 894| -------- | -------------------------------------------- | 895| 401 | Parameter error. | 896| 8300001 | Invalid parameter value. | 897| 8300002 | Operation failed. Cannot connect to service. | 898| 8300003 | System internal error. | 899| 8300999 | Unknown error code. | 900 901**Example** 902 903```ts 904import { BusinessError } from '@ohos.base'; 905import sim from '@ohos.telephony.sim'; 906 907sim.hasSimCard(0, (err: BusinessError, data: boolean) => { 908 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 909}); 910``` 911 912 913## sim.hasSimCard<sup>7+</sup> 914 915hasSimCard\(slotId: number\): Promise\<boolean\> 916 917Checks whether the SIM card in the specified slot is installed. This API uses a promise to return the result. 918 919**System capability**: SystemCapability.Telephony.CoreService 920 921**Parameters** 922 923| Name| Type | Mandatory| Description | 924| ------ | ------ | ---- | -------------------------------------- | 925| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 926 927**Return value** 928 929| Type | Description | 930| --------------------- | ---------------------------------- | 931| Promise<boolean> | Promise used to return the result. The value **true** indicates that the SIM card in the specified slot is installed, and the value **false** indicates the opposite.| 932 933**Error codes** 934 935For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 936 937| ID| Error Message | 938| -------- | -------------------------------------------- | 939| 401 | Parameter error. | 940| 8300001 | Invalid parameter value. | 941| 8300002 | Operation failed. Cannot connect to service. | 942| 8300003 | System internal error. | 943| 8300999 | Unknown error code. | 944 945**Example** 946 947```ts 948import { BusinessError } from '@ohos.base'; 949import sim from '@ohos.telephony.sim'; 950 951sim.hasSimCard(0).then((data: boolean) => { 952 console.log(`hasSimCard success, promise: data->${JSON.stringify(data)}`); 953}).catch((err: BusinessError) => { 954 console.error(`hasSimCard failed, promise: err->${JSON.stringify(err)}`); 955}); 956``` 957 958## sim.hasSimCardSync<sup>10+</sup> 959 960hasSimCardSync\(slotId: number\): boolean 961 962Checks whether the SIM card in the specified slot is installed. 963 964**System capability**: SystemCapability.Telephony.CoreService 965 966**Parameters** 967 968| Name| Type | Mandatory| Description | 969| ------ | ------ | ---- | -------------------------------------- | 970| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 971 972**Return value** 973 974| Type | Description | 975| --------------------- | ---------------------------------- | 976| boolean | Boolean value indicating whether the SIM card in the specified slot is installed. The value **true** means yes and the value **false** means no.| 977 978**Example** 979 980```ts 981import sim from '@ohos.telephony.sim'; 982 983let hasSimCard: boolean = sim.hasSimCardSync(0); 984console.log(`has sim card: ` + hasSimCard); 985``` 986 987## sim.getSimAccountInfo<sup>10+</sup> 988 989getSimAccountInfo\(slotId: number, callback: AsyncCallback\<IccAccountInfo\>\): void 990 991Obtains account information of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 992 993**Required permission**: ohos.permission.GET_TELEPHONY_STATE 994 995>**NOTE** 996> 997>The **GET_TELEPHONY_STATE** permission is required only when you need to obtain the ICCID and phone number. Such information is sensitive and not open to third-party applications. When this API is called, the returned ICCID and phone number are empty. 998 999**System capability**: SystemCapability.Telephony.CoreService 1000 1001**Parameters** 1002 1003| Name | Type | Mandatory| Description | 1004| -------- | --------------------------------------------------- | ---- | -------------------------------------- | 1005| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1006| callback | AsyncCallback\<[IccAccountInfo](#iccaccountinfo10)\> | Yes | Callback used to return the result. | 1007 1008**Error codes** 1009 1010For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1011 1012| ID| Error Message | 1013| -------- | -------------------------------------------- | 1014| 401 | Parameter error. | 1015| 8300001 | Invalid parameter value. | 1016| 8300002 | Operation failed. Cannot connect to service. | 1017| 8300003 | System internal error. | 1018| 8300004 | Do not have sim card. | 1019| 8300999 | Unknown error code. | 1020| 8301002 | SIM card operation error. | 1021 1022**Example** 1023 1024```ts 1025import { BusinessError } from '@ohos.base'; 1026import sim from '@ohos.telephony.sim'; 1027 1028sim.getSimAccountInfo(0, (err:BusinessError , data: sim.IccAccountInfo) => { 1029 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 1030}); 1031``` 1032 1033 1034## sim.getSimAccountInfo<sup>10+</sup> 1035 1036getSimAccountInfo\(slotId: number\): Promise\<IccAccountInfo\> 1037 1038Obtains account information of the SIM card in the specified slot. This API uses a promise to return the result. 1039 1040**Required permission**: ohos.permission.GET_TELEPHONY_STATE 1041 1042>**NOTE** 1043> 1044>The **GET_TELEPHONY_STATE** permission is required only when you need to obtain the ICCID and phone number. Such information is sensitive and not open to third-party applications. When this API is called, the returned ICCID and phone number are empty. 1045 1046**System capability**: SystemCapability.Telephony.CoreService 1047 1048**Parameters** 1049 1050| Name| Type | Mandatory| Description | 1051| ------ | ------ | ---- | -------------------------------------- | 1052| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1053 1054**Return value** 1055 1056| Type | Description | 1057| -------------------------------------------- | ------------------------------------------ | 1058| Promise<[IccAccountInfo](#iccaccountinfo10)\> | Promise used to return the result.| 1059 1060**Error codes** 1061 1062For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1063 1064| ID| Error Message | 1065| -------- | -------------------------------------------- | 1066| 401 | Parameter error. | 1067| 8300001 | Invalid parameter value. | 1068| 8300002 | Operation failed. Cannot connect to service. | 1069| 8300003 | System internal error. | 1070| 8300004 | Do not have sim card. | 1071| 8300999 | Unknown error code. | 1072| 8301002 | SIM card operation error. | 1073 1074**Example** 1075 1076```ts 1077import { BusinessError } from '@ohos.base'; 1078import sim from '@ohos.telephony.sim'; 1079 1080sim.getSimAccountInfo(0).then((data: sim.IccAccountInfo) => { 1081 console.log(`getSimAccountInfo success, promise: data->${JSON.stringify(data)}`); 1082}).catch((err: BusinessError) => { 1083 console.error(`getSimAccountInfo failed, promise: err->${JSON.stringify(err)}`); 1084}); 1085``` 1086 1087## sim.getActiveSimAccountInfoList<sup>10+</sup> 1088 1089getActiveSimAccountInfoList\(callback: AsyncCallback\<Array\<IccAccountInfo\>\>\): void 1090 1091Obtains the list of activated SIM card accounts. This API uses an asynchronous callback to return the result. 1092 1093**Required permission**: ohos.permission.GET_TELEPHONY_STATE 1094 1095>**NOTE** 1096> 1097>The **GET_TELEPHONY_STATE** permission is required only when you need to obtain the ICCID and phone number. Such information is sensitive and not open to third-party applications. When this API is called, the returned ICCID and phone number are empty. 1098 1099**System capability**: SystemCapability.Telephony.CoreService 1100 1101**Parameters** 1102 1103| Name | Type | Mandatory| Description | 1104| -------- | ----------------------------------------------------------- | ---- | ---------- | 1105| callback | AsyncCallback\<Array<[IccAccountInfo](#iccaccountinfo10)\>\> | Yes | Callback used to return the result. | 1106 1107**Error codes** 1108 1109For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1110 1111| ID| Error Message | 1112| -------- | -------------------------------------------- | 1113| 401 | Parameter error. | 1114| 8300001 | Invalid parameter value. | 1115| 8300002 | Operation failed. Cannot connect to service. | 1116| 8300003 | System internal error. | 1117| 8300004 | Do not have sim card. | 1118| 8300999 | Unknown error code. | 1119 1120**Example** 1121 1122```ts 1123import { BusinessError } from '@ohos.base'; 1124import sim from '@ohos.telephony.sim'; 1125 1126sim.getActiveSimAccountInfoList((err: BusinessError, data: Array<sim.IccAccountInfo>) => { 1127 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 1128}); 1129``` 1130 1131 1132## sim.getActiveSimAccountInfoList<sup>10+</sup> 1133 1134getActiveSimAccountInfoList\(\): Promise\<Array\<IccAccountInfo\>\> 1135 1136Obtains the list of activated SIM card accounts. This API uses a promise to return the result. 1137 1138**Required permission**: ohos.permission.GET_TELEPHONY_STATE 1139 1140>**NOTE** 1141> 1142>The **GET_TELEPHONY_STATE** permission is required only when you need to obtain the ICCID and phone number. Such information is sensitive and not open to third-party applications. When this API is called, the returned ICCID and phone number are empty. 1143 1144**System capability**: SystemCapability.Telephony.CoreService 1145 1146**Return value** 1147 1148| Type | Description | 1149| ---------------------------------------------------- | ---------------------------------------------- | 1150| Promise<Array<[IccAccountInfo](#iccaccountinfo10)\>\> | Promise used to return the result.| 1151 1152**Error codes** 1153 1154For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1155 1156| ID| Error Message | 1157| -------- | -------------------------------------------- | 1158| 8300002 | Operation failed. Cannot connect to service. | 1159| 8300003 | System internal error. | 1160| 8300004 | Do not have sim card. | 1161| 8300999 | Unknown error code. | 1162 1163**Example** 1164 1165```ts 1166import { BusinessError } from '@ohos.base'; 1167import sim from '@ohos.telephony.sim'; 1168 1169sim.getActiveSimAccountInfoList().then((data: Array<sim.IccAccountInfo>) => { 1170 console.log(`getActiveSimAccountInfoList success, promise: data->${JSON.stringify(data)}`); 1171}).catch((err: BusinessError) => { 1172 console.error(`getActiveSimAccountInfoList failed, promise: err->${JSON.stringify(err)}`); 1173}); 1174``` 1175 1176## sim.setDefaultVoiceSlotId<sup>7+</sup> 1177 1178setDefaultVoiceSlotId\(slotId: number, callback: AsyncCallback\<void\>\): void 1179 1180Sets the default slot ID of the SIM card that provides voice services. This API uses an asynchronous callback to return the result. 1181 1182**System API**: This is a system API. 1183 1184**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1185 1186**System capability**: SystemCapability.Telephony.CoreService 1187 1188**Parameters** 1189 1190| Name | Type | Mandatory| Description | 1191| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 1192| slotId | number | Yes | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2<br>- **-1**: Clears the default configuration.| 1193| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1194 1195**Error codes** 1196 1197For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1198 1199| ID| Error Message | 1200| -------- | -------------------------------------------- | 1201| 201 | Permission denied. | 1202| 202 | Non-system applications use system APIs. | 1203| 401 | Parameter error. | 1204| 8300001 | Invalid parameter value. | 1205| 8300002 | Operation failed. Cannot connect to service. | 1206| 8300003 | System internal error. | 1207| 8300004 | Do not have sim card. | 1208| 8300999 | Unknown error code. | 1209| 8301001 | SIM card is not activated. | 1210 1211**Example** 1212 1213```ts 1214import { BusinessError } from '@ohos.base'; 1215import sim from '@ohos.telephony.sim'; 1216 1217sim.setDefaultVoiceSlotId(0, (err: BusinessError) => { 1218 console.log(`callback: err->${JSON.stringify(err)}`); 1219}); 1220``` 1221 1222 1223## sim.setDefaultVoiceSlotId<sup>7+</sup> 1224 1225setDefaultVoiceSlotId\(slotId: number\): Promise\<void\> 1226 1227Sets the default slot ID of the SIM card that provides voice services. This API uses a promise to return the result. 1228 1229**System API**: This is a system API. 1230 1231**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1232 1233**System capability**: SystemCapability.Telephony.CoreService 1234 1235**Parameters** 1236 1237| Name| Type | Mandatory| Description | 1238| ------ | ------ | ---- | ------------------------------------------------------------ | 1239| slotId | number | Yes | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2<br>- **-1**: Clears the default configuration.| 1240 1241**Return value** 1242 1243| Type | Description | 1244| --------------- | ------------------------------- | 1245| Promise\<void\> | Promise used to return the result.| 1246 1247**Error codes** 1248 1249For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1250 1251| ID| Error Message | 1252| -------- | -------------------------------------------- | 1253| 201 | Permission denied. | 1254| 202 | Non-system applications use system APIs. | 1255| 401 | Parameter error. | 1256| 8300001 | Invalid parameter value. | 1257| 8300002 | Operation failed. Cannot connect to service. | 1258| 8300003 | System internal error. | 1259| 8300004 | Do not have sim card. | 1260| 8300999 | Unknown error code. | 1261| 8301001 | SIM card is not activated. | 1262 1263**Example** 1264 1265```ts 1266import { BusinessError } from '@ohos.base'; 1267import sim from '@ohos.telephony.sim'; 1268 1269sim.setDefaultVoiceSlotId(0).then(() => { 1270 console.log(`setDefaultVoiceSlotId success.`); 1271}).catch((err: BusinessError) => { 1272 console.error(`setDefaultVoiceSlotId failed, promise: err->${JSON.stringify(err)}`); 1273}); 1274``` 1275 1276## sim.setShowName<sup>8+</sup> 1277 1278setShowName\(slotId: number, name: string, callback: AsyncCallback\<void\>\): void 1279 1280Sets a display name for the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 1281 1282**System API**: This is a system API. 1283 1284**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1285 1286**System capability**: SystemCapability.Telephony.CoreService 1287 1288**Parameters** 1289 1290| Name | Type | Mandatory| Description | 1291| -------- | ------------------------- | ---- | -------------------------------------- | 1292| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1293| name | string | Yes | SIM card name. | 1294| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1295 1296**Error codes** 1297 1298For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1299 1300| ID| Error Message | 1301| -------- | -------------------------------------------- | 1302| 201 | Permission denied. | 1303| 202 | Non-system applications use system APIs. | 1304| 401 | Parameter error. | 1305| 8300001 | Invalid parameter value. | 1306| 8300002 | Operation failed. Cannot connect to service. | 1307| 8300003 | System internal error. | 1308| 8300004 | Do not have sim card. | 1309| 8300999 | Unknown error code. | 1310 1311**Example** 1312 1313```ts 1314import { BusinessError } from '@ohos.base'; 1315import sim from '@ohos.telephony.sim'; 1316 1317let name: string = "ShowName"; 1318sim.setShowName(0, name, (err: BusinessError) => { 1319 console.log(`callback: err->${JSON.stringify(err)}`); 1320}); 1321``` 1322 1323## sim.setShowName<sup>8+</sup> 1324 1325setShowName\(slotId: number, name: string\): Promise\<void\> 1326 1327Sets a display name for the SIM card in the specified slot. This API uses a promise to return the result. 1328 1329**System API**: This is a system API. 1330 1331**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1332 1333**System capability**: SystemCapability.Telephony.CoreService 1334 1335**Parameters** 1336 1337| Name| Type | Mandatory| Description | 1338| ------ | ------ | ---- | -------------------------------------- | 1339| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1340| name | string | Yes | SIM card name. | 1341 1342**Return value** 1343 1344| Type | Description | 1345| --------------- | ------------------------------- | 1346| Promise\<void\> | Promise used to return the result.| 1347 1348**Error codes** 1349 1350For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1351 1352| ID| Error Message | 1353| -------- | -------------------------------------------- | 1354| 201 | Permission denied. | 1355| 202 | Non-system applications use system APIs. | 1356| 401 | Parameter error. | 1357| 8300001 | Invalid parameter value. | 1358| 8300002 | Operation failed. Cannot connect to service. | 1359| 8300003 | System internal error. | 1360| 8300004 | Do not have sim card. | 1361| 8300999 | Unknown error code. | 1362 1363**Example** 1364 1365```ts 1366import { BusinessError } from '@ohos.base'; 1367import sim from '@ohos.telephony.sim'; 1368 1369let name: string = "ShowName"; 1370sim.setShowName(0, name).then(() => { 1371 console.log(`setShowName success.`); 1372}).catch((err: BusinessError) => { 1373 console.error(`setShowName failed, promise: err->${JSON.stringify(err)}`); 1374}); 1375``` 1376 1377## sim.getShowName<sup>8+</sup> 1378 1379getShowName\(slotId: number, callback: AsyncCallback\<string\>\): void 1380 1381Obtains the name of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 1382 1383**System API**: This is a system API. 1384 1385**Required permission**: ohos.permission.GET_TELEPHONY_STATE 1386 1387**System capability**: SystemCapability.Telephony.CoreService 1388 1389**Parameters** 1390 1391| Name | Type | Mandatory| Description | 1392| -------- | --------------------------- | ---- | -------------------------------------- | 1393| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1394| callback | AsyncCallback<string> | Yes | Callback used to return the result. | 1395 1396**Error codes** 1397 1398For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1399 1400| ID| Error Message | 1401| -------- | -------------------------------------------- | 1402| 201 | Permission denied. | 1403| 202 | Non-system applications use system APIs. | 1404| 401 | Parameter error. | 1405| 8300001 | Invalid parameter value. | 1406| 8300002 | Operation failed. Cannot connect to service. | 1407| 8300003 | System internal error. | 1408| 8300004 | Do not have sim card. | 1409| 8300999 | Unknown error code. | 1410 1411**Example** 1412 1413```ts 1414import { BusinessError } from '@ohos.base'; 1415import sim from '@ohos.telephony.sim'; 1416 1417sim.getShowName(0, (err: BusinessError, data: string) => { 1418 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 1419}); 1420``` 1421 1422 1423## sim.getShowName<sup>8+</sup> 1424 1425getShowName\(slotId: number\): Promise\<string\> 1426 1427Obtains the name of the SIM card in the specified slot. This API uses a promise to return the result. 1428 1429**System API**: This is a system API. 1430 1431**Required permission**: ohos.permission.GET_TELEPHONY_STATE 1432 1433**System capability**: SystemCapability.Telephony.CoreService 1434 1435**Parameters** 1436 1437| Name| Type | Mandatory| Description | 1438| ------ | ------ | ---- | -------------------------------------- | 1439| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1440 1441**Return value** 1442 1443| Type | Description | 1444| --------------------- | -------------------------------------- | 1445| Promise<string> | Promise used to return the result.| 1446 1447**Error codes** 1448 1449For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1450 1451| ID| Error Message | 1452| -------- | -------------------------------------------- | 1453| 201 | Permission denied. | 1454| 202 | Non-system applications use system APIs. | 1455| 401 | Parameter error. | 1456| 8300001 | Invalid parameter value. | 1457| 8300002 | Operation failed. Cannot connect to service. | 1458| 8300003 | System internal error. | 1459| 8300004 | Do not have sim card. | 1460| 8300999 | Unknown error code. | 1461 1462**Example** 1463 1464```ts 1465import { BusinessError } from '@ohos.base'; 1466import sim from '@ohos.telephony.sim'; 1467 1468sim.getShowName(0).then((data: string) => { 1469 console.log(`getShowName success, promise: data->${JSON.stringify(data)}`); 1470}).catch((err: BusinessError) => { 1471 console.error(`getShowName failed, promise: err->${JSON.stringify(err)}`); 1472}); 1473``` 1474 1475## sim.setShowNumber<sup>8+</sup> 1476 1477setShowNumber\(slotId: number, number: string, callback: AsyncCallback\<void\>\): void 1478 1479Sets a display number for the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 1480 1481**System API**: This is a system API. 1482 1483**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1484 1485**System capability**: SystemCapability.Telephony.CoreService 1486 1487**Parameters** 1488 1489| Name | Type | Mandatory| Description | 1490| -------- | ------------------------- | ---- | -------------------------------------- | 1491| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1492| number | string | Yes | SIM card number. | 1493| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1494 1495**Error codes** 1496 1497For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1498 1499| ID| Error Message | 1500| -------- | -------------------------------------------- | 1501| 201 | Permission denied. | 1502| 202 | Non-system applications use system APIs. | 1503| 401 | Parameter error. | 1504| 8300001 | Invalid parameter value. | 1505| 8300002 | Operation failed. Cannot connect to service. | 1506| 8300003 | System internal error. | 1507| 8300004 | Do not have sim card. | 1508| 8300999 | Unknown error code. | 1509 1510**Example** 1511 1512```ts 1513import { BusinessError } from '@ohos.base'; 1514import sim from '@ohos.telephony.sim'; 1515 1516let number: string = '+861xxxxxxxxxx'; 1517sim.setShowNumber(0, number, (err: BusinessError) => { 1518 console.log(`callback: err->${JSON.stringify(err)}`); 1519}); 1520``` 1521 1522 1523## sim.setShowNumber<sup>8+</sup> 1524 1525setShowNumber\(slotId: number, number: string\): Promise\<void\> 1526 1527Sets a display number for the SIM card in the specified slot. This API uses a promise to return the result. 1528 1529**System API**: This is a system API. 1530 1531**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1532 1533**System capability**: SystemCapability.Telephony.CoreService 1534 1535**Parameters** 1536 1537| Name| Type | Mandatory| Description | 1538| ------ | ------ | ---- | -------------------------------------- | 1539| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1540| number | string | Yes | SIM card number. | 1541 1542**Return value** 1543 1544| Type | Description | 1545| -------------- | ------------------------------- | 1546| Promise<void\> | Promise used to return the result.| 1547 1548**Error codes** 1549 1550For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1551 1552| ID| Error Message | 1553| -------- | -------------------------------------------- | 1554| 201 | Permission denied. | 1555| 202 | Non-system applications use system APIs. | 1556| 401 | Parameter error. | 1557| 8300001 | Invalid parameter value. | 1558| 8300002 | Operation failed. Cannot connect to service. | 1559| 8300003 | System internal error. | 1560| 8300004 | Do not have sim card. | 1561| 8300999 | Unknown error code. | 1562 1563**Example** 1564 1565```ts 1566import { BusinessError } from '@ohos.base'; 1567import sim from '@ohos.telephony.sim'; 1568 1569let number: string = '+861xxxxxxxxxx'; 1570sim.setShowNumber(0, number).then(() => { 1571 console.log(`setShowNumber success.`); 1572}).catch((err: BusinessError) => { 1573 console.error(`setShowNumber failed, promise: err->${JSON.stringify(err)}`); 1574}); 1575``` 1576 1577## sim.getShowNumber<sup>8+</sup> 1578 1579getShowNumber\(slotId: number, callback: AsyncCallback\<string\>): void 1580 1581Obtains the display number of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 1582 1583**System API**: This is a system API. 1584 1585**Required permission**: ohos.permission.GET_TELEPHONY_STATE 1586 1587**System capability**: SystemCapability.Telephony.CoreService 1588 1589**Parameters** 1590 1591| Name | Type | Mandatory| Description | 1592| -------- | --------------------------- | ---- | -------------------------------------- | 1593| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1594| callback | AsyncCallback<string> | Yes | Callback used to return the result. | 1595 1596**Error codes** 1597 1598For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1599 1600| ID| Error Message | 1601| -------- | -------------------------------------------- | 1602| 201 | Permission denied. | 1603| 202 | Non-system applications use system APIs. | 1604| 401 | Parameter error. | 1605| 8300001 | Invalid parameter value. | 1606| 8300002 | Operation failed. Cannot connect to service. | 1607| 8300003 | System internal error. | 1608| 8300004 | Do not have sim card. | 1609| 8300999 | Unknown error code. | 1610 1611**Example** 1612 1613```ts 1614import { BusinessError } from '@ohos.base'; 1615import sim from '@ohos.telephony.sim'; 1616 1617sim.getShowNumber(0, (err: BusinessError, data: string) => { 1618 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 1619}); 1620``` 1621 1622 1623## sim.getShowNumber<sup>8+</sup> 1624 1625getShowNumber\(slotId: number\): Promise\<string\> 1626 1627Obtains the display number of the SIM card in the specified slot. This API uses a promise to return the result. 1628 1629**System API**: This is a system API. 1630 1631**Required permission**: ohos.permission.GET_TELEPHONY_STATE 1632 1633**System capability**: SystemCapability.Telephony.CoreService 1634 1635**Parameters** 1636 1637| Name| Type | Mandatory| Description | 1638| ------ | ------ | ---- | -------------------------------------- | 1639| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1640 1641**Return value** 1642 1643| Type | Description | 1644| --------------------- | --------------------------------- | 1645| Promise<string> | Promise used to return the result.| 1646 1647**Error codes** 1648 1649For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1650 1651| ID| Error Message | 1652| -------- | -------------------------------------------- | 1653| 201 | Permission denied. | 1654| 202 | Non-system applications use system APIs. | 1655| 401 | Parameter error. | 1656| 8300001 | Invalid parameter value. | 1657| 8300002 | Operation failed. Cannot connect to service. | 1658| 8300003 | System internal error. | 1659| 8300004 | Do not have sim card. | 1660| 8300999 | Unknown error code. | 1661 1662**Example** 1663 1664```ts 1665import { BusinessError } from '@ohos.base'; 1666import sim from '@ohos.telephony.sim'; 1667 1668sim.getShowNumber(0).then((data: string) => { 1669 console.log(`getShowNumber success, promise: data->${JSON.stringify(data)}`); 1670}).catch((err: BusinessError) => { 1671 console.error(`getShowNumber failed, promise: err->${JSON.stringify(err)}`); 1672}); 1673``` 1674 1675## sim.activateSim<sup>8+</sup> 1676 1677activateSim\(slotId: number, callback: AsyncCallback\<void\>\): void 1678 1679Activates the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 1680 1681**System API**: This is a system API. 1682 1683**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1684 1685**System capability**: SystemCapability.Telephony.CoreService 1686 1687**Parameters** 1688 1689| Name | Type | Mandatory| Description | 1690| -------- | ------------------------- | ---- | -------------------------------------- | 1691| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1692| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1693 1694**Error codes** 1695 1696For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1697 1698| ID| Error Message | 1699| -------- | -------------------------------------------- | 1700| 201 | Permission denied. | 1701| 202 | Non-system applications use system APIs. | 1702| 401 | Parameter error. | 1703| 8300001 | Invalid parameter value. | 1704| 8300002 | Operation failed. Cannot connect to service. | 1705| 8300003 | System internal error. | 1706| 8300004 | Do not have sim card. | 1707| 8300999 | Unknown error code. | 1708 1709**Example** 1710 1711```ts 1712import { BusinessError } from '@ohos.base'; 1713import sim from '@ohos.telephony.sim'; 1714 1715sim.activateSim(0, (err: BusinessError) => { 1716 console.log(`callback: err->${JSON.stringify(err)}`); 1717}); 1718``` 1719 1720 1721## sim.activateSim<sup>8+</sup> 1722 1723activateSim\(slotId: number\): Promise\<void\> 1724 1725Activates the SIM card in the specified slot. This API uses a promise to return the result. 1726 1727**System API**: This is a system API. 1728 1729**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1730 1731**System capability**: SystemCapability.Telephony.CoreService 1732 1733**Parameters** 1734 1735| Name| Type | Mandatory| Description | 1736| ------ | ------ | ---- | -------------------------------------- | 1737| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1738 1739**Return value** 1740 1741| Type | Description | 1742| --------------- | ------------------------------- | 1743| Promise\<void\> | Promise used to return the result.| 1744 1745**Error codes** 1746 1747For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1748 1749| ID| Error Message | 1750| -------- | -------------------------------------------- | 1751| 201 | Permission denied. | 1752| 202 | Non-system applications use system APIs. | 1753| 401 | Parameter error. | 1754| 8300001 | Invalid parameter value. | 1755| 8300002 | Operation failed. Cannot connect to service. | 1756| 8300003 | System internal error. | 1757| 8300004 | Do not have sim card. | 1758| 8300999 | Unknown error code. | 1759 1760**Example** 1761 1762```ts 1763import { BusinessError } from '@ohos.base'; 1764import sim from '@ohos.telephony.sim'; 1765 1766sim.activateSim(0).then(() => { 1767 console.log(`activateSim success.`); 1768}).catch((err: BusinessError) => { 1769 console.error(`activateSim failed, promise: err->${JSON.stringify(err)}`); 1770}); 1771``` 1772 1773## sim.deactivateSim<sup>8+</sup> 1774 1775deactivateSim\(slotId: number, callback: AsyncCallback\<void\>\): void 1776 1777Disables the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 1778 1779**System API**: This is a system API. 1780 1781**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1782 1783**System capability**: SystemCapability.Telephony.CoreService 1784 1785**Parameters** 1786 1787| Name | Type | Mandatory| Description | 1788| -------- | ------------------------- | ---- | -------------------------------------- | 1789| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1790| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1791 1792**Error codes** 1793 1794For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1795 1796| ID| Error Message | 1797| -------- | -------------------------------------------- | 1798| 201 | Permission denied. | 1799| 202 | Non-system applications use system APIs. | 1800| 401 | Parameter error. | 1801| 8300001 | Invalid parameter value. | 1802| 8300002 | Operation failed. Cannot connect to service. | 1803| 8300003 | System internal error. | 1804| 8300004 | Do not have sim card. | 1805| 8300999 | Unknown error code. | 1806 1807**Example** 1808 1809```ts 1810import { BusinessError } from '@ohos.base'; 1811import sim from '@ohos.telephony.sim'; 1812 1813sim.deactivateSim(0, (err: BusinessError) => { 1814 console.log(`callback: err->${JSON.stringify(err)}`); 1815}); 1816``` 1817 1818 1819## sim.deactivateSim<sup>8+</sup> 1820 1821deactivateSim\(slotId: number\): Promise\<void\> 1822 1823Disables the SIM card in the specified slot. This API uses a promise to return the result. 1824 1825**System API**: This is a system API. 1826 1827**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1828 1829**System capability**: SystemCapability.Telephony.CoreService 1830 1831**Parameters** 1832 1833| Name| Type | Mandatory| Description | 1834| ------ | ------ | ---- | -------------------------------------- | 1835| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1836 1837**Return value** 1838 1839| Type | Description | 1840| --------------- | ------------------------------- | 1841| Promise\<void\> | Promise used to return the result.| 1842 1843**Error codes** 1844 1845For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1846 1847| ID| Error Message | 1848| -------- | -------------------------------------------- | 1849| 201 | Permission denied. | 1850| 202 | Non-system applications use system APIs. | 1851| 401 | Parameter error. | 1852| 8300001 | Invalid parameter value. | 1853| 8300002 | Operation failed. Cannot connect to service. | 1854| 8300003 | System internal error. | 1855| 8300004 | Do not have sim card. | 1856| 8300999 | Unknown error code. | 1857 1858**Example** 1859 1860```ts 1861import { BusinessError } from '@ohos.base'; 1862import sim from '@ohos.telephony.sim'; 1863 1864sim.deactivateSim(0).then(() => { 1865 console.log(`deactivateSim success.`); 1866}).catch((err: BusinessError) => { 1867 console.error(`deactivateSim failed, promise: err->${JSON.stringify(err)}`); 1868}); 1869``` 1870 1871## sim.setLockState<sup>7+</sup> 1872 1873setLockState\(slotId: number, options: LockInfo, callback: AsyncCallback\<LockStatusResponse\>\): void 1874 1875Sets the lock status of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 1876 1877**System API**: This is a system API. 1878 1879**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1880 1881**System capability**: SystemCapability.Telephony.CoreService 1882 1883**Parameters** 1884 1885| Name | Type | Mandatory| Description | 1886| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 1887| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 1888| callback | AsyncCallback\<[LockStatusResponse](#lockstatusresponse7)\> | Yes | Callback used to return the result. | 1889| options | [LockInfo](#lockinfo8) | Yes | Lock information.<br>- lockType: [LockType](#locktype8)<br>- password: string<br>- state: [LockState](#lockstate8) | 1890 1891**Error codes** 1892 1893For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1894 1895| ID| Error Message | 1896| -------- | -------------------------------------------- | 1897| 201 | Permission denied. | 1898| 202 | Non-system applications use system APIs. | 1899| 401 | Parameter error. | 1900| 8300001 | Invalid parameter value. | 1901| 8300002 | Operation failed. Cannot connect to service. | 1902| 8300003 | System internal error. | 1903| 8300004 | Do not have sim card. | 1904| 8300999 | Unknown error code. | 1905| 8301002 | SIM card operation error. | 1906 1907**Example** 1908 1909```ts 1910import { BusinessError } from '@ohos.base'; 1911import sim from '@ohos.telephony.sim'; 1912 1913let lockInfo: sim.LockInfo = { 1914 lockType: sim.LockType.PIN_LOCK, 1915 password: "1234", 1916 state: sim.LockState.LOCK_OFF 1917}; 1918sim.setLockState(0, lockInfo, (err: BusinessError, data: sim.LockStatusResponse) => { 1919 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 1920}); 1921``` 1922 1923 1924## sim.setLockState<sup>7+</sup> 1925 1926setLockState\(slotId: number, options: LockInfo\): Promise\<LockStatusResponse\> 1927 1928Sets the lock status of the SIM card in the specified slot. This API uses a promise to return the result. 1929 1930**System API**: This is a system API. 1931 1932**Required permission**: ohos.permission.SET_TELEPHONY_STATE 1933 1934**System capability**: SystemCapability.Telephony.CoreService 1935 1936**Parameters** 1937 1938| Name | Type | Mandatory| Description | 1939| ------- | ---------------------- | ---- | ------------------------------------------------------------ | 1940| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 1941| options | [LockInfo](#lockinfo8) | Yes | Lock information.<br>- lockType: [LockType](#locktype8)<br>- password: string<br>- state: [LockState](#lockstate8) | 1942 1943**Return value** 1944 1945| Type | Description | 1946| ---------------------------------------------------- | -------------------------------------------- | 1947| Promise<[LockStatusResponse](#lockstatusresponse7)\> | Promise used to return the result.| 1948 1949**Error codes** 1950 1951For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 1952 1953| ID| Error Message | 1954| -------- | -------------------------------------------- | 1955| 201 | Permission denied. | 1956| 202 | Non-system applications use system APIs. | 1957| 401 | Parameter error. | 1958| 8300001 | Invalid parameter value. | 1959| 8300002 | Operation failed. Cannot connect to service. | 1960| 8300003 | System internal error. | 1961| 8300004 | Do not have sim card. | 1962| 8300999 | Unknown error code. | 1963| 8301002 | SIM card operation error. | 1964 1965**Example** 1966 1967```ts 1968import { BusinessError } from '@ohos.base'; 1969import sim from '@ohos.telephony.sim'; 1970 1971let lockInfo: sim.LockInfo = { 1972 lockType: sim.LockType.PIN_LOCK, 1973 password: "1234", 1974 state: sim.LockState.LOCK_OFF 1975}; 1976sim.setLockState(0, lockInfo).then((data: sim.LockStatusResponse) => { 1977 console.log(`setLockState success, promise: data->${JSON.stringify(data)}`); 1978}).catch((err: BusinessError) => { 1979 console.error(`setLockState failed, promise: err->${JSON.stringify(err)}`); 1980}); 1981``` 1982 1983## sim.getLockState<sup>8+</sup> 1984 1985getLockState\(slotId: number, lockType: LockType, callback: AsyncCallback\<LockState\>\): void 1986 1987Obtains the lock status of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 1988 1989**System API**: This is a system API. 1990 1991**Required permission**: ohos.permission.GET_TELEPHONY_STATE 1992 1993**System capability**: SystemCapability.Telephony.CoreService 1994 1995**Parameters** 1996 1997| Name | Type | Mandatory| Description | 1998| -------- | ----------------------------------------- | ---- | --------------------------------------- | 1999| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 2000| callback | AsyncCallback\<[LockState](#lockstate8)\> | Yes | Callback used to return the result. | 2001| options | [LockType](#locktype8) | Yes | Lock type.<br>- **1**: PIN lock<br>- **2**: PIN 2 lock| 2002 2003**Error codes** 2004 2005For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2006 2007| ID| Error Message | 2008| -------- | -------------------------------------------- | 2009| 201 | Permission denied. | 2010| 202 | Non-system applications use system APIs. | 2011| 401 | Parameter error. | 2012| 8300001 | Invalid parameter value. | 2013| 8300002 | Operation failed. Cannot connect to service. | 2014| 8300003 | System internal error. | 2015| 8300004 | Do not have sim card. | 2016| 8300999 | Unknown error code. | 2017| 8301002 | SIM card operation error. | 2018 2019**Example** 2020 2021```ts 2022import { BusinessError } from '@ohos.base'; 2023import sim from '@ohos.telephony.sim'; 2024 2025sim.getLockState(0, 1, (err: BusinessError, data: sim.LockState) => { 2026 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 2027}); 2028``` 2029 2030 2031## sim.getLockState<sup>8+</sup> 2032 2033getLockState\(slotId: number, lockType: LockType\): Promise\<LockState\> 2034 2035Obtains the lock status of the SIM card in the specified slot. This API uses a promise to return the result. 2036 2037**System API**: This is a system API. 2038 2039**Required permission**: ohos.permission.GET_TELEPHONY_STATE 2040 2041**System capability**: SystemCapability.Telephony.CoreService 2042 2043**Parameters** 2044 2045| Name | Type | Mandatory| Description | 2046| ------- | ---------------------- | ---- | --------------------------------------- | 2047| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 2048| options | [LockType](#locktype8) | Yes | Lock type.<br>- **1**: PIN lock<br>- **2**: PIN 2 lock| 2049 2050**Return value** 2051 2052| Type | Description | 2053| ---------------------------------- | -------------------------------------------- | 2054| Promise<[LockState](#lockstate8)\> | Promise used to return the result.| 2055 2056**Error codes** 2057 2058For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2059 2060| ID| Error Message | 2061| -------- | -------------------------------------------- | 2062| 201 | Permission denied. | 2063| 202 | Non-system applications use system APIs. | 2064| 401 | Parameter error. | 2065| 8300001 | Invalid parameter value. | 2066| 8300002 | Operation failed. Cannot connect to service. | 2067| 8300003 | System internal error. | 2068| 8300004 | Do not have sim card. | 2069| 8300999 | Unknown error code. | 2070| 8301002 | SIM card operation error. | 2071 2072**Example** 2073 2074```ts 2075import { BusinessError } from '@ohos.base'; 2076import sim from '@ohos.telephony.sim'; 2077 2078sim.getLockState(0, 1).then((data: sim.LockState) => { 2079 console.log(`getLockState success, promise: data->${JSON.stringify(data)}`); 2080}).catch((err: BusinessError) => { 2081 console.error(`getLockState failed, promise: err->${JSON.stringify(err)}`); 2082}); 2083``` 2084 2085## sim.alterPin<sup>7+</sup> 2086 2087alterPin\(slotId: number, newPin: string, oldPin: string, callback: AsyncCallback\<LockStatusResponse\>\): void 2088 2089Changes the PIN of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 2090 2091**System API**: This is a system API. 2092 2093**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2094 2095**System capability**: SystemCapability.Telephony.CoreService 2096 2097**Parameters** 2098 2099| Name | Type | Mandatory| Description | 2100| -------- | ----------------------------------------------------------- | ---- | -------------------------------------- | 2101| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2102| callback | AsyncCallback\<[LockStatusResponse](#lockstatusresponse7)\> | Yes | Callback used to return the result. | 2103| newPin | string | Yes | New PIN. | 2104| oldPin | string | Yes | Old PIN. | 2105 2106**Error codes** 2107 2108For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2109 2110| ID| Error Message | 2111| -------- | -------------------------------------------- | 2112| 201 | Permission denied. | 2113| 202 | Non-system applications use system APIs. | 2114| 401 | Parameter error. | 2115| 8300001 | Invalid parameter value. | 2116| 8300002 | Operation failed. Cannot connect to service. | 2117| 8300003 | System internal error. | 2118| 8300004 | Do not have sim card. | 2119| 8300999 | Unknown error code. | 2120| 8301002 | SIM card operation error. | 2121 2122**Example** 2123 2124```ts 2125import { BusinessError } from '@ohos.base'; 2126import sim from '@ohos.telephony.sim'; 2127 2128sim.alterPin(0, "1234", "0000", (err: BusinessError, data: sim.LockStatusResponse) => { 2129 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 2130}); 2131``` 2132 2133 2134## sim.alterPin<sup>7+</sup> 2135 2136alterPin\(slotId: number, newPin: string, oldPin: string\): Promise\<LockStatusResponse\> 2137 2138Changes the PIN of the SIM card in the specified slot. This API uses a promise to return the result. 2139 2140**System API**: This is a system API. 2141 2142**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2143 2144**System capability**: SystemCapability.Telephony.CoreService 2145 2146**Parameters** 2147 2148| Name| Type | Mandatory| Description | 2149| ------ | ------ | ---- | -------------------------------------- | 2150| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2151| newPin | string | Yes | New PIN. | 2152| oldPin | string | Yes | Old PIN. | 2153 2154**Return value** 2155 2156| Type | Description | 2157| ---------------------------------------------------- | --------------------------------------------- | 2158| Promise<[LockStatusResponse](#lockstatusresponse7)\> | Promise used to return the result.| 2159 2160**Error codes** 2161 2162For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2163 2164| ID| Error Message | 2165| -------- | -------------------------------------------- | 2166| 201 | Permission denied. | 2167| 202 | Non-system applications use system APIs. | 2168| 401 | Parameter error. | 2169| 8300001 | Invalid parameter value. | 2170| 8300002 | Operation failed. Cannot connect to service. | 2171| 8300003 | System internal error. | 2172| 8300004 | Do not have sim card. | 2173| 8300999 | Unknown error code. | 2174| 8301002 | SIM card operation error. | 2175 2176**Example** 2177 2178```ts 2179import { BusinessError } from '@ohos.base'; 2180import sim from '@ohos.telephony.sim'; 2181 2182sim.alterPin(0, "1234", "0000").then((data: sim.LockStatusResponse) => { 2183 console.log(`alterPin success, promise: data->${JSON.stringify(data)}`); 2184}).catch((err: BusinessError) => { 2185 console.error(`alterPin failed, promise: err->${JSON.stringify(err)}`); 2186}); 2187``` 2188 2189## sim.alterPin2<sup>8+</sup> 2190 2191alterPin2\(slotId: number, newPin2: string, oldPin2: string, callback: AsyncCallback\<LockStatusResponse\>\): void 2192 2193Changes PIN 2 of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 2194 2195**System API**: This is a system API. 2196 2197**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2198 2199**System capability**: SystemCapability.Telephony.CoreService 2200 2201**Parameters** 2202 2203| Name | Type | Mandatory| Description | 2204| -------- | ----------------------------------------------------------- | ---- | -------------------------------------- | 2205| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2206| callback | AsyncCallback\<[LockStatusResponse](#lockstatusresponse7)\> | Yes | Callback used to return the result. | 2207| newPin2 | string | Yes | New PIN. | 2208| oldPin2 | string | Yes | Old PIN. | 2209 2210**Error codes** 2211 2212For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2213 2214| ID| Error Message | 2215| -------- | -------------------------------------------- | 2216| 201 | Permission denied. | 2217| 202 | Non-system applications use system APIs. | 2218| 401 | Parameter error. | 2219| 8300001 | Invalid parameter value. | 2220| 8300002 | Operation failed. Cannot connect to service. | 2221| 8300003 | System internal error. | 2222| 8300004 | Do not have sim card. | 2223| 8300999 | Unknown error code. | 2224| 8301002 | SIM card operation error. | 2225 2226**Example** 2227 2228```ts 2229import { BusinessError } from '@ohos.base'; 2230import sim from '@ohos.telephony.sim'; 2231 2232sim.alterPin2(0, "1234", "0000", (err: BusinessError, data: sim.LockStatusResponse) => { 2233 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 2234}); 2235``` 2236 2237 2238## sim.alterPin2<sup>8+</sup> 2239 2240alterPin2\(slotId: number, newPin2: string, oldPin2: string\): Promise\<LockStatusResponse\> 2241 2242Changes PIN 2 of the SIM card in the specified slot. This API uses a promise to return the result. 2243 2244**System API**: This is a system API. 2245 2246**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2247 2248**System capability**: SystemCapability.Telephony.CoreService 2249 2250**Parameters** 2251 2252| Name | Type | Mandatory| Description | 2253| ------- | ------ | ---- | -------------------------------------- | 2254| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2255| newPin2 | string | Yes | New PIN. | 2256| oldPin2 | string | Yes | Old PIN. | 2257 2258**Return value** 2259 2260| Type | Description | 2261| ---------------------------------------------------- | --------------------------------------------- | 2262| Promise<[LockStatusResponse](#lockstatusresponse7)\> | Promise used to return the result.| 2263 2264**Error codes** 2265 2266For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2267 2268| ID| Error Message | 2269| -------- | -------------------------------------------- | 2270| 201 | Permission denied. | 2271| 202 | Non-system applications use system APIs. | 2272| 401 | Parameter error. | 2273| 8300001 | Invalid parameter value. | 2274| 8300002 | Operation failed. Cannot connect to service. | 2275| 8300003 | System internal error. | 2276| 8300004 | Do not have sim card. | 2277| 8300999 | Unknown error code. | 2278| 8301002 | SIM card operation error. | 2279 2280**Example** 2281 2282```ts 2283import { BusinessError } from '@ohos.base'; 2284import sim from '@ohos.telephony.sim'; 2285 2286sim.alterPin2(0, "1234", "0000").then((data: sim.LockStatusResponse) => { 2287 console.log(`alterPin2 success, promise: data->${JSON.stringify(data)}`); 2288}).catch((err: BusinessError) => { 2289 console.error(`alterPin2 failed, promise: err->${JSON.stringify(err)}`); 2290}); 2291``` 2292 2293## sim.unlockPin<sup>7+</sup> 2294 2295unlockPin\(slotId: number, pin: string, callback: AsyncCallback\<LockStatusResponse\>\): void 2296 2297Unlocks the PIN of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 2298 2299**System API**: This is a system API. 2300 2301**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2302 2303**System capability**: SystemCapability.Telephony.CoreService 2304 2305**Parameters** 2306 2307| Name | Type | Mandatory| Description | 2308| -------- | ------------------------------------------------------------ | ---- | -------------------------------------- | 2309| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2310| pin | string | Yes | PIN of the SIM card. | 2311| callback | AsyncCallback<[LockStatusResponse](#lockstatusresponse7)> | Yes | Callback used to return the result. | 2312 2313**Error codes** 2314 2315For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2316 2317| ID| Error Message | 2318| -------- | -------------------------------------------- | 2319| 201 | Permission denied. | 2320| 202 | Non-system applications use system APIs. | 2321| 401 | Parameter error. | 2322| 8300001 | Invalid parameter value. | 2323| 8300002 | Operation failed. Cannot connect to service. | 2324| 8300003 | System internal error. | 2325| 8300004 | Do not have sim card. | 2326| 8300999 | Unknown error code. | 2327| 8301002 | SIM card operation error. | 2328 2329**Example** 2330 2331```ts 2332import { BusinessError } from '@ohos.base'; 2333import sim from '@ohos.telephony.sim'; 2334 2335let pin: string = '1234'; 2336sim.unlockPin(0, pin, (err: BusinessError, data: sim.LockStatusResponse) => { 2337 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 2338}); 2339``` 2340 2341 2342## sim.unlockPin<sup>7+</sup> 2343 2344unlockPin\(slotId: number, pin: string\): Promise\<LockStatusResponse\> 2345 2346Unlocks the PIN of the SIM card in the specified slot. This API uses a promise to return the result. 2347 2348**System API**: This is a system API. 2349 2350**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2351 2352**System capability**: SystemCapability.Telephony.CoreService 2353 2354**Parameters** 2355 2356| Name| Type | Mandatory| Description | 2357| ------ | ------ | ---- | -------------------------------------- | 2358| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2359| pin | string | Yes | PIN of the SIM card. | 2360 2361**Return value** 2362 2363| Type | Description | 2364| ---------------------------------------------------- | -------------------------------------------------- | 2365| Promise\<[LockStatusResponse](#lockstatusresponse7)\> | Promise used to return the result.| 2366 2367**Error codes** 2368 2369For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2370 2371| ID| Error Message | 2372| -------- | -------------------------------------------- | 2373| 201 | Permission denied. | 2374| 202 | Non-system applications use system APIs. | 2375| 401 | Parameter error. | 2376| 8300001 | Invalid parameter value. | 2377| 8300002 | Operation failed. Cannot connect to service. | 2378| 8300003 | System internal error. | 2379| 8300004 | Do not have sim card. | 2380| 8300999 | Unknown error code. | 2381| 8301002 | SIM card operation error. | 2382 2383**Example** 2384 2385```ts 2386import { BusinessError } from '@ohos.base'; 2387import sim from '@ohos.telephony.sim'; 2388 2389let pin: string = '1234'; 2390sim.unlockPin(0, pin).then((data: sim.LockStatusResponse) => { 2391 console.log(`unlockPin success, promise: data->${JSON.stringify(data)}`); 2392}).catch((err: BusinessError) => { 2393 console.error(`unlockPin failed, promise: err->${JSON.stringify(err)}`); 2394}); 2395``` 2396 2397## sim.unlockPuk<sup>7+</sup> 2398 2399unlockPuk\(slotId: number, newPin: string, puk: string, callback: AsyncCallback\<LockStatusResponse\>\): void 2400 2401Unlocks the PUK of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 2402 2403**System API**: This is a system API. 2404 2405**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2406 2407**System capability**: SystemCapability.Telephony.CoreService 2408 2409**Parameters** 2410 2411| Name | Type | Mandatory| Description | 2412| -------- | ------------------------------------------------------------ | ---- | -------------------------------------- | 2413| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2414| newPin | string | Yes | New PIN. | 2415| puk | string | Yes | PUK of the SIM card. | 2416| callback | AsyncCallback<[LockStatusResponse](#lockstatusresponse7)> | Yes | Callback used to return the result. | 2417 2418**Error codes** 2419 2420For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2421 2422| ID| Error Message | 2423| -------- | -------------------------------------------- | 2424| 201 | Permission denied. | 2425| 202 | Non-system applications use system APIs. | 2426| 401 | Parameter error. | 2427| 8300001 | Invalid parameter value. | 2428| 8300002 | Operation failed. Cannot connect to service. | 2429| 8300003 | System internal error. | 2430| 8300004 | Do not have sim card. | 2431| 8300999 | Unknown error code. | 2432| 8301002 | SIM card operation error. | 2433 2434**Example** 2435 2436```ts 2437import { BusinessError } from '@ohos.base'; 2438import sim from '@ohos.telephony.sim'; 2439 2440let puk: string = '1xxxxxxx'; 2441let newPin: string = '1235'; 2442sim.unlockPuk(0, newPin, puk, (err: BusinessError, data: sim.LockStatusResponse) => { 2443 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 2444}); 2445``` 2446 2447 2448## sim.unlockPuk<sup>7+</sup> 2449 2450unlockPuk\(slotId: number, newPin: string, puk: string\): Promise\<LockStatusResponse\> 2451 2452Unlocks the PUK of the SIM card in the specified slot. This API uses a promise to return the result. 2453 2454**System API**: This is a system API. 2455 2456**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2457 2458**System capability**: SystemCapability.Telephony.CoreService 2459 2460**Parameters** 2461 2462| Name| Type | Mandatory| Description | 2463| ------ | ------ | ---- | -------------------------------------- | 2464| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2465| newPin | string | Yes | New PIN. | 2466| puk | string | Yes | PUK of the SIM card. | 2467 2468**Return value** 2469 2470| Type | Description | 2471| ---------------------------------------------------- | -------------------------------------------------- | 2472| Promise\<[LockStatusResponse](#lockstatusresponse7)\> | Promise used to return the result.| 2473 2474**Error codes** 2475 2476For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2477 2478| ID| Error Message | 2479| -------- | -------------------------------------------- | 2480| 201 | Permission denied. | 2481| 202 | Non-system applications use system APIs. | 2482| 401 | Parameter error. | 2483| 8300001 | Invalid parameter value. | 2484| 8300002 | Operation failed. Cannot connect to service. | 2485| 8300003 | System internal error. | 2486| 8300004 | Do not have sim card. | 2487| 8300999 | Unknown error code. | 2488| 8301002 | SIM card operation error. | 2489 2490**Example** 2491 2492```ts 2493import { BusinessError } from '@ohos.base'; 2494import sim from '@ohos.telephony.sim'; 2495 2496let puk: string = '1xxxxxxx'; 2497let newPin: string = '1235'; 2498sim.unlockPuk(0, newPin, puk).then((data: sim.LockStatusResponse) => { 2499 console.log(`unlockPuk success, promise: data->${JSON.stringify(data)}`); 2500}).catch((err: BusinessError) => { 2501 console.error(`unlockPuk failed, promise: err->${JSON.stringify(err)}`); 2502}); 2503``` 2504 2505## sim.unlockPin2<sup>8+</sup> 2506 2507unlockPin2\(slotId: number, pin2: string, callback: AsyncCallback\<LockStatusResponse\>\): void 2508 2509Unlocks the PIN of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 2510 2511**System API**: This is a system API. 2512 2513**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2514 2515**System capability**: SystemCapability.Telephony.CoreService 2516 2517**Parameters** 2518 2519| Name | Type | Mandatory| Description | 2520| -------- | ------------------------------------------------------------ | ---- | -------------------------------------- | 2521| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2522| pin2 | string | Yes | PIN of the SIM card. | 2523| callback | AsyncCallback<[LockStatusResponse](#lockstatusresponse7)> | Yes | Callback used to return the result. | 2524 2525**Error codes** 2526 2527For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2528 2529| ID| Error Message | 2530| -------- | -------------------------------------------- | 2531| 201 | Permission denied. | 2532| 202 | Non-system applications use system APIs. | 2533| 401 | Parameter error. | 2534| 8300001 | Invalid parameter value. | 2535| 8300002 | Operation failed. Cannot connect to service. | 2536| 8300003 | System internal error. | 2537| 8300004 | Do not have sim card. | 2538| 8300999 | Unknown error code. | 2539| 8301002 | SIM card operation error. | 2540 2541**Example** 2542 2543```ts 2544import { BusinessError } from '@ohos.base'; 2545import sim from '@ohos.telephony.sim'; 2546 2547let pin2: string = '1234'; 2548sim.unlockPin2(0, pin2, (err: BusinessError, data: sim.LockStatusResponse) => { 2549 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 2550}); 2551``` 2552 2553 2554## sim.unlockPin2<sup>8+</sup> 2555 2556unlockPin2\(slotId: number, pin2: string\): Promise\<LockStatusResponse\> 2557 2558Unlocks the PIN of the SIM card in the specified slot. This API uses a promise to return the result. 2559 2560**System API**: This is a system API. 2561 2562**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2563 2564**System capability**: SystemCapability.Telephony.CoreService 2565 2566**Parameters** 2567 2568| Name| Type | Mandatory| Description | 2569| ------ | ------ | ---- | -------------------------------------- | 2570| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2571| pin2 | string | Yes | PIN of the SIM card. | 2572 2573**Return value** 2574 2575| Type | Description | 2576| ----------------------------------------------------- | -------------------------------------------------- | 2577| Promise\<[LockStatusResponse](#lockstatusresponse7)\> | Promise used to return the result.| 2578 2579**Error codes** 2580 2581For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2582 2583| ID| Error Message | 2584| -------- | -------------------------------------------- | 2585| 201 | Permission denied. | 2586| 202 | Non-system applications use system APIs. | 2587| 401 | Parameter error. | 2588| 8300001 | Invalid parameter value. | 2589| 8300002 | Operation failed. Cannot connect to service. | 2590| 8300003 | System internal error. | 2591| 8300004 | Do not have sim card. | 2592| 8300999 | Unknown error code. | 2593| 8301002 | SIM card operation error. | 2594 2595**Example** 2596 2597```ts 2598import { BusinessError } from '@ohos.base'; 2599import sim from '@ohos.telephony.sim'; 2600 2601let pin2: string = '1234'; 2602sim.unlockPin2(0, pin2).then((data: sim.LockStatusResponse) => { 2603 console.log(`unlockPin2 success, promise: data->${JSON.stringify(data)}`); 2604}).catch((err: BusinessError) => { 2605 console.error(`unlockPin2 failed, promise: err->${JSON.stringify(err)}`); 2606}); 2607``` 2608 2609## sim.unlockPuk2<sup>8+</sup> 2610 2611unlockPuk2\(slotId: number, newPin2: string, puk2: string, callback: AsyncCallback\<LockStatusResponse\>\): void 2612 2613Unlocks the PUK of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 2614 2615**System API**: This is a system API. 2616 2617**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2618 2619**System capability**: SystemCapability.Telephony.CoreService 2620 2621**Parameters** 2622 2623| Name | Type | Mandatory| Description | 2624| -------- | ------------------------------------------------------------ | ---- | -------------------------------------- | 2625| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2626| newPin2 | string | Yes | New PIN 2. | 2627| puk2 | string | Yes | PUK of the SIM card. | 2628| callback | AsyncCallback<[LockStatusResponse](#lockstatusresponse7)> | Yes | Callback used to return the result. | 2629 2630**Error codes** 2631 2632For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2633 2634| ID| Error Message | 2635| -------- | -------------------------------------------- | 2636| 201 | Permission denied. | 2637| 202 | Non-system applications use system APIs. | 2638| 401 | Parameter error. | 2639| 8300001 | Invalid parameter value. | 2640| 8300002 | Operation failed. Cannot connect to service. | 2641| 8300003 | System internal error. | 2642| 8300004 | Do not have sim card. | 2643| 8300999 | Unknown error code. | 2644| 8301002 | SIM card operation error. | 2645 2646**Example** 2647 2648```ts 2649import { BusinessError } from '@ohos.base'; 2650import sim from '@ohos.telephony.sim'; 2651 2652let puk2: string = '1xxxxxxx'; 2653let newPin2: string = '1235'; 2654sim.unlockPuk2(0, newPin2, puk2, (err: BusinessError, data: sim.LockStatusResponse) => { 2655 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 2656}); 2657``` 2658 2659 2660## sim.unlockPuk2<sup>8+</sup> 2661 2662unlockPuk2\(slotId: number, newPin2: string, puk2: string\): Promise\<LockStatusResponse\> 2663 2664Unlocks the PUK of the SIM card in the specified slot. This API uses a promise to return the result. 2665 2666**System API**: This is a system API. 2667 2668**Required permission**: ohos.permission.SET_TELEPHONY_STATE 2669 2670**System capability**: SystemCapability.Telephony.CoreService 2671 2672**Parameters** 2673 2674| Name | Type | Mandatory| Description | 2675| ------- | ------ | ---- | -------------------------------------- | 2676| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2677| newPin2 | string | Yes | New PIN 2. | 2678| puk2 | string | Yes | PUK of the SIM card. | 2679 2680**Return value** 2681 2682| Type | Description | 2683| ---------------------------------------------------- | -------------------------------------------------- | 2684| Promise\<[LockStatusResponse](#lockstatusresponse7)\> | Promise used to return the result.| 2685 2686**Error codes** 2687 2688For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2689 2690| ID| Error Message | 2691| -------- | -------------------------------------------- | 2692| 201 | Permission denied. | 2693| 202 | Non-system applications use system APIs. | 2694| 401 | Parameter error. | 2695| 8300001 | Invalid parameter value. | 2696| 8300002 | Operation failed. Cannot connect to service. | 2697| 8300003 | System internal error. | 2698| 8300004 | Do not have sim card. | 2699| 8300999 | Unknown error code. | 2700| 8301002 | SIM card operation error. | 2701 2702**Example** 2703 2704```ts 2705import { BusinessError } from '@ohos.base'; 2706import sim from '@ohos.telephony.sim'; 2707 2708let puk2: string = '1xxxxxxx'; 2709let newPin2: string = '1235'; 2710sim.unlockPuk2(0, newPin2, puk2).then((data: sim.LockStatusResponse) => { 2711 console.log(`unlockPuk2 success, promise: data->${JSON.stringify(data)}`); 2712}).catch((err: BusinessError) => { 2713 console.error(`unlockPuk2 failed, promise: err->${JSON.stringify(err)}`); 2714}); 2715``` 2716 2717## sim.getMaxSimCount<sup>7+</sup> 2718 2719getMaxSimCount\(\): number 2720 2721Obtains the number of card slots. 2722 2723**System capability**: SystemCapability.Telephony.CoreService 2724 2725**Return value** 2726 2727| Type | Description | 2728| ----------------- | ------------------------------------------------------------ | 2729| number | Number of card slots.| 2730 2731**Example** 2732 2733```ts 2734import sim from '@ohos.telephony.sim'; 2735 2736console.log("Result: "+ sim.getMaxSimCount()); 2737``` 2738 2739## sim.getSimIccId<sup>7+</sup> 2740 2741getSimIccId\(slotId: number, callback: AsyncCallback\<string\>\): void 2742 2743Obtains the ICCID of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 2744 2745**System API**: This is a system API. 2746 2747**Required permission**: ohos.permission.GET_TELEPHONY_STATE 2748 2749**System capability**: SystemCapability.Telephony.CoreService 2750 2751**Parameters** 2752 2753| Name | Type | Mandatory| Description | 2754| -------- | ---------------------- | ---- | -------------------------------------- | 2755| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2756| callback | AsyncCallback<string\> | Yes | Callback used to return the result. | 2757 2758**Error codes** 2759 2760For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2761 2762| ID| Error Message | 2763| -------- | -------------------------------------------- | 2764| 201 | Permission denied. | 2765| 202 | Non-system applications use system APIs. | 2766| 401 | Parameter error. | 2767| 8300001 | Invalid parameter value. | 2768| 8300002 | Operation failed. Cannot connect to service. | 2769| 8300003 | System internal error. | 2770| 8300004 | Do not have sim card. | 2771| 8300999 | Unknown error code. | 2772 2773**Example** 2774 2775```ts 2776import { BusinessError } from '@ohos.base'; 2777import sim from '@ohos.telephony.sim'; 2778 2779sim.getSimIccId(0, (err: BusinessError, data: string) => { 2780 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 2781}); 2782``` 2783 2784 2785## sim.getSimIccId<sup>7+</sup> 2786 2787getSimIccId\(slotId: number\): Promise\<string\> 2788 2789Obtains the ICCID of the SIM card in the specified slot. This API uses a promise to return the result. 2790 2791**System API**: This is a system API. 2792 2793**Required permission**: ohos.permission.GET_TELEPHONY_STATE 2794 2795**System capability**: SystemCapability.Telephony.CoreService 2796 2797**Parameters** 2798 2799| Name| Type | Mandatory| Description | 2800| ------ | ------ | ---- | -------------------------------------- | 2801| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2802 2803**Return value** 2804 2805| Type | Description | 2806| ---------------- | ------------------------------------------- | 2807| Promise<string\> | Promise used to return the result.| 2808 2809**Error codes** 2810 2811For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2812 2813| ID| Error Message | 2814| -------- | -------------------------------------------- | 2815| 201 | Permission denied. | 2816| 202 | Non-system applications use system APIs. | 2817| 401 | Parameter error. | 2818| 8300001 | Invalid parameter value. | 2819| 8300002 | Operation failed. Cannot connect to service. | 2820| 8300003 | System internal error. | 2821| 8300004 | Do not have sim card. | 2822| 8300999 | Unknown error code. | 2823 2824**Example** 2825 2826```ts 2827import { BusinessError } from '@ohos.base'; 2828import sim from '@ohos.telephony.sim'; 2829 2830sim.getSimIccId(0).then((data:string) => { 2831 console.log(`getSimIccId success, promise: data->${JSON.stringify(data)}`); 2832}).catch((err: BusinessError) => { 2833 console.error(`getSimIccId failed, promise: err->${JSON.stringify(err)}`); 2834}); 2835``` 2836 2837## sim.getVoiceMailIdentifier<sup>8+</sup> 2838 2839getVoiceMailIdentifier\(slotId: number, callback: AsyncCallback\<string\>\): void 2840 2841Obtains the voice mailbox alpha identifier of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 2842 2843**System API**: This is a system API. 2844 2845**Required permission**: ohos.permission.GET_TELEPHONY_STATE 2846 2847**System capability**: SystemCapability.Telephony.CoreService 2848 2849**Parameters** 2850 2851| Name | Type | Mandatory| Description | 2852| -------- | ---------------------- | ---- | -------------------------------------- | 2853| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2854| callback | AsyncCallback<string\> | Yes | Callback used to return the result. | 2855 2856**Error codes** 2857 2858For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2859 2860| ID| Error Message | 2861| -------- | -------------------------------------------- | 2862| 201 | Permission denied. | 2863| 202 | Non-system applications use system APIs. | 2864| 401 | Parameter error. | 2865| 8300001 | Invalid parameter value. | 2866| 8300002 | Operation failed. Cannot connect to service. | 2867| 8300003 | System internal error. | 2868| 8300004 | Do not have sim card. | 2869| 8300999 | Unknown error code. | 2870 2871**Example** 2872 2873```ts 2874import { BusinessError } from '@ohos.base'; 2875import sim from '@ohos.telephony.sim'; 2876 2877sim.getVoiceMailIdentifier(0, (err: BusinessError, data: string) => { 2878 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 2879}); 2880``` 2881 2882 2883## sim.getVoiceMailIdentifier<sup>8+</sup> 2884 2885getVoiceMailIdentifier\(slotId: number\): Promise\<string\> 2886 2887Obtains the voice mailbox alpha identifier of the SIM card in the specified slot. This API uses a promise to return the result. 2888 2889**System API**: This is a system API. 2890 2891**Required permission**: ohos.permission.GET_TELEPHONY_STATE 2892 2893**System capability**: SystemCapability.Telephony.CoreService 2894 2895**Parameters** 2896 2897| Name| Type | Mandatory| Description | 2898| ------ | ------ | ---- | -------------------------------------- | 2899| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2900 2901**Return value** 2902 2903| Type | Description | 2904| ---------------- | ------------------------------------------------- | 2905| Promise<string\> | Promise used to return the result.| 2906 2907**Error codes** 2908 2909For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2910 2911| ID| Error Message | 2912| -------- | -------------------------------------------- | 2913| 201 | Permission denied. | 2914| 202 | Non-system applications use system APIs. | 2915| 401 | Parameter error. | 2916| 8300001 | Invalid parameter value. | 2917| 8300002 | Operation failed. Cannot connect to service. | 2918| 8300003 | System internal error. | 2919| 8300004 | Do not have sim card. | 2920| 8300999 | Unknown error code. | 2921 2922**Example** 2923 2924```ts 2925import { BusinessError } from '@ohos.base'; 2926import sim from '@ohos.telephony.sim'; 2927 2928sim.getVoiceMailIdentifier(0).then((data: string) => { 2929 console.log(`getVoiceMailIdentifier success, promise: data->${JSON.stringify(data)}`); 2930}).catch((err: BusinessError) => { 2931 console.error(`getVoiceMailIdentifier failed, promise: err->${JSON.stringify(err)}`); 2932}); 2933``` 2934 2935## sim.getVoiceMailNumber<sup>8+</sup> 2936 2937getVoiceMailNumber\(slotId: number, callback: AsyncCallback\<string\>): void 2938 2939Obtains the voice mailbox number of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 2940 2941**System API**: This is a system API. 2942 2943**Required permission**: ohos.permission.GET_TELEPHONY_STATE 2944 2945**System capability**: SystemCapability.Telephony.CoreService 2946 2947**Parameters** 2948 2949| Name | Type | Mandatory| Description | 2950| -------- | ---------------------- | ---- | -------------------------------------- | 2951| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2952| callback | AsyncCallback<string\> | Yes | Callback used to return the result. | 2953 2954**Error codes** 2955 2956For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 2957 2958| ID| Error Message | 2959| -------- | -------------------------------------------- | 2960| 201 | Permission denied. | 2961| 202 | Non-system applications use system APIs. | 2962| 401 | Parameter error. | 2963| 8300001 | Invalid parameter value. | 2964| 8300002 | Operation failed. Cannot connect to service. | 2965| 8300003 | System internal error. | 2966| 8300004 | Do not have sim card. | 2967| 8300999 | Unknown error code. | 2968 2969**Example** 2970 2971```ts 2972import { BusinessError } from '@ohos.base'; 2973import sim from '@ohos.telephony.sim'; 2974 2975sim.getVoiceMailNumber(0, (err: BusinessError, data: string) => { 2976 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 2977}); 2978``` 2979 2980 2981## sim.getVoiceMailNumber<sup>8+</sup> 2982 2983getVoiceMailNumber\(slotId: number\): Promise\<string\> 2984 2985Obtains the voice mailbox number of the SIM card in the specified slot. This API uses a promise to return the result. 2986 2987**System API**: This is a system API. 2988 2989**Required permission**: ohos.permission.GET_TELEPHONY_STATE 2990 2991**System capability**: SystemCapability.Telephony.CoreService 2992 2993**Parameters** 2994 2995| Name| Type | Mandatory| Description | 2996| ------ | ------ | ---- | -------------------------------------- | 2997| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 2998 2999**Return value** 3000 3001| Type | Description | 3002| ---------------- | ------------------------------------------------ | 3003| Promise<string\> | Promise used to return the result.| 3004 3005**Error codes** 3006 3007For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3008 3009| ID| Error Message | 3010| -------- | -------------------------------------------- | 3011| 201 | Permission denied. | 3012| 202 | Non-system applications use system APIs. | 3013| 401 | Parameter error. | 3014| 8300001 | Invalid parameter value. | 3015| 8300002 | Operation failed. Cannot connect to service. | 3016| 8300003 | System internal error. | 3017| 8300004 | Do not have sim card. | 3018| 8300999 | Unknown error code. | 3019 3020**Example** 3021 3022```ts 3023import { BusinessError } from '@ohos.base'; 3024import sim from '@ohos.telephony.sim'; 3025 3026sim.getVoiceMailNumber(0).then((data: string) => { 3027 console.log(`getVoiceMailNumber success, promise: data->${JSON.stringify(data)}`); 3028}).catch((err: BusinessError) => { 3029 console.error(`getVoiceMailNumber failed, promise: err->${JSON.stringify(err)}`); 3030}); 3031``` 3032 3033 3034## sim.setVoiceMailInfo<sup>8+</sup> 3035 3036setVoiceMailInfo\(slotId: number, mailName: string, mailNumber: string, callback: AsyncCallback\<void\>\): void 3037 3038Sets voice mailbox information for the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 3039 3040**System API**: This is a system API. 3041 3042**Required permission**: ohos.permission.SET_TELEPHONY_STATE 3043 3044**System capability**: SystemCapability.Telephony.CoreService 3045 3046**Parameters** 3047 3048| Name | Type | Mandatory| Description | 3049| ---------- | -------------------- | ---- | -------------------------------------- | 3050| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 3051| mailName | string | Yes | Voice mailbox name. | 3052| mailNumber | string | Yes | Voice mailbox number. | 3053| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 3054 3055**Error codes** 3056 3057For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3058 3059| ID| Error Message | 3060| -------- | -------------------------------------------- | 3061| 201 | Permission denied. | 3062| 202 | Non-system applications use system APIs. | 3063| 401 | Parameter error. | 3064| 8300001 | Invalid parameter value. | 3065| 8300002 | Operation failed. Cannot connect to service. | 3066| 8300003 | System internal error. | 3067| 8300004 | Do not have sim card. | 3068| 8300999 | Unknown error code. | 3069| 8301002 | SIM card operation error. | 3070 3071**Example** 3072 3073```ts 3074import { BusinessError } from '@ohos.base'; 3075import sim from '@ohos.telephony.sim'; 3076 3077sim.setVoiceMailInfo(0, "mail", "xxx@xxx.com", (err: BusinessError) => { 3078 console.log(`callback: err->${JSON.stringify(err)}`); 3079}); 3080``` 3081 3082 3083## sim.setVoiceMailInfo<sup>8+</sup> 3084 3085setVoiceMailInfo\(slotId: number, mailName: string, mailNumber: string\): Promise\<void\> 3086 3087Sets voice mailbox information for the SIM card in the specified slot. This API uses a promise to return the result. 3088 3089**System API**: This is a system API. 3090 3091**Required permission**: ohos.permission.SET_TELEPHONY_STATE 3092 3093**System capability**: SystemCapability.Telephony.CoreService 3094 3095**Parameters** 3096 3097| Name | Type | Mandatory| Description | 3098| ---------- | ------ | ---- | -------------------------------------- | 3099| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 3100| mailName | string | Yes | Voice mailbox name. | 3101| mailNumber | string | Yes | Voice mailbox number. | 3102 3103**Return value** 3104 3105| Type | Description | 3106| -------------- | ----------------------- | 3107| Promise<void\> | Promise used to return the result.| 3108 3109**Error codes** 3110 3111For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3112 3113| ID| Error Message | 3114| -------- | -------------------------------------------- | 3115| 201 | Permission denied. | 3116| 202 | Non-system applications use system APIs. | 3117| 401 | Parameter error. | 3118| 8300001 | Invalid parameter value. | 3119| 8300002 | Operation failed. Cannot connect to service. | 3120| 8300003 | System internal error. | 3121| 8300004 | Do not have sim card. | 3122| 8300999 | Unknown error code. | 3123| 8301002 | SIM card operation error. | 3124 3125**Example** 3126 3127```ts 3128import { BusinessError } from '@ohos.base'; 3129import sim from '@ohos.telephony.sim'; 3130 3131sim.setVoiceMailInfo(0, "mail", "xxx@xxx.com").then(() => { 3132 console.log(`setVoiceMailInfo success.`); 3133}).catch((err: BusinessError) => { 3134 console.error(`setVoiceMailInfo failed, promise: err->${JSON.stringify(err)}`); 3135}); 3136``` 3137 3138## sim.getSimTelephoneNumber<sup>8+</sup> 3139 3140getSimTelephoneNumber\(slotId: number, callback: AsyncCallback\<string\>\): void 3141 3142Obtains the MSISDN of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 3143 3144**System API**: This is a system API. 3145 3146**Required permission**: ohos.permission.GET_PHONE_NUMBERS 3147 3148**System capability**: SystemCapability.Telephony.CoreService 3149 3150**Parameters** 3151 3152| Name | Type | Mandatory| Description | 3153| -------- | ---------------------- | ---- | -------------------------------------- | 3154| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 3155| callback | AsyncCallback<string\> | Yes | Callback used to return the result. | 3156 3157**Error codes** 3158 3159For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3160 3161| ID| Error Message | 3162| -------- | -------------------------------------------- | 3163| 201 | Permission denied. | 3164| 202 | Non-system applications use system APIs. | 3165| 401 | Parameter error. | 3166| 8300001 | Invalid parameter value. | 3167| 8300002 | Operation failed. Cannot connect to service. | 3168| 8300003 | System internal error. | 3169| 8300004 | Do not have sim card. | 3170| 8300999 | Unknown error code. | 3171 3172**Example** 3173 3174```ts 3175import { BusinessError } from '@ohos.base'; 3176import sim from '@ohos.telephony.sim'; 3177 3178sim.getSimTelephoneNumber(0, (err: BusinessError, data: string) => { 3179 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 3180}); 3181``` 3182 3183 3184## sim.getSimTelephoneNumber<sup>8+</sup> 3185 3186getSimTelephoneNumber\(slotId: number\): Promise\<string\> 3187 3188Obtains the MSISDN of the SIM card in the specified slot. This API uses a promise to return the result. 3189 3190**System API**: This is a system API. 3191 3192**Required permission**: ohos.permission.GET_PHONE_NUMBERS 3193 3194**System capability**: SystemCapability.Telephony.CoreService 3195 3196**Parameters** 3197 3198| Name| Type | Mandatory| Description | 3199| ------ | ------ | ---- | -------------------------------------- | 3200| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 3201 3202**Return value** 3203 3204| Type | Description | 3205| ---------------- | -------------------------------------------- | 3206| Promise<string\> | Promise used to return the result.| 3207 3208**Error codes** 3209 3210For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3211 3212| ID| Error Message | 3213| -------- | -------------------------------------------- | 3214| 201 | Permission denied. | 3215| 202 | Non-system applications use system APIs. | 3216| 401 | Parameter error. | 3217| 8300001 | Invalid parameter value. | 3218| 8300002 | Operation failed. Cannot connect to service. | 3219| 8300003 | System internal error. | 3220| 8300004 | Do not have sim card. | 3221| 8300999 | Unknown error code. | 3222 3223**Example** 3224 3225```ts 3226import { BusinessError } from '@ohos.base'; 3227import sim from '@ohos.telephony.sim'; 3228 3229sim.getSimTelephoneNumber(0).then((data: string) => { 3230 console.log(`getSimTelephoneNumber success, promise: data->${JSON.stringify(data)}`); 3231}).catch((err: BusinessError) => { 3232 console.error(`getSimTelephoneNumber failed, promise: err->${JSON.stringify(err)}`); 3233}); 3234``` 3235 3236## sim.getSimGid1<sup>7+</sup> 3237 3238getSimGid1\(slotId: number, callback: AsyncCallback\<string\>\): void 3239 3240Obtains the group identifier level 1 (GID1) of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 3241 3242**System API**: This is a system API. 3243 3244**Required permission**: ohos.permission.GET_TELEPHONY_STATE 3245 3246**System capability**: SystemCapability.Telephony.CoreService 3247 3248**Parameters** 3249 3250| Name | Type | Mandatory| Description | 3251| -------- | ----------------------- | ---- | -------------------------------------- | 3252| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 3253| callback | AsyncCallback\<string\> | Yes | Callback used to return the result. | 3254 3255**Error codes** 3256 3257For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3258 3259| ID| Error Message | 3260| -------- | -------------------------------------------- | 3261| 201 | Permission denied. | 3262| 202 | Non-system applications use system APIs. | 3263| 401 | Parameter error. | 3264| 8300001 | Invalid parameter value. | 3265| 8300002 | Operation failed. Cannot connect to service. | 3266| 8300003 | System internal error. | 3267| 8300004 | Do not have sim card. | 3268| 8300999 | Unknown error code. | 3269 3270**Example** 3271 3272```ts 3273import { BusinessError } from '@ohos.base'; 3274import sim from '@ohos.telephony.sim'; 3275 3276sim.getSimGid1(0, (err: BusinessError, data: string) => { 3277 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 3278}); 3279``` 3280 3281 3282## sim.getSimGid1<sup>7+</sup> 3283 3284getSimGid1\(slotId: number\): Promise\<string\> 3285 3286Obtains the GID1 of the SIM card in the specified slot. This API uses a promise to return the result. 3287 3288**System API**: This is a system API. 3289 3290**Required permission**: ohos.permission.GET_TELEPHONY_STATE 3291 3292**System capability**: SystemCapability.Telephony.CoreService 3293 3294**Parameters** 3295 3296| Name| Type | Mandatory| Description | 3297| ------ | ------ | ---- | -------------------------------------- | 3298| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 3299 3300**Return value** 3301 3302| Type | Description | 3303| ---------------- | ------------------------------------------------- | 3304| Promise<string\> | Promise used to return the result.| 3305 3306**Error codes** 3307 3308For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3309 3310| ID| Error Message | 3311| -------- | -------------------------------------------- | 3312| 201 | Permission denied. | 3313| 202 | Non-system applications use system APIs. | 3314| 401 | Parameter error. | 3315| 8300001 | Invalid parameter value. | 3316| 8300002 | Operation failed. Cannot connect to service. | 3317| 8300003 | System internal error. | 3318| 8300004 | Do not have sim card. | 3319| 8300999 | Unknown error code. | 3320 3321**Example** 3322 3323```ts 3324import { BusinessError } from '@ohos.base'; 3325import sim from '@ohos.telephony.sim'; 3326 3327sim.getSimGid1(0).then((data: string) => { 3328 console.log(`getSimGid1 success, promise: data->${JSON.stringify(data)}`); 3329}).catch((err: BusinessError) => { 3330 console.error(`getSimGid1 failed, promise: err->${JSON.stringify(err)}`); 3331}); 3332``` 3333 3334## sim.getIMSI 3335 3336getIMSI\(slotId: number, callback: AsyncCallback\<string\>\): void 3337 3338Obtains the international mobile subscriber identity (IMSI) of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 3339 3340**System API**: This is a system API. 3341 3342**Required permission**: ohos.permission.GET_TELEPHONY_STATE 3343 3344**System capability**: SystemCapability.Telephony.CoreService 3345 3346**Parameters** 3347 3348| Name | Type | Mandatory| Description | 3349| -------- | ----------------------- | ---- | -------------------------------------- | 3350| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 3351| callback | AsyncCallback\<string\> | Yes | Callback used to return the result. | 3352 3353**Error codes** 3354 3355For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3356 3357| ID| Error Message | 3358| -------- | -------------------------------------------- | 3359| 201 | Permission denied. | 3360| 202 | Non-system applications use system APIs. | 3361| 401 | Parameter error. | 3362| 8300001 | Invalid parameter value. | 3363| 8300002 | Operation failed. Cannot connect to service. | 3364| 8300003 | System internal error. | 3365| 8300004 | Do not have sim card. | 3366| 8300999 | Unknown error code. | 3367 3368**Example** 3369 3370```ts 3371import { BusinessError } from '@ohos.base'; 3372import sim from '@ohos.telephony.sim'; 3373 3374sim.getIMSI(0, (err: BusinessError, data: string) => { 3375 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 3376}); 3377``` 3378 3379 3380## sim.getIMSI 3381 3382getIMSI\(slotId: number\): Promise\<string\> 3383 3384Obtains the IMSI of the SIM card in the specified slot. This API uses a promise to return the result. 3385 3386**System API**: This is a system API. 3387 3388**Required permission**: ohos.permission.GET_TELEPHONY_STATE 3389 3390**System capability**: SystemCapability.Telephony.CoreService 3391 3392**Parameters** 3393 3394| Name| Type | Mandatory| Description | 3395| ------ | ------ | ---- | -------------------------------------- | 3396| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 3397 3398**Return value** 3399 3400| Type | Description | 3401| ---------------- | ------------------------------------------- | 3402| Promise<string\> | Promise used to return the result.| 3403 3404**Error codes** 3405 3406For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3407 3408| ID| Error Message | 3409| -------- | -------------------------------------------- | 3410| 201 | Permission denied. | 3411| 202 | Non-system applications use system APIs. | 3412| 401 | Parameter error. | 3413| 8300001 | Invalid parameter value. | 3414| 8300002 | Operation failed. Cannot connect to service. | 3415| 8300003 | System internal error. | 3416| 8300004 | Do not have sim card. | 3417| 8300999 | Unknown error code. | 3418 3419**Example** 3420 3421```ts 3422import { BusinessError } from '@ohos.base'; 3423import sim from '@ohos.telephony.sim'; 3424 3425sim.getIMSI(0).then((data: string) => { 3426 console.log(`getIMSI success, promise: data->${JSON.stringify(data)}`); 3427}).catch((err: BusinessError) => { 3428 console.error(`getIMSI failed, promise: err->${JSON.stringify(err)}`); 3429}); 3430``` 3431 3432## sim.getOperatorConfigs<sup>8+</sup> 3433 3434getOperatorConfigs\(slotId: number, callback: AsyncCallback\<Array\<OperatorConfig\>\>\): void 3435 3436Obtains the carrier configuration of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 3437 3438**System API**: This is a system API. 3439 3440**Required permission**: ohos.permission.GET_TELEPHONY_STATE 3441 3442**System capability**: SystemCapability.Telephony.CoreService 3443 3444**Parameters** 3445 3446| Name | Type | Mandatory| Description | 3447| -------- | --------------------------------------------------------- | ---- | -------------------------------------- | 3448| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 3449| callback | AsyncCallback<Array<[OperatorConfig](#operatorconfig8)\>> | Yes | Callback used to return the result. | 3450 3451**Error codes** 3452 3453For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3454 3455| ID| Error Message | 3456| -------- | -------------------------------------------- | 3457| 201 | Permission denied. | 3458| 202 | Non-system applications use system APIs. | 3459| 401 | Parameter error. | 3460| 8300001 | Invalid parameter value. | 3461| 8300002 | Operation failed. Cannot connect to service. | 3462| 8300003 | System internal error. | 3463| 8300999 | Unknown error code. | 3464 3465**Example** 3466 3467```ts 3468import { BusinessError } from '@ohos.base'; 3469import sim from '@ohos.telephony.sim'; 3470 3471sim.getOperatorConfigs(0, (err: BusinessError, data: Array<sim.OperatorConfig>) => { 3472 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 3473}); 3474``` 3475 3476 3477## sim.getOperatorConfigs<sup>8+</sup> 3478 3479getOperatorConfigs\(slotId: number\): Promise\<Array\<OperatorConfig\>\> 3480 3481Obtains the carrier configuration of the SIM card in the specified slot. This API uses a promise to return the result. 3482 3483**System API**: This is a system API. 3484 3485**Required permission**: ohos.permission.GET_TELEPHONY_STATE 3486 3487**System capability**: SystemCapability.Telephony.CoreService 3488 3489**Parameters** 3490 3491| Name| Type | Mandatory| Description | 3492| ------ | ------ | ---- | -------------------------------------- | 3493| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 3494 3495**Return value** 3496 3497| Type | Description | 3498| --------------------------------------------------- | ----------------------------- | 3499| Promise<Array<[OperatorConfig](#operatorconfig8)\>> | Promise used to return the result.| 3500 3501**Error codes** 3502 3503For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3504 3505| ID| Error Message | 3506| -------- | -------------------------------------------- | 3507| 201 | Permission denied. | 3508| 202 | Non-system applications use system APIs. | 3509| 401 | Parameter error. | 3510| 8300001 | Invalid parameter value. | 3511| 8300002 | Operation failed. Cannot connect to service. | 3512| 8300003 | System internal error. | 3513| 8300999 | Unknown error code. | 3514 3515**Example** 3516 3517```ts 3518import { BusinessError } from '@ohos.base'; 3519import sim from '@ohos.telephony.sim'; 3520 3521sim.getOperatorConfigs(0).then((data: Array<sim.OperatorConfig>) => { 3522 console.log(`getOperatorConfigs success, promise: data->${JSON.stringify(data)}`); 3523}).catch((err: BusinessError) => { 3524 console.error(`getOperatorConfigs failed, promise: err->${JSON.stringify(err)}`); 3525}); 3526``` 3527 3528## sim.queryIccDiallingNumbers<sup>8+</sup> 3529 3530queryIccDiallingNumbers\(slotId: number, type: ContactType, callback: AsyncCallback\<Array\<DiallingNumbersInfo\>\>\): void 3531 3532Queries contact numbers of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 3533 3534>**NOTE** 3535> 3536>A cache mechanism is available for SIM card contacts. When a contact is added, deleted, or modified, a SIM card contact cache is maintained based on the corresponding card slot ID and contact type. Therefore, when calling **sim.queryIccDiallingNumbers** to query contact numbers, you must pass the card slot ID and contact type to generate a a SIM card contact cache. If no cache is generated, the attempt to call the **sim.addIccDiallingNumbers**, **sim.delIccDiallingNumbers**, or **sim.updateIccDiallingNumbers** API will fail. 3537> 3538 3539**System API**: This is a system API. 3540 3541**Permission required**: ohos.permission.READ_CONTACTS 3542 3543**System capability**: SystemCapability.Telephony.CoreService 3544 3545**Parameters** 3546 3547| Name | Type | Mandatory| Description | 3548| -------- | ------------------------------------------------------------ | ---- | ---------------------------------------------------------- | 3549| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 3550| type | [ContactType](#contacttype8) | Yes | Contact type.<br>- **1**: GENERAL_CONTACT<br>- **2**: FIXED_DIALING| 3551| callback | AsyncCallback<Array<[DiallingNumbersInfo](#diallingnumbersinfo8)\>> | Yes | Callback used to return the result. | 3552 3553**Error codes** 3554 3555For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3556 3557| ID| Error Message | 3558| -------- | -------------------------------------------- | 3559| 201 | Permission denied. | 3560| 202 | Non-system applications use system APIs. | 3561| 401 | Parameter error. | 3562| 8300001 | Invalid parameter value. | 3563| 8300002 | Operation failed. Cannot connect to service. | 3564| 8300003 | System internal error. | 3565| 8300004 | Do not have sim card. | 3566| 8300999 | Unknown error code. | 3567| 8301002 | SIM card operation error. | 3568 3569**Example** 3570 3571```ts 3572import { BusinessError } from '@ohos.base'; 3573import sim from '@ohos.telephony.sim'; 3574 3575sim.queryIccDiallingNumbers(0, 1, (err: BusinessError, data: Array<sim.DiallingNumbersInfo>) => { 3576 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 3577}); 3578``` 3579 3580 3581## sim.queryIccDiallingNumbers<sup>8+</sup> 3582 3583queryIccDiallingNumbers\(slotId: number, type: ContactType\): Promise\<Array\<DiallingNumbersInfo\>\> 3584 3585Queries contact numbers of the SIM card in the specified slot. This API uses a promise to return the result. 3586 3587>**NOTE** 3588> 3589>A cache mechanism is available for SIM card contacts. When a contact is added, deleted, or modified, a SIM card contact cache is maintained based on the corresponding card slot ID and contact type. Therefore, when calling **sim.queryIccDiallingNumbers** to query contact numbers, you must pass the card slot ID and contact type to generate a a SIM card contact cache. If no cache is generated, the attempt to call the **sim.addIccDiallingNumbers**, **sim.delIccDiallingNumbers**, or **sim.updateIccDiallingNumbers** API will fail. 3590> 3591 3592**System API**: This is a system API. 3593 3594**Permission required**: ohos.permission.READ_CONTACTS 3595 3596**System capability**: SystemCapability.Telephony.CoreService 3597 3598**Parameters** 3599 3600| Name| Type | Mandatory| Description | 3601| ------ | ----------- | ---- | ---------------------------------------------------------- | 3602| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 3603| type | [ContactType](#contacttype8) | Yes | Contact type.<br>- **1**: GENERAL_CONTACT<br>- **2**: FIXED_DIALING| 3604 3605**Return value** 3606 3607| Type | Description | 3608| ------------------------------------------------------------ | ------------------------------ | 3609| Promise<Array<[DiallingNumbersInfo](#diallingnumbersinfo8)\>> | Promise used to return the result.| 3610 3611**Error codes** 3612 3613For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3614 3615| ID| Error Message | 3616| -------- | -------------------------------------------- | 3617| 201 | Permission denied. | 3618| 202 | Non-system applications use system APIs. | 3619| 401 | Parameter error. | 3620| 8300001 | Invalid parameter value. | 3621| 8300002 | Operation failed. Cannot connect to service. | 3622| 8300003 | System internal error. | 3623| 8300004 | Do not have sim card. | 3624| 8300999 | Unknown error code. | 3625| 8301002 | SIM card operation error. | 3626 3627**Example** 3628 3629```ts 3630import { BusinessError } from '@ohos.base'; 3631import sim from '@ohos.telephony.sim'; 3632 3633sim.queryIccDiallingNumbers(0, 1).then((data: Array<sim.DiallingNumbersInfo>) => { 3634 console.log(`queryIccDiallingNumbers success, promise: data->${JSON.stringify(data)}`); 3635}).catch((err: BusinessError) => { 3636 console.error(`queryIccDiallingNumbers failed, promise: err->${JSON.stringify(err)}`); 3637}); 3638``` 3639 3640## sim.addIccDiallingNumbers<sup>8+</sup> 3641 3642addIccDiallingNumbers\(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo, callback: AsyncCallback\<void\>\): void 3643 3644Adds contact numbers to the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 3645 3646>**NOTE** 3647> 3648>A cache mechanism is available for SIM card contacts. When a contact is added, deleted, or modified, a SIM card contact cache is maintained based on the corresponding card slot ID and contact type. Therefore, when calling **sim.queryIccDiallingNumbers** to query contact numbers, you must pass the card slot ID and contact type to generate a a SIM card contact cache. If no cache is generated, the attempt to call the **sim.addIccDiallingNumbers**, **sim.delIccDiallingNumbers**, or **sim.updateIccDiallingNumbers** API will fail. 3649> 3650 3651**System API**: This is a system API. 3652 3653**Permission required**: ohos.permission.WRITE_CONTACTS 3654 3655**System capability**: SystemCapability.Telephony.CoreService 3656 3657**Parameters** 3658 3659| Name | Type | Mandatory| Description | 3660| --------------- | -------------------------------------------- | ---- | ---------------------------------------------------------- | 3661| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 3662| type | [ContactType](#contacttype8) | Yes | Contact type.<br>- **1**: GENERAL_CONTACT<br>- **2**: FIXED_DIALING | 3663| diallingNumbers | [DiallingNumbersInfo](#diallingnumbersinfo8) | Yes | Contact number information. | 3664| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 3665 3666**Error codes** 3667 3668For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3669 3670| ID| Error Message | 3671| -------- | -------------------------------------------- | 3672| 201 | Permission denied. | 3673| 202 | Non-system applications use system APIs. | 3674| 401 | Parameter error. | 3675| 8300001 | Invalid parameter value. | 3676| 8300002 | Operation failed. Cannot connect to service. | 3677| 8300003 | System internal error. | 3678| 8300004 | Do not have sim card. | 3679| 8300999 | Unknown error code. | 3680| 8301002 | SIM card operation error. | 3681 3682**Example** 3683 3684```ts 3685import { BusinessError } from '@ohos.base'; 3686import sim from '@ohos.telephony.sim'; 3687 3688let diallingNumbersInof: sim.DiallingNumbersInfo = { 3689 alphaTag: "alpha", 3690 number: "138xxxxxxxx", 3691 pin2: "1234" 3692}; 3693sim.addIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err: BusinessError) => { 3694 console.log(`callback: err->${JSON.stringify(err)}`); 3695}); 3696``` 3697 3698 3699## sim.addIccDiallingNumbers<sup>8+</sup> 3700 3701addIccDiallingNumbers\(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo\): Promise\<void\> 3702 3703Adds contact numbers to the SIM card in the specified slot. This API uses a promise to return the result. 3704 3705>**NOTE** 3706> 3707>A cache mechanism is available for SIM card contacts. When a contact is added, deleted, or modified, a SIM card contact cache is maintained based on the corresponding card slot ID and contact type. Therefore, when calling **sim.queryIccDiallingNumbers** to query contact numbers, you must pass the card slot ID and contact type to generate a a SIM card contact cache. If no cache is generated, the attempt to call the **sim.addIccDiallingNumbers**, **sim.delIccDiallingNumbers**, or **sim.updateIccDiallingNumbers** API will fail. 3708> 3709 3710**System API**: This is a system API. 3711 3712**Permission required**: ohos.permission.WRITE_CONTACTS 3713 3714**System capability**: SystemCapability.Telephony.CoreService 3715 3716**Parameters** 3717 3718| Name | Type | Mandatory| Description | 3719| --------------- | -------------------------------------------- | ---- | ---------------------------------------------------------- | 3720| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 3721| type | [ContactType](#contacttype8) | Yes | Contact type.<br>- **1**: GENERAL_CONTACT<br>- **2**: FIXED_DIALING | 3722| diallingNumbers | [DiallingNumbersInfo](#diallingnumbersinfo8) | Yes | Contact number information. | 3723 3724**Return value** 3725 3726| Type | Description | 3727| -------------- | --------------------------- | 3728| Promise<void\> | Promise used to return the result.| 3729 3730**Error codes** 3731 3732For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3733 3734| ID| Error Message | 3735| -------- | -------------------------------------------- | 3736| 201 | Permission denied. | 3737| 202 | Non-system applications use system APIs. | 3738| 401 | Parameter error. | 3739| 8300001 | Invalid parameter value. | 3740| 8300002 | Operation failed. Cannot connect to service. | 3741| 8300003 | System internal error. | 3742| 8300004 | Do not have sim card. | 3743| 8300999 | Unknown error code. | 3744| 8301002 | SIM card operation error. | 3745 3746**Example** 3747 3748```ts 3749import { BusinessError } from '@ohos.base'; 3750import sim from '@ohos.telephony.sim'; 3751 3752let diallingNumbersInof: sim.DiallingNumbersInfo = { 3753 alphaTag: "alpha", 3754 number: "138xxxxxxxx" 3755}; 3756sim.addIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof).then(() => { 3757 console.log(`addIccDiallingNumbers success.`); 3758}).catch((err: BusinessError) => { 3759 console.error(`addIccDiallingNumbers failed, promise: err->${JSON.stringify(err)}`); 3760}); 3761``` 3762 3763## sim.delIccDiallingNumbers<sup>8+</sup> 3764 3765delIccDiallingNumbers\(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo, callback: AsyncCallback\<void\>\): void 3766 3767Deletes contact numbers from the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 3768 3769>**NOTE** 3770> 3771>A cache mechanism is available for SIM card contacts. When a contact is added, deleted, or modified, a SIM card contact cache is maintained based on the corresponding card slot ID and contact type. Therefore, when calling **sim.queryIccDiallingNumbers** to query contact numbers, you must pass the card slot ID and contact type to generate a a SIM card contact cache. If no cache is generated, the attempt to call the **sim.addIccDiallingNumbers**, **sim.delIccDiallingNumbers**, or **sim.updateIccDiallingNumbers** API will fail. 3772> 3773 3774**System API**: This is a system API. 3775 3776**Permission required**: ohos.permission.WRITE_CONTACTS 3777 3778**System capability**: SystemCapability.Telephony.CoreService 3779 3780**Parameters** 3781 3782| Name | Type | Mandatory| Description | 3783| --------------- | -------------------------------------------- | ---- | ---------------------------------------------------------- | 3784| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 3785| type | [ContactType](#contacttype8) | Yes | Contact type.<br>- **1**: GENERAL_CONTACT<br>- **2**: FIXED_DIALING | 3786| diallingNumbers | [DiallingNumbersInfo](#diallingnumbersinfo8) | Yes | Contact number information. | 3787| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 3788 3789**Error codes** 3790 3791For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3792 3793| ID| Error Message | 3794| -------- | -------------------------------------------- | 3795| 201 | Permission denied. | 3796| 202 | Non-system applications use system APIs. | 3797| 401 | Parameter error. | 3798| 8300001 | Invalid parameter value. | 3799| 8300002 | Operation failed. Cannot connect to service. | 3800| 8300003 | System internal error. | 3801| 8300004 | Do not have sim card. | 3802| 8300999 | Unknown error code. | 3803| 8301002 | SIM card operation error. | 3804 3805**Example** 3806 3807```ts 3808import { BusinessError } from '@ohos.base'; 3809import sim from '@ohos.telephony.sim'; 3810 3811let diallingNumbersInof: sim.DiallingNumbersInfo = { 3812 alphaTag: "alpha", 3813 number: "138xxxxxxxx", 3814 recordNumber: 123, 3815 pin2: "1234" 3816}; 3817sim.delIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err: BusinessError) => { 3818 console.log(`callback: err->${JSON.stringify(err)}`); 3819}); 3820``` 3821 3822 3823## sim.delIccDiallingNumbers<sup>8+</sup> 3824 3825delIccDiallingNumbers\(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo\): Promise\<void\> 3826 3827Deletes contact numbers from the SIM card in the specified slot. This API uses a promise to return the result. 3828 3829>**NOTE** 3830> 3831>A cache mechanism is available for SIM card contacts. When a contact is added, deleted, or modified, a SIM card contact cache is maintained based on the corresponding card slot ID and contact type. Therefore, when calling **sim.queryIccDiallingNumbers** to query contact numbers, you must pass the card slot ID and contact type to generate a a SIM card contact cache. If no cache is generated, the attempt to call the **sim.addIccDiallingNumbers**, **sim.delIccDiallingNumbers**, or **sim.updateIccDiallingNumbers** API will fail. 3832> 3833 3834**System API**: This is a system API. 3835 3836**Permission required**: ohos.permission.WRITE_CONTACTS 3837 3838**System capability**: SystemCapability.Telephony.CoreService 3839 3840**Parameters** 3841 3842| Name | Type | Mandatory| Description | 3843| --------------- | -------------------------------------------- | ---- | ---------------------------------------------------------- | 3844| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 3845| type | [ContactType](#contacttype8) | Yes | Contact type.<br>- **1**: GENERAL_CONTACT<br>- **2**: FIXED_DIALING | 3846| diallingNumbers | [DiallingNumbersInfo](#diallingnumbersinfo8) | Yes | Contact number information. | 3847 3848**Return value** 3849 3850| Type | Description | 3851| -------------- | --------------------------- | 3852| Promise<void\> | Promise used to return the result.| 3853 3854**Error codes** 3855 3856For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3857 3858| ID| Error Message | 3859| -------- | -------------------------------------------- | 3860| 201 | Permission denied. | 3861| 202 | Non-system applications use system APIs. | 3862| 401 | Parameter error. | 3863| 8300001 | Invalid parameter value. | 3864| 8300002 | Operation failed. Cannot connect to service. | 3865| 8300003 | System internal error. | 3866| 8300004 | Do not have sim card. | 3867| 8300999 | Unknown error code. | 3868| 8301002 | SIM card operation error. | 3869 3870**Example** 3871 3872```ts 3873import { BusinessError } from '@ohos.base'; 3874import sim from '@ohos.telephony.sim'; 3875 3876let diallingNumbersInof: sim.DiallingNumbersInfo = { 3877 alphaTag: "alpha", 3878 number: "138xxxxxxxx" 3879}; 3880sim.delIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof).then(() => { 3881 console.log(`delIccDiallingNumbers success.`); 3882}).catch((err: BusinessError) => { 3883 console.error(`delIccDiallingNumbers failed, promise: err->${JSON.stringify(err)}`); 3884}); 3885``` 3886 3887## sim.updateIccDiallingNumbers<sup>8+</sup> 3888 3889updateIccDiallingNumbers\(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo, callback: AsyncCallback\<void\>\): void 3890 3891Updates contact numbers for the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 3892 3893>**NOTE** 3894> 3895>A cache mechanism is available for SIM card contacts. When a contact is added, deleted, or modified, a SIM card contact cache is maintained based on the corresponding card slot ID and contact type. Therefore, when calling **sim.queryIccDiallingNumbers** to query contact numbers, you must pass the card slot ID and contact type to generate a a SIM card contact cache. If no cache is generated, the attempt to call the **sim.addIccDiallingNumbers**, **sim.delIccDiallingNumbers**, or **sim.updateIccDiallingNumbers** API will fail. 3896> 3897 3898**System API**: This is a system API. 3899 3900**Permission required**: ohos.permission.WRITE_CONTACTS 3901 3902**System capability**: SystemCapability.Telephony.CoreService 3903 3904**Parameters** 3905 3906| Name | Type | Mandatory| Description | 3907| --------------- | -------------------------------------------- | ---- | ---------------------------------------------------------- | 3908| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 3909| type | [ContactType](#contacttype8) | Yes | Contact type.<br>- **1**: GENERAL_CONTACT<br>- **2**: FIXED_DIALING | 3910| diallingNumbers | [DiallingNumbersInfo](#diallingnumbersinfo8) | Yes | Contact number information. | 3911| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 3912 3913**Error codes** 3914 3915For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3916 3917| ID| Error Message | 3918| -------- | -------------------------------------------- | 3919| 201 | Permission denied. | 3920| 202 | Non-system applications use system APIs. | 3921| 401 | Parameter error. | 3922| 8300001 | Invalid parameter value. | 3923| 8300002 | Operation failed. Cannot connect to service. | 3924| 8300003 | System internal error. | 3925| 8300004 | Do not have sim card. | 3926| 8300999 | Unknown error code. | 3927| 8301002 | SIM card operation error. | 3928 3929**Example** 3930 3931```ts 3932import { BusinessError } from '@ohos.base'; 3933import sim from '@ohos.telephony.sim'; 3934 3935let diallingNumbersInof: sim.DiallingNumbersInfo = { 3936 alphaTag: "alpha", 3937 number: "138xxxxxxxx", 3938 recordNumber: 123, 3939 pin2: "1234" 3940}; 3941sim.updateIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err: BusinessError) => { 3942 console.log(`callback: err->${JSON.stringify(err)}`); 3943}); 3944``` 3945 3946 3947## sim.updateIccDiallingNumbers<sup>8+</sup> 3948 3949updateIccDiallingNumbers\(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo\): Promise\<void\> 3950 3951Updates contact numbers for the SIM card in the specified slot. This API uses a promise to return the result. 3952 3953>**NOTE** 3954> 3955>A cache mechanism is available for SIM card contacts. When a contact is added, deleted, or modified, a SIM card contact cache is maintained based on the corresponding card slot ID and contact type. Therefore, when calling **sim.queryIccDiallingNumbers** to query contact numbers, you must pass the card slot ID and contact type to generate a a SIM card contact cache. If no cache is generated, the attempt to call the **sim.addIccDiallingNumbers**, **sim.delIccDiallingNumbers**, or **sim.updateIccDiallingNumbers** API will fail. 3956> 3957 3958**System API**: This is a system API. 3959 3960**Permission required**: ohos.permission.WRITE_CONTACTS 3961 3962**System capability**: SystemCapability.Telephony.CoreService 3963 3964**Parameters** 3965 3966| Name | Type | Mandatory| Description | 3967| --------------- | -------------------------------------------- | ---- | ---------------------------------------------------------- | 3968| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 3969| type | [ContactType](#contacttype8) | Yes | Contact type.<br>- **1**: GENERAL_CONTACT<br>- **2**: FIXED_DIALING | 3970| diallingNumbers | [DiallingNumbersInfo](#diallingnumbersinfo8) | Yes | Contact number information. | 3971 3972**Return value** 3973 3974| Type | Description | 3975| -------------- | ----------------------------- | 3976| Promise<void\> | Promise used to return the result.| 3977 3978**Error codes** 3979 3980For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 3981 3982| ID| Error Message | 3983| -------- | -------------------------------------------- | 3984| 201 | Permission denied. | 3985| 202 | Non-system applications use system APIs. | 3986| 401 | Parameter error. | 3987| 8300001 | Invalid parameter value. | 3988| 8300002 | Operation failed. Cannot connect to service. | 3989| 8300003 | System internal error. | 3990| 8300004 | Do not have sim card. | 3991| 8300999 | Unknown error code. | 3992| 8301002 | SIM card operation error. | 3993 3994**Example** 3995 3996```ts 3997import { BusinessError } from '@ohos.base'; 3998import sim from '@ohos.telephony.sim'; 3999 4000let diallingNumbersInof: sim.DiallingNumbersInfo = { 4001 alphaTag: "alpha", 4002 number: "138xxxxxxxx", 4003 recordNumber: 123 4004}; 4005sim.updateIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof).then(() => { 4006 console.log(`updateIccDiallingNumbers success.`); 4007}).catch((err: BusinessError) => { 4008 console.error(`updateIccDiallingNumbers failed, promise: err->${JSON.stringify(err)}`); 4009}); 4010``` 4011 4012## sim.sendEnvelopeCmd<sup>8+</sup> 4013 4014sendEnvelopeCmd\(slotId: number, cmd: string, callback: AsyncCallback\<void\>\): void 4015 4016Sends an envelope command to the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 4017 4018**System API**: This is a system API. 4019 4020**Required permission**: ohos.permission.SET_TELEPHONY_STATE 4021 4022**System capability**: SystemCapability.Telephony.CoreService 4023 4024**Parameters** 4025 4026| Name | Type | Mandatory| Description | 4027| -------- | -------------------- | ---- | -------------------------------------- | 4028| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4029| cmd | string | Yes | Envelope command. | 4030| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 4031 4032**Error codes** 4033 4034For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4035 4036| ID| Error Message | 4037| -------- | -------------------------------------------- | 4038| 201 | Permission denied. | 4039| 202 | Non-system applications use system APIs. | 4040| 401 | Parameter error. | 4041| 8300001 | Invalid parameter value. | 4042| 8300002 | Operation failed. Cannot connect to service. | 4043| 8300003 | System internal error. | 4044| 8300004 | Do not have sim card. | 4045| 8300999 | Unknown error code. | 4046 4047**Example** 4048 4049```ts 4050import { BusinessError } from '@ohos.base'; 4051import sim from '@ohos.telephony.sim'; 4052 4053sim.sendEnvelopeCmd(0, "ls", (err: BusinessError) => { 4054 console.log(`callback: err->${JSON.stringify(err)}`); 4055}); 4056``` 4057 4058 4059## sim.sendEnvelopeCmd<sup>8+</sup> 4060 4061sendEnvelopeCmd\(slotId: number, cmd: string\): Promise\<void\> 4062 4063Sends an envelope command to the SIM card in the specified slot. This API uses a promise to return the result. 4064 4065**System API**: This is a system API. 4066 4067**Required permission**: ohos.permission.SET_TELEPHONY_STATE 4068 4069**System capability**: SystemCapability.Telephony.CoreService 4070 4071**Parameters** 4072 4073| Name| Type | Mandatory| Description | 4074| ------ | ------ | ---- | -------------------------------------- | 4075| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4076| cmd | string | Yes | Envelope command. | 4077 4078**Return value** 4079 4080| Type | Description | 4081| -------------- | --------------------------- | 4082| Promise<void\> | Promise used to return the result.| 4083 4084**Error codes** 4085 4086For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4087 4088| ID| Error Message | 4089| -------- | -------------------------------------------- | 4090| 201 | Permission denied. | 4091| 202 | Non-system applications use system APIs. | 4092| 401 | Parameter error. | 4093| 8300001 | Invalid parameter value. | 4094| 8300002 | Operation failed. Cannot connect to service. | 4095| 8300003 | System internal error. | 4096| 8300004 | Do not have sim card. | 4097| 8300999 | Unknown error code. | 4098 4099**Example** 4100 4101```ts 4102import { BusinessError } from '@ohos.base'; 4103import sim from '@ohos.telephony.sim'; 4104 4105sim.sendEnvelopeCmd(0, "ls").then(() => { 4106 console.log(`sendEnvelopeCmd success.`); 4107}).catch((err: BusinessError) => { 4108 console.error(`sendEnvelopeCmd failed, promise: err->${JSON.stringify(err)}`); 4109}); 4110``` 4111 4112## sim.sendTerminalResponseCmd<sup>8+</sup> 4113 4114sendTerminalResponseCmd\(slotId: number, cmd: string, callback: AsyncCallback\<void\>\): void 4115 4116Sends a terminal response command to the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 4117 4118**System API**: This is a system API. 4119 4120**Required permission**: ohos.permission.SET_TELEPHONY_STATE 4121 4122**System capability**: SystemCapability.Telephony.CoreService 4123 4124**Parameters** 4125 4126| Name | Type | Mandatory| Description | 4127| -------- | -------------------- | ---- | -------------------------------------- | 4128| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4129| cmd | string | Yes | Envelope command. | 4130| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 4131 4132**Error codes** 4133 4134For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4135 4136| ID| Error Message | 4137| -------- | -------------------------------------------- | 4138| 201 | Permission denied. | 4139| 202 | Non-system applications use system APIs. | 4140| 401 | Parameter error. | 4141| 8300001 | Invalid parameter value. | 4142| 8300002 | Operation failed. Cannot connect to service. | 4143| 8300003 | System internal error. | 4144| 8300004 | Do not have sim card. | 4145| 8300999 | Unknown error code. | 4146 4147**Example** 4148 4149```ts 4150import { BusinessError } from '@ohos.base'; 4151import sim from '@ohos.telephony.sim'; 4152 4153sim.sendTerminalResponseCmd(0, "ls", (err: BusinessError) => { 4154 console.log(`callback: err->${JSON.stringify(err)}`); 4155}); 4156``` 4157 4158 4159## sim.sendTerminalResponseCmd<sup>8+</sup> 4160 4161sendTerminalResponseCmd\(slotId: number, cmd: string\): Promise\<void\> 4162 4163Sends a terminal response command to the SIM card in the specified slot. This API uses a promise to return the result. 4164 4165**System API**: This is a system API. 4166 4167**Required permission**: ohos.permission.SET_TELEPHONY_STATE 4168 4169**System capability**: SystemCapability.Telephony.CoreService 4170 4171**Parameters** 4172 4173| Name| Type | Mandatory| Description | 4174| ------ | ------ | ---- | -------------------------------------- | 4175| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4176| cmd | string | Yes | Envelope command. | 4177 4178**Return value** 4179 4180| Type | Description | 4181| -------------- | --------------------------- | 4182| Promise<void\> | Promise used to return the result.| 4183 4184**Error codes** 4185 4186For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4187 4188| ID| Error Message | 4189| -------- | -------------------------------------------- | 4190| 201 | Permission denied. | 4191| 202 | Non-system applications use system APIs. | 4192| 401 | Parameter error. | 4193| 8300001 | Invalid parameter value. | 4194| 8300002 | Operation failed. Cannot connect to service. | 4195| 8300003 | System internal error. | 4196| 8300004 | Do not have sim card. | 4197| 8300999 | Unknown error code. | 4198 4199**Example** 4200 4201```ts 4202import { BusinessError } from '@ohos.base'; 4203import sim from '@ohos.telephony.sim'; 4204 4205sim.sendTerminalResponseCmd(0, "ls").then(() => { 4206 console.log(`sendTerminalResponseCmd success.`); 4207}).catch((err: BusinessError) => { 4208 console.error(`sendTerminalResponseCmd failed, promise: err->${JSON.stringify(err)}`); 4209}); 4210``` 4211 4212 4213## sim.unlockSimLock<sup>8+</sup> 4214 4215unlockSimLock\(slotId: number, lockInfo: PersoLockInfo, callback: AsyncCallback\<LockStatusResponse\>\): void 4216 4217Unlocks the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 4218 4219**System API**: This is a system API. 4220 4221**Required permission**: ohos.permission.SET_TELEPHONY_STATE 4222 4223**System capability**: SystemCapability.Telephony.CoreService 4224 4225**Parameters** 4226 4227| Name | Type | Mandatory| Description | 4228| -------- | ---------------------------------------------------------- | ---- | -------------------------------------- | 4229| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4230| lockInfo | [PersoLockInfo](#persolockinfo8) | Yes | Personalized lock information. | 4231| callback | AsyncCallback<[LockStatusResponse](#lockstatusresponse7)\> | Yes | Callback used to return the result. | 4232 4233**Error codes** 4234 4235For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4236 4237| ID| Error Message | 4238| -------- | -------------------------------------------- | 4239| 201 | Permission denied. | 4240| 202 | Non-system applications use system APIs. | 4241| 401 | Parameter error. | 4242| 8300001 | Invalid parameter value. | 4243| 8300002 | Operation failed. Cannot connect to service. | 4244| 8300003 | System internal error. | 4245| 8300004 | Do not have sim card. | 4246| 8300999 | Unknown error code. | 4247| 8301002 | SIM card operation error. | 4248 4249**Example** 4250 4251```ts 4252import { BusinessError } from '@ohos.base'; 4253import sim from '@ohos.telephony.sim'; 4254 4255let persoLockInfo: sim.PersoLockInfo = { 4256 lockType: sim.PersoLockType.PN_PIN_LOCK, 4257 password: "1234" 4258}; 4259sim.unlockSimLock(0, persoLockInfo, (err: BusinessError, data: sim.LockStatusResponse) => { 4260 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 4261}); 4262``` 4263 4264 4265## sim.unlockSimLock<sup>8+</sup> 4266 4267unlockSimLock\(slotId: number, lockInfo: PersoLockInfo\): Promise\<LockStatusResponse\> 4268 4269Unlocks the SIM card in the specified slot. This API uses a promise to return the result. 4270 4271**System API**: This is a system API. 4272 4273**Required permission**: ohos.permission.SET_TELEPHONY_STATE 4274 4275**System capability**: SystemCapability.Telephony.CoreService 4276 4277**Parameters** 4278 4279| Name | Type | Mandatory| Description | 4280| -------- | -------------------------------- | ---- | -------------------------------------- | 4281| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4282| lockInfo | [PersoLockInfo](#persolockinfo8) | Yes | Personalized lock information. | 4283 4284**Return value** 4285 4286| Type | Description | 4287| ---------------------------------------------------- | ------------------------- | 4288| Promise<[LockStatusResponse](#lockstatusresponse7)\> | Promise used to return the result.| 4289 4290**Error codes** 4291 4292For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4293 4294| ID| Error Message | 4295| -------- | -------------------------------------------- | 4296| 201 | Permission denied. | 4297| 202 | Non-system applications use system APIs. | 4298| 401 | Parameter error. | 4299| 8300001 | Invalid parameter value. | 4300| 8300002 | Operation failed. Cannot connect to service. | 4301| 8300003 | System internal error. | 4302| 8300004 | Do not have sim card. | 4303| 8300999 | Unknown error code. | 4304| 8301002 | SIM card operation error. | 4305 4306**Example** 4307 4308```ts 4309import { BusinessError } from '@ohos.base'; 4310import sim from '@ohos.telephony.sim'; 4311 4312let persoLockInfo: sim.PersoLockInfo = { 4313 lockType: sim.PersoLockType.PN_PIN_LOCK, 4314 password: "1234" 4315}; 4316sim.unlockSimLock(0, persoLockInfo).then((data: sim.LockStatusResponse) => { 4317 console.log(`unlockSimLock success, promise: data->${JSON.stringify(data)}`); 4318}).catch((err: BusinessError) => { 4319 console.error(`unlockSimLock failed, promise: err->${JSON.stringify(err)}`); 4320}); 4321``` 4322 4323## sim.getOpKey<sup>9+</sup> 4324 4325getOpKey\(slotId: number, callback: AsyncCallback\<string\>): void 4326 4327Obtains the opkey of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 4328 4329**System capability**: SystemCapability.Telephony.CoreService 4330 4331**Parameters** 4332 4333| Name | Type | Mandatory| Description | 4334| -------- | ---------------------- | ---- | -------------------------------------- | 4335| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4336| callback | AsyncCallback<string\> | Yes | Callback used to return the result. | 4337 4338**Error codes** 4339 4340For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4341 4342| ID| Error Message | 4343| -------- | -------------------------------------------- | 4344| 401 | Parameter error. | 4345| 801 | Capability not supported. | 4346| 8300001 | Invalid parameter value. | 4347| 8300002 | Operation failed. Cannot connect to service. | 4348| 8300003 | System internal error. | 4349| 8300999 | Unknown error code. | 4350 4351**Example** 4352 4353```ts 4354import { BusinessError } from '@ohos.base'; 4355import sim from '@ohos.telephony.sim'; 4356 4357try { 4358 sim.getOpKey(0, (err: BusinessError, data: string) => { 4359 if (err) { 4360 console.error("getOpKey failed, err: " + JSON.stringify(err)); 4361 } else { 4362 console.log('getOpKey successfully, data: ' + JSON.stringify(data)); 4363 } 4364 }); 4365} catch (err) { 4366 console.error("getOpKey err: " + JSON.stringify(err)); 4367} 4368``` 4369 4370 4371## sim.getOpKey<sup>9+</sup> 4372 4373getOpKey\(slotId: number\): Promise\<string\> 4374 4375Obtains the opkey of the SIM card in the specified slot. This API uses a promise to return the result. 4376 4377**System capability**: SystemCapability.Telephony.CoreService 4378 4379**Parameters** 4380 4381| Name| Type | Mandatory| Description | 4382| ------ | ------ | ---- | -------------------------------------- | 4383| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4384 4385**Return value** 4386 4387| Type | Description | 4388| ---------------- | ----------------------------------------- | 4389| Promise<string\> | Promise used to return the result.| 4390 4391**Error codes** 4392 4393For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4394 4395| ID| Error Message | 4396| -------- | -------------------------------------------- | 4397| 401 | Parameter error. | 4398| 801 | Capability not supported. | 4399| 8300001 | Invalid parameter value. | 4400| 8300002 | Operation failed. Cannot connect to service. | 4401| 8300003 | System internal error. | 4402| 8300999 | Unknown error code. | 4403 4404**Example** 4405 4406```ts 4407import { BusinessError } from '@ohos.base'; 4408import sim from '@ohos.telephony.sim'; 4409 4410sim.getOpKey(0).then((data: string) => { 4411 console.log(`getOpKey success, promise: data->${JSON.stringify(data)}`); 4412}).catch((err: BusinessError) => { 4413 console.error(`getOpKey failed, promise: err->${JSON.stringify(err)}`); 4414}); 4415``` 4416 4417## sim.getOpKeySync<sup>10+</sup> 4418 4419getOpKeySync\(slotId: number\): string 4420 4421Obtains the opkey of the SIM card in the specified slot. 4422 4423**System capability**: SystemCapability.Telephony.CoreService 4424 4425**Parameters** 4426 4427| Name| Type | Mandatory| Description | 4428| ------ | ------ | ---- | -------------------------------------- | 4429| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4430 4431**Return value** 4432 4433| Type | Description | 4434| ---------------- | ----------------------------------------- | 4435| string | opkey of the SIM card in the specified slot.| 4436 4437 4438**Example** 4439 4440```ts 4441import sim from '@ohos.telephony.sim'; 4442 4443let data: string = sim.getOpKeySync(0); 4444console.log(`getOpKey success, promise: data->${JSON.stringify(data)}`); 4445``` 4446 4447## sim.getOpName<sup>9+</sup> 4448 4449getOpName\(slotId: number, callback: AsyncCallback\<string\>\): void 4450 4451Obtains the OpName of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 4452 4453**System capability**: SystemCapability.Telephony.CoreService 4454 4455**Parameters** 4456 4457| Name | Type | Mandatory| Description | 4458| -------- | ---------------------- | ---- | -------------------------------------- | 4459| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4460| callback | AsyncCallback<string\> | Yes | Callback used to return the result. | 4461 4462**Error codes** 4463 4464For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4465 4466| ID| Error Message | 4467| -------- | -------------------------------------------- | 4468| 401 | Parameter error. | 4469| 801 | Capability not supported. | 4470| 8300001 | Invalid parameter value. | 4471| 8300002 | Operation failed. Cannot connect to service. | 4472| 8300003 | System internal error. | 4473| 8300999 | Unknown error code. | 4474 4475**Example** 4476 4477```ts 4478import { BusinessError } from '@ohos.base'; 4479import sim from '@ohos.telephony.sim'; 4480 4481try { 4482 sim.getOpName(0, (err: BusinessError, data: string) => { 4483 if (err) { 4484 console.error("getOpName failed, err: " + JSON.stringify(err)); 4485 } else { 4486 console.log('getOpName successfully, data: ' + JSON.stringify(data)); 4487 } 4488 }); 4489} catch (err) { 4490 console.error("getOpName err: " + JSON.stringify(err)); 4491} 4492``` 4493 4494 4495## sim.getOpName<sup>9+</sup> 4496 4497getOpName\(slotId: number\): Promise\<string\> 4498 4499Obtains the OpName of the SIM card in the specified slot. This API uses a promise to return the result. 4500 4501**System capability**: SystemCapability.Telephony.CoreService 4502 4503**Parameters** 4504 4505| Name| Type | Mandatory| Description | 4506| ------ | ------ | ---- | -------------------------------------- | 4507| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4508 4509**Return value** 4510 4511| Type | Description | 4512| ---------------- | ------------------------------------------ | 4513| Promise<string\> | Promise used to return the result.| 4514 4515**Error codes** 4516 4517For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4518 4519| ID| Error Message | 4520| -------- | -------------------------------------------- | 4521| 401 | Parameter error. | 4522| 801 | Capability not supported. | 4523| 8300001 | Invalid parameter value. | 4524| 8300002 | Operation failed. Cannot connect to service. | 4525| 8300003 | System internal error. | 4526| 8300999 | Unknown error code. | 4527 4528**Example** 4529 4530```ts 4531import { BusinessError } from '@ohos.base'; 4532import sim from '@ohos.telephony.sim'; 4533 4534sim.getOpName(0).then((data: string) => { 4535 console.log(`getOpName success, promise: data->${JSON.stringify(data)}`); 4536}).catch((err: BusinessError) => { 4537 console.error(`getOpName failed, promise: err->${JSON.stringify(err)}`); 4538}); 4539``` 4540 4541## sim.getOpNameSync<sup>10+</sup> 4542 4543getOpNameSync\(slotId: number\): string 4544 4545Obtains the OpName of the SIM card in the specified slot. 4546 4547**System capability**: SystemCapability.Telephony.CoreService 4548 4549**Parameters** 4550 4551| Name| Type | Mandatory| Description | 4552| ------ | ------ | ---- | -------------------------------------- | 4553| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 4554 4555**Return value** 4556 4557| Type | Description | 4558| ---------------- | ------------------------------------------ | 4559| string | OpName of the SIM card in the specified slot.| 4560 4561 4562**Example** 4563 4564```ts 4565import sim from '@ohos.telephony.sim'; 4566 4567let data: string = sim.getOpNameSync(0); 4568console.log(`getOpName success, promise: data->${JSON.stringify(data)}`); 4569``` 4570 4571## sim.getDefaultVoiceSimId<sup>10+</sup> 4572 4573getDefaultVoiceSimId\(callback: AsyncCallback\<number\>\): void 4574 4575Obtains the default slot ID of the SIM card that provides voice services. This API uses an asynchronous callback to return the result. 4576 4577**System capability**: SystemCapability.Telephony.CoreService 4578 4579**Parameters** 4580 4581| Name | Type | Mandatory| Description | 4582| -------- | --------------------------- | ---- | ---------- | 4583| callback | AsyncCallback<number> | Yes | Callback used to return the result.<br>The return value is bound to the SIM card and increases from 1.| 4584 4585**Error codes** 4586 4587For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4588 4589| ID| Error Message | 4590| -------- | -------------------------------------------- | 4591| 401 | Parameter error. | 4592| 8300001 | Invalid parameter value. | 4593| 8300002 | Operation failed. Cannot connect to service. | 4594| 8300003 | System internal error. | 4595| 8300004 | Do not have sim card. | 4596| 8300999 | Unknown error code. | 4597| 8301001 | SIM card is not activated. | 4598 4599**Example** 4600 4601```ts 4602import { BusinessError } from '@ohos.base'; 4603import sim from '@ohos.telephony.sim'; 4604 4605sim.getDefaultVoiceSimId((err: BusinessError, data: number) => { 4606 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 4607}); 4608``` 4609 4610## sim.getDefaultVoiceSimId<sup>10+</sup> 4611 4612getDefaultVoiceSimId\(\): Promise\<number\> 4613 4614Obtains the default slot ID of the SIM card that provides voice services. This API uses a promise to return the result. 4615 4616**System capability**: SystemCapability.Telephony.CoreService 4617 4618**Return value** 4619 4620| Type | Description | 4621| ----------------- | --------------------------------------- | 4622| Promise\<number\> | Promise used to return the result.<br>The return value is bound to the SIM card and increases from 1.| 4623 4624**Error codes** 4625 4626For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4627 4628| ID| Error Message | 4629| -------- | -------------------------------------------- | 4630| 8300001 | Invalid parameter value. | 4631| 8300002 | Operation failed. Cannot connect to service. | 4632| 8300003 | System internal error. | 4633| 8300004 | Do not have sim card. | 4634| 8300999 | Unknown error code. | 4635| 8301001 | SIM card is not activated. | 4636 4637**Example** 4638 4639```ts 4640import { BusinessError } from '@ohos.base'; 4641import sim from '@ohos.telephony.sim'; 4642 4643let promise = sim.getDefaultVoiceSimId(); 4644promise.then((data: number) => { 4645 console.log(`getDefaultVoiceSimId success, promise: data->${JSON.stringify(data)}`); 4646}).catch((err: BusinessError) => { 4647 console.error(`getDefaultVoiceSimId failed, promise: err->${JSON.stringify(err)}`); 4648}); 4649``` 4650 4651## sim.getDsdsMode<sup>11+</sup> 4652 4653getDsdsMode\(callback: AsyncCallback\<DsdsMode\>\): void 4654 4655Obtains the Dual Sim Dual Standby (DSDS) mode supported by the device. This API uses an asynchronous callback to return the result. 4656 4657**System API**: This is a system API. 4658 4659**Required permission**: ohos.permission.GET_TELEPHONY_STATE 4660 4661**System capability**: SystemCapability.Telephony.CoreService 4662 4663**Parameters** 4664 4665| Name | Type | Mandatory| Description | 4666| -------- | --------------------------- | ---- | ---------- | 4667| callback | AsyncCallback<DsdsMode> | Yes | Callback used to return the result, which can be:<br>- **0**: DSDS_MODE_V2<br>- **1**: DSDS_MODE_V3<br>- **2**: DSDS_MODE_V5_TDM<br>- **3**: DSDS_MODE_V5_DSDA| 4668 4669**Error codes** 4670 4671For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4672 4673| ID| Error Message | 4674| -------- | -------------------------------------------- | 4675| 201 | Permission denied. | 4676| 202 | Non-system applications use system APIs. | 4677| 401 | Parameter error. | 4678| 8300002 | Operation failed. Cannot connect to service. | 4679| 8300003 | System internal error. | 4680| 8300999 | Unknown error code. | 4681 4682**Example** 4683 4684```ts 4685import { BusinessError } from '@ohos.base'; 4686import sim from '@ohos.telephony.sim'; 4687 4688sim.getDsdsMode((err: BusinessError, data: sim.DsdsMode) => { 4689 if (err) { 4690 console.error(`getDsdsMode failed, callback: err->${JSON.stringify(err)}`); 4691 } else { 4692 console.log(`getDsdsMode success, callback: data->${JSON.stringify(data)}`); 4693 } 4694}); 4695``` 4696 4697## sim.getDsdsMode<sup>11+</sup> 4698 4699getDsdsMode\(\): Promise\<DsdsMode\> 4700 4701Obtains the Dual Sim Dual Standby (DSDS) mode supported by the device. This API uses a promise to return the result. 4702 4703**System API**: This is a system API. 4704 4705**Required permission**: ohos.permission.GET_TELEPHONY_STATE 4706 4707**System capability**: SystemCapability.Telephony.CoreService 4708 4709**Return value** 4710 4711| Type | Description | 4712| ----------------- | --------------------------------------- | 4713| Promise\<DsdsMode\> | Promise used to return the result.<br>- **0**: DSDS_MODE_V2<br>- **1**: DSDS_MODE_V3<br>- **2**: DSDS_MODE_V5_TDM<br>- **3**: DSDS_MODE_V5_DSDA| 4714 4715**Error codes** 4716 4717For details about the error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). 4718 4719| ID| Error Message | 4720| -------- | -------------------------------------------- | 4721| 201 | Permission denied. | 4722| 202 | Non-system applications use system APIs. | 4723| 401 | Parameter error. | 4724| 8300002 | Operation failed. Cannot connect to service. | 4725| 8300003 | System internal error. | 4726| 8300999 | Unknown error code. | 4727 4728**Example** 4729 4730```ts 4731import { BusinessError } from '@ohos.base'; 4732import sim from '@ohos.telephony.sim'; 4733 4734let promise = sim.getDsdsMode(); 4735promise.then((data: sim.DsdsMode) => { 4736 console.log(`getDsdsMode success, promise: data->${JSON.stringify(data)}`); 4737}).catch((err: BusinessError) => { 4738 console.error(`getDsdsMode failed, promise: err->${JSON.stringify(err)}`); 4739}); 4740``` 4741 4742## SimState 4743 4744Enumerates SIM card states. 4745 4746**System capability**: SystemCapability.Telephony.CoreService 4747 4748| Name | Value | Description | 4749| --------------------- | ---- | ---------------------------------------------------------- | 4750| SIM_STATE_UNKNOWN | 0 | The SIM card is in **unknown** state; that is, the SIM card status cannot be obtained. | 4751| SIM_STATE_NOT_PRESENT | 1 | The SIM card is in **not present** state; that is, no SIM card is inserted into the card slot. | 4752| SIM_STATE_LOCKED | 2 | The SIM card is in **locked** state; that is, the SIM card is locked by the personal identification number (PIN), PIN unblocking key (PUK), or network. | 4753| SIM_STATE_NOT_READY | 3 | The SIM card is in **not ready** state; that is, the SIM card has been installed but cannot work properly. | 4754| SIM_STATE_READY | 4 | The SIM card is in **ready** state; that is, the SIM card has been installed and is working properly. | 4755| SIM_STATE_LOADED | 5 | The SIM card is in **loaded** state; that is, the SIM card is present and all its files have been loaded.| 4756 4757## CardType<sup>7+</sup> 4758 4759Enumerates SIM card types. 4760 4761**System capability**: SystemCapability.Telephony.CoreService 4762 4763| Name| Value| Description| 4764| ----- | ----- | ----- | 4765|UNKNOWN_CARD | -1 | Unknown type.| 4766|SINGLE_MODE_SIM_CARD | 10 | Single-card (SIM).| 4767|SINGLE_MODE_USIM_CARD | 20 | Single-card (USIM).| 4768|SINGLE_MODE_RUIM_CARD | 30 | Single-card (RUIM).| 4769|DUAL_MODE_CG_CARD | 40 | Dual-card (CDMA+GSM).| 4770|CT_NATIONAL_ROAMING_CARD | 41 | China Telecom internal roaming card.| 4771|CU_DUAL_MODE_CARD | 42 | China Unicom dual-mode card.| 4772|DUAL_MODE_TELECOM_LTE_CARD | 43 | China Telecom dual-mode LTE card.| 4773|DUAL_MODE_UG_CARD | 50 | Dual-mode card (UMTS+GSM).| 4774|SINGLE_MODE_ISIM_CARD<sup>8+</sup> | 60 | Single-card (ISIM).| 4775 4776## LockType<sup>8+</sup> 4777 4778Enumerates lock types. 4779 4780**System API**: This is a system API. 4781 4782**System capability**: SystemCapability.Telephony.CoreService 4783 4784| Name | Value | Description | 4785| -------- | ---- | ----------- | 4786| PIN_LOCK | 1 | SIM card password lock.| 4787| FDN_LOCK | 2 | Fixed dialing lock. | 4788 4789## LockState<sup>8+</sup> 4790 4791Enumerates lock states. 4792 4793**System API**: This is a system API. 4794 4795**System capability**: SystemCapability.Telephony.CoreService 4796 4797| Name | Value | Description | 4798| -------- | ---- | ---------- | 4799| LOCK_OFF | 0 | The lock is off.| 4800| LOCK_ON | 1 | The lock is on.| 4801 4802## PersoLockType<sup>8+</sup> 4803 4804Enumerates personalized lock types. 4805 4806**System API**: This is a system API. 4807 4808**System capability**: SystemCapability.Telephony.CoreService 4809 4810| Name | Value | Description | 4811| ------------ | ---- | ------------------------------------------------ | 4812| PN_PIN_LOCK | 0 | Personalized network PIN lock. For details, see *3GPP TS 22.022 [33]*. | 4813| PN_PUK_LOCK | 1 | Personalized network PUK lock. | 4814| PU_PIN_LOCK | 2 | Personalized network subset PIN lock. For details, see *3GPP TS 22.022 [33]*. | 4815| PU_PUK_LOCK | 3 | Personalized network subset PUK lock. | 4816| PP_PIN_LOCK | 4 | Personalized service provider PIN lock. For details, see *3GPP TS 22.022 [33]*. | 4817| PP_PUK_LOCK | 5 | Personalized service provider PUK lock. | 4818| PC_PIN_LOCK | 6 | Personalized corporate PIN lock. For details, see *3GPP TS 22.022 [33]*. | 4819| PC_PUK_LOCK | 7 | Personalized corporate PUK lock. | 4820| SIM_PIN_LOCK | 8 | Personalized SIM card PIN lock. For details, see *3GPP TS 22.022 [33]*. | 4821| SIM_PUK_LOCK | 9 | Personalized SIM card PUK lock. | 4822 4823## LockStatusResponse<sup>7+</sup> 4824 4825Defines the personalized lock information. 4826 4827**System API**: This is a system API. 4828 4829**System capability**: SystemCapability.Telephony.CoreService 4830 4831| Name | Type | Mandatory| Description | 4832| --------------- | ------ | ---- | --------------------- | 4833| result | number | Yes | Operation result. | 4834| remain | number | No | Remaining attempts (can be null).| 4835 4836## LockInfo<sup>8+</sup> 4837 4838Defines the personalized lock information. 4839 4840**System API**: This is a system API. 4841 4842**System capability**: SystemCapability.Telephony.CoreService 4843 4844| Name | Type | Mandatory| Description | 4845| -------- | ------------------------ | ---- | -------- | 4846| lockType | [LockType](#locktype8) | Yes | Lock type.| 4847| password | string | Yes | Password. | 4848| state | [LockState](#lockstate8) | Yes | Lock state.| 4849 4850## PersoLockInfo<sup>8+</sup> 4851 4852Defines the personalized lock information. 4853 4854**System API**: This is a system API. 4855 4856**System capability**: SystemCapability.Telephony.CoreService 4857 4858| Name | Type | Mandatory| Description | 4859| -------- | -------------------------------- | ---- | ------------- | 4860| lockType | [PersoLockType](#persolocktype8) | Yes | Personalized lock type.| 4861| password | string | Yes | Password. | 4862 4863## IccAccountInfo<sup>10+</sup> 4864 4865ICC account information. 4866 4867**System capability**: SystemCapability.Telephony.CoreService 4868 4869| Name | Type | Mandatory| Description | 4870| ---------- | ------- | ---- | ---------------- | 4871| simId | number | Yes | SIM card ID. | 4872| slotIndex | number | Yes | Card slot ID. | 4873| isEsim | boolean | Yes | Whether the SIM card is an eSim card.| 4874| isActive | boolean | Yes | Whether the card is activated. | 4875| iccId | string | Yes | ICCID number. | 4876| showName | string | Yes | SIM card display name. | 4877| showNumber | string | Yes | SIM card display number. | 4878 4879## OperatorConfig<sup>8+</sup> 4880 4881Defines the carrier configuration. 4882 4883**System API**: This is a system API. 4884 4885**System capability**: SystemCapability.Telephony.CoreService 4886 4887| Name | Type | Mandatory| Description| 4888| ----- | ------ | ---- | ---- | 4889| field | string | Yes | Field name.| 4890| value | string | Yes | Field value. | 4891 4892## DiallingNumbersInfo<sup>8+</sup> 4893 4894Defines the contact number information. 4895 4896**System API**: This is a system API. 4897 4898**System capability**: SystemCapability.Telephony.CoreService 4899 4900| Name | Type | Mandatory| Description | 4901| ------------ | ------ | ---- | ---------- | 4902| alphaTag | string | Yes | Tag. | 4903| number | string | Yes | Call transfer number. | 4904| recordNumber | number | No | Record number.| 4905| pin2 | string | No | PIN 2.| 4906 4907## ContactType<sup>8+</sup> 4908 4909Enumerates contact types. 4910 4911**System API**: This is a system API. 4912 4913**System capability**: SystemCapability.Telephony.CoreService 4914 4915| Name | Value | Description | 4916| --------------- | ---- | ---------- | 4917| GENERAL_CONTACT | 1 | Common contact number.| 4918| FIXED_DIALING | 2 | Fixed dialing number. | 4919 4920## OperatorConfigKey<sup>9+</sup> 4921 4922Enumerates carrier configuration keys. 4923 4924**System API**: This is a system API. 4925 4926**System capability**: SystemCapability.Telephony.CoreService 4927 4928| Name | Value | Description | 4929| ------------------------------------------------------- | ------------------------------------------------------ | -------------------- | 4930| KEY_VOICE_MAIL_NUMBER_STRING | "voice_mail_number_string" | Voice mailbox number. | 4931| KEY_IMS_SWITCH_ON_BY_DEFAULT_BOOL | "ims_switch_on_by_default_bool" | Fixed dialing number. | 4932| KEY_HIDE_IMS_SWITCH_BOOL | "hide_ims_switch_bool" | Whether to hide the IMS switch. | 4933| KEY_VOLTE_SUPPORTED_BOOL | "volte_supported_bool" | Whether to support VoLTE. | 4934| KEY_NR_MODE_SUPPORTED_LIST_INT_ARRAY | "nr_mode_supported_list_int_array" | List of supported NR modes. | 4935| KEY_VOLTE_PROVISIONING_SUPPORTED_BOOL | "volte_provisioning_supported_bool" | Whether to support VoLTE provisioning. | 4936| KEY_SS_OVER_UT_SUPPORTED_BOOL | "ss_over_ut_supported_bool" | Whether SS over UT is supported. | 4937| KEY_IMS_GBA_REQUIRED_BOOL | "ims_gba_required_bool" | Whether GBA is required for IMS. | 4938| KEY_UT_PROVISIONING_SUPPORTED_BOOL | "ut_provisioning_supported_bool" | Whether to support UT provisioning. | 4939| KEY_IMS_PREFER_FOR_EMERGENCY_BOOL | "ims_prefer_for_emergency_bool" | IMS preferences for emergency. | 4940| KEY_CALL_WAITING_SERVICE_CLASS_INT | "call_waiting_service_class_int" | Call waiting service. | 4941| KEY_CALL_TRANSFER_VISIBILITY_BOOL | "call_transfer_visibility_bool" | Call transfer visibility. | 4942| KEY_IMS_CALL_DISCONNECT_REASON_INFO_MAPPING_STRING_ARRAY| "ims_call_disconnect_reason_info_mapping_string_array" | List of IMS call disconnection reasons.| 4943| KEY_FORCE_VOLTE_SWITCH_ON_BOOL | "force_volte_switch_on_bool" | Whether to forcibly turn on VoLTE. | 4944| KEY_ENABLE_OPERATOR_NAME_CUST_BOOL | "enable_operator_name_cust_bool" | Whether to display the carrier name.| 4945| KEY_OPERATOR_NAME_CUST_STRING | "operator_name_cust_string" | Carrier name. | 4946| KEY_SPN_DISPLAY_CONDITION_CUST_INT | "spn_display_condition_cust_int" | SPN display rule. | 4947| KEY_PNN_CUST_STRING_ARRAY | "pnn_cust_string_array" | PLMN name | 4948| KEY_OPL_CUST_STRING_ARRAY | "opl_cust_string_array" | PLMN information of the carrier. | 4949| KEY_EMERGENCY_CALL_STRING_ARRAY | "emergency_call_string_array" | Emergency call list. | 4950 4951## DsdsMode<sup>11+</sup> 4952 4953Enumerates DSDS modes supported by the device. 4954 4955**System API**: This is a system API. 4956 4957**System capability**: SystemCapability.Telephony.CoreService 4958 4959| Name | Value | Description | 4960| -------------------| ---- | -------------------------- | 4961| DSDS_MODE_V2 | 0 | DSDS 2.0 mode. | 4962| DSDS_MODE_V3 | 1 | DSDS 3.0 mode. | 4963| DSDS_MODE_V5_TDM | 2 | DSDS 5.0 TDM mode. | 4964| DSDS_MODE_V5_DSDA | 3 | DSDS 5.0 DSDA mode.| 4965 4966## OperatorSimCard<sup>11+</sup> 4967 4968Carrier name. 4969 4970**System API**: This is a system API. 4971 4972**System capability**: SystemCapability.Telephony.CoreService 4973 4974| Name | Value | Description | 4975| ------------------ | --------------------- | -------- | 4976| CHINA_TELECOM_CARD | "china_telecom_card" | SIM card of China Telecom.| 4977