js-apis-sim.md 19.8 KB
Newer Older
S
shawn_he 已提交
1 2
# SIM Management

S
shawn_he 已提交
3
>**NOTE**
S
shawn_he 已提交
4
>
Z
zengyawen 已提交
5
>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.
S
shawn_he 已提交
6
>
S
shawn_he 已提交
7 8 9 10 11 12 13

## Modules to Import

```
import sim from '@ohos.telephony.sim';
```

S
shawn_he 已提交
14
## sim.isSimActive<sup>7+</sup>
S
shawn_he 已提交
15

S
shawn_he 已提交
16
isSimActive\(slotId: number, callback: AsyncCallback<boolean\>\): void
S
shawn_he 已提交
17

S
shawn_he 已提交
18
Checks whether the SIM card in the specified slot is activated. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
19

S
shawn_he 已提交
20
**System capability**: SystemCapability.Communication.CoreService
S
shawn_he 已提交
21

S
shawn_he 已提交
22
**Parameters**
S
shawn_he 已提交
23

S
shawn_he 已提交
24
| Name  | Type                       | Mandatory| Description                                  |
S
shawn_he 已提交
25
| -------- | --------------------------- | ---- | -------------------------------------- |
S
shawn_he 已提交
26
| slotId   | number                      | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
27
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result.                            |
S
shawn_he 已提交
28

S
shawn_he 已提交
29
**Example**
S
shawn_he 已提交
30

S
shawn_he 已提交
31
```
S
shawn_he 已提交
32
sim.isSimActive(0, (err, data) => {
S
shawn_he 已提交
33 34 35
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
36 37


S
shawn_he 已提交
38
## sim.isSimActive<sup>7+</sup>
S
shawn_he 已提交
39

S
shawn_he 已提交
40
isSimActive\(slotId: number\): Promise<boolean\>
S
shawn_he 已提交
41

S
shawn_he 已提交
42
Checks whether the SIM card in the specified slot is activated. This API uses a promise to return the result.
S
shawn_he 已提交
43

S
shawn_he 已提交
44
**System capability**: SystemCapability.Communication.CoreService
S
shawn_he 已提交
45

S
shawn_he 已提交
46
**Parameters**
S
shawn_he 已提交
47

S
shawn_he 已提交
48
| Name| Type  | Mandatory| Description                                  |
S
shawn_he 已提交
49
| ------ | ------ | ---- | -------------------------------------- |
S
shawn_he 已提交
50
| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
51

S
shawn_he 已提交
52
**Return value**
S
shawn_he 已提交
53

S
shawn_he 已提交
54
| Type                 | Description                              |
S
shawn_he 已提交
55
| --------------------- | ---------------------------------- |
S
shawn_he 已提交
56
| 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.|
S
shawn_he 已提交
57

S
shawn_he 已提交
58
**Example**
S
shawn_he 已提交
59

S
shawn_he 已提交
60
```
S
shawn_he 已提交
61
let promise = sim.isSimActive(0);
S
shawn_he 已提交
62
promise.then(data => {
S
shawn_he 已提交
63
    console.log(`isSimActive success, promise: data->${JSON.stringify(data)}`);
S
shawn_he 已提交
64
}).catch(err => {
S
shawn_he 已提交
65
    console.log(`isSimActive fail, promise: err->${JSON.stringify(err)}`);
S
shawn_he 已提交
66 67
});
```
S
shawn_he 已提交
68

S
shawn_he 已提交
69 70

## sim.getDefaultVoiceSlotId<sup>7+</sup>
S
shawn_he 已提交
71 72 73

getDefaultVoiceSlotId\(callback: AsyncCallback<number\>\): void

S
shawn_he 已提交
74
Obtains the default slot ID of the SIM card that provides voice services. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
75

S
shawn_he 已提交
76 77
**System capability**: SystemCapability.Communication.CoreService

S
shawn_he 已提交
78
**Parameters**
S
shawn_he 已提交
79

S
shawn_he 已提交
80
| Name  | Type                       | Mandatory| Description      |
S
shawn_he 已提交
81
| -------- | --------------------------- | ---- | ---------- |
S
shawn_he 已提交
82
| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the result.|
S
shawn_he 已提交
83

S
shawn_he 已提交
84
**Example**
S
shawn_he 已提交
85

S
shawn_he 已提交
86 87 88 89 90
```
sim.getDefaultVoiceSlotId((err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
91 92


S
shawn_he 已提交
93
## sim.getDefaultVoiceSlotId<sup>7+</sup>
S
shawn_he 已提交
94 95 96

getDefaultVoiceSlotId\(\): Promise<number\>

S
shawn_he 已提交
97
Obtains the default slot ID of the SIM card that provides voice services. This API uses a promise to return the result.
S
shawn_he 已提交
98

S
shawn_he 已提交
99
**System capability**: SystemCapability.Communication.CoreService
S
shawn_he 已提交
100

S
shawn_he 已提交
101
**Return value**
S
shawn_he 已提交
102 103

| Type             | Description                                   |
S
shawn_he 已提交
104 105
| ----------------- | --------------------------------------- |
| Promise\<number\> | Promise used to return the result.|
S
shawn_he 已提交
106

S
shawn_he 已提交
107
**Example**
S
shawn_he 已提交
108

S
shawn_he 已提交
109 110 111 112 113 114 115 116
```
let promise = sim.getDefaultVoiceSlotId();
promise.then(data => {
    console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.log(`getDefaultVoiceSlotId fail, promise: err->${JSON.stringify(err)}`);
});
```
S
shawn_he 已提交
117

S
shawn_he 已提交
118 119 120 121
## sim.hasOperatorPrivileges<sup>7+</sup>

hasOperatorPrivileges(slotId: number, callback: AsyncCallback\<boolean\>): void

S
shawn_he 已提交
122
Checks whether the application (caller) has been granted the operator permission. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
123 124 125 126 127 128 129

**System capability**: SystemCapability.Communication.CoreService

**Parameters**

| Name  | Type                    | Mandatory| Description                                    |
| -------- | ------------------------ | ---- | ---------------------------------------- |
S
shawn_he 已提交
130
| slotId   | number                   | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
131 132 133 134 135 136 137 138 139 140 141 142
| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.                              |

**Example**

```
sim.hasOperatorPrivileges(0, (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```

## sim.hasOperatorPrivileges<sup>7+</sup>

S
shawn_he 已提交
143
hasOperatorPrivileges(slotId: number): Promise<boolean\>
S
shawn_he 已提交
144

S
shawn_he 已提交
145
Checks whether the application (caller) has been granted the operator permission. This API uses a promise to return the result. 
S
shawn_he 已提交
146 147 148 149 150 151 152

**System capability**: SystemCapability.Communication.CoreService

**Parameters**

| Name| Type  | Mandatory| Description                                    |
| ------ | ------ | ---- | ---------------------------------------- |
S
shawn_he 已提交
153
| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
154

S
shawn_he 已提交
155
**Return value**
S
shawn_he 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

| Type              | Description                                                       |
| :----------------- | :---------------------------------------------------------- |
| 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.|

**Example**

```
let promise = sim.hasOperatorPrivileges(0);
promise.then(data => {
    console.log(`hasOperatorPrivileges success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.log(`hasOperatorPrivileges fail, promise: err->${JSON.stringify(err)}`);
});
```

## sim.getISOCountryCodeForSim
S
shawn_he 已提交
173 174 175

getISOCountryCodeForSim\(slotId: number, callback: AsyncCallback<string\>\): void

S
shawn_he 已提交
176
Obtains the ISO country code of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
177

S
shawn_he 已提交
178 179
**System capability**: SystemCapability.Communication.CoreService

S
shawn_he 已提交
180
**Parameters**
S
shawn_he 已提交
181

S
shawn_he 已提交
182
| Name  | Type                   | Mandatory| Description                                    |
S
shawn_he 已提交
183
| -------- | ----------------------- | ---- | ---------------------------------------- |
S
shawn_he 已提交
184
| slotId   | number                  | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2  |
S
shawn_he 已提交
185
| callback | AsyncCallback\<string\> | Yes  | Callback used to return the result, which is a country code, for example, **CN** (China).|
S
shawn_he 已提交
186

S
shawn_he 已提交
187
**Example**
S
shawn_he 已提交
188

S
shawn_he 已提交
189 190 191 192 193
```
sim.getISOCountryCodeForSim(0, (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
194 195


S
shawn_he 已提交
196
## sim.getISOCountryCodeForSim
S
shawn_he 已提交
197 198 199

getISOCountryCodeForSim\(slotId: number\): Promise<string\>

S
shawn_he 已提交
200
Obtains the ISO country code of the SIM card in the specified slot. This API uses a promise to return the result.
S
shawn_he 已提交
201

S
shawn_he 已提交
202 203
**System capability**: SystemCapability.Communication.CoreService

S
shawn_he 已提交
204
**Parameters**
S
shawn_he 已提交
205

S
shawn_he 已提交
206
| Name| Type  | Mandatory| Description                                  |
S
shawn_he 已提交
207
| ------ | ------ | ---- | -------------------------------------- |
S
shawn_he 已提交
208
| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
209

S
shawn_he 已提交
210
**Return value**
S
shawn_he 已提交
211

S
shawn_he 已提交
212
| Type             | Description                                                        |
S
shawn_he 已提交
213 214
| ----------------- | ------------------------------------------------------------ |
| Promise\<string\> | Promise used to return the result, which is a country code, for example, **CN** (China).|
S
shawn_he 已提交
215

S
shawn_he 已提交
216
**Example**
S
shawn_he 已提交
217

S
shawn_he 已提交
218 219 220 221 222 223 224 225
```
let promise = sim.getISOCountryCodeForSim(0);
promise.then(data => {
    console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.log(`getISOCountryCodeForSim fail, promise: err->${JSON.stringify(err)}`);
});
```
S
shawn_he 已提交
226 227


S
shawn_he 已提交
228
## sim.getSimOperatorNumeric
S
shawn_he 已提交
229 230 231

getSimOperatorNumeric\(slotId: number, callback: AsyncCallback<string\>\): void

S
shawn_he 已提交
232
Obtains 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.
S
shawn_he 已提交
233

S
shawn_he 已提交
234 235
**System capability**: SystemCapability.Communication.CoreService

S
shawn_he 已提交
236
**Parameters**
S
shawn_he 已提交
237

S
shawn_he 已提交
238
| Name  | Type                   | Mandatory| Description                                  |
S
shawn_he 已提交
239
| -------- | ----------------------- | ---- | -------------------------------------- |
S
shawn_he 已提交
240
| slotId   | number                  | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
241
| callback | AsyncCallback\<string\> | Yes  | Callback used to return the result.                            |
S
shawn_he 已提交
242

S
shawn_he 已提交
243
**Example**
S
shawn_he 已提交
244

S
shawn_he 已提交
245 246 247 248 249
```
sim.getSimOperatorNumeric(0, (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
250 251


S
shawn_he 已提交
252
## sim.getSimOperatorNumeric
S
shawn_he 已提交
253 254 255

getSimOperatorNumeric\(slotId: number\): Promise<string\>

S
shawn_he 已提交
256
Obtains the PLMN ID of the SIM card in the specified slot. This API uses a promise to return the result.
S
shawn_he 已提交
257

S
shawn_he 已提交
258 259
**System capability**: SystemCapability.Communication.CoreService

S
shawn_he 已提交
260
**Parameters**
S
shawn_he 已提交
261

S
shawn_he 已提交
262
| Name| Type  | Mandatory| Description                                  |
S
shawn_he 已提交
263
| ------ | ------ | ---- | -------------------------------------- |
S
shawn_he 已提交
264
| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
265

S
shawn_he 已提交
266
**Return value**
S
shawn_he 已提交
267

S
shawn_he 已提交
268
| Type             | Description                                            |
S
shawn_he 已提交
269 270
| ----------------- | ------------------------------------------------ |
| Promise\<string\> | Promise used to return the result.|
S
shawn_he 已提交
271

S
shawn_he 已提交
272
**Example**
S
shawn_he 已提交
273

S
shawn_he 已提交
274 275 276 277 278 279 280 281
```
let promise = sim.getSimOperatorNumeric(0);
promise.then(data => {
    console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.log(`getSimOperatorNumeric fail, promise: err->${JSON.stringify(err)}`);
});
```
S
shawn_he 已提交
282 283


S
shawn_he 已提交
284
## sim.getSimSpn
S
shawn_he 已提交
285 286 287

getSimSpn\(slotId: number, callback: AsyncCallback<string\>\): void

S
shawn_he 已提交
288
Obtains the service provider name (SPN) of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
289

S
shawn_he 已提交
290 291
**System capability**: SystemCapability.Communication.CoreService

S
shawn_he 已提交
292
**Parameters**
S
shawn_he 已提交
293

S
shawn_he 已提交
294
| Name  | Type                   | Mandatory| Description                                  |
S
shawn_he 已提交
295
| -------- | ----------------------- | ---- | -------------------------------------- |
S
shawn_he 已提交
296
| slotId   | number                  | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
297
| callback | AsyncCallback\<string\> | Yes  | Callback used to return the result.                            |
S
shawn_he 已提交
298

S
shawn_he 已提交
299
**Example**
S
shawn_he 已提交
300

S
shawn_he 已提交
301 302 303 304 305
```
sim.getSimSpn(0, (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
306 307


S
shawn_he 已提交
308
## sim.getSimSpn
S
shawn_he 已提交
309 310 311

getSimSpn\(slotId: number\): Promise<string\>

S
shawn_he 已提交
312
Obtains the SPN of the SIM card in the specified slot. This API uses a promise to return the result. 
S
shawn_he 已提交
313

S
shawn_he 已提交
314 315
**System capability**: SystemCapability.Communication.CoreService

S
shawn_he 已提交
316
**Parameters**
S
shawn_he 已提交
317

S
shawn_he 已提交
318
| Name| Type  | Mandatory| Description                                  |
S
shawn_he 已提交
319
| ------ | ------ | ---- | -------------------------------------- |
S
shawn_he 已提交
320
| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
321

S
shawn_he 已提交
322
**Return value**
S
shawn_he 已提交
323

S
shawn_he 已提交
324
| Type             | Description                                     |
S
shawn_he 已提交
325 326
| ----------------- | ----------------------------------------- |
| Promise\<string\> | Promise used to return the result.|
S
shawn_he 已提交
327

S
shawn_he 已提交
328
**Example**
S
shawn_he 已提交
329

S
shawn_he 已提交
330 331 332 333 334 335 336 337
```
let promise = sim.getSimSpn(0);
promise.then(data => {
    console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.log(`getSimSpn fail, promise: err->${JSON.stringify(err)}`);
});
```
S
shawn_he 已提交
338 339


S
shawn_he 已提交
340
## sim.getSimState
S
shawn_he 已提交
341 342 343

getSimState\(slotId: number, callback: AsyncCallback<SimState\>\): void

S
shawn_he 已提交
344
Obtains the status of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
345

S
shawn_he 已提交
346 347
**System capability**: SystemCapability.Communication.CoreService

S
shawn_he 已提交
348
**Parameters**
S
shawn_he 已提交
349

S
shawn_he 已提交
350
| Name  | Type                                  | Mandatory| Description                                  |
S
shawn_he 已提交
351
| -------- | -------------------------------------- | ---- | -------------------------------------- |
S
shawn_he 已提交
352
| slotId   | number                                 | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
353
| callback | AsyncCallback\<[SimState](#simstate)\> | Yes  | Callback used to return the result. For details, see [SimState](#simState). |
S
shawn_he 已提交
354

S
shawn_he 已提交
355
**Example**
S
shawn_he 已提交
356

S
shawn_he 已提交
357 358 359 360 361
```
sim.getSimState(0, (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
362 363


S
shawn_he 已提交
364
## sim.getSimState
S
shawn_he 已提交
365 366 367

getSimState\(slotId: number\): Promise<SimState\>

S
shawn_he 已提交
368
Obtains the status of the SIM card in the specified slot. This API uses a promise to return the result.
S
shawn_he 已提交
369

S
shawn_he 已提交
370 371
**System capability**: SystemCapability.Communication.CoreService

S
shawn_he 已提交
372
**Parameters**
S
shawn_he 已提交
373

S
shawn_he 已提交
374
| Name| Type  | Mandatory| Description                                  |
S
shawn_he 已提交
375
| ------ | ------ | ---- | -------------------------------------- |
S
shawn_he 已提交
376
| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
377

S
shawn_he 已提交
378
**Return value**
S
shawn_he 已提交
379

S
shawn_he 已提交
380
| Type                            | Description                                      |
S
shawn_he 已提交
381
| -------------------------------- | ------------------------------------------ |
S
shawn_he 已提交
382
| Promise\<[SimState](#simstate)\> | Promise used to return the result.|
S
shawn_he 已提交
383

S
shawn_he 已提交
384
**Example**
S
shawn_he 已提交
385

S
shawn_he 已提交
386 387 388 389 390 391 392 393
```
let promise = sim.getSimState(0);
promise.then(data => {
    console.log(`getSimState success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.log(`getSimState fail, promise: err->${JSON.stringify(err)}`);
});
```
S
shawn_he 已提交
394

S
shawn_he 已提交
395
## sim.getCardType<sup>7+</sup>
S
shawn_he 已提交
396

S
shawn_he 已提交
397
getCardType\(slotId: number, callback: AsyncCallback<CardType\>\): void
S
shawn_he 已提交
398

S
shawn_he 已提交
399
Obtains the type of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
400

S
shawn_he 已提交
401
**System capability**: SystemCapability.Communication.CoreService
S
shawn_he 已提交
402

S
shawn_he 已提交
403
**Parameters**
S
shawn_he 已提交
404

S
shawn_he 已提交
405
| Name  | Type                   | Mandatory| Description                                  |
S
shawn_he 已提交
406
| -------- | ----------------------- | ---- | -------------------------------------- |
S
shawn_he 已提交
407
| slotId   | number                  | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
408
| callback | AsyncCallback\<[CardType](#cardtype7)\> | Yes  | Callback used to return the result.                            |
S
shawn_he 已提交
409

S
shawn_he 已提交
410
**Example**
S
shawn_he 已提交
411

S
shawn_he 已提交
412
```
S
shawn_he 已提交
413
sim.getCardType(0, (err, data) => {
S
shawn_he 已提交
414 415 416
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
S
shawn_he 已提交
417 418


S
shawn_he 已提交
419
## sim.getCardType<sup>7+</sup>
S
shawn_he 已提交
420

S
shawn_he 已提交
421
getCardType\(slotId: number\): Promise<CardType\>
S
shawn_he 已提交
422

S
shawn_he 已提交
423
Obtains the type of the SIM card in the specified slot. This API uses a promise to return the result.
S
shawn_he 已提交
424

S
shawn_he 已提交
425
**System capability**: SystemCapability.Communication.CoreService
S
shawn_he 已提交
426

S
shawn_he 已提交
427
**Parameters**
S
shawn_he 已提交
428

S
shawn_he 已提交
429
| Name| Type  | Mandatory| Description                                  |
S
shawn_he 已提交
430
| ------ | ------ | ---- | -------------------------------------- |
S
shawn_he 已提交
431
| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
432

S
shawn_he 已提交
433
**Return value**
S
shawn_he 已提交
434

S
shawn_he 已提交
435
| Type             | Description                                                        |
S
shawn_he 已提交
436
| ----------------- | ------------------------------------------------------------ |
S
shawn_he 已提交
437
| Promise\<[CardType](#cardtype7)\> | Promise used to return the result.|
S
shawn_he 已提交
438

S
shawn_he 已提交
439
**Example**
S
shawn_he 已提交
440

S
shawn_he 已提交
441
```
S
shawn_he 已提交
442
let promise = sim.getCardType(0);
S
shawn_he 已提交
443
promise.then(data => {
S
shawn_he 已提交
444
    console.log(`getCardType success, promise: data->${JSON.stringify(data)}`);
S
shawn_he 已提交
445
}).catch(err => {
S
shawn_he 已提交
446
    console.log(`getCardType fail, promise: err->${JSON.stringify(err)}`);
S
shawn_he 已提交
447 448
});
```
S
shawn_he 已提交
449 450


S
shawn_he 已提交
451 452 453 454
## sim.hasSimCard<sup>7+</sup>

hasSimCard\(slotId: number, callback: AsyncCallback<boolean\>\): void

S
shawn_he 已提交
455
Checks whether the SIM card in the specified slot is installed. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
456 457 458 459 460 461 462

**System capability**: SystemCapability.Communication.CoreService

**Parameters**

| Name  | Type                       | Mandatory| Description                                  |
| -------- | --------------------------- | ---- | -------------------------------------- |
S
shawn_he 已提交
463
| slotId   | number                      | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result.                            |

**Example**

```
sim.hasSimCard(0, (err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```


## sim.hasSimCard<sup>7+</sup>

hasSimCard\(slotId: number\): Promise<boolean\>

S
shawn_he 已提交
479
Checks whether the SIM card in the specified slot is installed. This API uses a promise to return the result.
S
shawn_he 已提交
480 481 482 483 484 485 486

**System capability**: SystemCapability.Communication.CoreService

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
S
shawn_he 已提交
487
| slotId | number | Yes  | Card slot ID. The options are as follows:<br>- **0**: card slot 1<br>- **1**: card slot 2|
S
shawn_he 已提交
488

S
shawn_he 已提交
489
**Return value**
S
shawn_he 已提交
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514

| Type                 | Description                              |
| --------------------- | ---------------------------------- |
| 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.|

**Example**

```
let promise = sim.hasSimCard(0);
promise.then(data => {
    console.log(`hasSimCard success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
    console.log(`hasSimCard fail, promise: err->${JSON.stringify(err)}`);
});
```


## sim.getMaxSimCount<sup>7+</sup>

getMaxSimCount\(\): number

Obtains the number of card slots.

**System capability**: SystemCapability.Communication.CoreService

S
shawn_he 已提交
515
**Return value**
S
shawn_he 已提交
516 517 518 519 520 521 522 523 524 525 526 527 528

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| number | Number of card slots.|

**Example**

```
console.log(sim.getMaxSimCount())
```


## SimState
S
shawn_he 已提交
529 530 531

Enumerates SIM card states.

S
shawn_he 已提交
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
**System capability**: SystemCapability.Telephony.CoreService

| Name                 | Value  | Description                                                      |
| --------------------- | ---- | ---------------------------------------------------------- |
| SIM_STATE_UNKNOWN     | 0    | The SIM card is in **unknown** state; that is, the SIM card status cannot be obtained.                     |
| SIM_STATE_NOT_PRESENT | 1    | The SIM card is in **not present** state; that is, no SIM card is inserted into the slot.     |
| 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.  |
| SIM_STATE_NOT_READY   | 3    | The SIM card is in **not ready** state; that is, the SIM card is present but cannot work properly.   |
| SIM_STATE_READY       | 4    | The SIM card is in **ready** state; that is, the SIM card is present and is working properly.           |
| 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.|

## CardType<sup>7+</sup>

Enumerates card types.

**System capability**: SystemCapability.Telephony.CoreService

| Name| Value| Description|
| ----- | ----- | ----- |
|UNKNOWN_CARD | -1 | Unknown|
|SINGLE_MODE_SIM_CARD | 10 | Single-card (SIM)|
|SINGLE_MODE_USIM_CARD | 20 | Single-card (USIM)|
|SINGLE_MODE_RUIM_CARD | 30 | Single-card (RUIM)|
|DUAL_MODE_CG_CARD | 40 | Dual-card (CDMA+GSM)|
|CT_NATIONAL_ROAMING_CARD | 41 | China Telecom internal roaming card|
|CU_DUAL_MODE_CARD | 42 | China Unicom dual-mode card|
|DUAL_MODE_TELECOM_LTE_CARD | 43 | China Telecom dual-mode LTE card|
|DUAL_MODE_UG_CARD | 50 | Dual-mode card (UMTS+GSM)|
S
shawn_he 已提交
560
|SINGLE_MODE_ISIM_CARD<sup>8+</sup> | 60 | Single-card (ISIM)|