The sim module provides basic SIM card management functions. With the APIs provided by this module, you can obtain the ISO country code, home PLMN number, service provider name, status, and type of a SIM card in a specified card slot, as well as whether a card is inserted, whether a card is activated, SIM card account information, carrier permissions, OpKey/OpName, default voice service card information, number of card slots, and SIM card label. This module is applicable to scenarios where basic SIM card information and status need to be queried and managed.
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.
isSimActive(slotId: number, callback: AsyncCallback<boolean>): void
Checks whether the SIM card in a specified slot is activated. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slot ID. The correspondence between the slot ID and the eSIM number must be dynamically queried by calling sim.getSimLabel. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result, which indicates whether the SIM card in the specified slot is activated. - true: activated. false: not activated. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.isSimActive(0, (err: BusinessError, data: boolean) => {
if (err) {
console.error(`isSimActive failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); isSimActive(slotId: number): Promise<boolean>
Checks whether the SIM card in a specified slot is activated. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slot ID. The correspondence between the slot ID and the eSIM number must be dynamically queried by calling sim.getSimLabel. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. - true: activated. false: not activated. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.isSimActive(0).then((data: boolean) => {
console.info(`isSimActive success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`isSimActive failed, promise: err->${JSON.stringify(err)}`);
}); isSimActiveSync(slotId: number): boolean
Checks whether the SIM card in a specified slot is activated. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slot ID. The correspondence between the slot ID and the eSIM number must be dynamically queried by calling sim.getSimLabel.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| boolean | Whether the SIM card in the specified slot is activated. - true: activated. false: not activated. |
Example
import { sim } from '@kit.TelephonyKit';
let isSimActive: boolean = sim.isSimActiveSync(0);
console.info(`the sim is active:` + isSimActive); getDefaultVoiceSlotId(callback: AsyncCallback<number>): void
Obtains the slot ID of the default voice service. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slot ID. The correspondence between the slot ID and the eSIM number must be dynamically queried by calling sim.getSimLabel. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<number> | Yes | Callback used to return the result. - 0: card slot 1. - 1: card slot 2. - -1: card slot not set or service not unavailable |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getDefaultVoiceSlotId((err: BusinessError, data: number) => {
if (err) {
console.error(`getDefaultVoiceSlotId failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); getDefaultVoiceSlotId(): Promise<number>
Obtains the slot ID of the default voice service. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slot ID. The correspondence between the slot ID and the eSIM number must be dynamically queried by calling sim.getSimLabel. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Return value
| Type | Description |
|---|---|
| Promise<number> | Promise used to return the result. - 0: card slot 1. - 1: card slot 2. - -1: card slot not set or service not unavailable |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getDefaultVoiceSlotId().then((data: number) => {
console.info(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getDefaultVoiceSlotId failed, promise: err->${JSON.stringify(err)}`);
}); hasOperatorPrivileges(slotId: number, callback: AsyncCallback<boolean>): void
Checks whether the app (caller) has been granted the operator permission. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result, which indicates whether the application (caller) has been granted the operator permission. - true: The application (caller) has been granted the operator permission. - false: The application (caller) has not been granted the operator permission (no SIM card inserted or the SIM card is invalid). |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.hasOperatorPrivileges(0, (err: BusinessError, data: boolean) => {
if (err) {
console.error(`hasOperatorPrivileges failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); hasOperatorPrivileges(slotId: number): Promise<boolean>
Checks whether the app (caller) has been granted the operator permission. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. The value true indicates that the application (caller) has been granted the carrier permission, and the value false indicates the opposite. - true: The application (caller) has been granted the operator permission. - false: The application (caller) has not been granted the operator permission (no SIM card inserted or the SIM card is invalid). |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.hasOperatorPrivileges(0).then((data: boolean) => {
console.info(`hasOperatorPrivileges success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`hasOperatorPrivileges failed, promise: err->${JSON.stringify(err)}`);
}); getISOCountryCodeForSim(slotId: number, callback: AsyncCallback<string>): void
Obtains the ISO country code of the SIM card in a specified slot. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slot ID. The correspondence between the slot ID and the eSIM number must be dynamically queried by calling sim.getSimLabel. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is an ISO country code, for example, CN (China). |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getISOCountryCodeForSim(0, (err: BusinessError, data: string) => {
if (err) {
console.error(`getISOCountryCodeForSim failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); getISOCountryCodeForSim(slotId: number): Promise<string>
Obtains the ISO country code of the SIM card in a specified slot. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slot ID. The correspondence between the slot ID and the eSIM number must be dynamically queried by calling sim.getSimLabel. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the result, which is the ISO country code of the SIM card in the specified slot, for example, CN (China). |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getISOCountryCodeForSim(0).then((data: string) => {
console.info(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getISOCountryCodeForSim failed, promise: err->${JSON.stringify(err)}`);
}); getISOCountryCodeForSimSync(slotId: number): string
Obtains the ISO country code of the SIM card in the specified SIM slot. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| string | ISO country code of the SIM card in the specified slot, for example, CN (China). |
Example
import { sim } from '@kit.TelephonyKit';
let countryCode: string = sim.getISOCountryCodeForSimSync(0);
console.info(`the country ISO is:` + countryCode); getSimOperatorNumeric(slotId: number, callback: AsyncCallback<string>): void
Obtains the PLMN (Public Land Mobile Network) number of the SIM card in the specified SIM slot. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the home PLMN ID of the SIM card in the specified slot. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getSimOperatorNumeric(0, (err: BusinessError, data: string) => {
if (err) {
console.error(`getSimOperatorNumeric failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); getSimOperatorNumeric(slotId: number): Promise<string>
Obtains the PLMN (Public Land Mobile Network) number of the SIM card in the specified SIM slot. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the result. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getSimOperatorNumeric(0).then((data: string) => {
console.info(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getSimOperatorNumeric failed, promise: err->${JSON.stringify(err)}`);
}); getSimOperatorNumericSync(slotId: number): string
Obtains the PLMN (Public Land Mobile Network) number of the SIM card in the specified SIM slot. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| string | Home PLMN ID of the SIM card in the specified slot. |
Example
import { sim } from '@kit.TelephonyKit';
let numeric: string = sim.getSimOperatorNumericSync(0);
console.info(`the sim operator numeric is:` + numeric); getSimSpn(slotId: number, callback: AsyncCallback<string>): void
Obtains the service provider name (SPN) of the SIM card in the specified SIM slot. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the SPN of the SIM card in the specified slot. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getSimSpn(0, (err: BusinessError, data: string) => {
if (err) {
console.error(`getSimSpn failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); getSimSpn(slotId: number): Promise<string>
Obtains the service provider name (SPN) of the SIM card in the specified SIM slot. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the result. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getSimSpn(0).then((data: string) => {
console.info(`getSimSpn success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getSimSpn failed, promise: err->${JSON.stringify(err)}`);
}); getSimSpnSync(slotId: number): string
Obtains the service provider name (SPN) of the SIM card in the specified SIM slot. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| string | SPN of the SIM card in the specified slot. |
Example
import { sim } from '@kit.TelephonyKit';
let spn: string = sim.getSimSpnSync(0);
console.info(`the sim card spn is:` + spn); getSimState(slotId: number, callback: AsyncCallback<SimState>): void
Obtains the state of the SIM card in the specified SIM slot. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<SimState> | Yes | Callback used to return the result, which is the state of the SIM card in the specified slot. For details, see SimState. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getSimState(0, (err: BusinessError, data: sim.SimState) => {
if (err) {
console.error(`getSimState failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); getSimState(slotId: number): Promise<SimState>
Obtains the state of the SIM card in the specified SIM slot. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<SimState> | Promise used to return the result. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getSimState(0).then((data: sim.SimState) => {
console.info(`getSimState success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getSimState failed, promise: err->${JSON.stringify(err)}`);
}); getSimStateSync(slotId: number): SimState
Obtains the state of the SIM card in the specified SIM slot. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| SimState | State of the SIM card in the specified slot. |
Example
import { sim } from '@kit.TelephonyKit';
let simState: sim.SimState = sim.getSimStateSync(0);
console.info(`The sim state is:` + simState); getCardType(slotId: number, callback: AsyncCallback<CardType>): void
Obtains the SIM card type of the specified SIM slot. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<CardType> | Yes | Callback used to return the result. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getCardType(0, (err: BusinessError, data: sim.CardType) => {
if (err) {
console.error(`getCardType failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); getCardType(slotId: number): Promise<CardType>
Obtains the SIM card type of the specified SIM slot. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<CardType> | Promise used to return the result. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getCardType(0).then((data: sim.CardType) => {
console.info(`getCardType success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getCardType failed, promise: err->${JSON.stringify(err)}`);
}); getCardTypeSync(slotId: number): CardType
Obtains the SIM card type of the specified SIM slot. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| CardType | Type of the SIM card in the specified slot. |
Example
import { sim } from '@kit.TelephonyKit';
let cardType: sim.CardType = sim.getCardTypeSync(0);
console.info(`the card type is:` + cardType); hasSimCard(slotId: number, callback: AsyncCallback<boolean>): void
Checks whether a SIM card is inserted in the specified SIM slot. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. - true: installed. - false: not installed. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.hasSimCard(0, (err: BusinessError, data: boolean) => {
if (err) {
console.error(`hasSimCard failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); hasSimCard(slotId: number): Promise<boolean>
Checks whether a SIM card is inserted in the specified SIM slot. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. - true: installed. - false: not installed. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.hasSimCard(0).then((data: boolean) => {
console.info(`hasSimCard success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`hasSimCard failed, promise: err->${JSON.stringify(err)}`);
}); hasSimCardSync(slotId: number): boolean
Checks whether a SIM card is inserted in the specified SIM slot. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| boolean | Whether the SIM card in the specified slot is installed. - true: installed. - false: not installed. |
Example
import { sim } from '@kit.TelephonyKit';
let hasSimCard: boolean = sim.hasSimCardSync(0);
console.info(`has sim card: ` + hasSimCard); getSimAccountInfo(slotId: number, callback: AsyncCallback<IccAccountInfo>): void
Obtains the SIM account information. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel. This API uses an asynchronous callback to return the result.
Required permission: ohos.permission.GET_TELEPHONY_STATE
The GET_TELEPHONY_STATE permission is required to obtain the ICCID and phone number. Such information is sensitive and not open to third-party applications. When this API is called, the returned ICCID and phone number are empty.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<IccAccountInfo> | Yes | Callback used to return the result, which is the account information of the SIM card in the specified slot. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
| 8301002 | The SIM card failed to read or update data. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getSimAccountInfo(0, (err:BusinessError , data: sim.IccAccountInfo) => {
if (err) {
console.error(`getSimAccountInfo failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); getSimAccountInfo(slotId: number): Promise<IccAccountInfo>
Obtains the SIM account information. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel. This API uses a promise to return the result.
Required permission: ohos.permission.GET_TELEPHONY_STATE
The GET_TELEPHONY_STATE permission is required to obtain the ICCID and phone number. Such information is sensitive and not open to third-party applications. When this API is called, the returned ICCID and phone number are empty.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<IccAccountInfo> | Promise used to return the result. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
| 8301002 | The SIM card failed to read or update data. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getSimAccountInfo(0).then((data: sim.IccAccountInfo) => {
console.info(`getSimAccountInfo success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getSimAccountInfo failed, promise: err->${JSON.stringify(err)}`);
}); getActiveSimAccountInfoList(callback: AsyncCallback<Array<IccAccountInfo>>): void
Obtains the list of active SIM account information. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel. This API uses an asynchronous callback to return the result.
Required permission: ohos.permission.GET_TELEPHONY_STATE
The GET_TELEPHONY_STATE permission is required to obtain the ICCID and phone number. Such information is sensitive and not open to third-party applications. When this API is called, the returned ICCID and phone number are empty.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<Array<IccAccountInfo>> | Yes | Callback used to return the result, which is a list of activated SIM card accounts. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getActiveSimAccountInfoList((err: BusinessError, data: Array<sim.IccAccountInfo>) => {
if (err) {
console.error(`getActiveSimAccountInfoList failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); getMaxSimCount(): number
Obtains the number of SIM slots. For devices that support eSIM, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling sim.getSimLabel.
System capability: SystemCapability.Telephony.CoreService
Return value
| Type | Description |
|---|---|
| number | Number of card slots. |
Example
import { sim } from '@kit.TelephonyKit';
console.info('Result: '+ sim.getMaxSimCount()); getActiveSimAccountInfoList(): Promise<Array<IccAccountInfo>>
Obtains the list of activated SIM account information. For devices that support eSIM, the activation status of the eSIM corresponding to the specified slotID can be obtained. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses an asynchronous callback to return the result.
Required permission: ohos.permission.GET_TELEPHONY_STATE
The GET_TELEPHONY_STATE permission is required to obtain the ICCID and phone number. Such information is sensitive and not open to third-party applications. When this API is called, the returned ICCID and phone number are empty.
System capability: SystemCapability.Telephony.CoreService
Return value
| Type | Description |
|---|---|
| Promise<Array<IccAccountInfo>> | Promise used to return the result. |
Error codes
For details about the error codes, see Telephony Error Codes.
| ID | Error Message |
|---|---|
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getActiveSimAccountInfoList().then((data: Array<sim.IccAccountInfo>) => {
console.info(`getActiveSimAccountInfoList success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getActiveSimAccountInfoList failed, promise: err->${JSON.stringify(err)}`);
}); getOpKey(slotId: number, callback: AsyncCallback<string>): void
Obtains the OpKey of the SIM card in the specified SIM slot. For devices that support eSIM, the activation status of the eSIM corresponding to the specified slotID can be obtained. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result, OpKey of the SIM card in the specified slot. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 801 | Capability not supported. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
try {
sim.getOpKey(0, (err: BusinessError, data: string) => {
if (err) {
console.error("getOpKey failed, err: " + JSON.stringify(err));
} else {
console.info('getOpKey successfully, data: ' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getOpKey err: ' + JSON.stringify(err));
} getOpKey(slotId: number): Promise<string>
Obtains the OpKey of the SIM card in the specified SIM slot. For devices that support eSIM, the activation status of the eSIM corresponding to the specified slotID can be obtained. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the result. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 801 | Capability not supported. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getOpKey(0).then((data: string) => {
console.info(`getOpKey success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getOpKey failed, promise: err->${JSON.stringify(err)}`);
}); getOpKeySync(slotId: number): string
Obtains the OpKey of the SIM card in the specified SIM slot. For devices that support eSIM, the activation status of the eSIM corresponding to the specified slotID can be obtained. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| string | OpKey of the SIM card in the specified slot. |
Example
import { sim } from '@kit.TelephonyKit';
let data: string = sim.getOpKeySync(0);
console.info(`getOpKey success, data->${JSON.stringify(data)}`); getOpName(slotId: number, callback: AsyncCallback<string>): void
Obtains the OpName (operator name) of the SIM card in the specified SIM slot. For devices that support eSIM, the activation status of the eSIM corresponding to the specified slotID can be obtained. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result, OpName of the SIM card in the specified slot. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 801 | Capability not supported. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
try {
sim.getOpName(0, (err: BusinessError, data: string) => {
if (err) {
console.error('getOpName failed, err: ' + JSON.stringify(err));
} else {
console.info('getOpName successfully, data: ' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getOpName err: ' + JSON.stringify(err));
} getOpName(slotId: number): Promise<string>
Obtains the OpName of the SIM card in the specified SIM slot. For devices that support eSIM, the activation status of the eSIM corresponding to the specified slotID can be obtained. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the result. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 801 | Capability not supported. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getOpName(0).then((data: string) => {
console.info(`getOpName success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getOpName failed, promise: err->${JSON.stringify(err)}`);
}); getOpNameSync(slotId: number): string
Obtains the OpName of the SIM card in the specified SIM slot. For devices that support eSIM, the activation status of the eSIM corresponding to the specified slotID can be obtained. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| string | OpName of the SIM card in the specified slot. |
Example
import { sim } from '@kit.TelephonyKit';
let data: string = sim.getOpNameSync(0);
console.info(`getOpName success, data->${JSON.stringify(data)}`); getDefaultVoiceSimId(callback: AsyncCallback<number>): void
Obtains the SIM card ID of the default voice service. For devices that support eSIM, the activation status of the eSIM corresponding to the specified slotID can be obtained. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<number> | Yes | Callback used to return the result. The return value is bound to the SIM card and increases from 1. |
Error codes
For details about the error codes, see Universal Error Codes and Telephony Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
| 8301001 | SIM card is not activated. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getDefaultVoiceSimId((err: BusinessError, data: number) => {
if (err) {
console.error(`getDefaultVoiceSimId failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); getDefaultVoiceSimId(): Promise<number>
Obtains the SIM card ID of the default voice service. For devices that support eSIM, the activation status of the eSIM corresponding to the specified slotID can be obtained. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Return value
| Type | Description |
|---|---|
| Promise<number> | Promise used to return the result. The return value is bound to the SIM card and increases from 1. |
Error codes
For details about the error codes, see Telephony Error Codes.
| ID | Error Message |
|---|---|
| 8300001 | Invalid parameter value. |
| 8300002 | Service connection failed. |
| 8300003 | System internal error. |
| 8300004 | No SIM card found. |
| 8300999 | Unknown error. |
| 8301001 | SIM card is not activated. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
let promise = sim.getDefaultVoiceSimId();
promise.then((data: number) => {
console.info(`getDefaultVoiceSimId success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getDefaultVoiceSimId failed, promise: err->${JSON.stringify(err)}`);
}); getSimLabel(slotId: number, callback: AsyncCallback<SimLabel>): void
Obtains the label information of the SIM card. For devices that support eSIM, the activation status of the eSIM corresponding to the specified slotID can be obtained. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| callback | AsyncCallback<SimLabel> | Yes | Callback used to return the result, which is the SIM card label. |
Error codes
For details about the error codes, see Telephony Error Codes.
| ID | Error Message |
|---|---|
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getSimLabel(0, (err: BusinessError, data: sim.SimLabel) => {
if (err) {
console.error(`getSimLabel failed. callback: err->${JSON.stringify(err)}`);
return;
}
console.info(`callback: data->${JSON.stringify(data)}`);
}); getSimLabel(slotId: number): Promise<SimLabel>
Obtains the label information of the SIM card. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API. This API uses a promise to return the result.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| Promise<SimLabel > | Promise used to return the SIM card label information. |
Error codes
For details about the error codes, see Telephony Error Codes.
| ID | Error Message |
|---|---|
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { sim } from '@kit.TelephonyKit';
sim.getSimLabel(0).then((data: sim.SimLabel) => {
console.info(`getSimLabel success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getSimLabel failed, promise: err->${JSON.stringify(err)}`);
}); getSimLabelSync(slotId: number): SimLabel
Obtains the label of the corresponding SIM card by passing in the ID of the SIM card slot. For supported eSIM devices, this API can obtain the activation status of the eSIM corresponding to the specified slotID. The correspondence between slotID and eSIM numbers must be dynamically queried by calling the sim.getSimLabel API.
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotId | number | Yes | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
Return value
| Type | Description |
|---|---|
| SimLabel | SIM card label. |
Example
import { sim } from '@kit.TelephonyKit';
let simLabel: sim.SimLabel = sim.getSimLabelSync(0);
console.info(`The sim label is:` + simLabel); Enumerates the SIM card types.
System capability: SystemCapability.Telephony.CoreService
| Name | Value | Description |
|---|---|---|
| PSIM | 0 | Physical SIM card. |
| ESIM | 1 | eSIM card. |
Defines the SIM card label.
System capability: SystemCapability.Telephony.CoreService
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| simType | SimType | No | No | SIM card type. |
| index | number | No | No | Unique index ID of the SIM card. The value starts from 1 and increases by 1. The value ranges from 1 to 2. |
Enumerates SIM card states.
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 card 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 has been installed but cannot work properly. |
| SIM_STATE_READY | 4 | The SIM card is in ready state; that is, the SIM card has been installed 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. |
Enumerates SIM card types.
System capability: SystemCapability.Telephony.CoreService
| Name | Value | Description |
|---|---|---|
| UNKNOWN_CARD | -1 | Unknown type. |
| 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). |
| SINGLE_MODE_ISIM_CARD8+ | 60 | Single-card (ISIM). |
Defines the ICC account information.
System capability: SystemCapability.Telephony.CoreService
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| simId | number | No | No | SIM card ID. The return value is bound to the SIM card and increases from 1. |
| slotIndex | number | No | No | SIM slot ID. For devices that support eSIM, this value indicates the logical SIM slot ID. - 0: SIM slot 1. - 1: SIM slot 2. |
| isEsim | boolean | No | No | Whether the SIM card is an eSIM. - true: The SIM card is an eSIM. - false: The SIM card is not an eSIM. |
| isActive | boolean | No | No | Whether the card is activated. - true: activated. false: not activated. |
| iccId | string | No | No | ICCID number. |
| showName | string | No | No | SIM card display name. |
| showNumber | string | No | No | SIM card display number. |