1# @ohos.telephony.sim (SIM Management) 2 3The **sim** module provides basic SIM card management functions. With the APIs provided by this module, you can obtain the ISO country code, home PLMN ID, service provider name, SIM card status, type, installation status, and activation status of the SIM card in the specified slot. 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 '@kit.TelephonyKit'; 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 '@kit.BasicServicesKit'; 35import { sim } from '@kit.TelephonyKit'; 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 '@kit.BasicServicesKit'; 67import { sim } from '@kit.TelephonyKit'; 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 '@kit.TelephonyKit'; 100 101let isSimActive: boolean = sim.isSimActiveSync(0); 102console.log(`the sim is active:` + isSimActive); 103``` 104 105 106## sim.getDefaultVoiceSlotId<sup>7+</sup> 107 108getDefaultVoiceSlotId\(callback: AsyncCallback\<number\>\): void 109 110Obtains the default slot ID of the SIM card that provides voice services. This API uses an asynchronous callback to return the result. 111 112**System capability**: SystemCapability.Telephony.CoreService 113 114**Parameters** 115 116| Name | Type | Mandatory| Description | 117| -------- | --------------------------- | ---- | ---------- | 118| 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| 119 120**Example** 121 122```ts 123import { BusinessError } from '@kit.BasicServicesKit'; 124import { sim } from '@kit.TelephonyKit'; 125 126sim.getDefaultVoiceSlotId((err: BusinessError, data: number) => { 127 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 128}); 129``` 130 131## sim.getDefaultVoiceSlotId<sup>7+</sup> 132 133getDefaultVoiceSlotId\(\): Promise\<number\> 134 135Obtains the default slot ID of the SIM card that provides voice services. This API uses a promise to return the result. 136 137**System capability**: SystemCapability.Telephony.CoreService 138 139**Return value** 140 141| Type | Description | 142| ----------------- | --------------------------------------- | 143| 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| 144 145**Example** 146 147```ts 148import { BusinessError } from '@kit.BasicServicesKit'; 149import { sim } from '@kit.TelephonyKit'; 150 151sim.getDefaultVoiceSlotId().then((data: number) => { 152 console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`); 153}).catch((err: BusinessError) => { 154 console.error(`getDefaultVoiceSlotId failed, promise: err->${JSON.stringify(err)}`); 155}); 156``` 157 158## sim.hasOperatorPrivileges<sup>7+</sup> 159 160hasOperatorPrivileges\(slotId: number, callback: AsyncCallback\<boolean\>\): void 161 162Checks whether the application (caller) has been granted the operator permission. This API uses an asynchronous callback to return the result. 163 164**System capability**: SystemCapability.Telephony.CoreService 165 166**Parameters** 167 168| Name | Type | Mandatory| Description | 169| -------- | ------------------------ | ---- | ---------------------------------------- | 170| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 171| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result. | 172 173**Error codes** 174 175For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 176 177| ID| Error Message | 178| -------- | -------------------------------------------- | 179| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 180| 8300001 | Invalid parameter value. | 181| 8300002 | Service connection failed. | 182| 8300003 | System internal error. | 183| 8300999 | Unknown error. | 184 185**Example** 186 187```ts 188import { BusinessError } from '@kit.BasicServicesKit'; 189import { sim } from '@kit.TelephonyKit'; 190 191sim.hasOperatorPrivileges(0, (err: BusinessError, data: boolean) => { 192 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 193}); 194``` 195 196## sim.hasOperatorPrivileges<sup>7+</sup> 197 198hasOperatorPrivileges\(slotId: number\): Promise\<boolean\> 199 200Checks whether the application (caller) has been granted the operator permission. This API uses a promise to return the result. 201 202**System capability**: SystemCapability.Telephony.CoreService 203 204**Parameters** 205 206| Name| Type | Mandatory| Description | 207| ------ | ------ | ---- | ---------------------------------------- | 208| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 209 210**Return value** 211 212| Type | Description | 213| :----------------- | :---------------------------------------------------------- | 214| 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.| 215 216**Error codes** 217 218For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 219 220| ID| Error Message | 221| -------- | -------------------------------------------- | 222| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 223| 8300001 | Invalid parameter value. | 224| 8300002 | Service connection failed. | 225| 8300003 | System internal error. | 226| 8300999 | Unknown error. | 227 228**Example** 229 230```ts 231import { BusinessError } from '@kit.BasicServicesKit'; 232import { sim } from '@kit.TelephonyKit'; 233 234sim.hasOperatorPrivileges(0).then((data: boolean) => { 235 console.log(`hasOperatorPrivileges success, promise: data->${JSON.stringify(data)}`); 236}).catch((err: BusinessError) => { 237 console.error(`hasOperatorPrivileges failed, promise: err->${JSON.stringify(err)}`); 238}); 239``` 240 241## sim.getISOCountryCodeForSim 242 243getISOCountryCodeForSim\(slotId: number, callback: AsyncCallback\<string\>\): void 244 245Obtains the ISO country code of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 246 247**System capability**: SystemCapability.Telephony.CoreService 248 249**Parameters** 250 251| Name | Type | Mandatory| Description | 252| -------- | ----------------------- | ---- | ---------------------------------------- | 253| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | 254| callback | AsyncCallback\<string\> | Yes | Callback used to return the result, which is an ISO country code, for example, **CN** (China).| 255 256**Error codes** 257 258For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 259 260| ID| Error Message | 261| -------- | -------------------------------------------- | 262| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 263| 8300001 | Invalid parameter value. | 264| 8300002 | Service connection failed. | 265| 8300003 | System internal error. | 266| 8300004 | No SIM card found. | 267| 8300999 | Unknown error. | 268 269**Example** 270 271```ts 272import { BusinessError } from '@kit.BasicServicesKit'; 273import { sim } from '@kit.TelephonyKit'; 274 275sim.getISOCountryCodeForSim(0, (err: BusinessError, data: string) => { 276 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 277}); 278``` 279 280 281## sim.getISOCountryCodeForSim 282 283getISOCountryCodeForSim\(slotId: number\): Promise\<string\> 284 285Obtains the ISO country code of the SIM card in the specified slot. This API uses a promise to return the result. 286 287**System capability**: SystemCapability.Telephony.CoreService 288 289**Parameters** 290 291| Name| Type | Mandatory| Description | 292| ------ | ------ | ---- | -------------------------------------- | 293| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 294 295**Return value** 296 297| Type | Description | 298| ----------------- | ------------------------------------------------------------ | 299| Promise\<string\> | Promise used to return the result, which is an ISO country code, for example, **CN** (China).| 300 301**Error codes** 302 303For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 304 305| ID| Error Message | 306| -------- | -------------------------------------------- | 307| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 308| 8300001 | Invalid parameter value. | 309| 8300002 | Service connection failed. | 310| 8300003 | System internal error. | 311| 8300004 | No SIM card found. | 312| 8300999 | Unknown error. | 313 314**Example** 315 316```ts 317import { BusinessError } from '@kit.BasicServicesKit'; 318import { sim } from '@kit.TelephonyKit'; 319 320sim.getISOCountryCodeForSim(0).then((data: string) => { 321 console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`); 322}).catch((err: BusinessError) => { 323 console.error(`getISOCountryCodeForSim failed, promise: err->${JSON.stringify(err)}`); 324}); 325``` 326 327## sim.getISOCountryCodeForSimSync<sup>10+</sup> 328 329getISOCountryCodeForSimSync\(slotId: number\): string 330 331Obtains the ISO country code of the SIM card in the specified slot. 332 333**System capability**: SystemCapability.Telephony.CoreService 334 335**Parameters** 336 337| Name| Type | Mandatory| Description | 338| ------ | ------ | ---- | -------------------------------------- | 339| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 340 341**Return value** 342 343| Type | Description | 344| ----------------- | ------------------------------------------------------------ | 345| string | ISO country code of the SIM card in the specified slot, for example, **CN** (China).| 346 347 348**Example** 349 350```ts 351import { sim } from '@kit.TelephonyKit'; 352 353let countryCode: string = sim.getISOCountryCodeForSimSync(0); 354console.log(`the country ISO is:` + countryCode); 355``` 356 357 358## sim.getSimOperatorNumeric 359 360getSimOperatorNumeric\(slotId: number, callback: AsyncCallback\<string\>\): void 361 362Obtains 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. 363 364**System capability**: SystemCapability.Telephony.CoreService 365 366**Parameters** 367 368| Name | Type | Mandatory| Description | 369| -------- | ----------------------- | ---- | -------------------------------------- | 370| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 371| callback | AsyncCallback\<string\> | Yes | Callback used to return the result. | 372 373**Error codes** 374 375For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 376 377| ID| Error Message | 378| -------- | -------------------------------------------- | 379| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 380| 8300001 | Invalid parameter value. | 381| 8300002 | Service connection failed. | 382| 8300003 | System internal error. | 383| 8300004 | No SIM card found. | 384| 8300999 | Unknown error. | 385 386**Example** 387 388```ts 389import { BusinessError } from '@kit.BasicServicesKit'; 390import { sim } from '@kit.TelephonyKit'; 391 392sim.getSimOperatorNumeric(0, (err: BusinessError, data: string) => { 393 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 394}); 395``` 396 397 398## sim.getSimOperatorNumeric 399 400getSimOperatorNumeric\(slotId: number\): Promise\<string\> 401 402Obtains the home PLMN ID of the SIM card in the specified slot. This API uses a promise to return the result. 403 404**System capability**: SystemCapability.Telephony.CoreService 405 406**Parameters** 407 408| Name| Type | Mandatory| Description | 409| ------ | ------ | ---- | -------------------------------------- | 410| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 411 412**Return value** 413 414| Type | Description | 415| ----------------- | ------------------------------------------------ | 416| Promise\<string\> | Promise used to return the result.| 417 418**Error codes** 419 420For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 421 422| ID| Error Message | 423| -------- | -------------------------------------------- | 424| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 425| 8300001 | Invalid parameter value. | 426| 8300002 | Service connection failed. | 427| 8300003 | System internal error. | 428| 8300004 | No SIM card found. | 429| 8300999 | Unknown error. | 430 431**Example** 432 433```ts 434import { BusinessError } from '@kit.BasicServicesKit'; 435import { sim } from '@kit.TelephonyKit'; 436 437sim.getSimOperatorNumeric(0).then((data: string) => { 438 console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`); 439}).catch((err: BusinessError) => { 440 console.error(`getSimOperatorNumeric failed, promise: err->${JSON.stringify(err)}`); 441}); 442``` 443 444## sim.getSimOperatorNumericSync<sup>10+</sup> 445 446getSimOperatorNumericSync\(slotId: number\): string 447 448Obtains the home PLMN ID of the SIM card in the specified slot. 449 450**System capability**: SystemCapability.Telephony.CoreService 451 452**Parameters** 453 454| Name| Type | Mandatory| Description | 455| ------ | ------ | ---- | -------------------------------------- | 456| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 457 458**Return value** 459 460| Type | Description | 461| ----------------- | ------------------------------------------------ | 462| string | Home PLMN number of the SIM card in the specified slot.| 463 464 465**Example** 466 467```ts 468import { sim } from '@kit.TelephonyKit'; 469 470let numeric: string = sim.getSimOperatorNumericSync(0); 471console.log(`the sim operator numeric is:` + numeric); 472``` 473 474 475## sim.getSimSpn 476 477getSimSpn\(slotId: number, callback: AsyncCallback\<string\>\): void 478 479Obtains the service provider name (SPN) of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 480 481**System capability**: SystemCapability.Telephony.CoreService 482 483**Parameters** 484 485| Name | Type | Mandatory| Description | 486| -------- | ----------------------- | ---- | -------------------------------------- | 487| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 488| callback | AsyncCallback\<string\> | Yes | Callback used to return the result. | 489 490**Error codes** 491 492For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 493 494| ID| Error Message | 495| -------- | -------------------------------------------- | 496| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 497| 8300001 | Invalid parameter value. | 498| 8300002 | Service connection failed. | 499| 8300003 | System internal error. | 500| 8300004 | No SIM card found. | 501| 8300999 | Unknown error. | 502 503**Example** 504 505```ts 506import { BusinessError } from '@kit.BasicServicesKit'; 507import { sim } from '@kit.TelephonyKit'; 508 509sim.getSimSpn(0, (err: BusinessError, data: string) => { 510 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 511}); 512``` 513 514 515## sim.getSimSpn 516 517getSimSpn\(slotId: number\): Promise\<string\> 518 519Obtains the SPN of the SIM card in the specified slot. This API uses a promise to return the result. 520 521**System capability**: SystemCapability.Telephony.CoreService 522 523**Parameters** 524 525| Name| Type | Mandatory| Description | 526| ------ | ------ | ---- | -------------------------------------- | 527| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 528 529**Return value** 530 531| Type | Description | 532| ----------------- | ----------------------------------------- | 533| Promise\<string\> | Promise used to return the result.| 534 535**Error codes** 536 537For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 538 539| ID| Error Message | 540| -------- | -------------------------------------------- | 541| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 542| 8300001 | Invalid parameter value. | 543| 8300002 | Service connection failed. | 544| 8300003 | System internal error. | 545| 8300004 | No SIM card found. | 546| 8300999 | Unknown error. | 547 548**Example** 549 550```ts 551import { BusinessError } from '@kit.BasicServicesKit'; 552import { sim } from '@kit.TelephonyKit'; 553 554sim.getSimSpn(0).then((data: string) => { 555 console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`); 556}).catch((err: BusinessError) => { 557 console.error(`getSimSpn failed, promise: err->${JSON.stringify(err)}`); 558}); 559``` 560 561## sim.getSimSpnSync<sup>10+</sup> 562 563getSimSpnSync\(slotId: number\): string 564 565Obtains the SPN of the SIM card in the specified slot. 566 567**System capability**: SystemCapability.Telephony.CoreService 568 569**Parameters** 570 571| Name| Type | Mandatory| Description | 572| ------ | ------ | ---- | -------------------------------------- | 573| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 574 575**Return value** 576 577| Type | Description | 578| ----------------- | ----------------------------------------- | 579| string | SPN of the SIM card in the specified slot.| 580 581 582**Example** 583 584```ts 585import { sim } from '@kit.TelephonyKit'; 586 587let spn: string = sim.getSimSpnSync(0); 588console.log(`the sim card spn is:` + spn); 589``` 590 591 592## sim.getSimState 593 594getSimState\(slotId: number, callback: AsyncCallback\<SimState\>\): void 595 596Obtains the state of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 597 598**System capability**: SystemCapability.Telephony.CoreService 599 600**Parameters** 601 602| Name | Type | Mandatory| Description | 603| -------- | -------------------------------------- | ---- | -------------------------------------- | 604| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 605| callback | AsyncCallback\<[SimState](#simstate)\> | Yes | Callback used to return the result. For details, see [SimState](#simstate). | 606 607**Error codes** 608 609For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 610 611| ID| Error Message | 612| -------- | -------------------------------------------- | 613| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 614| 8300001 | Invalid parameter value. | 615| 8300002 | Service connection failed. | 616| 8300003 | System internal error. | 617| 8300999 | Unknown error. | 618 619**Example** 620 621```ts 622import { BusinessError } from '@kit.BasicServicesKit'; 623import { sim } from '@kit.TelephonyKit'; 624 625sim.getSimState(0, (err: BusinessError, data: sim.SimState) => { 626 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 627}); 628``` 629 630 631## sim.getSimState 632 633getSimState\(slotId: number\): Promise\<SimState\> 634 635Obtains the state of the SIM card in the specified slot. This API uses a promise to return the result. 636 637**System capability**: SystemCapability.Telephony.CoreService 638 639**Parameters** 640 641| Name| Type | Mandatory| Description | 642| ------ | ------ | ---- | -------------------------------------- | 643| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 644 645**Return value** 646 647| Type | Description | 648| -------------------------------- | ------------------------------------------ | 649| Promise\<[SimState](#simstate)\> | Promise used to return the result.| 650 651**Error codes** 652 653For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 654 655| ID| Error Message | 656| -------- | -------------------------------------------- | 657| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 658| 8300001 | Invalid parameter value. | 659| 8300002 | Service connection failed. | 660| 8300003 | System internal error. | 661| 8300999 | Unknown error. | 662 663**Example** 664 665```ts 666import { BusinessError } from '@kit.BasicServicesKit'; 667import { sim } from '@kit.TelephonyKit'; 668 669sim.getSimState(0).then((data: sim.SimState) => { 670 console.log(`getSimState success, promise: data->${JSON.stringify(data)}`); 671}).catch((err: BusinessError) => { 672 console.error(`getSimState failed, promise: err->${JSON.stringify(err)}`); 673}); 674``` 675 676## sim.getSimStateSync<sup>10+</sup> 677 678getSimStateSync\(slotId: number\): SimState 679 680Obtains the state of the SIM card in the specified slot. 681 682**System capability**: SystemCapability.Telephony.CoreService 683 684**Parameters** 685 686| Name| Type | Mandatory| Description | 687| ------ | ------ | ---- | -------------------------------------- | 688| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 689 690**Return value** 691 692| Type | Description | 693| ---------------------------- | ------------------------------------------ | 694| [SimState](#simstate) | State of the SIM card in the specified slot.| 695 696 697**Example** 698 699```ts 700import { sim } from '@kit.TelephonyKit'; 701 702let simState: sim.SimState = sim.getSimStateSync(0); 703console.log(`The sim state is:` + simState); 704``` 705 706## sim.getCardType<sup>7+</sup> 707 708getCardType\(slotId: number, callback: AsyncCallback\<CardType\>\): void 709 710Obtains the type of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 711 712**System capability**: SystemCapability.Telephony.CoreService 713 714**Parameters** 715 716| Name | Type | Mandatory| Description | 717| -------- | ----------------------- | ---- | -------------------------------------- | 718| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 719| callback | AsyncCallback\<[CardType](#cardtype7)\> | Yes | Callback used to return the result. | 720 721**Error codes** 722 723For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 724 725| ID| Error Message | 726| -------- | -------------------------------------------- | 727| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 728| 8300001 | Invalid parameter value. | 729| 8300002 | Service connection failed. | 730| 8300003 | System internal error. | 731| 8300004 | No SIM card found. | 732| 8300999 | Unknown error. | 733 734**Example** 735 736```ts 737import { BusinessError } from '@kit.BasicServicesKit'; 738import { sim } from '@kit.TelephonyKit'; 739 740sim.getCardType(0, (err: BusinessError, data: sim.CardType) => { 741 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 742}); 743``` 744 745 746## sim.getCardType<sup>7+</sup> 747 748getCardType\(slotId: number\): Promise\<CardType\> 749 750Obtains the type of the SIM card in the specified slot. This API uses a promise to return the result. 751 752**System capability**: SystemCapability.Telephony.CoreService 753 754**Parameters** 755 756| Name| Type | Mandatory| Description | 757| ------ | ------ | ---- | -------------------------------------- | 758| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 759 760**Return value** 761 762| Type | Description | 763| ----------------- | ------------------------------------------------------------ | 764| Promise\<[CardType](#cardtype7)\> | Promise used to return the result.| 765 766**Error codes** 767 768For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 769 770| ID| Error Message | 771| -------- | -------------------------------------------- | 772| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 773| 8300001 | Invalid parameter value. | 774| 8300002 | Service connection failed. | 775| 8300003 | System internal error. | 776| 8300004 | No SIM card found. | 777| 8300999 | Unknown error. | 778 779**Example** 780 781```ts 782import { BusinessError } from '@kit.BasicServicesKit'; 783import { sim } from '@kit.TelephonyKit'; 784 785sim.getCardType(0).then((data: sim.CardType) => { 786 console.log(`getCardType success, promise: data->${JSON.stringify(data)}`); 787}).catch((err: BusinessError) => { 788 console.error(`getCardType failed, promise: err->${JSON.stringify(err)}`); 789}); 790``` 791 792## sim.getCardTypeSync<sup>10+</sup> 793 794getCardTypeSync\(slotId: number\): CardType 795 796Obtains the type of the SIM card in the specified slot. 797 798**System capability**: SystemCapability.Telephony.CoreService 799 800**Parameters** 801 802| Name| Type | Mandatory| Description | 803| ------ | ------ | ---- | -------------------------------------- | 804| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 805 806**Return value** 807 808| Type | Description | 809| ----------------- | ------------------------------------------------------------ | 810| [CardType](#cardtype7) | Type of the SIM card in the specified slot.| 811 812 813**Example** 814 815```ts 816import { sim } from '@kit.TelephonyKit'; 817 818let cardType: sim.CardType = sim.getCardTypeSync(0); 819console.log(`the card type is:` + cardType); 820``` 821 822 823## sim.hasSimCard<sup>7+</sup> 824 825hasSimCard\(slotId: number, callback: AsyncCallback\<boolean\>\): void 826 827Checks whether the SIM card in the specified slot is installed. This API uses an asynchronous callback to return the result. 828 829**System capability**: SystemCapability.Telephony.CoreService 830 831**Parameters** 832 833| Name | Type | Mandatory| Description | 834| -------- | --------------------------- | ---- | -------------------------------------- | 835| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 836| 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. | 837 838**Error codes** 839 840For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 841 842| ID| Error Message | 843| -------- | -------------------------------------------- | 844| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 845| 8300001 | Invalid parameter value. | 846| 8300002 | Service connection failed. | 847| 8300003 | System internal error. | 848| 8300999 | Unknown error. | 849 850**Example** 851 852```ts 853import { BusinessError } from '@kit.BasicServicesKit'; 854import { sim } from '@kit.TelephonyKit'; 855 856sim.hasSimCard(0, (err: BusinessError, data: boolean) => { 857 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 858}); 859``` 860 861 862## sim.hasSimCard<sup>7+</sup> 863 864hasSimCard\(slotId: number\): Promise\<boolean\> 865 866Checks whether the SIM card in the specified slot is installed. This API uses a promise to return the result. 867 868**System capability**: SystemCapability.Telephony.CoreService 869 870**Parameters** 871 872| Name| Type | Mandatory| Description | 873| ------ | ------ | ---- | -------------------------------------- | 874| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 875 876**Return value** 877 878| Type | Description | 879| --------------------- | ---------------------------------- | 880| 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.| 881 882**Error codes** 883 884For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 885 886| ID| Error Message | 887| -------- | -------------------------------------------- | 888| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 889| 8300001 | Invalid parameter value. | 890| 8300002 | Service connection failed. | 891| 8300003 | System internal error. | 892| 8300999 | Unknown error. | 893 894**Example** 895 896```ts 897import { BusinessError } from '@kit.BasicServicesKit'; 898import { sim } from '@kit.TelephonyKit'; 899 900sim.hasSimCard(0).then((data: boolean) => { 901 console.log(`hasSimCard success, promise: data->${JSON.stringify(data)}`); 902}).catch((err: BusinessError) => { 903 console.error(`hasSimCard failed, promise: err->${JSON.stringify(err)}`); 904}); 905``` 906 907## sim.hasSimCardSync<sup>10+</sup> 908 909hasSimCardSync\(slotId: number\): boolean 910 911Checks whether the SIM card in the specified slot is installed. 912 913**System capability**: SystemCapability.Telephony.CoreService 914 915**Parameters** 916 917| Name| Type | Mandatory| Description | 918| ------ | ------ | ---- | -------------------------------------- | 919| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 920 921**Return value** 922 923| Type | Description | 924| --------------------- | ---------------------------------- | 925| 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.| 926 927**Example** 928 929```ts 930import { sim } from '@kit.TelephonyKit'; 931 932let hasSimCard: boolean = sim.hasSimCardSync(0); 933console.log(`has sim card: ` + hasSimCard); 934``` 935 936## sim.getSimAccountInfo<sup>10+</sup> 937 938getSimAccountInfo\(slotId: number, callback: AsyncCallback\<IccAccountInfo\>\): void 939 940Obtains account information of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 941 942**Required permission**: ohos.permission.GET_TELEPHONY_STATE 943 944>**NOTE** 945> 946>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. 947 948**System capability**: SystemCapability.Telephony.CoreService 949 950**Parameters** 951 952| Name | Type | Mandatory| Description | 953| -------- | --------------------------------------------------- | ---- | -------------------------------------- | 954| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 955| callback | AsyncCallback<[IccAccountInfo](#iccaccountinfo10)> | Yes | Callback used to return the result. | 956 957**Error codes** 958 959For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 960 961| ID| Error Message | 962| -------- | -------------------------------------------- | 963| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 964| 8300001 | Invalid parameter value. | 965| 8300002 | Service connection failed. | 966| 8300003 | System internal error. | 967| 8300004 | No SIM card found. | 968| 8300999 | Unknown error. | 969| 8301002 | The SIM card failed to read or update data. | 970 971**Example** 972 973```ts 974import { BusinessError } from '@kit.BasicServicesKit'; 975import { sim } from '@kit.TelephonyKit'; 976 977sim.getSimAccountInfo(0, (err:BusinessError , data: sim.IccAccountInfo) => { 978 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 979}); 980``` 981 982 983## sim.getSimAccountInfo<sup>10+</sup> 984 985getSimAccountInfo\(slotId: number\): Promise\<IccAccountInfo\> 986 987Obtains account information of the SIM card in the specified slot. This API uses a promise to return the result. 988 989**Required permission**: ohos.permission.GET_TELEPHONY_STATE 990 991>**NOTE** 992> 993>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. 994 995**System capability**: SystemCapability.Telephony.CoreService 996 997**Parameters** 998 999| Name| Type | Mandatory| Description | 1000| ------ | ------ | ---- | -------------------------------------- | 1001| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1002 1003**Return value** 1004 1005| Type | Description | 1006| -------------------------------------------- | ------------------------------------------ | 1007| Promise<[IccAccountInfo](#iccaccountinfo10)> | Promise used to return the result.| 1008 1009**Error codes** 1010 1011For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 1012 1013| ID| Error Message | 1014| -------- | -------------------------------------------- | 1015| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1016| 8300001 | Invalid parameter value. | 1017| 8300002 | Service connection failed. | 1018| 8300003 | System internal error. | 1019| 8300004 | No SIM card found. | 1020| 8300999 | Unknown error. | 1021| 8301002 | The SIM card failed to read or update data. | 1022 1023**Example** 1024 1025```ts 1026import { BusinessError } from '@kit.BasicServicesKit'; 1027import { sim } from '@kit.TelephonyKit'; 1028 1029sim.getSimAccountInfo(0).then((data: sim.IccAccountInfo) => { 1030 console.log(`getSimAccountInfo success, promise: data->${JSON.stringify(data)}`); 1031}).catch((err: BusinessError) => { 1032 console.error(`getSimAccountInfo failed, promise: err->${JSON.stringify(err)}`); 1033}); 1034``` 1035 1036## sim.getActiveSimAccountInfoList<sup>10+</sup> 1037 1038getActiveSimAccountInfoList\(callback: AsyncCallback\<Array\<IccAccountInfo\>\>\): void 1039 1040Obtains the list of activated SIM card accounts. This API uses an asynchronous callback to return the result. 1041 1042**Required permission**: ohos.permission.GET_TELEPHONY_STATE 1043 1044>**NOTE** 1045> 1046>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. 1047 1048**System capability**: SystemCapability.Telephony.CoreService 1049 1050**Parameters** 1051 1052| Name | Type | Mandatory| Description | 1053| -------- | ----------------------------------------------------------- | ---- | ---------- | 1054| callback | AsyncCallback<Array<[IccAccountInfo](#iccaccountinfo10)>> | Yes | Callback used to return the result. | 1055 1056**Error codes** 1057 1058For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 1059 1060| ID| Error Message | 1061| -------- | -------------------------------------------- | 1062| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1063| 8300001 | Invalid parameter value. | 1064| 8300002 | Service connection failed. | 1065| 8300003 | System internal error. | 1066| 8300004 | No SIM card found. | 1067| 8300999 | Unknown error. | 1068 1069**Example** 1070 1071```ts 1072import { BusinessError } from '@kit.BasicServicesKit'; 1073import { sim } from '@kit.TelephonyKit'; 1074 1075sim.getActiveSimAccountInfoList((err: BusinessError, data: Array<sim.IccAccountInfo>) => { 1076 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 1077}); 1078``` 1079 1080## sim.getMaxSimCount<sup>7+</sup> 1081 1082getMaxSimCount\(\): number 1083 1084Obtains the number of card slots. 1085 1086**System capability**: SystemCapability.Telephony.CoreService 1087 1088**Return value** 1089 1090| Type | Description | 1091| ----------------- | ------------------------------------------------------------ | 1092| number | Number of card slots.| 1093 1094**Example** 1095 1096```ts 1097import { sim } from '@kit.TelephonyKit'; 1098 1099console.log("Result: "+ sim.getMaxSimCount()); 1100``` 1101 1102 1103## sim.getActiveSimAccountInfoList<sup>10+</sup> 1104 1105getActiveSimAccountInfoList\(\): Promise\<Array\<IccAccountInfo\>\> 1106 1107Obtains the list of activated SIM card accounts. This API uses a promise to return the result. 1108 1109**Required permission**: ohos.permission.GET_TELEPHONY_STATE 1110 1111>**NOTE** 1112> 1113>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. 1114 1115**System capability**: SystemCapability.Telephony.CoreService 1116 1117**Return value** 1118 1119| Type | Description | 1120| ---------------------------------------------------- | ---------------------------------------------- | 1121| Promise<Array<[IccAccountInfo](#iccaccountinfo10)>> | Promise used to return the result.| 1122 1123**Error codes** 1124 1125For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 1126 1127| ID| Error Message | 1128| -------- | -------------------------------------------- | 1129| 8300002 | Service connection failed. | 1130| 8300003 | System internal error. | 1131| 8300004 | No SIM card found. | 1132| 8300999 | Unknown error. | 1133 1134**Example** 1135 1136```ts 1137import { BusinessError } from '@kit.BasicServicesKit'; 1138import { sim } from '@kit.TelephonyKit'; 1139 1140sim.getActiveSimAccountInfoList().then((data: Array<sim.IccAccountInfo>) => { 1141 console.log(`getActiveSimAccountInfoList success, promise: data->${JSON.stringify(data)}`); 1142}).catch((err: BusinessError) => { 1143 console.error(`getActiveSimAccountInfoList failed, promise: err->${JSON.stringify(err)}`); 1144}); 1145``` 1146 1147 1148## sim.getOpKey<sup>9+</sup> 1149 1150getOpKey\(slotId: number, callback: AsyncCallback\<string\>): void 1151 1152Obtains the opkey of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 1153 1154**System capability**: SystemCapability.Telephony.CoreService 1155 1156**Parameters** 1157 1158| Name | Type | Mandatory| Description | 1159| -------- | ---------------------- | ---- | -------------------------------------- | 1160| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1161| callback | AsyncCallback<string\> | Yes | Callback used to return the result. | 1162 1163**Error codes** 1164 1165For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 1166 1167| ID| Error Message | 1168| -------- | -------------------------------------------- | 1169| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1170| 801 | Capability not supported. | 1171| 8300001 | Invalid parameter value. | 1172| 8300002 | Service connection failed. | 1173| 8300003 | System internal error. | 1174| 8300999 | Unknown error. | 1175 1176**Example** 1177 1178```ts 1179import { BusinessError } from '@kit.BasicServicesKit'; 1180import { sim } from '@kit.TelephonyKit'; 1181 1182try { 1183 sim.getOpKey(0, (err: BusinessError, data: string) => { 1184 if (err) { 1185 console.error("getOpKey failed, err: " + JSON.stringify(err)); 1186 } else { 1187 console.log('getOpKey successfully, data: ' + JSON.stringify(data)); 1188 } 1189 }); 1190} catch (err) { 1191 console.error("getOpKey err: " + JSON.stringify(err)); 1192} 1193``` 1194 1195 1196## sim.getOpKey<sup>9+</sup> 1197 1198getOpKey\(slotId: number\): Promise\<string\> 1199 1200Obtains the opkey of the SIM card in the specified slot. This API uses a promise to return the result. 1201 1202**System capability**: SystemCapability.Telephony.CoreService 1203 1204**Parameters** 1205 1206| Name| Type | Mandatory| Description | 1207| ------ | ------ | ---- | -------------------------------------- | 1208| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1209 1210**Return value** 1211 1212| Type | Description | 1213| ---------------- | ----------------------------------------- | 1214| Promise<string\> | Promise used to return the result.| 1215 1216**Error codes** 1217 1218For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 1219 1220| ID| Error Message | 1221| -------- | -------------------------------------------- | 1222| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1223| 801 | Capability not supported. | 1224| 8300001 | Invalid parameter value. | 1225| 8300002 | Service connection failed. | 1226| 8300003 | System internal error. | 1227| 8300999 | Unknown error. | 1228 1229**Example** 1230 1231```ts 1232import { BusinessError } from '@kit.BasicServicesKit'; 1233import { sim } from '@kit.TelephonyKit'; 1234 1235sim.getOpKey(0).then((data: string) => { 1236 console.log(`getOpKey success, promise: data->${JSON.stringify(data)}`); 1237}).catch((err: BusinessError) => { 1238 console.error(`getOpKey failed, promise: err->${JSON.stringify(err)}`); 1239}); 1240``` 1241 1242## sim.getOpKeySync<sup>10+</sup> 1243 1244getOpKeySync\(slotId: number\): string 1245 1246Obtains the opkey of the SIM card in the specified slot. 1247 1248**System capability**: SystemCapability.Telephony.CoreService 1249 1250**Parameters** 1251 1252| Name| Type | Mandatory| Description | 1253| ------ | ------ | ---- | -------------------------------------- | 1254| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1255 1256**Return value** 1257 1258| Type | Description | 1259| ---------------- | ----------------------------------------- | 1260| string | opkey of the SIM card in the specified slot.| 1261 1262 1263**Example** 1264 1265```ts 1266import { sim } from '@kit.TelephonyKit'; 1267 1268let data: string = sim.getOpKeySync(0); 1269console.log(`getOpKey success, promise: data->${JSON.stringify(data)}`); 1270``` 1271 1272## sim.getOpName<sup>9+</sup> 1273 1274getOpName\(slotId: number, callback: AsyncCallback\<string\>\): void 1275 1276Obtains the OpName of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 1277 1278**System capability**: SystemCapability.Telephony.CoreService 1279 1280**Parameters** 1281 1282| Name | Type | Mandatory| Description | 1283| -------- | ---------------------- | ---- | -------------------------------------- | 1284| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1285| callback | AsyncCallback<string\> | Yes | Callback used to return the result. | 1286 1287**Error codes** 1288 1289For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 1290 1291| ID| Error Message | 1292| -------- | -------------------------------------------- | 1293| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1294| 801 | Capability not supported. | 1295| 8300001 | Invalid parameter value. | 1296| 8300002 | Service connection failed. | 1297| 8300003 | System internal error. | 1298| 8300999 | Unknown error. | 1299 1300**Example** 1301 1302```ts 1303import { BusinessError } from '@kit.BasicServicesKit'; 1304import { sim } from '@kit.TelephonyKit'; 1305 1306try { 1307 sim.getOpName(0, (err: BusinessError, data: string) => { 1308 if (err) { 1309 console.error("getOpName failed, err: " + JSON.stringify(err)); 1310 } else { 1311 console.log('getOpName successfully, data: ' + JSON.stringify(data)); 1312 } 1313 }); 1314} catch (err) { 1315 console.error("getOpName err: " + JSON.stringify(err)); 1316} 1317``` 1318 1319 1320## sim.getOpName<sup>9+</sup> 1321 1322getOpName\(slotId: number\): Promise\<string\> 1323 1324Obtains the OpName of the SIM card in the specified slot. This API uses a promise to return the result. 1325 1326**System capability**: SystemCapability.Telephony.CoreService 1327 1328**Parameters** 1329 1330| Name| Type | Mandatory| Description | 1331| ------ | ------ | ---- | -------------------------------------- | 1332| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1333 1334**Return value** 1335 1336| Type | Description | 1337| ---------------- | ------------------------------------------ | 1338| Promise<string\> | Promise used to return the result.| 1339 1340**Error codes** 1341 1342For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 1343 1344| ID| Error Message | 1345| -------- | -------------------------------------------- | 1346| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1347| 801 | Capability not supported. | 1348| 8300001 | Invalid parameter value. | 1349| 8300002 | Service connection failed. | 1350| 8300003 | System internal error. | 1351| 8300999 | Unknown error. | 1352 1353**Example** 1354 1355```ts 1356import { BusinessError } from '@kit.BasicServicesKit'; 1357import { sim } from '@kit.TelephonyKit'; 1358 1359sim.getOpName(0).then((data: string) => { 1360 console.log(`getOpName success, promise: data->${JSON.stringify(data)}`); 1361}).catch((err: BusinessError) => { 1362 console.error(`getOpName failed, promise: err->${JSON.stringify(err)}`); 1363}); 1364``` 1365 1366## sim.getOpNameSync<sup>10+</sup> 1367 1368getOpNameSync\(slotId: number\): string 1369 1370Obtains the OpName of the SIM card in the specified slot. 1371 1372**System capability**: SystemCapability.Telephony.CoreService 1373 1374**Parameters** 1375 1376| Name| Type | Mandatory| Description | 1377| ------ | ------ | ---- | -------------------------------------- | 1378| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2| 1379 1380**Return value** 1381 1382| Type | Description | 1383| ---------------- | ------------------------------------------ | 1384| string | OpName of the SIM card in the specified slot.| 1385 1386 1387**Example** 1388 1389```ts 1390import { sim } from '@kit.TelephonyKit'; 1391 1392let data: string = sim.getOpNameSync(0); 1393console.log(`getOpName success, promise: data->${JSON.stringify(data)}`); 1394``` 1395 1396## sim.getDefaultVoiceSimId<sup>10+</sup> 1397 1398getDefaultVoiceSimId\(callback: AsyncCallback\<number\>\): void 1399 1400Obtains the default slot ID of the SIM card that provides voice services. This API uses an asynchronous callback to return the result. 1401 1402**System capability**: SystemCapability.Telephony.CoreService 1403 1404**Parameters** 1405 1406| Name | Type | Mandatory| Description | 1407| -------- | --------------------------- | ---- | ---------- | 1408| callback | AsyncCallback<number> | Yes | Callback used to return the result.<br>The return value is bound to the SIM card and increases from 1.| 1409 1410**Error codes** 1411 1412For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 1413 1414| ID| Error Message | 1415| -------- | -------------------------------------------- | 1416| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1417| 8300001 | Invalid parameter value. | 1418| 8300002 | Service connection failed. | 1419| 8300003 | System internal error. | 1420| 8300004 | No SIM card found. | 1421| 8300999 | Unknown error. | 1422| 8301001 | SIM card is not activated. | 1423 1424**Example** 1425 1426```ts 1427import { BusinessError } from '@kit.BasicServicesKit'; 1428import { sim } from '@kit.TelephonyKit'; 1429 1430sim.getDefaultVoiceSimId((err: BusinessError, data: number) => { 1431 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 1432}); 1433``` 1434 1435## sim.getDefaultVoiceSimId<sup>10+</sup> 1436 1437getDefaultVoiceSimId\(\): Promise\<number\> 1438 1439Obtains the default slot ID of the SIM card that provides voice services. This API uses a promise to return the result. 1440 1441**System capability**: SystemCapability.Telephony.CoreService 1442 1443**Return value** 1444 1445| Type | Description | 1446| ----------------- | --------------------------------------- | 1447| Promise\<number\> | Promise used to return the result.<br>The return value is bound to the SIM card and increases from 1.| 1448 1449**Error codes** 1450 1451For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 1452 1453| ID| Error Message | 1454| -------- | -------------------------------------------- | 1455| 8300001 | Invalid parameter value. | 1456| 8300002 | Service connection failed. | 1457| 8300003 | System internal error. | 1458| 8300004 | No SIM card found. | 1459| 8300999 | Unknown error. | 1460| 8301001 | SIM card is not activated. | 1461 1462**Example** 1463 1464```ts 1465import { BusinessError } from '@kit.BasicServicesKit'; 1466import { sim } from '@kit.TelephonyKit'; 1467 1468let promise = sim.getDefaultVoiceSimId(); 1469promise.then((data: number) => { 1470 console.log(`getDefaultVoiceSimId success, promise: data->${JSON.stringify(data)}`); 1471}).catch((err: BusinessError) => { 1472 console.error(`getDefaultVoiceSimId failed, promise: err->${JSON.stringify(err)}`); 1473}); 1474``` 1475 1476 1477## SimState 1478 1479Enumerates SIM card states. 1480 1481**System capability**: SystemCapability.Telephony.CoreService 1482 1483| Name | Value | Description | 1484| --------------------- | ---- | ---------------------------------------------------------- | 1485| SIM_STATE_UNKNOWN | 0 | The SIM card is in **unknown** state; that is, the SIM card status cannot be obtained. | 1486| SIM_STATE_NOT_PRESENT | 1 | The SIM card is in **not present** state; that is, no SIM card is inserted into the card slot. | 1487| 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. | 1488| 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. | 1489| SIM_STATE_READY | 4 | The SIM card is in **ready** state; that is, the SIM card has been installed and is working properly. | 1490| 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.| 1491 1492## CardType<sup>7+</sup> 1493 1494Enumerates SIM card types. 1495 1496**System capability**: SystemCapability.Telephony.CoreService 1497 1498| Name| Value| Description| 1499| ----- | ----- | ----- | 1500|UNKNOWN_CARD | -1 | Unknown type.| 1501|SINGLE_MODE_SIM_CARD | 10 | Single-card (SIM).| 1502|SINGLE_MODE_USIM_CARD | 20 | Single-card (USIM).| 1503|SINGLE_MODE_RUIM_CARD | 30 | Single-card (RUIM).| 1504|DUAL_MODE_CG_CARD | 40 | Dual-card (CDMA+GSM).| 1505|CT_NATIONAL_ROAMING_CARD | 41 | China Telecom internal roaming card.| 1506|CU_DUAL_MODE_CARD | 42 | China Unicom dual-mode card.| 1507|DUAL_MODE_TELECOM_LTE_CARD | 43 | China Telecom dual-mode LTE card.| 1508|DUAL_MODE_UG_CARD | 50 | Dual-mode card (UMTS+GSM).| 1509|SINGLE_MODE_ISIM_CARD<sup>8+</sup> | 60 | Single-card (ISIM).| 1510 1511## IccAccountInfo<sup>10+</sup> 1512 1513ICC account information. 1514 1515**System capability**: SystemCapability.Telephony.CoreService 1516 1517| Name | Type | Mandatory| Description | 1518| ---------- | ------- | ---- | ---------------- | 1519| simId | number | Yes | SIM card ID. | 1520| slotIndex | number | Yes | Card slot ID. | 1521| isEsim | boolean | Yes | Whether the SIM card is an eSim card.| 1522| isActive | boolean | Yes | Whether the card is activated. | 1523| iccId | string | Yes | ICCID number. | 1524| showName | string | Yes | SIM card display name. | 1525| showNumber | string | Yes | SIM card display number. | 1526