• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.telephony.sim (SIM卡管理)
2<!--Kit: Telephony Kit-->
3<!--Subsystem: Telephony-->
4<!--Owner: @Fanyl8-->
5<!--Designer: @ghxbob-->
6<!--Tester: @weitiantian-->
7<!--Adviser: @zhang_yixin13-->
8
9SIM卡管理模块提供了SIM卡管理的基础能力,包括获取指定卡槽SIM卡的ISO国家码、归属PLMN号、服务提供商名称、SIM卡状态、卡类型、是否插卡、是否激活等。
10
11> **说明:**
12>
13> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14>
15
16## 导入模块
17
18```ts
19import { sim } from '@kit.TelephonyKit';
20```
21
22## sim.isSimActive<sup>7+</sup>
23
24isSimActive\(slotId: number, callback: AsyncCallback\<boolean\>\): void
25
26获取指定卡槽SIM卡是否激活。使用callback异步回调。
27
28**系统能力**:SystemCapability.Telephony.CoreService
29
30**参数:**
31
32| 参数名   | 类型                        | 必填 | 说明                                   |
33| -------- | --------------------------- | ---- | -------------------------------------- |
34| slotId   | number                      | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
35| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回指定卡槽是否激活。<br/>- true:激活。<br/>- false:未激活。                               |
36
37**示例:**
38
39```ts
40import { BusinessError } from '@kit.BasicServicesKit';
41import { sim } from '@kit.TelephonyKit';
42
43sim.isSimActive(0, (err: BusinessError, data: boolean) => {
44    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
45});
46```
47
48
49## sim.isSimActive<sup>7+</sup>
50
51isSimActive\(slotId: number\): Promise\<boolean\>
52
53获取指定卡槽SIM卡是否激活。使用Promise异步回调。
54
55**系统能力**:SystemCapability.Telephony.CoreService
56
57**参数:**
58
59| 参数名 | 类型   | 必填 | 说明                                   |
60| ------ | ------ | ---- | -------------------------------------- |
61| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
62
63**返回值:**
64
65| 类型                  | 说明                               |
66| --------------------- | ---------------------------------- |
67| Promise&lt;boolean&gt; | 以Promise形式返回指定卡槽是否激活。<br/>- true:激活。<br/>- false:未激活。 |
68
69**示例:**
70
71```ts
72import { BusinessError } from '@kit.BasicServicesKit';
73import { sim } from '@kit.TelephonyKit';
74
75sim.isSimActive(0).then((data: boolean) => {
76    console.log(`isSimActive success, promise: data->${JSON.stringify(data)}`);
77}).catch((err: BusinessError) => {
78    console.error(`isSimActive failed, promise: err->${JSON.stringify(err)}`);
79});
80```
81
82## sim.isSimActiveSync<sup>10+</sup>
83
84isSimActiveSync\(slotId: number\): boolean
85
86获取指定卡槽SIM卡是否激活。
87
88**系统能力**:SystemCapability.Telephony.CoreService
89
90**参数:**
91
92| 参数名 | 类型   | 必填 | 说明                                   |
93| ------ | ------ | ---- | -------------------------------------- |
94| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
95
96**返回值:**
97
98| 类型                  | 说明                               |
99| --------------------- | ---------------------------------- |
100| boolean | 返回指定卡槽是否激活。<br/>- true:激活。<br/>- false:未激活。 |
101
102**示例:**
103
104```ts
105import { sim } from '@kit.TelephonyKit';
106
107let isSimActive: boolean = sim.isSimActiveSync(0);
108console.log(`the sim is active:` + isSimActive);
109```
110
111
112## sim.getDefaultVoiceSlotId<sup>7+</sup>
113
114getDefaultVoiceSlotId\(callback: AsyncCallback\<number\>\): void
115
116获取默认语音业务的卡槽ID。使用callback异步回调。
117
118**系统能力**:SystemCapability.Telephony.CoreService
119
120**参数:**
121
122| 参数名   | 类型                        | 必填 | 说明       |
123| -------- | --------------------------- | ---- | ---------- |
124| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。<br />- 0:卡槽1。<br />- 1:卡槽2。<br />- -1:未设置或服务不可用。 |
125
126**示例:**
127
128```ts
129import { BusinessError } from '@kit.BasicServicesKit';
130import { sim } from '@kit.TelephonyKit';
131
132sim.getDefaultVoiceSlotId((err: BusinessError, data: number) => {
133    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
134});
135```
136
137## sim.getDefaultVoiceSlotId<sup>7+</sup>
138
139getDefaultVoiceSlotId\(\): Promise\<number\>
140
141获取默认语音业务的卡槽ID。使用Promise异步回调。
142
143**系统能力**:SystemCapability.Telephony.CoreService
144
145**返回值:**
146
147| 类型              | 说明                                    |
148| ----------------- | --------------------------------------- |
149| Promise\<number\> | 以Promise形式返回默认语音业务的卡槽ID。<br />- 0:卡槽1。<br />- 1:卡槽2。<br />- -1:未设置或服务不可用。 |
150
151**示例:**
152
153```ts
154import { BusinessError } from '@kit.BasicServicesKit';
155import { sim } from '@kit.TelephonyKit';
156
157sim.getDefaultVoiceSlotId().then((data: number) => {
158    console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`);
159}).catch((err: BusinessError) => {
160    console.error(`getDefaultVoiceSlotId failed, promise: err->${JSON.stringify(err)}`);
161});
162```
163
164## sim.hasOperatorPrivileges<sup>7+</sup>
165
166hasOperatorPrivileges\(slotId: number, callback: AsyncCallback\<boolean\>\): void
167
168检查应用(调用者)是否已被授予运营商权限。使用callback异步回调。
169
170**系统能力**:SystemCapability.Telephony.CoreService
171
172**参数:**
173
174| 参数名   | 类型                     | 必填 | 说明                                     |
175| -------- | ------------------------ | ---- | ---------------------------------------- |
176| slotId   | number                   | 是   | 卡槽ID。<br />- 0:卡槽1。<br />- 1:卡槽2。 |
177| callback | AsyncCallback\<boolean\> | 是   | 回调函数。 返回检查应用(调用者)是否已被授予运营商权限。<br/>- true:授权。<br/>- false:未授权。                              |
178
179**错误码:**
180
181以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
182
183| 错误码ID |                 错误信息                     |
184| -------- | -------------------------------------------- |
185| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
186| 8300001  | Invalid parameter value.                     |
187| 8300002  | Service connection failed.                   |
188| 8300003  | System internal error.                       |
189| 8300999  | Unknown error.                               |
190
191**示例:**
192
193```ts
194import { BusinessError } from '@kit.BasicServicesKit';
195import { sim } from '@kit.TelephonyKit';
196
197sim.hasOperatorPrivileges(0, (err: BusinessError, data: boolean) => {
198    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
199});
200```
201
202## sim.hasOperatorPrivileges<sup>7+</sup>
203
204hasOperatorPrivileges\(slotId: number\): Promise\<boolean\>
205
206检查应用(调用者)是否已被授予运营商权限。使用Promise异步回调。
207
208**系统能力**:SystemCapability.Telephony.CoreService
209
210**参数:**
211
212| 参数名 | 类型   | 必填 | 说明                                     |
213| ------ | ------ | ---- | ---------------------------------------- |
214| slotId | number | 是   | 卡槽ID。<br />- 0:卡槽1。<br />- 1:卡槽2。 |
215
216**返回值:**
217
218| 类型               | 说明                                                        |
219| :----------------- | :---------------------------------------------------------- |
220| Promise\<boolean\> | 以Promise形式返回检查应用(调用者)是否已被授予运营商权限。 |
221
222**错误码:**
223
224以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
225
226| 错误码ID |                 错误信息                     |
227| -------- | -------------------------------------------- |
228| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
229| 8300001  | Invalid parameter value.                     |
230| 8300002  | Service connection failed.                   |
231| 8300003  | System internal error.                       |
232| 8300999  | Unknown error.                               |
233
234**示例:**
235
236```ts
237import { BusinessError } from '@kit.BasicServicesKit';
238import { sim } from '@kit.TelephonyKit';
239
240sim.hasOperatorPrivileges(0).then((data: boolean) => {
241    console.log(`hasOperatorPrivileges success, promise: data->${JSON.stringify(data)}`);
242}).catch((err: BusinessError) => {
243    console.error(`hasOperatorPrivileges failed, promise: err->${JSON.stringify(err)}`);
244});
245```
246
247## sim.getISOCountryCodeForSim
248
249getISOCountryCodeForSim\(slotId: number, callback: AsyncCallback\<string\>\): void
250
251获取指定卡槽SIM卡的ISO国家码。使用callback异步回调。
252
253**系统能力**:SystemCapability.Telephony.CoreService
254
255**参数:**
256
257| 参数名   | 类型                    | 必填 | 说明                                     |
258| -------- | ----------------------- | ---- | ---------------------------------------- |
259| slotId   | number                  | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。   |
260| callback | AsyncCallback\<string\> | 是   | 回调函数。返回国家码,例如:CN(中国)。 |
261
262**错误码:**
263
264以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
265
266| 错误码ID |                 错误信息                     |
267| -------- | -------------------------------------------- |
268| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
269| 8300001  | Invalid parameter value.                     |
270| 8300002  | Service connection failed.                   |
271| 8300003  | System internal error.                       |
272| 8300004  | No SIM card found.                           |
273| 8300999  | Unknown error.                               |
274
275**示例:**
276
277```ts
278import { BusinessError } from '@kit.BasicServicesKit';
279import { sim } from '@kit.TelephonyKit';
280
281sim.getISOCountryCodeForSim(0, (err: BusinessError, data: string) => {
282    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
283});
284```
285
286
287## sim.getISOCountryCodeForSim
288
289getISOCountryCodeForSim\(slotId: number\): Promise\<string\>
290
291获取指定卡槽SIM卡的ISO国家码。使用Promise异步回调。
292
293**系统能力**:SystemCapability.Telephony.CoreService
294
295**参数:**
296
297| 参数名 | 类型   | 必填 | 说明                                   |
298| ------ | ------ | ---- | -------------------------------------- |
299| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
300
301**返回值:**
302
303| 类型              | 说明                                                         |
304| ----------------- | ------------------------------------------------------------ |
305| Promise\<string\> | 以Promise形式返回获取指定卡槽SIM卡的ISO国家码。例如:CN(中国)。 |
306
307**错误码:**
308
309以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
310
311| 错误码ID |                 错误信息                     |
312| -------- | -------------------------------------------- |
313| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
314| 8300001  | Invalid parameter value.                     |
315| 8300002  | Service connection failed.                   |
316| 8300003  | System internal error.                       |
317| 8300004  | No SIM card found.                           |
318| 8300999  | Unknown error.                               |
319
320**示例:**
321
322```ts
323import { BusinessError } from '@kit.BasicServicesKit';
324import { sim } from '@kit.TelephonyKit';
325
326sim.getISOCountryCodeForSim(0).then((data: string) => {
327    console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`);
328}).catch((err: BusinessError) => {
329    console.error(`getISOCountryCodeForSim failed, promise: err->${JSON.stringify(err)}`);
330});
331```
332
333## sim.getISOCountryCodeForSimSync<sup>10+</sup>
334
335getISOCountryCodeForSimSync\(slotId: number\): string
336
337获取指定卡槽SIM卡的ISO国家码。
338
339**系统能力**:SystemCapability.Telephony.CoreService
340
341**参数:**
342
343| 参数名 | 类型   | 必填 | 说明                                   |
344| ------ | ------ | ---- | -------------------------------------- |
345| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
346
347**返回值:**
348
349| 类型              | 说明                                                         |
350| ----------------- | ------------------------------------------------------------ |
351| string | 返回获取指定卡槽SIM卡的ISO国家码。例如:CN(中国)。 |
352
353
354**示例:**
355
356```ts
357import { sim } from '@kit.TelephonyKit';
358
359let countryCode: string = sim.getISOCountryCodeForSimSync(0);
360console.log(`the country ISO is:` + countryCode);
361```
362
363
364## sim.getSimOperatorNumeric
365
366getSimOperatorNumeric\(slotId: number, callback: AsyncCallback\<string\>\): void
367
368获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号。使用callback异步回调。
369
370**系统能力**:SystemCapability.Telephony.CoreService
371
372**参数:**
373
374| 参数名   | 类型                    | 必填 | 说明                                   |
375| -------- | ----------------------- | ---- | -------------------------------------- |
376| slotId   | number                  | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
377| callback | AsyncCallback\<string\> | 是   | 回调函数。返回指定卡槽SIM卡的归属PLMN号。                          |
378
379**错误码:**
380
381以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
382
383| 错误码ID |                 错误信息                     |
384| -------- | -------------------------------------------- |
385| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
386| 8300001  | Invalid parameter value.                     |
387| 8300002  | Service connection failed.                   |
388| 8300003  | System internal error.                       |
389| 8300004  | No SIM card found.                           |
390| 8300999  | Unknown error.                               |
391
392**示例:**
393
394```ts
395import { BusinessError } from '@kit.BasicServicesKit';
396import { sim } from '@kit.TelephonyKit';
397
398sim.getSimOperatorNumeric(0, (err: BusinessError, data: string) => {
399    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
400});
401```
402
403
404## sim.getSimOperatorNumeric
405
406getSimOperatorNumeric\(slotId: number\): Promise\<string\>
407
408获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号。使用Promise异步回调。
409
410**系统能力**:SystemCapability.Telephony.CoreService
411
412**参数:**
413
414| 参数名 | 类型   | 必填 | 说明                                   |
415| ------ | ------ | ---- | -------------------------------------- |
416| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
417
418**返回值:**
419
420| 类型              | 说明                                             |
421| ----------------- | ------------------------------------------------ |
422| Promise\<string\> | 以Promise形式返回获取指定卡槽SIM卡的归属PLMN号。 |
423
424**错误码:**
425
426以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
427
428| 错误码ID |                 错误信息                     |
429| -------- | -------------------------------------------- |
430| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
431| 8300001  | Invalid parameter value.                     |
432| 8300002  | Service connection failed.                   |
433| 8300003  | System internal error.                       |
434| 8300004  | No SIM card found.                           |
435| 8300999  | Unknown error.                               |
436
437**示例:**
438
439```ts
440import { BusinessError } from '@kit.BasicServicesKit';
441import { sim } from '@kit.TelephonyKit';
442
443sim.getSimOperatorNumeric(0).then((data: string) => {
444    console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`);
445}).catch((err: BusinessError) => {
446    console.error(`getSimOperatorNumeric failed, promise: err->${JSON.stringify(err)}`);
447});
448```
449
450## sim.getSimOperatorNumericSync<sup>10+</sup>
451
452getSimOperatorNumericSync\(slotId: number\): string
453
454获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号。
455
456**系统能力**:SystemCapability.Telephony.CoreService
457
458**参数:**
459
460| 参数名 | 类型   | 必填 | 说明                                   |
461| ------ | ------ | ---- | -------------------------------------- |
462| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
463
464**返回值:**
465
466| 类型              | 说明                                             |
467| ----------------- | ------------------------------------------------ |
468| string | 返回获取指定卡槽SIM卡的归属PLMN号。 |
469
470
471**示例:**
472
473```ts
474import { sim } from '@kit.TelephonyKit';
475
476let numeric: string = sim.getSimOperatorNumericSync(0);
477console.log(`the sim operator numeric is:` + numeric);
478```
479
480
481## sim.getSimSpn
482
483getSimSpn\(slotId: number, callback: AsyncCallback\<string\>\): void
484
485获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN)。使用callback异步回调。
486
487**系统能力**:SystemCapability.Telephony.CoreService
488
489**参数:**
490
491| 参数名   | 类型                    | 必填 | 说明                                   |
492| -------- | ----------------------- | ---- | -------------------------------------- |
493| slotId   | number                  | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
494| callback | AsyncCallback\<string\> | 是   | 回调函数。返回指定卡槽SIM卡的SPN。                             |
495
496**错误码:**
497
498以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
499
500| 错误码ID |                 错误信息                     |
501| -------- | -------------------------------------------- |
502| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
503| 8300001  | Invalid parameter value.                     |
504| 8300002  | Service connection failed.                   |
505| 8300003  | System internal error.                       |
506| 8300004  | No SIM card found.                           |
507| 8300999  | Unknown error.                               |
508
509**示例:**
510
511```ts
512import { BusinessError } from '@kit.BasicServicesKit';
513import { sim } from '@kit.TelephonyKit';
514
515sim.getSimSpn(0, (err: BusinessError, data: string) => {
516    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
517});
518```
519
520
521## sim.getSimSpn
522
523getSimSpn\(slotId: number\): Promise\<string\>
524
525获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN)。使用Promise异步回调。
526
527**系统能力**:SystemCapability.Telephony.CoreService
528
529**参数:**
530
531| 参数名 | 类型   | 必填 | 说明                                   |
532| ------ | ------ | ---- | -------------------------------------- |
533| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
534
535**返回值:**
536
537| 类型              | 说明                                      |
538| ----------------- | ----------------------------------------- |
539| Promise\<string\> | 以Promise形式返回获取指定卡槽SIM卡的SPN。 |
540
541**错误码:**
542
543以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
544
545| 错误码ID |                 错误信息                     |
546| -------- | -------------------------------------------- |
547| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
548| 8300001  | Invalid parameter value.                     |
549| 8300002  | Service connection failed.                   |
550| 8300003  | System internal error.                       |
551| 8300004  | No SIM card found.                           |
552| 8300999  | Unknown error.                               |
553
554**示例:**
555
556```ts
557import { BusinessError } from '@kit.BasicServicesKit';
558import { sim } from '@kit.TelephonyKit';
559
560sim.getSimSpn(0).then((data: string) => {
561    console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`);
562}).catch((err: BusinessError) => {
563    console.error(`getSimSpn failed, promise: err->${JSON.stringify(err)}`);
564});
565```
566
567## sim.getSimSpnSync<sup>10+</sup>
568
569getSimSpnSync\(slotId: number\): string
570
571获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN)。
572
573**系统能力**:SystemCapability.Telephony.CoreService
574
575**参数:**
576
577| 参数名 | 类型   | 必填 | 说明                                   |
578| ------ | ------ | ---- | -------------------------------------- |
579| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
580
581**返回值:**
582
583| 类型              | 说明                                      |
584| ----------------- | ----------------------------------------- |
585| string | 返回获取指定卡槽SIM卡的SPN。 |
586
587
588**示例:**
589
590```ts
591import { sim } from '@kit.TelephonyKit';
592
593let spn: string = sim.getSimSpnSync(0);
594console.log(`the sim card spn is:` + spn);
595```
596
597
598## sim.getSimState
599
600getSimState\(slotId: number, callback: AsyncCallback\<SimState\>\): void
601
602获取指定卡槽的SIM卡状态。使用callback异步回调。
603
604**系统能力**:SystemCapability.Telephony.CoreService
605
606**参数:**
607
608| 参数名   | 类型                                   | 必填 | 说明                                   |
609| -------- | -------------------------------------- | ---- | -------------------------------------- |
610| slotId   | number                                 | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
611| callback | AsyncCallback\<[SimState](#simstate)\> | 是   | 回调函数。参考[SimState](#simstate)。  |
612
613**错误码:**
614
615以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
616
617| 错误码ID |                 错误信息                     |
618| -------- | -------------------------------------------- |
619| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
620| 8300001  | Invalid parameter value.                     |
621| 8300002  | Service connection failed.                   |
622| 8300003  | System internal error.                       |
623| 8300999  | Unknown error.                               |
624
625**示例:**
626
627```ts
628import { BusinessError } from '@kit.BasicServicesKit';
629import { sim } from '@kit.TelephonyKit';
630
631sim.getSimState(0, (err: BusinessError, data: sim.SimState) => {
632    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
633});
634```
635
636
637## sim.getSimState
638
639getSimState\(slotId: number\): Promise\<SimState\>
640
641获取指定卡槽的SIM卡状态。使用Promise异步回调。
642
643**系统能力**:SystemCapability.Telephony.CoreService
644
645**参数:**
646
647| 参数名 | 类型   | 必填 | 说明                                   |
648| ------ | ------ | ---- | -------------------------------------- |
649| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
650
651**返回值:**
652
653| 类型                             | 说明                                       |
654| -------------------------------- | ------------------------------------------ |
655| Promise\<[SimState](#simstate)\> | 以Promise形式返回获取指定卡槽的SIM卡状态。 |
656
657**错误码:**
658
659以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
660
661| 错误码ID |                 错误信息                     |
662| -------- | -------------------------------------------- |
663| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
664| 8300001  | Invalid parameter value.                     |
665| 8300002  | Service connection failed.                   |
666| 8300003  | System internal error.                       |
667| 8300999  | Unknown error.                               |
668
669**示例:**
670
671```ts
672import { BusinessError } from '@kit.BasicServicesKit';
673import { sim } from '@kit.TelephonyKit';
674
675sim.getSimState(0).then((data: sim.SimState) => {
676    console.log(`getSimState success, promise: data->${JSON.stringify(data)}`);
677}).catch((err: BusinessError) => {
678    console.error(`getSimState failed, promise: err->${JSON.stringify(err)}`);
679});
680```
681
682## sim.getSimStateSync<sup>10+</sup>
683
684getSimStateSync\(slotId: number\): SimState
685
686获取指定卡槽的SIM卡状态。
687
688**系统能力**:SystemCapability.Telephony.CoreService
689
690**参数:**
691
692| 参数名 | 类型   | 必填 | 说明                                   |
693| ------ | ------ | ---- | -------------------------------------- |
694| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
695
696**返回值:**
697
698| 类型                         | 说明                                       |
699| ---------------------------- | ------------------------------------------ |
700| [SimState](#simstate) | 返回获取指定卡槽的SIM卡状态。 |
701
702
703**示例:**
704
705```ts
706import { sim } from '@kit.TelephonyKit';
707
708let simState: sim.SimState = sim.getSimStateSync(0);
709console.log(`The sim state is:` + simState);
710```
711
712## sim.getCardType<sup>7+</sup>
713
714getCardType\(slotId: number, callback: AsyncCallback\<CardType\>\): void
715
716获取指定卡槽SIM卡的卡类型。使用callback异步回调。
717
718**系统能力**:SystemCapability.Telephony.CoreService
719
720**参数:**
721
722| 参数名   | 类型                    | 必填 | 说明                                   |
723| -------- | ----------------------- | ---- | -------------------------------------- |
724| slotId   | number                  | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
725| callback | AsyncCallback\<[CardType](#cardtype7)\> | 是   | 回调函数。                             |
726
727**错误码:**
728
729以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
730
731| 错误码ID |                 错误信息                     |
732| -------- | -------------------------------------------- |
733| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
734| 8300001  | Invalid parameter value.                     |
735| 8300002  | Service connection failed.                   |
736| 8300003  | System internal error.                       |
737| 8300004  | No SIM card found.                           |
738| 8300999  | Unknown error.                               |
739
740**示例:**
741
742```ts
743import { BusinessError } from '@kit.BasicServicesKit';
744import { sim } from '@kit.TelephonyKit';
745
746sim.getCardType(0, (err: BusinessError, data: sim.CardType) => {
747    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
748});
749```
750
751
752## sim.getCardType<sup>7+</sup>
753
754getCardType\(slotId: number\): Promise\<CardType\>
755
756获取指定卡槽SIM卡的卡类型。使用Promise异步回调。
757
758**系统能力**:SystemCapability.Telephony.CoreService
759
760**参数:**
761
762| 参数名 | 类型   | 必填 | 说明                                   |
763| ------ | ------ | ---- | -------------------------------------- |
764| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
765
766**返回值:**
767
768| 类型              | 说明                                                         |
769| ----------------- | ------------------------------------------------------------ |
770| Promise\<[CardType](#cardtype7)\> | 以Promise形式返回指定卡槽SIM卡的卡类型。 |
771
772**错误码:**
773
774以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
775
776| 错误码ID |                 错误信息                     |
777| -------- | -------------------------------------------- |
778| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
779| 8300001  | Invalid parameter value.                     |
780| 8300002  | Service connection failed.                   |
781| 8300003  | System internal error.                       |
782| 8300004  | No SIM card found.                           |
783| 8300999  | Unknown error.                               |
784
785**示例:**
786
787```ts
788import { BusinessError } from '@kit.BasicServicesKit';
789import { sim } from '@kit.TelephonyKit';
790
791sim.getCardType(0).then((data: sim.CardType) => {
792    console.log(`getCardType success, promise: data->${JSON.stringify(data)}`);
793}).catch((err: BusinessError) => {
794    console.error(`getCardType failed, promise: err->${JSON.stringify(err)}`);
795});
796```
797
798## sim.getCardTypeSync<sup>10+</sup>
799
800getCardTypeSync\(slotId: number\): CardType
801
802获取指定卡槽SIM卡的卡类型。
803
804**系统能力**:SystemCapability.Telephony.CoreService
805
806**参数:**
807
808| 参数名 | 类型   | 必填 | 说明                                   |
809| ------ | ------ | ---- | -------------------------------------- |
810| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
811
812**返回值:**
813
814| 类型              | 说明                                                         |
815| ----------------- | ------------------------------------------------------------ |
816| [CardType](#cardtype7) | 返回指定卡槽SIM卡的卡类型。 |
817
818
819**示例:**
820
821```ts
822import { sim } from '@kit.TelephonyKit';
823
824let cardType: sim.CardType = sim.getCardTypeSync(0);
825console.log(`the card type is:` + cardType);
826```
827
828
829## sim.hasSimCard<sup>7+</sup>
830
831hasSimCard\(slotId: number, callback: AsyncCallback\<boolean\>\): void
832
833获取指定卡槽SIM卡是否插卡。使用callback异步回调。
834
835**系统能力**:SystemCapability.Telephony.CoreService
836
837**参数:**
838
839| 参数名   | 类型                        | 必填 | 说明                                   |
840| -------- | --------------------------- | ---- | -------------------------------------- |
841| slotId   | number                      | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
842| callback | AsyncCallback&lt;boolean&gt; | 是  | 回调返回指定卡槽是否插卡。<br/>- true:插卡。<br/>- false:未插卡。                           |
843
844**错误码:**
845
846以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
847
848| 错误码ID |                 错误信息                     |
849| -------- | -------------------------------------------- |
850| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
851| 8300001  | Invalid parameter value.                     |
852| 8300002  | Service connection failed.                   |
853| 8300003  | System internal error.                       |
854| 8300999  | Unknown error.                               |
855
856**示例:**
857
858```ts
859import { BusinessError } from '@kit.BasicServicesKit';
860import { sim } from '@kit.TelephonyKit';
861
862sim.hasSimCard(0, (err: BusinessError, data: boolean) => {
863    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
864});
865```
866
867
868## sim.hasSimCard<sup>7+</sup>
869
870hasSimCard\(slotId: number\): Promise\<boolean\>
871
872获取指定卡槽SIM卡是否插卡。使用Promise异步回调。
873
874**系统能力**:SystemCapability.Telephony.CoreService
875
876**参数:**
877
878| 参数名 | 类型   | 必填 | 说明                                   |
879| ------ | ------ | ---- | -------------------------------------- |
880| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
881
882**返回值:**
883
884| 类型                  | 说明                               |
885| --------------------- | ---------------------------------- |
886| Promise&lt;boolean&gt; | 以Promise形式返回指定卡槽是否插卡。<br/>- true:插卡。<br/>- false:未插卡。 |
887
888**错误码:**
889
890以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
891
892| 错误码ID |                 错误信息                     |
893| -------- | -------------------------------------------- |
894| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
895| 8300001  | Invalid parameter value.                     |
896| 8300002  | Service connection failed.                   |
897| 8300003  | System internal error.                       |
898| 8300999  | Unknown error.                               |
899
900**示例:**
901
902```ts
903import { BusinessError } from '@kit.BasicServicesKit';
904import { sim } from '@kit.TelephonyKit';
905
906sim.hasSimCard(0).then((data: boolean) => {
907    console.log(`hasSimCard success, promise: data->${JSON.stringify(data)}`);
908}).catch((err: BusinessError) => {
909    console.error(`hasSimCard failed, promise: err->${JSON.stringify(err)}`);
910});
911```
912
913## sim.hasSimCardSync<sup>10+</sup>
914
915hasSimCardSync\(slotId: number\): boolean
916
917获取指定卡槽SIM卡是否插卡。
918
919**系统能力**:SystemCapability.Telephony.CoreService
920
921**参数:**
922
923| 参数名 | 类型   | 必填 | 说明                                   |
924| ------ | ------ | ---- | -------------------------------------- |
925| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
926
927**返回值:**
928
929| 类型                  | 说明                               |
930| --------------------- | ---------------------------------- |
931| boolean | 返回指定卡槽是否插卡。<br/>- true:插卡。<br/>- false:未插卡。 |
932
933**示例:**
934
935```ts
936import { sim } from '@kit.TelephonyKit';
937
938let hasSimCard: boolean = sim.hasSimCardSync(0);
939console.log(`has sim card: ` + hasSimCard);
940```
941
942## sim.getSimAccountInfo<sup>10+</sup>
943
944getSimAccountInfo\(slotId: number, callback: AsyncCallback\<IccAccountInfo\>\): void
945
946获取SIM卡帐户信息。使用callback异步回调。
947
948**需要权限**:ohos.permission.GET_TELEPHONY_STATE
949
950> **说明:**
951>
952> 获取ICCID和号码信息时需要GET_TELEPHONY_STATE权限,ICCID和号码信息为敏感数据,不向三方应用开放。调用接口时,获取到的ICCID和号码信息为空。
953
954**系统能力**:SystemCapability.Telephony.CoreService
955
956**参数:**
957
958| 参数名   | 类型                                                | 必填 | 说明                                   |
959| -------- | --------------------------------------------------- | ---- | -------------------------------------- |
960| slotId   | number                                              | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
961| callback | AsyncCallback&lt;[IccAccountInfo](#iccaccountinfo10)&gt; | 是   | 回调函数。返回指定卡槽SIM卡的帐户信息。                             |
962
963**错误码:**
964
965以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
966
967| 错误码ID |                 错误信息                     |
968| -------- | -------------------------------------------- |
969| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
970| 8300001  | Invalid parameter value.                     |
971| 8300002  | Service connection failed.                   |
972| 8300003  | System internal error.                       |
973| 8300004  | No SIM card found.                           |
974| 8300999  | Unknown error.                               |
975| 8301002  | The SIM card failed to read or update data.  |
976
977**示例:**
978
979```ts
980import { BusinessError } from '@kit.BasicServicesKit';
981import { sim } from '@kit.TelephonyKit';
982
983sim.getSimAccountInfo(0, (err:BusinessError , data: sim.IccAccountInfo) => {
984    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
985});
986```
987
988
989## sim.getSimAccountInfo<sup>10+</sup>
990
991getSimAccountInfo\(slotId: number\): Promise\<IccAccountInfo\>
992
993获取SIM卡帐户信息。使用Promise异步回调。
994
995**需要权限**:ohos.permission.GET_TELEPHONY_STATE
996
997> **说明:**
998>
999> 获取ICCID和号码信息时需要GET_TELEPHONY_STATE权限,ICCID和号码信息为敏感数据,不向三方应用开放。调用接口时,获取到的ICCID和号码信息为空。
1000
1001**系统能力**:SystemCapability.Telephony.CoreService
1002
1003**参数:**
1004
1005| 参数名 | 类型   | 必填 | 说明                                   |
1006| ------ | ------ | ---- | -------------------------------------- |
1007| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
1008
1009**返回值:**
1010
1011| 类型                                         | 说明                                       |
1012| -------------------------------------------- | ------------------------------------------ |
1013| Promise&lt;[IccAccountInfo](#iccaccountinfo10)&gt; | 以Promise形式返回指定卡槽SIM卡的帐户信息。 |
1014
1015**错误码:**
1016
1017以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
1018
1019| 错误码ID |                 错误信息                     |
1020| -------- | -------------------------------------------- |
1021| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
1022| 8300001  | Invalid parameter value.                     |
1023| 8300002  | Service connection failed.                   |
1024| 8300003  | System internal error.                       |
1025| 8300004  | No SIM card found.                           |
1026| 8300999  | Unknown error.                               |
1027| 8301002  | The SIM card failed to read or update data.  |
1028
1029**示例:**
1030
1031```ts
1032import { BusinessError } from '@kit.BasicServicesKit';
1033import { sim } from '@kit.TelephonyKit';
1034
1035sim.getSimAccountInfo(0).then((data: sim.IccAccountInfo) => {
1036    console.log(`getSimAccountInfo success, promise: data->${JSON.stringify(data)}`);
1037}).catch((err: BusinessError) => {
1038    console.error(`getSimAccountInfo failed, promise: err->${JSON.stringify(err)}`);
1039});
1040```
1041
1042## sim.getActiveSimAccountInfoList<sup>10+</sup>
1043
1044getActiveSimAccountInfoList\(callback: AsyncCallback\<Array\<IccAccountInfo\>\>\): void
1045
1046获取激活SIM卡帐户信息列表。使用callback异步回调。
1047
1048**需要权限**:ohos.permission.GET_TELEPHONY_STATE
1049
1050> **说明:**
1051>
1052> 获取ICCID和号码信息时需要GET_TELEPHONY_STATE权限,ICCID和号码信息为敏感数据,不向三方应用开放。调用接口时,获取到的ICCID和号码信息为空。
1053
1054**系统能力**:SystemCapability.Telephony.CoreService
1055
1056**参数:**
1057
1058| 参数名   | 类型                                                        | 必填 | 说明       |
1059| -------- | ----------------------------------------------------------- | ---- | ---------- |
1060| callback | AsyncCallback&lt;Array&lt;[IccAccountInfo](#iccaccountinfo10)&gt;&gt; | 是   | 回调函数。返回激活SIM卡帐户信息列表。 |
1061
1062**错误码:**
1063
1064以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
1065
1066| 错误码ID |                 错误信息                     |
1067| -------- | -------------------------------------------- |
1068| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
1069| 8300001  | Invalid parameter value.                     |
1070| 8300002  | Service connection failed.                   |
1071| 8300003  | System internal error.                       |
1072| 8300004  | No SIM card found.                           |
1073| 8300999  | Unknown error.                               |
1074
1075**示例:**
1076
1077```ts
1078import { BusinessError } from '@kit.BasicServicesKit';
1079import { sim } from '@kit.TelephonyKit';
1080
1081sim.getActiveSimAccountInfoList((err: BusinessError, data: Array<sim.IccAccountInfo>) => {
1082    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
1083});
1084```
1085
1086## sim.getMaxSimCount<sup>7+</sup>
1087
1088getMaxSimCount\(\): number
1089
1090获取卡槽数量。
1091
1092**系统能力**:SystemCapability.Telephony.CoreService
1093
1094**返回值:**
1095
1096| 类型              | 说明                                                         |
1097| ----------------- | ------------------------------------------------------------ |
1098| number | 卡槽数量。 |
1099
1100**示例:**
1101
1102```ts
1103import { sim } from '@kit.TelephonyKit';
1104
1105console.log("Result: "+ sim.getMaxSimCount());
1106```
1107
1108
1109## sim.getActiveSimAccountInfoList<sup>10+</sup>
1110
1111getActiveSimAccountInfoList\(\): Promise\<Array\<IccAccountInfo\>\>
1112
1113获取激活SIM卡帐户信息列表。使用Promise异步回调。
1114
1115**需要权限**:ohos.permission.GET_TELEPHONY_STATE
1116
1117> **说明:**
1118>
1119> 获取ICCID和号码信息时需要GET_TELEPHONY_STATE权限,ICCID和号码信息为敏感数据,不向三方应用开放。调用接口时,获取到的ICCID和号码信息为空。
1120
1121**系统能力**:SystemCapability.Telephony.CoreService
1122
1123**返回值:**
1124
1125| 类型                                                 | 说明                                           |
1126| ---------------------------------------------------- | ---------------------------------------------- |
1127| Promise&lt;Array&lt;[IccAccountInfo](#iccaccountinfo10)&gt;&gt; | 以Promise形式返回激活卡槽SIM卡的帐户信息列表。 |
1128
1129**错误码:**
1130
1131以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
1132
1133| 错误码ID |                 错误信息                     |
1134| -------- | -------------------------------------------- |
1135| 8300002  | Service connection failed.                   |
1136| 8300003  | System internal error.                       |
1137| 8300004  | No SIM card found.                           |
1138| 8300999  | Unknown error.                               |
1139
1140**示例:**
1141
1142```ts
1143import { BusinessError } from '@kit.BasicServicesKit';
1144import { sim } from '@kit.TelephonyKit';
1145
1146sim.getActiveSimAccountInfoList().then((data: Array<sim.IccAccountInfo>) => {
1147    console.log(`getActiveSimAccountInfoList success, promise: data->${JSON.stringify(data)}`);
1148}).catch((err: BusinessError) => {
1149    console.error(`getActiveSimAccountInfoList failed, promise: err->${JSON.stringify(err)}`);
1150});
1151```
1152
1153
1154## sim.getOpKey<sup>9+</sup>
1155
1156getOpKey\(slotId: number, callback: AsyncCallback\<string\>): void
1157
1158获取指定卡槽中SIM卡的opkey。使用callback异步回调。
1159
1160**系统能力**:SystemCapability.Telephony.CoreService
1161
1162**参数:**
1163
1164| 参数名   | 类型                   | 必填 | 说明                                   |
1165| -------- | ---------------------- | ---- | -------------------------------------- |
1166| slotId   | number                 | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
1167| callback | AsyncCallback<string\> | 是   | 回调函数。                             |
1168
1169**错误码:**
1170
1171以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
1172
1173| 错误码ID |                 错误信息                     |
1174| -------- | -------------------------------------------- |
1175| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
1176| 801      | Capability not supported.                    |
1177| 8300001  | Invalid parameter value.                     |
1178| 8300002  | Service connection failed.                   |
1179| 8300003  | System internal error.                       |
1180| 8300999  | Unknown error.                               |
1181
1182**示例:**
1183
1184```ts
1185import { BusinessError } from '@kit.BasicServicesKit';
1186import { sim } from '@kit.TelephonyKit';
1187
1188try {
1189    sim.getOpKey(0, (err: BusinessError, data: string) => {
1190    if (err) {
1191      console.error("getOpKey failed, err: " + JSON.stringify(err));
1192    } else {
1193      console.log('getOpKey successfully, data: ' + JSON.stringify(data));
1194    }
1195  });
1196} catch (err) {
1197  console.error("getOpKey err: " + JSON.stringify(err));
1198}
1199```
1200
1201
1202## sim.getOpKey<sup>9+</sup>
1203
1204getOpKey\(slotId: number\): Promise\<string\>
1205
1206获取指定卡槽中SIM卡的opkey。使用Promise异步回调。
1207
1208**系统能力**:SystemCapability.Telephony.CoreService
1209
1210**参数:**
1211
1212| 参数名 | 类型   | 必填 | 说明                                   |
1213| ------ | ------ | ---- | -------------------------------------- |
1214| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
1215
1216**返回值:**
1217
1218| 类型             | 说明                                      |
1219| ---------------- | ----------------------------------------- |
1220| Promise<string\> | 以Promise形式返回指定卡槽中SIM卡的opkey。 |
1221
1222**错误码:**
1223
1224以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
1225
1226| 错误码ID |                 错误信息                     |
1227| -------- | -------------------------------------------- |
1228| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
1229| 801      | Capability not supported.                    |
1230| 8300001  | Invalid parameter value.                     |
1231| 8300002  | Service connection failed.                   |
1232| 8300003  | System internal error.                       |
1233| 8300999  | Unknown error.                               |
1234
1235**示例:**
1236
1237```ts
1238import { BusinessError } from '@kit.BasicServicesKit';
1239import { sim } from '@kit.TelephonyKit';
1240
1241sim.getOpKey(0).then((data: string) => {
1242    console.log(`getOpKey success, promise: data->${JSON.stringify(data)}`);
1243}).catch((err: BusinessError) => {
1244    console.error(`getOpKey failed, promise: err->${JSON.stringify(err)}`);
1245});
1246```
1247
1248## sim.getOpKeySync<sup>10+</sup>
1249
1250getOpKeySync\(slotId: number\): string
1251
1252获取指定卡槽中SIM卡的opkey。
1253
1254**系统能力**:SystemCapability.Telephony.CoreService
1255
1256**参数:**
1257
1258| 参数名 | 类型   | 必填 | 说明                                   |
1259| ------ | ------ | ---- | -------------------------------------- |
1260| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
1261
1262**返回值:**
1263
1264| 类型             | 说明                                      |
1265| ---------------- | ----------------------------------------- |
1266| string | 返回指定卡槽中SIM卡的opkey。 |
1267
1268
1269**示例:**
1270
1271```ts
1272import { sim } from '@kit.TelephonyKit';
1273
1274let data: string = sim.getOpKeySync(0);
1275console.log(`getOpKey success, promise: data->${JSON.stringify(data)}`);
1276```
1277
1278## sim.getOpName<sup>9+</sup>
1279
1280getOpName\(slotId: number, callback: AsyncCallback\<string\>\): void
1281
1282获取指定卡槽中SIM卡的OpName。使用callback异步回调。
1283
1284**系统能力**:SystemCapability.Telephony.CoreService
1285
1286**参数:**
1287
1288| 参数名   | 类型                   | 必填 | 说明                                   |
1289| -------- | ---------------------- | ---- | -------------------------------------- |
1290| slotId   | number                 | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
1291| callback | AsyncCallback<string\> | 是   | 回调函数。                               |
1292
1293**错误码:**
1294
1295以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
1296
1297| 错误码ID |                 错误信息                     |
1298| -------- | -------------------------------------------- |
1299| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
1300| 801      | Capability not supported.                    |
1301| 8300001  | Invalid parameter value.                     |
1302| 8300002  | Service connection failed.                   |
1303| 8300003  | System internal error.                       |
1304| 8300999  | Unknown error.                               |
1305
1306**示例:**
1307
1308```ts
1309import { BusinessError } from '@kit.BasicServicesKit';
1310import { sim } from '@kit.TelephonyKit';
1311
1312try {
1313    sim.getOpName(0, (err: BusinessError, data: string) => {
1314    if (err) {
1315      console.error("getOpName failed, err: " + JSON.stringify(err));
1316    } else {
1317      console.log('getOpName successfully, data: ' + JSON.stringify(data));
1318    }
1319  });
1320} catch (err) {
1321  console.error("getOpName err: " + JSON.stringify(err));
1322}
1323```
1324
1325
1326## sim.getOpName<sup>9+</sup>
1327
1328getOpName\(slotId: number\): Promise\<string\>
1329
1330获取指定卡槽中SIM卡的OpName。使用Promise异步回调。
1331
1332**系统能力**:SystemCapability.Telephony.CoreService
1333
1334**参数:**
1335
1336| 参数名 | 类型   | 必填 | 说明                                   |
1337| ------ | ------ | ---- | -------------------------------------- |
1338| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
1339
1340**返回值:**
1341
1342| 类型             | 说明                                       |
1343| ---------------- | ------------------------------------------ |
1344| Promise<string\> | 以Promise形式返回指定卡槽中SIM卡的OpName。 |
1345
1346**错误码:**
1347
1348以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
1349
1350| 错误码ID |                 错误信息                     |
1351| -------- | -------------------------------------------- |
1352| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
1353| 801      | Capability not supported.                    |
1354| 8300001  | Invalid parameter value.                     |
1355| 8300002  | Service connection failed.                   |
1356| 8300003  | System internal error.                       |
1357| 8300999  | Unknown error.                               |
1358
1359**示例:**
1360
1361```ts
1362import { BusinessError } from '@kit.BasicServicesKit';
1363import { sim } from '@kit.TelephonyKit';
1364
1365sim.getOpName(0).then((data: string) => {
1366    console.log(`getOpName success, promise: data->${JSON.stringify(data)}`);
1367}).catch((err: BusinessError) => {
1368    console.error(`getOpName failed, promise: err->${JSON.stringify(err)}`);
1369});
1370```
1371
1372## sim.getOpNameSync<sup>10+</sup>
1373
1374getOpNameSync\(slotId: number\): string
1375
1376获取指定卡槽中SIM卡的OpName。
1377
1378**系统能力**:SystemCapability.Telephony.CoreService
1379
1380**参数:**
1381
1382| 参数名 | 类型   | 必填 | 说明                                   |
1383| ------ | ------ | ---- | -------------------------------------- |
1384| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 |
1385
1386**返回值:**
1387
1388| 类型             | 说明                                       |
1389| ---------------- | ------------------------------------------ |
1390| string | 返回指定卡槽中SIM卡的OpName。 |
1391
1392
1393**示例:**
1394
1395```ts
1396import { sim } from '@kit.TelephonyKit';
1397
1398let data: string = sim.getOpNameSync(0);
1399console.log(`getOpName success, promise: data->${JSON.stringify(data)}`);
1400```
1401
1402## sim.getDefaultVoiceSimId<sup>10+</sup>
1403
1404getDefaultVoiceSimId\(callback: AsyncCallback\<number\>\): void
1405
1406获取默认语音业务的SIM卡ID。使用callback异步回调。
1407
1408**系统能力**:SystemCapability.Telephony.CoreService
1409
1410**参数:**
1411
1412| 参数名   | 类型                        | 必填 | 说明       |
1413| -------- | --------------------------- | ---- | ---------- |
1414| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。<br/>与SIM卡绑定,从1开始递增。 |
1415
1416**错误码:**
1417
1418以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
1419
1420| 错误码ID |                 错误信息                     |
1421| -------- | -------------------------------------------- |
1422| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
1423| 8300001  | Invalid parameter value.                     |
1424| 8300002  | Service connection failed.                   |
1425| 8300003  | System internal error.                       |
1426| 8300004  | No SIM card found.                           |
1427| 8300999  | Unknown error.                               |
1428| 8301001  | SIM card is not activated.                   |
1429
1430**示例:**
1431
1432```ts
1433import { BusinessError } from '@kit.BasicServicesKit';
1434import { sim } from '@kit.TelephonyKit';
1435
1436sim.getDefaultVoiceSimId((err: BusinessError, data: number) => {
1437    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
1438});
1439```
1440
1441## sim.getDefaultVoiceSimId<sup>10+</sup>
1442
1443getDefaultVoiceSimId\(\): Promise\<number\>
1444
1445获取默认语音业务的SIM卡ID。使用Promise异步回调。
1446
1447**系统能力**:SystemCapability.Telephony.CoreService
1448
1449**返回值:**
1450
1451| 类型              | 说明                                    |
1452| ----------------- | --------------------------------------- |
1453| Promise\<number\> | 以Promise形式返回默认语音业务的SIM卡ID。<br/>与SIM卡绑定,从1开始递增。 |
1454
1455**错误码:**
1456
1457以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。
1458
1459| 错误码ID |                 错误信息                     |
1460| -------- | -------------------------------------------- |
1461| 8300001  | Invalid parameter value.                     |
1462| 8300002  | Service connection failed.                   |
1463| 8300003  | System internal error.                       |
1464| 8300004  | No SIM card found.                           |
1465| 8300999  | Unknown error.                               |
1466| 8301001  | SIM card is not activated.                   |
1467
1468**示例:**
1469
1470```ts
1471import { BusinessError } from '@kit.BasicServicesKit';
1472import { sim } from '@kit.TelephonyKit';
1473
1474let promise = sim.getDefaultVoiceSimId();
1475promise.then((data: number) => {
1476    console.log(`getDefaultVoiceSimId success, promise: data->${JSON.stringify(data)}`);
1477}).catch((err: BusinessError) => {
1478    console.error(`getDefaultVoiceSimId failed, promise: err->${JSON.stringify(err)}`);
1479});
1480```
1481
1482
1483## SimState
1484
1485SIM卡状态。
1486
1487**系统能力**:SystemCapability.Telephony.CoreService
1488
1489| 名称                  | 值   | 说明                                                       |
1490| --------------------- | ---- | ---------------------------------------------------------- |
1491| SIM_STATE_UNKNOWN     | 0    | SIM卡状态未知,即无法获取准确的状态。                      |
1492| SIM_STATE_NOT_PRESENT | 1    | 表示SIM卡处于not present状态,即卡槽中没有插入SIM卡。      |
1493| SIM_STATE_LOCKED      | 2    | 表示SIM卡处于locked状态,即SIM卡被PIN、PUK或网络锁锁定。   |
1494| SIM_STATE_NOT_READY   | 3    | 表示SIM卡处于not ready状态,即SIM卡在位但无法正常工作。    |
1495| SIM_STATE_READY       | 4    | 表示SIM卡处于ready状态,即SIM卡在位且工作正常。            |
1496| SIM_STATE_LOADED      | 5    | 表示SIM卡处于loaded状态,即SIM卡在位且所有卡文件加载完毕。 |
1497
1498## CardType<sup>7+</sup>
1499
1500卡类型。
1501
1502**系统能力**:SystemCapability.Telephony.CoreService
1503
1504| 名称 | 值 | 说明 |
1505| ----- | ----- | ----- |
1506|UNKNOWN_CARD | -1 | 未知类型。 |
1507|SINGLE_MODE_SIM_CARD | 10 | 单SIM卡。 |
1508|SINGLE_MODE_USIM_CARD | 20 | 单USIM卡。 |
1509|SINGLE_MODE_RUIM_CARD | 30 | 单RUIM卡。 |
1510|DUAL_MODE_CG_CARD | 40 | 双卡模式C+G。 |
1511|CT_NATIONAL_ROAMING_CARD | 41 | 中国电信内部漫游卡。 |
1512|CU_DUAL_MODE_CARD | 42 | 中国联通双模卡。 |
1513|DUAL_MODE_TELECOM_LTE_CARD | 43 | 双模式电信LTE卡。 |
1514|DUAL_MODE_UG_CARD | 50 | 双模式UG卡。 |
1515|SINGLE_MODE_ISIM_CARD<sup>8+</sup> | 60 | 单一ISIM卡类型。 |
1516
1517## IccAccountInfo<sup>10+</sup>
1518
1519Icc帐户信息。
1520
1521**系统能力**:SystemCapability.Telephony.CoreService
1522
1523| 名称       | 类型    | 必填 | 说明             |
1524| ---------- | ------- | ---- | ---------------- |
1525| simId      | number  |  是  | SIM卡ID。          |
1526| slotIndex  | number  |  是  | 卡槽ID。           |
1527| isEsim     | boolean |  是  | 标记卡是否是eSim。<br/>- true:是eSim。<br/>- false:不是eSim。 |
1528| isActive   | boolean |  是  | 卡是否被激活。   <br/>- true:激活。<br/>- false:未激活。  |
1529| iccId      | string  |  是  | ICCID号码。        |
1530| showName   | string  |  是  | SIM卡显示名称。    |
1531| showNumber | string  |  是  | SIM卡显示号码。    |