• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SIM卡管理
2
3>**说明:**
4>
5>本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
6>
7
8## 导入模块
9
10```
11import sim from '@ohos.telephony.sim';
12```
13
14## sim.isSimActive<sup>7+</sup>
15
16isSimActive\(slotId: number, callback: AsyncCallback<boolean\>\): void
17
18获取指定卡槽SIM卡是否激活,使用callback方式作为异步方法。
19
20**系统能力**:SystemCapability.Communication.CoreService
21
22**参数:**
23
24| 参数名   | 类型                        | 必填 | 说明                                   |
25| -------- | --------------------------- | ---- | -------------------------------------- |
26| slotId   | number                      | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
27| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。                             |
28
29**示例:**
30
31```
32sim.isSimActive(0, (err, data) => {
33    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
34});
35```
36
37
38## sim.isSimActive<sup>7+</sup>
39
40isSimActive\(slotId: number\): Promise<boolean\>
41
42获取指定卡槽SIM卡是否激活,使用Promise方式作为异步方法。
43
44**系统能力**:SystemCapability.Communication.CoreService
45
46**参数:**
47
48| 参数名 | 类型   | 必填 | 说明                                   |
49| ------ | ------ | ---- | -------------------------------------- |
50| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
51
52**返回值:**
53
54| 类型                  | 说明                               |
55| --------------------- | ---------------------------------- |
56| Promise&lt;boolean&gt; | 以Promise形式返回指定卡槽是否激活,如果激活返回true。 |
57
58**示例:**
59
60```
61let promise = sim.isSimActive(0);
62promise.then(data => {
63    console.log(`isSimActive success, promise: data->${JSON.stringify(data)}`);
64}).catch(err => {
65    console.log(`isSimActive fail, promise: err->${JSON.stringify(err)}`);
66});
67```
68
69
70## sim.getDefaultVoiceSlotId<sup>7+</sup>
71
72getDefaultVoiceSlotId\(callback: AsyncCallback<number\>\): void
73
74获取默认语音业务的卡槽ID,使用callback方式作为异步方法。
75
76**系统能力**:SystemCapability.Communication.CoreService
77
78**参数:**
79
80| 参数名   | 类型                        | 必填 | 说明       |
81| -------- | --------------------------- | ---- | ---------- |
82| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。 |
83
84**示例:**
85
86```
87sim.getDefaultVoiceSlotId((err, data) => {
88    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
89});
90```
91
92
93## sim.getDefaultVoiceSlotId<sup>7+</sup>
94
95getDefaultVoiceSlotId\(\): Promise<number\>
96
97获取默认语音业务的卡槽ID,使用Promise方式作为异步方法。
98
99**系统能力**:SystemCapability.Communication.CoreService
100
101**返回值:**
102
103| 类型              | 说明                                    |
104| ----------------- | --------------------------------------- |
105| Promise\<number\> | 以Promise形式返回默认语音业务的卡槽ID。 |
106
107**示例:**
108
109```
110let promise = sim.getDefaultVoiceSlotId();
111promise.then(data => {
112    console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`);
113}).catch(err => {
114    console.log(`getDefaultVoiceSlotId fail, promise: err->${JSON.stringify(err)}`);
115});
116```
117
118## sim.hasOperatorPrivileges<sup>7+</sup>
119
120hasOperatorPrivileges(slotId: number, callback: AsyncCallback\<boolean\>): void
121
122检查应用(调用者)是否已被授予运营商权限,使用callback方式作为异步方法。
123
124**系统能力**:SystemCapability.Communication.CoreService
125
126**参数:**
127
128| 参数名   | 类型                     | 必填 | 说明                                     |
129| -------- | ------------------------ | ---- | ---------------------------------------- |
130| slotId   | number                   | 是   | 卡槽ID。<br />- 0:卡槽1<br />- 1:卡槽2 |
131| callback | AsyncCallback\<boolean\> | 是   | 回调函数。                               |
132
133**示例:**
134
135```
136sim.hasOperatorPrivileges(0, (err, data) => {
137    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
138});
139```
140
141## sim.hasOperatorPrivileges<sup>7+</sup>
142
143hasOperatorPrivileges(slotId: number): Promise<boolean\>
144
145检查应用(调用者)是否已被授予运营商权限,使用Promise方式作为异步方法。
146
147**系统能力**:SystemCapability.Communication.CoreService
148
149**参数:**
150
151| 参数名 | 类型   | 必填 | 说明                                     |
152| ------ | ------ | ---- | ---------------------------------------- |
153| slotId | number | 是   | 卡槽ID。<br />- 0:卡槽1<br />- 1:卡槽2 |
154
155**返回值:**
156
157| 类型               | 说明                                                        |
158| :----------------- | :---------------------------------------------------------- |
159| Promise\<boolean\> | 以Promise形式返回检查应用(调用者)是否已被授予运营商权限。 |
160
161**示例:**
162
163```
164let promise = sim.hasOperatorPrivileges(0);
165promise.then(data => {
166    console.log(`hasOperatorPrivileges success, promise: data->${JSON.stringify(data)}`);
167}).catch(err => {
168    console.log(`hasOperatorPrivileges fail, promise: err->${JSON.stringify(err)}`);
169});
170```
171
172## sim.getISOCountryCodeForSim
173
174getISOCountryCodeForSim\(slotId: number, callback: AsyncCallback<string\>\): void
175
176获取指定卡槽SIM卡的ISO国家码,使用callback方式作为异步方法。
177
178**系统能力**:SystemCapability.Communication.CoreService
179
180**参数:**
181
182| 参数名   | 类型                    | 必填 | 说明                                     |
183| -------- | ----------------------- | ---- | ---------------------------------------- |
184| slotId   | number                  | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2   |
185| callback | AsyncCallback\<string\> | 是   | 回调函数。返回国家码,例如:CN(中国)。 |
186
187**示例:**
188
189```
190sim.getISOCountryCodeForSim(0, (err, data) => {
191    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
192});
193```
194
195
196## sim.getISOCountryCodeForSim
197
198getISOCountryCodeForSim\(slotId: number\): Promise<string\>
199
200获取指定卡槽SIM卡的ISO国家码,使用Promise方式作为异步方法。
201
202**系统能力**:SystemCapability.Communication.CoreService
203
204**参数:**
205
206| 参数名 | 类型   | 必填 | 说明                                   |
207| ------ | ------ | ---- | -------------------------------------- |
208| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
209
210**返回值:**
211
212| 类型              | 说明                                                         |
213| ----------------- | ------------------------------------------------------------ |
214| Promise\<string\> | 以Promise形式返回获取指定卡槽SIM卡的ISO国家码,例如:CN(中国)。 |
215
216**示例:**
217
218```
219let promise = sim.getISOCountryCodeForSim(0);
220promise.then(data => {
221    console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`);
222}).catch(err => {
223    console.log(`getISOCountryCodeForSim fail, promise: err->${JSON.stringify(err)}`);
224});
225```
226
227
228## sim.getSimOperatorNumeric
229
230getSimOperatorNumeric\(slotId: number, callback: AsyncCallback<string\>\): void
231
232获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号,使用callback方式作为异步方法。
233
234**系统能力**:SystemCapability.Communication.CoreService
235
236**参数:**
237
238| 参数名   | 类型                    | 必填 | 说明                                   |
239| -------- | ----------------------- | ---- | -------------------------------------- |
240| slotId   | number                  | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
241| callback | AsyncCallback\<string\> | 是   | 回调函数。                             |
242
243**示例:**
244
245```
246sim.getSimOperatorNumeric(0, (err, data) => {
247    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
248});
249```
250
251
252## sim.getSimOperatorNumeric
253
254getSimOperatorNumeric\(slotId: number\): Promise<string\>
255
256获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号,使用Promise方式作为异步方法。
257
258**系统能力**:SystemCapability.Communication.CoreService
259
260**参数:**
261
262| 参数名 | 类型   | 必填 | 说明                                   |
263| ------ | ------ | ---- | -------------------------------------- |
264| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
265
266**返回值:**
267
268| 类型              | 说明                                             |
269| ----------------- | ------------------------------------------------ |
270| Promise\<string\> | 以Promise形式返回获取指定卡槽SIM卡的归属PLMN号。 |
271
272**示例:**
273
274```
275let promise = sim.getSimOperatorNumeric(0);
276promise.then(data => {
277    console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`);
278}).catch(err => {
279    console.log(`getSimOperatorNumeric fail, promise: err->${JSON.stringify(err)}`);
280});
281```
282
283
284## sim.getSimSpn
285
286getSimSpn\(slotId: number, callback: AsyncCallback<string\>\): void
287
288获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN),使用callback方式作为异步方法。
289
290**系统能力**:SystemCapability.Communication.CoreService
291
292**参数:**
293
294| 参数名   | 类型                    | 必填 | 说明                                   |
295| -------- | ----------------------- | ---- | -------------------------------------- |
296| slotId   | number                  | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
297| callback | AsyncCallback\<string\> | 是   | 回调函数。                             |
298
299**示例:**
300
301```
302sim.getSimSpn(0, (err, data) => {
303    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
304});
305```
306
307
308## sim.getSimSpn
309
310getSimSpn\(slotId: number\): Promise<string\>
311
312获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN),使用Promise方式作为异步方法。
313
314**系统能力**:SystemCapability.Communication.CoreService
315
316**参数:**
317
318| 参数名 | 类型   | 必填 | 说明                                   |
319| ------ | ------ | ---- | -------------------------------------- |
320| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
321
322**返回值:**
323
324| 类型              | 说明                                      |
325| ----------------- | ----------------------------------------- |
326| Promise\<string\> | 以Promise形式返回获取指定卡槽SIM卡的SPN。 |
327
328**示例:**
329
330```
331let promise = sim.getSimSpn(0);
332promise.then(data => {
333    console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`);
334}).catch(err => {
335    console.log(`getSimSpn fail, promise: err->${JSON.stringify(err)}`);
336});
337```
338
339
340## sim.getSimState
341
342getSimState\(slotId: number, callback: AsyncCallback<SimState\>\): void
343
344获取指定卡槽的SIM卡状态,使用callback方式作为异步方法。
345
346**系统能力**:SystemCapability.Communication.CoreService
347
348**参数:**
349
350| 参数名   | 类型                                   | 必填 | 说明                                   |
351| -------- | -------------------------------------- | ---- | -------------------------------------- |
352| slotId   | number                                 | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
353| callback | AsyncCallback\<[SimState](#simstate)\> | 是   | 回调函数。参考[SimState](#simstate)。  |
354
355**示例:**
356
357```
358sim.getSimState(0, (err, data) => {
359    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
360});
361```
362
363
364## sim.getSimState
365
366getSimState\(slotId: number\): Promise<SimState\>
367
368获取指定卡槽的SIM卡状态,使用Promise方式作为异步方法。
369
370**系统能力**:SystemCapability.Communication.CoreService
371
372**参数:**
373
374| 参数名 | 类型   | 必填 | 说明                                   |
375| ------ | ------ | ---- | -------------------------------------- |
376| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
377
378**返回值:**
379
380| 类型                             | 说明                                       |
381| -------------------------------- | ------------------------------------------ |
382| Promise\<[SimState](#simstate)\> | 以Promise形式返回获取指定卡槽的SIM卡状态。 |
383
384**示例:**
385
386```
387let promise = sim.getSimState(0);
388promise.then(data => {
389    console.log(`getSimState success, promise: data->${JSON.stringify(data)}`);
390}).catch(err => {
391    console.log(`getSimState fail, promise: err->${JSON.stringify(err)}`);
392});
393```
394
395## sim.getCardType<sup>7+</sup>
396
397getCardType\(slotId: number, callback: AsyncCallback<CardType\>\): void
398
399获取指定卡槽SIM卡的卡类型,使用callback方式作为异步方法。
400
401**系统能力**:SystemCapability.Communication.CoreService
402
403**参数:**
404
405| 参数名   | 类型                    | 必填 | 说明                                   |
406| -------- | ----------------------- | ---- | -------------------------------------- |
407| slotId   | number                  | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
408| callback | AsyncCallback\<[CardType](#cardtype7)\> | 是   | 回调函数。                             |
409
410**示例:**
411
412```
413sim.getCardType(0, (err, data) => {
414    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
415});
416```
417
418
419## sim.getCardType<sup>7+</sup>
420
421getCardType\(slotId: number\): Promise<CardType\>
422
423获取指定卡槽SIM卡的卡类型,使用Promise方式作为异步方法。
424
425**系统能力**:SystemCapability.Communication.CoreService
426
427**参数:**
428
429| 参数名 | 类型   | 必填 | 说明                                   |
430| ------ | ------ | ---- | -------------------------------------- |
431| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
432
433**返回值:**
434
435| 类型              | 说明                                                         |
436| ----------------- | ------------------------------------------------------------ |
437| Promise\<[CardType](#cardtype7)\> | 以Promise形式返回指定卡槽SIM卡的卡类型。 |
438
439**示例:**
440
441```
442let promise = sim.getCardType(0);
443promise.then(data => {
444    console.log(`getCardType success, promise: data->${JSON.stringify(data)}`);
445}).catch(err => {
446    console.log(`getCardType fail, promise: err->${JSON.stringify(err)}`);
447});
448```
449
450
451## sim.hasSimCard<sup>7+</sup>
452
453hasSimCard\(slotId: number, callback: AsyncCallback<boolean\>\): void
454
455获取指定卡槽SIM卡是否插卡,使用callback方式作为异步方法。
456
457**系统能力**:SystemCapability.Communication.CoreService
458
459**参数:**
460
461| 参数名   | 类型                        | 必填 | 说明                                   |
462| -------- | --------------------------- | ---- | -------------------------------------- |
463| slotId   | number                      | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
464| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。                             |
465
466**示例:**
467
468```
469sim.hasSimCard(0, (err, data) => {
470    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
471});
472```
473
474
475## sim.hasSimCard<sup>7+</sup>
476
477hasSimCard\(slotId: number\): Promise<boolean\>
478
479获取指定卡槽SIM卡是否插卡,使用Promise方式作为异步方法。
480
481**系统能力**:SystemCapability.Communication.CoreService
482
483**参数:**
484
485| 参数名 | 类型   | 必填 | 说明                                   |
486| ------ | ------ | ---- | -------------------------------------- |
487| slotId | number | 是   | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 |
488
489**返回值:**
490
491| 类型                  | 说明                               |
492| --------------------- | ---------------------------------- |
493| Promise&lt;boolean&gt; | 以Promise形式返回指定卡槽是否插卡,如果插卡返回true。 |
494
495**示例:**
496
497```
498let promise = sim.hasSimCard(0);
499promise.then(data => {
500    console.log(`hasSimCard success, promise: data->${JSON.stringify(data)}`);
501}).catch(err => {
502    console.log(`hasSimCard fail, promise: err->${JSON.stringify(err)}`);
503});
504```
505
506
507## sim.getMaxSimCount<sup>7+</sup>
508
509getMaxSimCount\(\): number
510
511获取卡槽数量。
512
513**系统能力**:SystemCapability.Communication.CoreService
514
515**返回值:**
516
517| 类型              | 说明                                                         |
518| ----------------- | ------------------------------------------------------------ |
519| number | 卡槽数量。 |
520
521**示例:**
522
523```
524console.log("Result: "+ sim.getMaxSimCount())
525```
526
527
528## SimState
529
530SIM卡状态。
531
532**系统能力**:以下各项对应的系统能力均为SystemCapability.Telephony.CoreService533
534| 名称                  | 值   | 说明                                                       |
535| --------------------- | ---- | ---------------------------------------------------------- |
536| SIM_STATE_UNKNOWN     | 0    | SIM卡状态未知,即无法获取准确的状态。                      |
537| SIM_STATE_NOT_PRESENT | 1    | 表示SIM卡处于not present状态,即卡槽中没有插入SIM卡。      |
538| SIM_STATE_LOCKED      | 2    | 表示SIM卡处于locked状态,即SIM卡被PIN、PUK或网络锁锁定。   |
539| SIM_STATE_NOT_READY   | 3    | 表示SIM卡处于not ready状态,即SIM卡在位但无法正常工作。    |
540| SIM_STATE_READY       | 4    | 表示SIM卡处于ready状态,即SIM卡在位且工作正常。            |
541| SIM_STATE_LOADED      | 5    | 表示SIM卡处于loaded状态,即SIM卡在位且所有卡文件加载完毕。 |
542
543## CardType<sup>7+</sup>
544
545卡类型。
546
547**系统能力**:以下各项对应的系统能力均为SystemCapability.Telephony.CoreService548
549| 名称 | 值 | 说明 |
550| ----- | ----- | ----- |
551|UNKNOWN_CARD | -1 | 未知类型 |
552|SINGLE_MODE_SIM_CARD | 10 | 单SIM卡 |
553|SINGLE_MODE_USIM_CARD | 20 | 单USIM卡 |
554|SINGLE_MODE_RUIM_CARD | 30 | 单RUIM卡 |
555|DUAL_MODE_CG_CARD | 40 | 双卡模式C+G |
556|CT_NATIONAL_ROAMING_CARD | 41 | 中国电信内部漫游卡 |
557|CU_DUAL_MODE_CARD | 42 | 中国联通双模卡 |
558|DUAL_MODE_TELECOM_LTE_CARD | 43 | 双模式电信LTE卡 |
559|DUAL_MODE_UG_CARD | 50 | 双模式UG卡 |
560|SINGLE_MODE_ISIM_CARD<sup>8+</sup> | 60 | 单一ISIM卡类型 |