• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SIM Management
2
3> **NOTE**<br>
4> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
5
6## Modules to Import
7
8```js
9import sim from '@ohos.telephony.sim';
10```
11
12## sim.isSimActive<sup>7+</sup>
13
14isSimActive\(slotId: number, callback: AsyncCallback<boolean\>\): void
15
16Checks whether the SIM card in the specified slot is activated. This API uses an asynchronous callback to return the result.
17
18**System capability**: SystemCapability.Communication.CoreService
19
20**Parameters**
21
22| Name  | Type                       | Mandatory| Description                                  |
23| -------- | --------------------------- | ---- | -------------------------------------- |
24| slotId   | number                      | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
25| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result.                            |
26
27**Example**
28
29```js
30sim.isSimActive(0, (err, data) => {
31    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
32});
33```
34
35
36## sim.isSimActive<sup>7+</sup>
37
38isSimActive\(slotId: number\): Promise<boolean\>
39
40Checks whether the SIM card in the specified slot is activated. This API uses a promise to return the result.
41
42**System capability**: SystemCapability.Communication.CoreService
43
44**Parameters**
45
46| Name| Type  | Mandatory| Description                                  |
47| ------ | ------ | ---- | -------------------------------------- |
48| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
49
50**Return value**
51
52| Type                 | Description                              |
53| --------------------- | ---------------------------------- |
54| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** indicates that the SIM card in the specified slot is activated, and the value **false** indicates the opposite.|
55
56**Example**
57
58```js
59let promise = sim.isSimActive(0);
60promise.then(data => {
61    console.log(`isSimActive success, promise: data->${JSON.stringify(data)}`);
62}).catch(err => {
63    console.log(`isSimActive fail, promise: err->${JSON.stringify(err)}`);
64});
65```
66
67
68## sim.getDefaultVoiceSlotId<sup>7+</sup>
69
70getDefaultVoiceSlotId\(callback: AsyncCallback<number\>\): void
71
72Obtains the default slot ID of the SIM card that provides voice services. This API uses an asynchronous callback to return the result.
73
74**System capability**: SystemCapability.Communication.CoreService
75
76**Parameters**
77
78| Name  | Type                       | Mandatory| Description      |
79| -------- | --------------------------- | ---- | ---------- |
80| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the result.|
81
82**Example**
83
84```js
85sim.getDefaultVoiceSlotId((err, data) => {
86    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
87});
88```
89
90
91## sim.getDefaultVoiceSlotId<sup>7+</sup>
92
93getDefaultVoiceSlotId\(\): Promise<number\>
94
95Obtains the default slot ID of the SIM card that provides voice services. This API uses a promise to return the result.
96
97**System capability**: SystemCapability.Communication.CoreService
98
99**Return value**
100
101| Type             | Description                                   |
102| ----------------- | --------------------------------------- |
103| Promise\<number\> | Promise used to return the result.|
104
105**Example**
106
107```js
108let promise = sim.getDefaultVoiceSlotId();
109promise.then(data => {
110    console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`);
111}).catch(err => {
112    console.log(`getDefaultVoiceSlotId fail, promise: err->${JSON.stringify(err)}`);
113});
114```
115
116## sim.hasOperatorPrivileges<sup>7+</sup>
117
118hasOperatorPrivileges(slotId: number, callback: AsyncCallback\<boolean\>): void
119
120Checks whether the application (caller) has been granted the operator permission. This API uses an asynchronous callback to return the result.
121
122**System capability**: SystemCapability.Communication.CoreService
123
124**Parameters**
125
126| Name  | Type                    | Mandatory| Description                                    |
127| -------- | ------------------------ | ---- | ---------------------------------------- |
128| slotId   | number                   | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
129| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.                              |
130
131**Example**
132
133```js
134sim.hasOperatorPrivileges(0, (err, data) => {
135    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
136});
137```
138
139## sim.hasOperatorPrivileges<sup>7+</sup>
140
141hasOperatorPrivileges(slotId: number): Promise<boolean\>
142
143Checks whether the application (caller) has been granted the operator permission. This API uses a promise to return the result.
144
145**System capability**: SystemCapability.Communication.CoreService
146
147**Parameters**
148
149| Name| Type  | Mandatory| Description                                    |
150| ------ | ------ | ---- | ---------------------------------------- |
151| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
152
153**Return value**
154
155| Type              | Description                                                       |
156| :----------------- | :---------------------------------------------------------- |
157| Promise\<boolean\> | Promise used to return the result. The value **true** indicates that the application (caller) has been granted the operator permission, and the value **false** indicates the opposite.|
158
159**Example**
160
161```js
162let promise = sim.hasOperatorPrivileges(0);
163promise.then(data => {
164    console.log(`hasOperatorPrivileges success, promise: data->${JSON.stringify(data)}`);
165}).catch(err => {
166    console.log(`hasOperatorPrivileges fail, promise: err->${JSON.stringify(err)}`);
167});
168```
169
170## sim.getISOCountryCodeForSim
171
172getISOCountryCodeForSim\(slotId: number, callback: AsyncCallback<string\>\): void
173
174Obtains the ISO country code of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.
175
176**System capability**: SystemCapability.Communication.CoreService
177
178**Parameters**
179
180| Name  | Type                   | Mandatory| Description                                    |
181| -------- | ----------------------- | ---- | ---------------------------------------- |
182| slotId   | number                  | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2  |
183| callback | AsyncCallback\<string\> | Yes  | Callback used to return the result, which is a country code, for example, **CN** (China).|
184
185**Example**
186
187```js
188sim.getISOCountryCodeForSim(0, (err, data) => {
189    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
190});
191```
192
193
194## sim.getISOCountryCodeForSim
195
196getISOCountryCodeForSim\(slotId: number\): Promise<string\>
197
198Obtains the ISO country code of the SIM card in the specified slot. This API uses a promise to return the result.
199
200**System capability**: SystemCapability.Communication.CoreService
201
202**Parameters**
203
204| Name| Type  | Mandatory| Description                                  |
205| ------ | ------ | ---- | -------------------------------------- |
206| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
207
208**Return value**
209
210| Type             | Description                                                        |
211| ----------------- | ------------------------------------------------------------ |
212| Promise\<string\> | Promise used to return the result, which is a country code, for example, **CN** (China).|
213
214**Example**
215
216```js
217let promise = sim.getISOCountryCodeForSim(0);
218promise.then(data => {
219    console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`);
220}).catch(err => {
221    console.log(`getISOCountryCodeForSim fail, promise: err->${JSON.stringify(err)}`);
222});
223```
224
225
226## sim.getSimOperatorNumeric
227
228getSimOperatorNumeric\(slotId: number, callback: AsyncCallback<string\>\): void
229
230Obtains the public land mobile network (PLMN) ID of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.
231
232**System capability**: SystemCapability.Communication.CoreService
233
234**Parameters**
235
236| Name  | Type                   | Mandatory| Description                                  |
237| -------- | ----------------------- | ---- | -------------------------------------- |
238| slotId   | number                  | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
239| callback | AsyncCallback\<string\> | Yes  | Callback used to return the result.                            |
240
241**Example**
242
243```js
244sim.getSimOperatorNumeric(0, (err, data) => {
245    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
246});
247```
248
249
250## sim.getSimOperatorNumeric
251
252getSimOperatorNumeric\(slotId: number\): Promise<string\>
253
254Obtains the PLMN ID of the SIM card in the specified slot. This API uses a promise to return the result.
255
256**System capability**: SystemCapability.Communication.CoreService
257
258**Parameters**
259
260| Name| Type  | Mandatory| Description                                  |
261| ------ | ------ | ---- | -------------------------------------- |
262| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
263
264**Return value**
265
266| Type             | Description                                            |
267| ----------------- | ------------------------------------------------ |
268| Promise\<string\> | Promise used to return the result.|
269
270**Example**
271
272```js
273let promise = sim.getSimOperatorNumeric(0);
274promise.then(data => {
275    console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`);
276}).catch(err => {
277    console.log(`getSimOperatorNumeric fail, promise: err->${JSON.stringify(err)}`);
278});
279```
280
281
282## sim.getSimSpn
283
284getSimSpn\(slotId: number, callback: AsyncCallback<string\>\): void
285
286Obtains the service provider name (SPN) of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.
287
288**System capability**: SystemCapability.Communication.CoreService
289
290**Parameters**
291
292| Name  | Type                   | Mandatory| Description                                  |
293| -------- | ----------------------- | ---- | -------------------------------------- |
294| slotId   | number                  | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
295| callback | AsyncCallback\<string\> | Yes  | Callback used to return the result.                            |
296
297**Example**
298
299```js
300sim.getSimSpn(0, (err, data) => {
301    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
302});
303```
304
305
306## sim.getSimSpn
307
308getSimSpn\(slotId: number\): Promise<string\>
309
310Obtains the SPN of the SIM card in the specified slot. This API uses a promise to return the result.
311
312**System capability**: SystemCapability.Communication.CoreService
313
314**Parameters**
315
316| Name| Type  | Mandatory| Description                                  |
317| ------ | ------ | ---- | -------------------------------------- |
318| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
319
320**Return value**
321
322| Type             | Description                                     |
323| ----------------- | ----------------------------------------- |
324| Promise\<string\> | Promise used to return the result.|
325
326**Example**
327
328```js
329let promise = sim.getSimSpn(0);
330promise.then(data => {
331    console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`);
332}).catch(err => {
333    console.log(`getSimSpn fail, promise: err->${JSON.stringify(err)}`);
334});
335```
336
337
338## sim.getSimState
339
340getSimState\(slotId: number, callback: AsyncCallback<SimState\>\): void
341
342Obtains the status of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.
343
344**System capability**: SystemCapability.Communication.CoreService
345
346**Parameters**
347
348| Name  | Type                                  | Mandatory| Description                                  |
349| -------- | -------------------------------------- | ---- | -------------------------------------- |
350| slotId   | number                                 | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
351| callback | AsyncCallback\<[SimState](#simstate)\> | Yes  | Callback used to return the result. For details, see [SimState](#simstate). |
352
353**Example**
354
355```js
356sim.getSimState(0, (err, data) => {
357    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
358});
359```
360
361
362## sim.getSimState
363
364getSimState\(slotId: number\): Promise<SimState\>
365
366Obtains the status of the SIM card in the specified slot. This API uses a promise to return the result.
367
368**System capability**: SystemCapability.Communication.CoreService
369
370**Parameters**
371
372| Name| Type  | Mandatory| Description                                  |
373| ------ | ------ | ---- | -------------------------------------- |
374| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
375
376**Return value**
377
378| Type                            | Description                                      |
379| -------------------------------- | ------------------------------------------ |
380| Promise\<[SimState](#simstate)\> | Promise used to return the result.|
381
382**Example**
383
384```js
385let promise = sim.getSimState(0);
386promise.then(data => {
387    console.log(`getSimState success, promise: data->${JSON.stringify(data)}`);
388}).catch(err => {
389    console.log(`getSimState fail, promise: err->${JSON.stringify(err)}`);
390});
391```
392
393## sim.getCardType<sup>7+</sup>
394
395getCardType\(slotId: number, callback: AsyncCallback<CardType\>\): void
396
397Obtains the type of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.
398
399**System capability**: SystemCapability.Communication.CoreService
400
401**Parameters**
402
403| Name  | Type                   | Mandatory| Description                                  |
404| -------- | ----------------------- | ---- | -------------------------------------- |
405| slotId   | number                  | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
406| callback | AsyncCallback\<[CardType](#cardtype7)\> | Yes  | Callback used to return the result.                            |
407
408**Example**
409
410```js
411sim.getCardType(0, (err, data) => {
412    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
413});
414```
415
416
417## sim.getCardType<sup>7+</sup>
418
419getCardType\(slotId: number\): Promise<CardType\>
420
421Obtains the type of the SIM card in the specified slot. This API uses a promise to return the result.
422
423**System capability**: SystemCapability.Communication.CoreService
424
425**Parameters**
426
427| Name| Type  | Mandatory| Description                                  |
428| ------ | ------ | ---- | -------------------------------------- |
429| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
430
431**Return value**
432
433| Type             | Description                                                        |
434| ----------------- | ------------------------------------------------------------ |
435| Promise\<[CardType](#cardtype7)\> | Promise used to return the result.|
436
437**Example**
438
439```js
440let promise = sim.getCardType(0);
441promise.then(data => {
442    console.log(`getCardType success, promise: data->${JSON.stringify(data)}`);
443}).catch(err => {
444    console.log(`getCardType fail, promise: err->${JSON.stringify(err)}`);
445});
446```
447
448
449## sim.hasSimCard<sup>7+</sup>
450
451hasSimCard\(slotId: number, callback: AsyncCallback<boolean\>\): void
452
453Checks whether the SIM card in the specified slot is installed. This API uses an asynchronous callback to return the result.
454
455**System capability**: SystemCapability.Communication.CoreService
456
457**Parameters**
458
459| Name  | Type                       | Mandatory| Description                                  |
460| -------- | --------------------------- | ---- | -------------------------------------- |
461| slotId   | number                      | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
462| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result.                            |
463
464**Example**
465
466```js
467sim.hasSimCard(0, (err, data) => {
468    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
469});
470```
471
472
473## sim.hasSimCard<sup>7+</sup>
474
475hasSimCard\(slotId: number\): Promise<boolean\>
476
477Checks whether the SIM card in the specified slot is installed. This API uses a promise to return the result.
478
479**System capability**: SystemCapability.Communication.CoreService
480
481**Parameters**
482
483| Name| Type  | Mandatory| Description                                  |
484| ------ | ------ | ---- | -------------------------------------- |
485| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
486
487**Return value**
488
489| Type                 | Description                              |
490| --------------------- | ---------------------------------- |
491| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** indicates that the SIM card in the specified slot is installed, and the value **false** indicates the opposite.|
492
493**Example**
494
495```js
496let promise = sim.hasSimCard(0);
497promise.then(data => {
498    console.log(`hasSimCard success, promise: data->${JSON.stringify(data)}`);
499}).catch(err => {
500    console.log(`hasSimCard fail, promise: err->${JSON.stringify(err)}`);
501});
502```
503
504
505## sim.getMaxSimCount<sup>7+</sup>
506
507getMaxSimCount\(\): number
508
509Obtains the number of card slots.
510
511**System capability**: SystemCapability.Communication.CoreService
512
513**Return value**
514
515| Type             | Description                                                        |
516| ----------------- | ------------------------------------------------------------ |
517| number | Number of card slots.|
518
519**Example**
520
521```js
522console.log("Result: "+ sim.getMaxSimCount())
523```
524
525
526## SimState
527
528Enumerates SIM card states.
529
530**System capability**: SystemCapability.Telephony.CoreService
531
532| Name                 | Value  | Description                                                      |
533| --------------------- | ---- | ---------------------------------------------------------- |
534| SIM_STATE_UNKNOWN     | 0    | The SIM card is in **unknown** state; that is, the SIM card status cannot be obtained.                     |
535| SIM_STATE_NOT_PRESENT | 1    | The SIM card is in **not present** state; that is, no SIM card is inserted into the slot.     |
536| SIM_STATE_LOCKED      | 2    | The SIM card is in **locked** state; that is, the SIM card is locked by the personal identification number (PIN), PIN unblocking key (PUK), or network.  |
537| SIM_STATE_NOT_READY   | 3    | The SIM card is in **not ready** state; that is, the SIM card is present but cannot work properly.   |
538| SIM_STATE_READY       | 4    | The SIM card is in **ready** state; that is, the SIM card is present and is working properly.           |
539| SIM_STATE_LOADED      | 5    | The SIM card is in **loaded** state; that is, the SIM card is present and all its files have been loaded.|
540
541## CardType<sup>7+</sup>
542
543Enumerates card types.
544
545**System capability**: SystemCapability.Telephony.CoreService
546
547| Name| Value| Description|
548| ----- | ----- | ----- |
549|UNKNOWN_CARD | -1 | Unknown|
550|SINGLE_MODE_SIM_CARD | 10 | Single-card (SIM)|
551|SINGLE_MODE_USIM_CARD | 20 | Single-card (USIM)|
552|SINGLE_MODE_RUIM_CARD | 30 | Single-card (RUIM)|
553|DUAL_MODE_CG_CARD | 40 | Dual-card (CDMA+GSM)|
554|CT_NATIONAL_ROAMING_CARD | 41 | China Telecom internal roaming card|
555|CU_DUAL_MODE_CARD | 42 | China Unicom dual-mode card|
556|DUAL_MODE_TELECOM_LTE_CARD | 43 | China Telecom dual-mode LTE card|
557|DUAL_MODE_UG_CARD | 50 | Dual-mode card (UMTS+GSM)|
558|SINGLE_MODE_ISIM_CARD<sup>8+</sup> | 60 | Single-card (ISIM)|
559