1# @ohos.telephony.sim (SIM卡管理) 2 3SIM卡管理模块提供了SIM卡管理的基础能力,包括获取指定卡槽SIM卡的ISO国家码、归属PLMN号、服务提供商名称、SIM卡状态、卡类型、是否插卡、是否激活等。 4 5>**说明:** 6> 7>本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9 10## 导入模块 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 20获取指定卡槽SIM卡是否激活。使用callback异步回调。 21 22**系统能力**:SystemCapability.Telephony.CoreService 23 24**参数:** 25 26| 参数名 | 类型 | 必填 | 说明 | 27| -------- | --------------------------- | ---- | -------------------------------------- | 28| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 29| callback | AsyncCallback<boolean> | 是 | 回调函数。返回指定卡槽是否激活,如果激活返回true。 | 30 31**示例:** 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 47获取指定卡槽SIM卡是否激活。使用Promise异步回调。 48 49**系统能力**:SystemCapability.Telephony.CoreService 50 51**参数:** 52 53| 参数名 | 类型 | 必填 | 说明 | 54| ------ | ------ | ---- | -------------------------------------- | 55| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 56 57**返回值:** 58 59| 类型 | 说明 | 60| --------------------- | ---------------------------------- | 61| Promise<boolean> | 以Promise形式返回指定卡槽是否激活,如果激活返回true。 | 62 63**示例:** 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 80获取指定卡槽SIM卡是否激活。 81 82**系统能力**:SystemCapability.Telephony.CoreService 83 84**参数:** 85 86| 参数名 | 类型 | 必填 | 说明 | 87| ------ | ------ | ---- | -------------------------------------- | 88| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 89 90**返回值:** 91 92| 类型 | 说明 | 93| --------------------- | ---------------------------------- | 94| boolean | 返回指定卡槽是否激活,如果激活返回true。 | 95 96**示例:** 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 110获取默认语音业务的卡槽ID。使用callback异步回调。 111 112**系统能力**:SystemCapability.Telephony.CoreService 113 114**参数:** 115 116| 参数名 | 类型 | 必填 | 说明 | 117| -------- | --------------------------- | ---- | ---------- | 118| callback | AsyncCallback<number> | 是 | 回调函数。<br />- 0:卡槽1<br />- 1:卡槽2<br />- -1:未设置或服务不可用 | 119 120**示例:** 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 135获取默认语音业务的卡槽ID。使用Promise异步回调。 136 137**系统能力**:SystemCapability.Telephony.CoreService 138 139**返回值:** 140 141| 类型 | 说明 | 142| ----------------- | --------------------------------------- | 143| Promise\<number\> | 以Promise形式返回默认语音业务的卡槽ID。<br />- 0:卡槽1<br />- 1:卡槽2<br />- -1:未设置或服务不可用 | 144 145**示例:** 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 162检查应用(调用者)是否已被授予运营商权限。使用callback异步回调。 163 164**系统能力**:SystemCapability.Telephony.CoreService 165 166**参数:** 167 168| 参数名 | 类型 | 必填 | 说明 | 169| -------- | ------------------------ | ---- | ---------------------------------------- | 170| slotId | number | 是 | 卡槽ID。<br />- 0:卡槽1<br />- 1:卡槽2 | 171| callback | AsyncCallback\<boolean\> | 是 | 回调函数。 返回检查应用(调用者)是否已被授予运营商权限。 | 172 173**错误码:** 174 175以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 176 177| 错误码ID | 错误信息 | 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**示例:** 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 200检查应用(调用者)是否已被授予运营商权限。使用Promise异步回调。 201 202**系统能力**:SystemCapability.Telephony.CoreService 203 204**参数:** 205 206| 参数名 | 类型 | 必填 | 说明 | 207| ------ | ------ | ---- | ---------------------------------------- | 208| slotId | number | 是 | 卡槽ID。<br />- 0:卡槽1<br />- 1:卡槽2 | 209 210**返回值:** 211 212| 类型 | 说明 | 213| :----------------- | :---------------------------------------------------------- | 214| Promise\<boolean\> | 以Promise形式返回检查应用(调用者)是否已被授予运营商权限。 | 215 216**错误码:** 217 218以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 219 220| 错误码ID | 错误信息 | 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**示例:** 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 245获取指定卡槽SIM卡的ISO国家码。使用callback异步回调。 246 247**系统能力**:SystemCapability.Telephony.CoreService 248 249**参数:** 250 251| 参数名 | 类型 | 必填 | 说明 | 252| -------- | ----------------------- | ---- | ---------------------------------------- | 253| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 254| callback | AsyncCallback\<string\> | 是 | 回调函数。返回国家码,例如:CN(中国)。 | 255 256**错误码:** 257 258以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 259 260| 错误码ID | 错误信息 | 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**示例:** 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 285获取指定卡槽SIM卡的ISO国家码。使用Promise异步回调。 286 287**系统能力**:SystemCapability.Telephony.CoreService 288 289**参数:** 290 291| 参数名 | 类型 | 必填 | 说明 | 292| ------ | ------ | ---- | -------------------------------------- | 293| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 294 295**返回值:** 296 297| 类型 | 说明 | 298| ----------------- | ------------------------------------------------------------ | 299| Promise\<string\> | 以Promise形式返回获取指定卡槽SIM卡的ISO国家码,例如:CN(中国)。 | 300 301**错误码:** 302 303以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 304 305| 错误码ID | 错误信息 | 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**示例:** 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 331获取指定卡槽SIM卡的ISO国家码。 332 333**系统能力**:SystemCapability.Telephony.CoreService 334 335**参数:** 336 337| 参数名 | 类型 | 必填 | 说明 | 338| ------ | ------ | ---- | -------------------------------------- | 339| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 340 341**返回值:** 342 343| 类型 | 说明 | 344| ----------------- | ------------------------------------------------------------ | 345| string | 返回获取指定卡槽SIM卡的ISO国家码,例如:CN(中国)。 | 346 347 348**示例:** 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 362获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号。使用callback异步回调。 363 364**系统能力**:SystemCapability.Telephony.CoreService 365 366**参数:** 367 368| 参数名 | 类型 | 必填 | 说明 | 369| -------- | ----------------------- | ---- | -------------------------------------- | 370| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 371| callback | AsyncCallback\<string\> | 是 | 回调函数。返回指定卡槽SIM卡的归属PLMN号。 | 372 373**错误码:** 374 375以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 376 377| 错误码ID | 错误信息 | 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**示例:** 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 402获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号。使用Promise异步回调。 403 404**系统能力**:SystemCapability.Telephony.CoreService 405 406**参数:** 407 408| 参数名 | 类型 | 必填 | 说明 | 409| ------ | ------ | ---- | -------------------------------------- | 410| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 411 412**返回值:** 413 414| 类型 | 说明 | 415| ----------------- | ------------------------------------------------ | 416| Promise\<string\> | 以Promise形式返回获取指定卡槽SIM卡的归属PLMN号。 | 417 418**错误码:** 419 420以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 421 422| 错误码ID | 错误信息 | 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**示例:** 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 448获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号。 449 450**系统能力**:SystemCapability.Telephony.CoreService 451 452**参数:** 453 454| 参数名 | 类型 | 必填 | 说明 | 455| ------ | ------ | ---- | -------------------------------------- | 456| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 457 458**返回值:** 459 460| 类型 | 说明 | 461| ----------------- | ------------------------------------------------ | 462| string | 返回获取指定卡槽SIM卡的归属PLMN号。 | 463 464 465**示例:** 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 479获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN)。使用callback异步回调。 480 481**系统能力**:SystemCapability.Telephony.CoreService 482 483**参数:** 484 485| 参数名 | 类型 | 必填 | 说明 | 486| -------- | ----------------------- | ---- | -------------------------------------- | 487| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 488| callback | AsyncCallback\<string\> | 是 | 回调函数。返回指定卡槽SIM卡的SPN。 | 489 490**错误码:** 491 492以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 493 494| 错误码ID | 错误信息 | 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**示例:** 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 519获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN)。使用Promise异步回调。 520 521**系统能力**:SystemCapability.Telephony.CoreService 522 523**参数:** 524 525| 参数名 | 类型 | 必填 | 说明 | 526| ------ | ------ | ---- | -------------------------------------- | 527| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 528 529**返回值:** 530 531| 类型 | 说明 | 532| ----------------- | ----------------------------------------- | 533| Promise\<string\> | 以Promise形式返回获取指定卡槽SIM卡的SPN。 | 534 535**错误码:** 536 537以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 538 539| 错误码ID | 错误信息 | 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**示例:** 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 565获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN)。 566 567**系统能力**:SystemCapability.Telephony.CoreService 568 569**参数:** 570 571| 参数名 | 类型 | 必填 | 说明 | 572| ------ | ------ | ---- | -------------------------------------- | 573| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 574 575**返回值:** 576 577| 类型 | 说明 | 578| ----------------- | ----------------------------------------- | 579| string | 返回获取指定卡槽SIM卡的SPN。 | 580 581 582**示例:** 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 596获取指定卡槽的SIM卡状态。使用callback异步回调。 597 598**系统能力**:SystemCapability.Telephony.CoreService 599 600**参数:** 601 602| 参数名 | 类型 | 必填 | 说明 | 603| -------- | -------------------------------------- | ---- | -------------------------------------- | 604| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 605| callback | AsyncCallback\<[SimState](#simstate)\> | 是 | 回调函数。参考[SimState](#simstate)。 | 606 607**错误码:** 608 609以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 610 611| 错误码ID | 错误信息 | 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**示例:** 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 635获取指定卡槽的SIM卡状态。使用Promise异步回调。 636 637**系统能力**:SystemCapability.Telephony.CoreService 638 639**参数:** 640 641| 参数名 | 类型 | 必填 | 说明 | 642| ------ | ------ | ---- | -------------------------------------- | 643| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 644 645**返回值:** 646 647| 类型 | 说明 | 648| -------------------------------- | ------------------------------------------ | 649| Promise\<[SimState](#simstate)\> | 以Promise形式返回获取指定卡槽的SIM卡状态。 | 650 651**错误码:** 652 653以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 654 655| 错误码ID | 错误信息 | 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**示例:** 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 680获取指定卡槽的SIM卡状态。 681 682**系统能力**:SystemCapability.Telephony.CoreService 683 684**参数:** 685 686| 参数名 | 类型 | 必填 | 说明 | 687| ------ | ------ | ---- | -------------------------------------- | 688| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 689 690**返回值:** 691 692| 类型 | 说明 | 693| ---------------------------- | ------------------------------------------ | 694| [SimState](#simstate) | 返回获取指定卡槽的SIM卡状态。 | 695 696 697**示例:** 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 710获取指定卡槽SIM卡的卡类型。使用callback异步回调。 711 712**系统能力**:SystemCapability.Telephony.CoreService 713 714**参数:** 715 716| 参数名 | 类型 | 必填 | 说明 | 717| -------- | ----------------------- | ---- | -------------------------------------- | 718| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 719| callback | AsyncCallback\<[CardType](#cardtype7)\> | 是 | 回调函数。 | 720 721**错误码:** 722 723以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 724 725| 错误码ID | 错误信息 | 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**示例:** 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 750获取指定卡槽SIM卡的卡类型。使用Promise异步回调。 751 752**系统能力**:SystemCapability.Telephony.CoreService 753 754**参数:** 755 756| 参数名 | 类型 | 必填 | 说明 | 757| ------ | ------ | ---- | -------------------------------------- | 758| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 759 760**返回值:** 761 762| 类型 | 说明 | 763| ----------------- | ------------------------------------------------------------ | 764| Promise\<[CardType](#cardtype7)\> | 以Promise形式返回指定卡槽SIM卡的卡类型。 | 765 766**错误码:** 767 768以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 769 770| 错误码ID | 错误信息 | 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**示例:** 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 796获取指定卡槽SIM卡的卡类型。 797 798**系统能力**:SystemCapability.Telephony.CoreService 799 800**参数:** 801 802| 参数名 | 类型 | 必填 | 说明 | 803| ------ | ------ | ---- | -------------------------------------- | 804| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 805 806**返回值:** 807 808| 类型 | 说明 | 809| ----------------- | ------------------------------------------------------------ | 810| [CardType](#cardtype7) | 返回指定卡槽SIM卡的卡类型。 | 811 812 813**示例:** 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 827获取指定卡槽SIM卡是否插卡。使用callback异步回调。 828 829**系统能力**:SystemCapability.Telephony.CoreService 830 831**参数:** 832 833| 参数名 | 类型 | 必填 | 说明 | 834| -------- | --------------------------- | ---- | -------------------------------------- | 835| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 836| callback | AsyncCallback<boolean> | 是 | 回调返回指定卡槽是否插卡,如果插卡返回true。 | 837 838**错误码:** 839 840以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 841 842| 错误码ID | 错误信息 | 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**示例:** 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 866获取指定卡槽SIM卡是否插卡。使用Promise异步回调。 867 868**系统能力**:SystemCapability.Telephony.CoreService 869 870**参数:** 871 872| 参数名 | 类型 | 必填 | 说明 | 873| ------ | ------ | ---- | -------------------------------------- | 874| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 875 876**返回值:** 877 878| 类型 | 说明 | 879| --------------------- | ---------------------------------- | 880| Promise<boolean> | 以Promise形式返回指定卡槽是否插卡,如果插卡返回true。 | 881 882**错误码:** 883 884以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 885 886| 错误码ID | 错误信息 | 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**示例:** 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 911获取指定卡槽SIM卡是否插卡。 912 913**系统能力**:SystemCapability.Telephony.CoreService 914 915**参数:** 916 917| 参数名 | 类型 | 必填 | 说明 | 918| ------ | ------ | ---- | -------------------------------------- | 919| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 920 921**返回值:** 922 923| 类型 | 说明 | 924| --------------------- | ---------------------------------- | 925| boolean | 返回指定卡槽是否插卡,如果插卡返回true。 | 926 927**示例:** 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 940获取SIM卡帐户信息。使用callback异步回调。 941 942**需要权限**:ohos.permission.GET_TELEPHONY_STATE 943 944>**说明:** 945> 946>仅需获取ICCID和号码信息时需要GET_TELEPHONY_STATE权限,ICCID和号码信息为敏感数据,不向三方应用开放。调用接口时,获取到的ICCID和号码信息为空。 947 948**系统能力**:SystemCapability.Telephony.CoreService 949 950**参数:** 951 952| 参数名 | 类型 | 必填 | 说明 | 953| -------- | --------------------------------------------------- | ---- | -------------------------------------- | 954| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 955| callback | AsyncCallback<[IccAccountInfo](#iccaccountinfo10)> | 是 | 回调函数。返回指定卡槽SIM卡的帐户信息。 | 956 957**错误码:** 958 959以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 960 961| 错误码ID | 错误信息 | 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**示例:** 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 987获取SIM卡帐户信息。使用Promise异步回调。 988 989**需要权限**:ohos.permission.GET_TELEPHONY_STATE 990 991>**说明:** 992> 993>仅需获取ICCID和号码信息时需要GET_TELEPHONY_STATE权限,ICCID和号码信息为敏感数据,不向三方应用开放。调用接口时,获取到的ICCID和号码信息为空。 994 995**系统能力**:SystemCapability.Telephony.CoreService 996 997**参数:** 998 999| 参数名 | 类型 | 必填 | 说明 | 1000| ------ | ------ | ---- | -------------------------------------- | 1001| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1002 1003**返回值:** 1004 1005| 类型 | 说明 | 1006| -------------------------------------------- | ------------------------------------------ | 1007| Promise<[IccAccountInfo](#iccaccountinfo10)> | 以Promise形式返回指定卡槽SIM卡的帐户信息。 | 1008 1009**错误码:** 1010 1011以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1012 1013| 错误码ID | 错误信息 | 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**示例:** 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 1040获取激活SIM卡帐户信息列表。使用callback异步回调。 1041 1042**需要权限**:ohos.permission.GET_TELEPHONY_STATE 1043 1044>**说明:** 1045> 1046>仅需获取ICCID和号码信息时需要GET_TELEPHONY_STATE权限,ICCID和号码信息为敏感数据,不向三方应用开放。调用接口时,获取到的ICCID和号码信息为空。 1047 1048**系统能力**:SystemCapability.Telephony.CoreService 1049 1050**参数:** 1051 1052| 参数名 | 类型 | 必填 | 说明 | 1053| -------- | ----------------------------------------------------------- | ---- | ---------- | 1054| callback | AsyncCallback<Array<[IccAccountInfo](#iccaccountinfo10)>> | 是 | 回调函数。返回激活SIM卡帐户信息列表。 | 1055 1056**错误码:** 1057 1058以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1059 1060| 错误码ID | 错误信息 | 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**示例:** 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 1084获取卡槽数量。 1085 1086**系统能力**:SystemCapability.Telephony.CoreService 1087 1088**返回值:** 1089 1090| 类型 | 说明 | 1091| ----------------- | ------------------------------------------------------------ | 1092| number | 卡槽数量。 | 1093 1094**示例:** 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 1107获取激活SIM卡帐户信息列表。使用Promise异步回调。 1108 1109**需要权限**:ohos.permission.GET_TELEPHONY_STATE 1110 1111>**说明:** 1112> 1113>仅需获取ICCID和号码信息时需要GET_TELEPHONY_STATE权限,ICCID和号码信息为敏感数据,不向三方应用开放。调用接口时,获取到的ICCID和号码信息为空。 1114 1115**系统能力**:SystemCapability.Telephony.CoreService 1116 1117**返回值:** 1118 1119| 类型 | 说明 | 1120| ---------------------------------------------------- | ---------------------------------------------- | 1121| Promise<Array<[IccAccountInfo](#iccaccountinfo10)>> | 以Promise形式返回激活卡槽SIM卡的帐户信息列表。 | 1122 1123**错误码:** 1124 1125以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1126 1127| 错误码ID | 错误信息 | 1128| -------- | -------------------------------------------- | 1129| 8300002 | Service connection failed. | 1130| 8300003 | System internal error. | 1131| 8300004 | No SIM card found. | 1132| 8300999 | Unknown error. | 1133 1134**示例:** 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 1152获取指定卡槽中SIM卡的opkey。使用callback异步回调。 1153 1154**系统能力**:SystemCapability.Telephony.CoreService 1155 1156**参数:** 1157 1158| 参数名 | 类型 | 必填 | 说明 | 1159| -------- | ---------------------- | ---- | -------------------------------------- | 1160| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1161| callback | AsyncCallback<string\> | 是 | 回调函数。 | 1162 1163**错误码:** 1164 1165以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1166 1167| 错误码ID | 错误信息 | 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**示例:** 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 1200获取指定卡槽中SIM卡的opkey。使用Promise异步回调。 1201 1202**系统能力**:SystemCapability.Telephony.CoreService 1203 1204**参数:** 1205 1206| 参数名 | 类型 | 必填 | 说明 | 1207| ------ | ------ | ---- | -------------------------------------- | 1208| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1209 1210**返回值:** 1211 1212| 类型 | 说明 | 1213| ---------------- | ----------------------------------------- | 1214| Promise<string\> | 以Promise形式返回指定卡槽中SIM卡的opkey。 | 1215 1216**错误码:** 1217 1218以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1219 1220| 错误码ID | 错误信息 | 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**示例:** 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 1246获取指定卡槽中SIM卡的opkey。 1247 1248**系统能力**:SystemCapability.Telephony.CoreService 1249 1250**参数:** 1251 1252| 参数名 | 类型 | 必填 | 说明 | 1253| ------ | ------ | ---- | -------------------------------------- | 1254| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1255 1256**返回值:** 1257 1258| 类型 | 说明 | 1259| ---------------- | ----------------------------------------- | 1260| string | 返回指定卡槽中SIM卡的opkey。 | 1261 1262 1263**示例:** 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 1276获取指定卡槽中SIM卡的OpName。使用callback异步回调。 1277 1278**系统能力**:SystemCapability.Telephony.CoreService 1279 1280**参数:** 1281 1282| 参数名 | 类型 | 必填 | 说明 | 1283| -------- | ---------------------- | ---- | -------------------------------------- | 1284| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1285| callback | AsyncCallback<string\> | 是 | 回调函数。 | 1286 1287**错误码:** 1288 1289以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1290 1291| 错误码ID | 错误信息 | 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**示例:** 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 1324获取指定卡槽中SIM卡的OpName。使用Promise异步回调。 1325 1326**系统能力**:SystemCapability.Telephony.CoreService 1327 1328**参数:** 1329 1330| 参数名 | 类型 | 必填 | 说明 | 1331| ------ | ------ | ---- | -------------------------------------- | 1332| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1333 1334**返回值:** 1335 1336| 类型 | 说明 | 1337| ---------------- | ------------------------------------------ | 1338| Promise<string\> | 以Promise形式返回指定卡槽中SIM卡的OpName。 | 1339 1340**错误码:** 1341 1342以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1343 1344| 错误码ID | 错误信息 | 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**示例:** 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 1370获取指定卡槽中SIM卡的OpName。 1371 1372**系统能力**:SystemCapability.Telephony.CoreService 1373 1374**参数:** 1375 1376| 参数名 | 类型 | 必填 | 说明 | 1377| ------ | ------ | ---- | -------------------------------------- | 1378| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1379 1380**返回值:** 1381 1382| 类型 | 说明 | 1383| ---------------- | ------------------------------------------ | 1384| string | 返回指定卡槽中SIM卡的OpName。 | 1385 1386 1387**示例:** 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 1400获取默认语音业务的SIM卡ID。使用callback异步回调。 1401 1402**系统能力**:SystemCapability.Telephony.CoreService 1403 1404**参数:** 1405 1406| 参数名 | 类型 | 必填 | 说明 | 1407| -------- | --------------------------- | ---- | ---------- | 1408| callback | AsyncCallback<number> | 是 | 回调函数。<br/>与SIM卡绑定,从1开始递增。 | 1409 1410**错误码:** 1411 1412以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1413 1414| 错误码ID | 错误信息 | 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**示例:** 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 1439获取默认语音业务的SIM卡ID。使用Promise异步回调。 1440 1441**系统能力**:SystemCapability.Telephony.CoreService 1442 1443**返回值:** 1444 1445| 类型 | 说明 | 1446| ----------------- | --------------------------------------- | 1447| Promise\<number\> | 以Promise形式返回默认语音业务的SIM卡ID。<br/>与SIM卡绑定,从1开始递增。 | 1448 1449**错误码:** 1450 1451以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1452 1453| 错误码ID | 错误信息 | 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**示例:** 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 1479SIM卡状态。 1480 1481**系统能力**:SystemCapability.Telephony.CoreService 1482 1483| 名称 | 值 | 说明 | 1484| --------------------- | ---- | ---------------------------------------------------------- | 1485| SIM_STATE_UNKNOWN | 0 | SIM卡状态未知,即无法获取准确的状态。 | 1486| SIM_STATE_NOT_PRESENT | 1 | 表示SIM卡处于not present状态,即卡槽中没有插入SIM卡。 | 1487| SIM_STATE_LOCKED | 2 | 表示SIM卡处于locked状态,即SIM卡被PIN、PUK或网络锁锁定。 | 1488| SIM_STATE_NOT_READY | 3 | 表示SIM卡处于not ready状态,即SIM卡在位但无法正常工作。 | 1489| SIM_STATE_READY | 4 | 表示SIM卡处于ready状态,即SIM卡在位且工作正常。 | 1490| SIM_STATE_LOADED | 5 | 表示SIM卡处于loaded状态,即SIM卡在位且所有卡文件加载完毕。 | 1491 1492## CardType<sup>7+</sup> 1493 1494卡类型。 1495 1496**系统能力**:SystemCapability.Telephony.CoreService 1497 1498| 名称 | 值 | 说明 | 1499| ----- | ----- | ----- | 1500|UNKNOWN_CARD | -1 | 未知类型。 | 1501|SINGLE_MODE_SIM_CARD | 10 | 单SIM卡。 | 1502|SINGLE_MODE_USIM_CARD | 20 | 单USIM卡。 | 1503|SINGLE_MODE_RUIM_CARD | 30 | 单RUIM卡。 | 1504|DUAL_MODE_CG_CARD | 40 | 双卡模式C+G。 | 1505|CT_NATIONAL_ROAMING_CARD | 41 | 中国电信内部漫游卡。 | 1506|CU_DUAL_MODE_CARD | 42 | 中国联通双模卡。 | 1507|DUAL_MODE_TELECOM_LTE_CARD | 43 | 双模式电信LTE卡。 | 1508|DUAL_MODE_UG_CARD | 50 | 双模式UG卡。 | 1509|SINGLE_MODE_ISIM_CARD<sup>8+</sup> | 60 | 单一ISIM卡类型。 | 1510 1511## IccAccountInfo<sup>10+</sup> 1512 1513Icc帐户信息。 1514 1515**系统能力**:SystemCapability.Telephony.CoreService 1516 1517| 名称 | 类型 | 必填 | 说明 | 1518| ---------- | ------- | ---- | ---------------- | 1519| simId | number | 是 | SIM卡ID。 | 1520| slotIndex | number | 是 | 卡槽ID。 | 1521| isEsim | boolean | 是 | 标记卡是否是eSim。 | 1522| isActive | boolean | 是 | 卡是否被激活。 | 1523| iccId | string | 是 | ICCID号码。 | 1524| showName | string | 是 | SIM卡显示名称。 | 1525| showNumber | string | 是 | SIM卡显示号码。 |