harmony 鸿蒙@ohos.telephony.sim (SIM Management)

2022-08-09 浏览 (1188)

@ohos.telephony.sim (SIM Management)

The sim module provides basic SIM card management functions. You can obtain the name, number, ISO country code, home PLMN ID, service provider name, SIM card status, type, installation status, activation status, and lock status of the SIM card in the specified slot. Besides, you can set the name, number, and lock status of the SIM card, activate or deactivate the SIM card, and change the PIN or unlock the PIN or PUK of the SIM card.

NOTE

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.

Modules to Import

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

sim.isSimActive7+

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

Checks whether the SIM card in the specified slot is activated. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<boolean>YesCallback used to return the result, which is a Boolean value indicating whether the SIM card in the specified slot is activated. The value true means yes and the value false means no.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.isSimActive7+

isSimActive(slotId: number): Promise<boolean>

Checks whether the SIM card in the specified slot is activated. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<boolean>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.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.isSimActive(0).then((data: boolean) => {
    console.log(`isSimActive success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`isSimActive failed, promise: err->${JSON.stringify(err)}`);
});

sim.isSimActiveSync10+

isSimActiveSync(slotId: number): boolean

Checks whether the SIM card in the specified slot is activated.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
booleanBoolean value indicating whether the SIM card in the specified slot is activated. The value true means yes and the value false means no.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let isSimActive: boolean = sim.isSimActiveSync(0);
console.log(`the sim is active:` + isSimActive);

sim.getDefaultVoiceSlotId7+

getDefaultVoiceSlotId(callback: AsyncCallback<number>): void

Obtains the default slot ID of the SIM card that provides voice services. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback 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 '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getDefaultVoiceSlotId7+

getDefaultVoiceSlotId(): Promise<number>

Obtains the default slot ID of the SIM card that provides voice services. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Return value

TypeDescription
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 '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getDefaultVoiceSlotId().then((data: number) => {
    console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getDefaultVoiceSlotId failed, promise: err->${JSON.stringify(err)}`);
});

sim.hasOperatorPrivileges7+

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

Checks whether the application (caller) has been granted the operator permission. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<boolean>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.hasOperatorPrivileges7+

hasOperatorPrivileges(slotId: number): Promise<boolean>

Checks whether the application (caller) has been granted the operator permission. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
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.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getISOCountryCodeForSim

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

Obtains the ISO country code of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result, which is an ISO country code, for example, CN (China).

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getISOCountryCodeForSim

getISOCountryCodeForSim(slotId: number): Promise<string>

Obtains the ISO country code of the SIM card in the specified slot. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result, which is an ISO country code, for example, CN (China).

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getISOCountryCodeForSim(0).then((data: string) => {
    console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getISOCountryCodeForSim failed, promise: err->${JSON.stringify(err)}`);
});

sim.getISOCountryCodeForSimSync10+

getISOCountryCodeForSimSync(slotId: number): string

Obtains the ISO country code of the SIM card in the specified slot.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
stringISO country code of the SIM card in the specified slot, for example, CN (China).

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let countryCode: string = sim.getISOCountryCodeForSimSync(0);
console.log(`the country ISO is:` + countryCode);

sim.getSimOperatorNumeric

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

Obtains the home public land mobile network (PLMN) ID of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getSimOperatorNumeric

getSimOperatorNumeric(slotId: number): Promise<string>

Obtains the home PLMN ID of the SIM card in the specified slot. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getSimOperatorNumeric(0).then((data: string) => {
    console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getSimOperatorNumeric failed, promise: err->${JSON.stringify(err)}`);
});

sim.getSimOperatorNumericSync10+

getSimOperatorNumericSync(slotId: number): string

Obtains the home PLMN ID of the SIM card in the specified slot.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
stringHome PLMN number of the SIM card in the specified slot.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let numeric: string = sim.getSimOperatorNumericSync(0);
console.log(`the sim operator numeric is:` + numeric);

sim.getSimSpn

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

Obtains the service provider name (SPN) of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getSimSpn

getSimSpn(slotId: number): Promise<string>

Obtains the SPN of the SIM card in the specified slot. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getSimSpn(0).then((data: string) => {
    console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getSimSpn failed, promise: err->${JSON.stringify(err)}`);
});

sim.getSimSpnSync10+

getSimSpnSync(slotId: number): string

Obtains the SPN of the SIM card in the specified slot.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
stringSPN of the SIM card in the specified slot.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let spn: string = sim.getSimSpnSync(0);
console.log(`the sim card spn is:` + spn);

sim.getSimState

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

Obtains the state of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<SimState>YesCallback used to return the result. For details, see SimState.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getSimState

getSimState(slotId: number): Promise<SimState>

Obtains the state of the SIM card in the specified slot. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<SimState>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getSimState(0).then((data: sim.SimState) => {
    console.log(`getSimState success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getSimState failed, promise: err->${JSON.stringify(err)}`);
});

sim.getSimStateSync10+

getSimStateSync(slotId: number): SimState

Obtains the state of the SIM card in the specified slot.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
SimStateState of the SIM card in the specified slot.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let simState: sim.SimState = sim.getSimStateSync(0);
console.log(`The sim state is:` + simState);

sim.getCardType7+

getCardType(slotId: number, callback: AsyncCallback<CardType>): void

Obtains the type of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<CardType>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getCardType7+

getCardType(slotId: number): Promise<CardType>

Obtains the type of the SIM card in the specified slot. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<CardType>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getCardType(0).then((data: sim.CardType) => {
    console.log(`getCardType success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getCardType failed, promise: err->${JSON.stringify(err)}`);
});

sim.getCardTypeSync10+

getCardTypeSync(slotId: number): CardType

Obtains the type of the SIM card in the specified slot.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
CardTypeType of the SIM card in the specified slot.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let cardType: sim.CardType = sim.getCardTypeSync(0);
console.log(`the card type is:` + cardType);

sim.hasSimCard7+

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

Checks whether the SIM card in the specified slot is installed. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<boolean>YesCallback 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.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.hasSimCard7+

hasSimCard(slotId: number): Promise<boolean>

Checks whether the SIM card in the specified slot is installed. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<boolean>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.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.hasSimCardSync10+

hasSimCardSync(slotId: number): boolean

Checks whether the SIM card in the specified slot is installed.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
booleanBoolean value indicating whether the SIM card in the specified slot is installed. The value true means yes and the value false means no.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let hasSimCard: boolean = sim.hasSimCardSync(0);
console.log(`has sim card: ` + hasSimCard);

sim.getSimAccountInfo10+

getSimAccountInfo(slotId: number, callback: AsyncCallback<IccAccountInfo>): void

Obtains account information of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

NOTE

If you do not have the GET_TELEPHONY_STATE permission, the ICCID and number information is empty.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<IccAccountInfo>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getSimAccountInfo10+

getSimAccountInfo(slotId: number): Promise<IccAccountInfo>

Obtains account information of the SIM card in the specified slot. This API uses a promise to return the result.

NOTE

If you do not have the GET_TELEPHONY_STATE permission, the ICCID and number information is empty.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<IccAccountInfo>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getSimAccountInfo(0).then((data: sim.IccAccountInfo) => {
    console.log(`getSimAccountInfo success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getSimAccountInfo failed, promise: err->${JSON.stringify(err)}`);
});

sim.getActiveSimAccountInfoList10+

getActiveSimAccountInfoList(callback: AsyncCallback<Array<IccAccountInfo>>): void

Obtains the list of activated SIM card accounts. This API uses an asynchronous callback to return the result.

NOTE

If you do not have the GET_TELEPHONY_STATE permission, the ICCID and number information is empty.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<IccAccountInfo>>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getActiveSimAccountInfoList((err: BusinessError, data: Array<sim.IccAccountInfo>) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sim.getActiveSimAccountInfoList10+

getActiveSimAccountInfoList(): Promise<Array<IccAccountInfo>>;

Obtains the list of activated SIM card accounts. This API uses a promise to return the result.

NOTE

If you do not have the GET_TELEPHONY_STATE permission, the ICCID and number information is empty.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Return value

TypeDescription
Promise<Array<IccAccountInfo>>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getActiveSimAccountInfoList().then((data: Array<sim.IccAccountInfo>) => {
    console.log(`getActiveSimAccountInfoList success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getActiveSimAccountInfoList failed, promise: err->${JSON.stringify(err)}`);
});

sim.setDefaultVoiceSlotId7+

setDefaultVoiceSlotId(slotId: number, callback: AsyncCallback<void>): void

Sets the default slot ID of the SIM card that provides voice services. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
- -1: Clears the default configuration.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301001SIM card is not activated.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.setDefaultVoiceSlotId7+

setDefaultVoiceSlotId(slotId: number): Promise<void>

Sets the default slot ID of the SIM card that provides voice services. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
- -1: Clears the default configuration.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301001SIM card is not activated.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.setDefaultVoiceSlotId(0).then(() => {
    console.log(`setDefaultVoiceSlotId success.`);
}).catch((err: BusinessError) => {
    console.log(`setDefaultVoiceSlotId failed, promise: err->${JSON.stringify(err)}`);
});

sim.setShowName8+

setShowName(slotId: number, name: string, callback: AsyncCallback<void>): void

Sets a display name for the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
namestringYesSIM card name.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let name: string = "ShowName";
sim.setShowName(0, name, (err: BusinessError) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
});

sim.setShowName8+

setShowName(slotId: number, name: string): Promise<void>

Sets a display name for the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
namestringYesSIM card name.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let name: string = "ShowName";
sim.setShowName(0, name).then(() => {
    console.log(`setShowName success.`);
}).catch((err: BusinessError) => {
    console.log(`setShowName failed, promise: err->${JSON.stringify(err)}`);
});

sim.getShowName8+

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

Obtains the name of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getShowName8+

getShowName(slotId: number): Promise<string>

Obtains the name of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getShowName(0).then((data: string) => {
    console.log(`getShowName success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getShowName failed, promise: err->${JSON.stringify(err)}`);
});

sim.setShowNumber8+

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

Sets a display number for the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
numberstringYesSIM card number.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let number: string = '+861xxxxxxxxxx';
sim.setShowNumber(0, number, (err: BusinessError) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
});

sim.setShowNumber8+

setShowNumber(slotId: number, number: string): Promise<void>

Sets a display number for the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
numberstringYesSIM card number.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let number: string = '+861xxxxxxxxxx';
sim.setShowNumber(0, number).then(() => {
    console.log(`setShowNumber success.`);
}).catch((err: BusinessError) => {
    console.log(`setShowNumber failed, promise: err->${JSON.stringify(err)}`);
});

sim.getShowNumber8+

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

Obtains the display number of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getShowNumber8+

getShowNumber(slotId: number): Promise<string>

Obtains the display number of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getShowNumber(0).then((data: string) => {
    console.log(`getShowNumber success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getShowNumber failed, promise: err->${JSON.stringify(err)}`);
});

sim.activateSim8+

activateSim(slotId: number, callback: AsyncCallback<void>): void

Activates a SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.activateSim8+

activateSim(slotId: number): Promise<void>

Activates the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.activateSim(0).then(() => {
    console.log(`activateSim success.`);
}).catch((err: BusinessError) => {
    console.log(`activateSim failed, promise: err->${JSON.stringify(err)}`);
});

sim.deactivateSim8+

deactivateSim(slotId: number, callback: AsyncCallback<void>): void

Disables the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.deactivateSim8+

deactivateSim(slotId: number): Promise<void>

Disables the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.deactivateSim(0).then(() => {
    console.log(`deactivateSim success.`);
}).catch((err: BusinessError) => {
    console.log(`deactivateSim failed, promise: err->${JSON.stringify(err)}`);
});

sim.setLockState7+

setLockState(slotId: number, options: LockInfo, callback: AsyncCallback<LockStatusResponse>): void

Sets the lock status of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<LockStatusResponse>YesCallback used to return the result.
optionsLockInfoYesLock information.
- lockType: LockType
- password: string
- state: LockState

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let lockInfo: sim.LockInfo = {
    lockType: sim.LockType.PIN_LOCK,
    password: "1234",
    state: sim.LockState.LOCK_OFF
};
sim.setLockState(0, lockInfo, (err: BusinessError, data: sim.LockStatusResponse) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sim.setLockState7+

setLockState(slotId: number, options: LockInfo): Promise<LockStatusResponse>

Sets the lock status of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
optionsLockInfoYesLock information.
- lockType: LockType
- password: string
- state: LockState

Return value

TypeDescription
Promise<LockStatusResponse>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let lockInfo: sim.LockInfo = {
    lockType: sim.LockType.PIN_LOCK,
    password: "1234",
    state: sim.LockState.LOCK_OFF
};
sim.setLockState(0, lockInfo).then((data: sim.LockStatusResponse) => {
    console.log(`setLockState success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`setLockState failed, promise: err->${JSON.stringify(err)}`);
});

sim.getLockState8+

getLockState(slotId: number, lockType: LockType, callback: AsyncCallback<LockState>): void

Obtains the lock status of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<LockState>YesCallback used to return the result.
optionsLockTypeYesLock type.
- 1: PIN lock
- 2: PIN 2 lock

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getLockState8+

getLockState(slotId: number, lockType: LockType): Promise<LockState>

Obtains the lock status of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
optionsLockTypeYesLock type.
- 1: PIN lock
- 2: PIN 2 lock

Return value

TypeDescription
Promise<LockState>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getLockState(0, 1).then((data: sim.LockState) => {
    console.log(`getLockState success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getLockState failed, promise: err->${JSON.stringify(err)}`);
});

sim.alterPin7+

alterPin(slotId: number, newPin: string, oldPin: string, callback: AsyncCallback<LockStatusResponse>): void

Changes the PIN of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<LockStatusResponse>YesCallback used to return the result.
newPinstringYesNew PIN.
oldPinstringYesOld PIN.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.alterPin(0, "1234", "0000", (err: BusinessError, data: sim.LockStatusResponse) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sim.alterPin7+

alterPin(slotId: number, newPin: string, oldPin: string): Promise<LockStatusResponse>;

Changes the PIN of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
newPinstringYesNew PIN.
oldPinstringYesOld PIN.

Return value

TypeDescription
Promise<LockStatusResponse>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.alterPin(0, "1234", "0000").then((data: sim.LockStatusResponse) => {
    console.log(`alterPin success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`alterPin failed, promise: err->${JSON.stringify(err)}`);
});

sim.alterPin28+

alterPin2(slotId: number, newPin2: string, oldPin2: string, callback: AsyncCallback<LockStatusResponse>): void

Changes PIN 2 of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<LockStatusResponse>YesCallback used to return the result.
newPin2stringYesNew PIN.
oldPin2stringYesOld PIN.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.alterPin2(0, "1234", "0000", (err: BusinessError, data: sim.LockStatusResponse) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sim.alterPin28+

alterPin2(slotId: number, newPin2: string, oldPin2: string): Promise<LockStatusResponse>

Changes PIN 2 of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
newPin2stringYesNew PIN.
oldPin2stringYesOld PIN.

Return value

TypeDescription
Promise<LockStatusResponse>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.alterPin2(0, "1234", "0000").then((data: sim.LockStatusResponse) => {
    console.log(`alterPin2 success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`alterPin2 failed, promise: err->${JSON.stringify(err)}`);
});

sim.unlockPin7+

unlockPin(slotId: number, pin: string, callback: AsyncCallback<LockStatusResponse>): void

Unlocks the PIN of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
pinstringYesPIN of the SIM card.
callbackAsyncCallback<LockStatusResponse>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let pin: string = '1234';
sim.unlockPin(0, pin, (err: BusinessError, data: sim.LockStatusResponse) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sim.unlockPin7+

unlockPin(slotId: number, pin: string): Promise<LockStatusResponse>

Unlocks the PIN of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
pinstringYesPIN of the SIM card.

Return value

TypeDescription
Promise<LockStatusResponse>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let pin: string = '1234';
sim.unlockPin(0, pin).then((data: sim.LockStatusResponse) => {
    console.log(`unlockPin success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`unlockPin failed, promise: err->${JSON.stringify(err)}`);
});

sim.unlockPuk7+

unlockPuk(slotId: number, newPin: string, puk: string, callback: AsyncCallback<LockStatusResponse>): void

Unlocks the PUK of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
newPinstringYesNew PIN.
pukstringYesPUK of the SIM card.
callbackAsyncCallback<LockStatusResponse>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let puk: string = '1xxxxxxx';
let newPin: string = '1235';
sim.unlockPuk(0, newPin, puk, (err: BusinessError, data: sim.LockStatusResponse) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sim.unlockPuk7+

unlockPuk(slotId: number, newPin: string, puk: string): Promise<LockStatusResponse>

Unlocks the PUK of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
newPinstringYesNew PIN.
pukstringYesPUK of the SIM card.

Return value

TypeDescription
Promise<LockStatusResponse>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let puk: string = '1xxxxxxx';
let newPin: string = '1235';
sim.unlockPuk(0, newPin, puk).then((data: sim.LockStatusResponse) => {
    console.log(`unlockPuk success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`unlockPuk failed, promise: err->${JSON.stringify(err)}`);
});

sim.unlockPin28+

unlockPin2(slotId: number, pin2: string, callback: AsyncCallback<LockStatusResponse>): void

Unlocks the PIN of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
pin2stringYesPIN of the SIM card.
callbackAsyncCallback<LockStatusResponse>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let pin2: string = '1234';
sim.unlockPin2(0, pin2, (err: BusinessError, data: sim.LockStatusResponse) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sim.unlockPin28+

unlockPin2(slotId: number, pin2: string): Promise<LockStatusResponse>

Unlocks the PIN of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
pin2stringYesPIN of the SIM card.

Return value

TypeDescription
Promise<LockStatusResponse>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let pin2: string = '1234';
sim.unlockPin2(0, pin2).then((data: sim.LockStatusResponse) => {
    console.log(`unlockPin2 success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`unlockPin2 failed, promise: err->${JSON.stringify(err)}`);
});

sim.unlockPuk28+

unlockPuk2(slotId: number, newPin2: string, puk2: string, callback: AsyncCallback<LockStatusResponse>): void

Unlocks the PUK of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
newPin2stringYesNew PIN 2.
puk2stringYesPUK of the SIM card.
callbackAsyncCallback<LockStatusResponse>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let puk2: string = '1xxxxxxx';
let newPin2: string = '1235';
sim.unlockPuk2(0, newPin2, puk2, (err: BusinessError, data: sim.LockStatusResponse) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sim.unlockPuk28+

unlockPuk2(slotId: number, newPin2: string, puk2: string): Promise<LockStatusResponse>

Unlocks the PUK of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
newPin2stringYesNew PIN 2.
puk2stringYesPUK of the SIM card.

Return value

TypeDescription
Promise<LockStatusResponse>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let puk2: string = '1xxxxxxx';
let newPin2: string = '1235';
sim.unlockPuk2(0, newPin2, puk2).then((data: sim.LockStatusResponse) => {
    console.log(`unlockPuk2 success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`unlockPuk2 failed, promise: err->${JSON.stringify(err)}`);
});

sim.getMaxSimCount7+

getMaxSimCount(): number

Obtains the number of card slots.

System capability: SystemCapability.Telephony.CoreService

Return value

TypeDescription
numberNumber of card slots.

Example

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

console.log("Result: "+ sim.getMaxSimCount());

sim.getSimIccId7+

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

Obtains the ICCID of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getSimIccId7+

getSimIccId(slotId: number): Promise<string>

Obtains the ICCID of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getSimIccId(0).then((data:string) => {
    console.log(`getSimIccId success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getSimIccId failed, promise: err->${JSON.stringify(err)}`);
});

sim.getVoiceMailIdentifier8+

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

Obtains the voice mailbox alpha identifier of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getVoiceMailIdentifier8+

getVoiceMailIdentifier(slotId: number): Promise<string>

Obtains the voice mailbox alpha identifier of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getVoiceMailIdentifier(0).then((data: string) => {
    console.log(`getVoiceMailIdentifier success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getVoiceMailIdentifier failed, promise: err->${JSON.stringify(err)}`);
});

sim.getVoiceMailNumber8+

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

Obtains the voice mailbox number of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getVoiceMailNumber8+

getVoiceMailNumber(slotId: number): Promise<string>

Obtains the voice mailbox number of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getVoiceMailNumber(0).then((data: string) => {
    console.log(`getVoiceMailNumber success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getVoiceMailNumber failed, promise: err->${JSON.stringify(err)}`);
});

sim.setVoiceMailInfo8+

setVoiceMailInfo(slotId: number, mailName: string, mailNumber: string, callback: AsyncCallback<void>): void

Sets voice mailbox information for the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
mailNamestringYesVoice mailbox name.
mailNumberstringYesVoice mailbox number.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.setVoiceMailInfo(0, "mail", "xxx@xxx.com", (err: BusinessError) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
});

sim.setVoiceMailInfo8+

setVoiceMailInfo(slotId: number, mailName: string, mailNumber: string): Promise<void>

Sets voice mailbox information for the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
mailNamestringYesVoice mailbox name.
mailNumberstringYesVoice mailbox number.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.setVoiceMailInfo(0, "mail", "xxx@xxx.com").then(() => {
    console.log(`setVoiceMailInfo success.`);
}).catch((err: BusinessError) => {
    console.log(`setVoiceMailInfo failed, promise: err->${JSON.stringify(err)}`);
});

sim.getSimTelephoneNumber8+

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

Obtains the MSISDN of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_PHONE_NUMBERS

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getSimTelephoneNumber8+

getSimTelephoneNumber(slotId: number): Promise<string>

Obtains the MSISDN of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_PHONE_NUMBERS

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getSimTelephoneNumber(0).then((data: string) => {
    console.log(`getSimTelephoneNumber success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getSimTelephoneNumber failed, promise: err->${JSON.stringify(err)}`);
});

sim.getSimGid17+

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

Obtains the group identifier level 1 (GID1) of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getSimGid17+

getSimGid1(slotId: number): Promise<string>

Obtains the GID1 of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getSimGid1(0).then((data: string) => {
    console.log(`getSimGid1 success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getSimGid1 failed, promise: err->${JSON.stringify(err)}`);
});

sim.getIMSI

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

Obtains the international mobile subscriber identity (IMSI) of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getIMSI

getIMSI(slotId: number): Promise<string>

Obtains the IMSI of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getIMSI(0).then((data: string) => {
    console.log(`getIMSI success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getIMSI failed, promise: err->${JSON.stringify(err)}`);
});

sim.getOperatorConfigs8+

getOperatorConfigs(slotId: number, callback: AsyncCallback<Array<OperatorConfig>>): void

Obtains the carrier configuration of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<Array<OperatorConfig>>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getOperatorConfigs(0, (err: BusinessError, data: Array<sim.OperatorConfig>) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sim.getOperatorConfigs8+

getOperatorConfigs(slotId: number): Promise<Array<OperatorConfig>>

Obtains the carrier configuration of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.GET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<Array<OperatorConfig>>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.getOperatorConfigs(0).then((data: Array<sim.OperatorConfig>) => {
    console.log(`getOperatorConfigs success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getOperatorConfigs failed, promise: err->${JSON.stringify(err)}`);
});

sim.queryIccDiallingNumbers8+

queryIccDiallingNumbers(slotId: number, type: ContactType, callback: AsyncCallback<Array<DiallingNumbersInfo>>): void

Queries contact numbers of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Permission required: ohos.permission.READ_CONTACTS

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
typeContactTypeYesContact type.
- 1: GENERAL_CONTACT
- 2: FIXED_DIALING
callbackAsyncCallback<Array<DiallingNumbersInfo>>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.queryIccDiallingNumbers(0, 1, (err: BusinessError, data: Array<sim.DiallingNumbersInfo>) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sim.queryIccDiallingNumbers8+

queryIccDiallingNumbers(slotId: number, type: ContactType): Promise<Array<DiallingNumbersInfo>>

Queries contact numbers of the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Permission required: ohos.permission.READ_CONTACTS

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
typeContactTypeYesContact type.
- 1: GENERAL_CONTACT
- 2: FIXED_DIALING

Return value

TypeDescription
Promise<Array<DiallingNumbersInfo>>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.queryIccDiallingNumbers(0, 1).then((data:  Array<sim.DiallingNumbersInfo>) => {
    console.log(`queryIccDiallingNumbers success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`queryIccDiallingNumbers failed, promise: err->${JSON.stringify(err)}`);
});

sim.addIccDiallingNumbers8+

addIccDiallingNumbers(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo, callback: AsyncCallback<void>): void

Adds contact numbers to the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Permission required: ohos.permission.WRITE_CONTACTS

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
typeContactTypeYesContact type.
- 1: GENERAL_CONTACT
- 2: FIXED_DIALING
diallingNumbersDiallingNumbersInfoYesContact number information.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let diallingNumbersInof: sim.DiallingNumbersInfo = {
    alphaTag: "alpha",
    number: "138xxxxxxxx",
    pin2: "1234"
};
sim.addIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err: BusinessError) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
});

sim.addIccDiallingNumbers8+

addIccDiallingNumbers(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo): Promise<void>

Adds contact numbers to the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Permission required: ohos.permission.WRITE_CONTACTS

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
typeContactTypeYesContact type.
- 1: GENERAL_CONTACT
- 2: FIXED_DIALING
diallingNumbersDiallingNumbersInfoYesContact number information.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let diallingNumbersInof: sim.DiallingNumbersInfo = {
    alphaTag: "alpha",
    number: "138xxxxxxxx"
};
sim.addIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof).then(() => {
    console.log(`addIccDiallingNumbers success.`);
}).catch((err: BusinessError) => {
    console.log(`addIccDiallingNumbers failed, promise: err->${JSON.stringify(err)}`);
});

sim.delIccDiallingNumbers8+

delIccDiallingNumbers(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo, callback: AsyncCallback<void>): void

Deletes contact numbers from the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Permission required: ohos.permission.WRITE_CONTACTS

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
typeContactTypeYesContact type.
- 1: GENERAL_CONTACT
- 2: FIXED_DIALING
diallingNumbersDiallingNumbersInfoYesContact number information.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let diallingNumbersInof: sim.DiallingNumbersInfo = {
    alphaTag: "alpha",
    number: "138xxxxxxxx",
    recordNumber: 123,
    pin2: "1234"
};
sim.delIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err: BusinessError) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
});

sim.delIccDiallingNumbers8+

delIccDiallingNumbers(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo): Promise<void>

Deletes contact numbers from the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Permission required: ohos.permission.WRITE_CONTACTS

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
typeContactTypeYesContact type.
- 1: GENERAL_CONTACT
- 2: FIXED_DIALING
diallingNumbersDiallingNumbersInfoYesContact number information.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let diallingNumbersInof: sim.DiallingNumbersInfo = {
    alphaTag: "alpha",
    number: "138xxxxxxxx"
};
sim.delIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof).then(() => {
    console.log(`delIccDiallingNumbers success.`);
}).catch((err: BusinessError) => {
    console.log(`delIccDiallingNumbers failed, promise: err->${JSON.stringify(err)}`);
});

sim.updateIccDiallingNumbers8+

updateIccDiallingNumbers(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo, callback: AsyncCallback<void>): void

Updates contact numbers for the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Permission required: ohos.permission.WRITE_CONTACTS

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
typeContactTypeYesContact type.
- 1: GENERAL_CONTACT
- 2: FIXED_DIALING
diallingNumbersDiallingNumbersInfoYesContact number information.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let diallingNumbersInof: sim.DiallingNumbersInfo = {
    alphaTag: "alpha",
    number: "138xxxxxxxx",
    recordNumber: 123,
    pin2: "1234"
};
sim.updateIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof, (err: BusinessError) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
});

sim.updateIccDiallingNumbers8+

updateIccDiallingNumbers(slotId: number, type: ContactType, diallingNumbers: DiallingNumbersInfo): Promise<void>

Updates contact numbers for the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Permission required: ohos.permission.WRITE_CONTACTS

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
typeContactTypeYesContact type.
- 1: GENERAL_CONTACT
- 2: FIXED_DIALING
diallingNumbersDiallingNumbersInfoYesContact number information.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let diallingNumbersInof: sim.DiallingNumbersInfo = {
    alphaTag: "alpha",
    number: "138xxxxxxxx",
    recordNumber: 123
};
sim.updateIccDiallingNumbers(0, sim.ContactType.GENERAL_CONTACT, diallingNumbersInof).then(() => {
    console.log(`updateIccDiallingNumbers success.`);
}).catch((err: BusinessError) => {
    console.log(`updateIccDiallingNumbers failed, promise: err->${JSON.stringify(err)}`);
});

sim.sendEnvelopeCmd8+

sendEnvelopeCmd(slotId: number, cmd: string, callback: AsyncCallback<void>): void

Sends an envelope command to the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
cmdstringYesEnvelope command.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.sendEnvelopeCmd(0, "ls", (err: BusinessError) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
});

sim.sendEnvelopeCmd8+

sendEnvelopeCmd(slotId: number, cmd: string): Promise<void>

Sends an envelope command to the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
cmdstringYesEnvelope command.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.sendEnvelopeCmd(0, "ls").then(() => {
    console.log(`sendEnvelopeCmd success.`);
}).catch((err: BusinessError) => {
    console.log(`sendEnvelopeCmd failed, promise: err->${JSON.stringify(err)}`);
});

sim.sendTerminalResponseCmd8+

sendTerminalResponseCmd(slotId: number, cmd: string, callback: AsyncCallback<void>): void

Sends a terminal response command to the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
cmdstringYesEnvelope command.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.sendTerminalResponseCmd(0, "ls", (err: BusinessError) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
});

sim.sendTerminalResponseCmd8+

sendTerminalResponseCmd(slotId: number, cmd: string): Promise<void>

Sends a terminal response command to the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
cmdstringYesEnvelope command.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

sim.sendTerminalResponseCmd(0, "ls").then(() => {
    console.log(`sendTerminalResponseCmd success.`);
}).catch((err: BusinessError) => {
    console.log(`sendTerminalResponseCmd failed, promise: err->${JSON.stringify(err)}`);
});

sim.unlockSimLock8+

unlockSimLock(slotId: number, lockInfo: PersoLockInfo, callback: AsyncCallback<LockStatusResponse>): void

Unlocks the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
lockInfoPersoLockInfoYesPersonalized lock information.
callbackAsyncCallback<LockStatusResponse>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let persoLockInfo: sim.PersoLockInfo = {
    lockType: sim.PersoLockType.PN_PIN_LOCK,
    password: "1234"
};
sim.unlockSimLock(0, persoLockInfo, (err: BusinessError, data: sim.LockStatusResponse) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sim.unlockSimLock8+

unlockSimLock(slotId: number, lockInfo: PersoLockInfo): Promise<LockStatusResponse>

Unlocks the SIM card in the specified slot. This API uses a promise to return the result.

System API: This is a system API.

Required permission: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
lockInfoPersoLockInfoYesPersonalized lock information.

Return value

TypeDescription
Promise<LockStatusResponse>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301002SIM card operation error.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let persoLockInfo: sim.PersoLockInfo = {
    lockType: sim.PersoLockType.PN_PIN_LOCK,
    password: "1234"
};
sim.unlockSimLock(0, persoLockInfo).then((data: sim.LockStatusResponse) => {
    console.log(`unlockSimLock success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`unlockSimLock failed, promise: err->${JSON.stringify(err)}`);
});

sim.getOpKey9+

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

Obtains the opkey of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
801Capability not supported.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

try {
    sim.getOpKey(0, (err: BusinessError, data: string) => {
    if (err) {
      console.log("getOpKey failed, err: " + JSON.stringify(err));
    } else {
      console.log('getOpKey successfully, data: ' + JSON.stringify(data));
    }
  });
} catch (err) {
  console.log("getOpKey err: " + JSON.stringify(err));
}

sim.getOpKey9+

getOpKey(slotId: number): Promise<string>

Obtains the opkey of the SIM card in the specified slot. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
801Capability not supported.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

try {
    let data: Promise<string> = sim.getOpKey(0);
    console.log(`getOpKey success, promise: data->${JSON.stringify(data)}`);
} catch (error) {
    console.log(`getOpKey failed, promise: err->${JSON.stringify(error)}`);
}

sim.getOpKeySync10+

getOpKeySync(slotId: number): string

Obtains the opkey of the SIM card in the specified slot.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
stringopkey of the SIM card in the specified slot.

Example

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

let data: string = sim.getOpKeySync(0);
console.log(`getOpKey success, promise: data->${JSON.stringify(data)}`);

sim.getOpName9+

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

Obtains the OpName of the SIM card in the specified slot. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
801Capability not supported.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

try {
    sim.getOpName(0, (err: BusinessError, data: string) => {
    if (err) {
      console.log("getOpName failed, err: " + JSON.stringify(err));
    } else {
      console.log('getOpName successfully, data: ' + JSON.stringify(data));
    }
  });
} catch (err) {
  console.log("getOpName err: " + JSON.stringify(err));
}

sim.getOpName9+

getOpName(slotId: number): Promise<string>

Obtains the OpName of the SIM card in the specified slot. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
401Parameter error.
801Capability not supported.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

try {
    let data: Promise<string> = sim.getOpName(0);
    console.log(`getOpName success, promise: data->${JSON.stringify(data)}`);
} catch (error) {
    console.log(`getOpName failed, promise: err->${JSON.stringify(error)}`);
}

sim.getOpNameSync10+

getOpNameSync(slotId: number): string

Obtains the OpName of the SIM card in the specified slot.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
stringOpName of the SIM card in the specified slot.

Example

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

let data: string = sim.getOpNameSync(0);
console.log(`getOpName success, promise: data->${JSON.stringify(data)}`);

sim.getDefaultVoiceSimId10+

getDefaultVoiceSimId(callback: AsyncCallback<number>): void

Obtains the default slot ID of the SIM card that provides voice services. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Telephony.CoreService

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback 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.

IDError Message
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301001SIM card is not activated.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

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

sim.getDefaultVoiceSimId10+

getDefaultVoiceSimId(): Promise<number>

Obtains the default slot ID of the SIM card that provides voice services. This API uses a promise to return the result.

System capability: SystemCapability.Telephony.CoreService

Return value

TypeDescription
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.

IDError Message
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.
8301001SIM card is not activated.

Example

import { BusinessError } from '@ohos.base';
import sim from '@ohos.telephony.sim';

let promise = sim.getDefaultVoiceSimId();
promise.then((data: number) => {
    console.log(`getDefaultVoiceSimId success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.log(`getDefaultVoiceSimId failed, promise: err->${JSON.stringify(err)}`);
});

SimState

Enumerates SIM card states.

System capability: SystemCapability.Telephony.CoreService

NameValueDescription
SIM_STATE_UNKNOWN0The SIM card is in unknown state; that is, the SIM card status cannot be obtained.
SIM_STATE_NOT_PRESENT1The SIM card is in not present state; that is, no SIM card is inserted into the card slot.
SIM_STATE_LOCKED2The 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_READY3The SIM card is in not ready state; that is, the SIM card has been installed but cannot work properly.
SIM_STATE_READY4The SIM card is in ready state; that is, the SIM card has been installed and is working properly.
SIM_STATE_LOADED5The SIM card is in loaded state; that is, the SIM card is present and all its files have been loaded.

CardType7+

Enumerates SIM card types.

System capability: SystemCapability.Telephony.CoreService

NameValueDescription
UNKNOWN_CARD-1Unknown type.
SINGLE_MODE_SIM_CARD10Single-card (SIM).
SINGLE_MODE_USIM_CARD20Single-card (USIM).
SINGLE_MODE_RUIM_CARD30Single-card (RUIM).
DUAL_MODE_CG_CARD40Dual-card (CDMA+GSM).
CT_NATIONAL_ROAMING_CARD41China Telecom internal roaming card.
CU_DUAL_MODE_CARD42China Unicom dual-mode card.
DUAL_MODE_TELECOM_LTE_CARD43China Telecom dual-mode LTE card.
DUAL_MODE_UG_CARD50Dual-mode card (UMTS+GSM).
SINGLE_MODE_ISIM_CARD8+60Single-card (ISIM).

LockType8+

Enumerates lock types.

System API: This is a system API.

System capability: SystemCapability.Telephony.CoreService

NameValueDescription
PIN_LOCK1SIM card password lock.
FDN_LOCK2Fixed dialing lock.

LockState8+

Enumerates lock states.

System API: This is a system API.

System capability: SystemCapability.Telephony.CoreService

NameValueDescription
LOCK_OFF0The lock is off.
LOCK_ON1The lock is on.

PersoLockType8+

Enumerates personalized lock types.

System API: This is a system API.

System capability: SystemCapability.Telephony.CoreService

NameValueDescription
PN_PIN_LOCK0Personalized network PIN lock. For details, see 3GPP TS 22.022 [33].
PN_PUK_LOCK1Personalized network PUK lock.
PU_PIN_LOCK2Personalized network subset PIN lock. For details, see 3GPP TS 22.022 [33].
PU_PUK_LOCK3Personalized network subset PUK lock.
PP_PIN_LOCK4Personalized service provider PIN lock. For details, see 3GPP TS 22.022 [33].
PP_PUK_LOCK5Personalized service provider PUK lock.
PC_PIN_LOCK6Personalized corporate PIN lock. For details, see 3GPP TS 22.022 [33].
PC_PUK_LOCK7Personalized corporate PUK lock.
SIM_PIN_LOCK8Personalized SIM card PIN lock. For details, see 3GPP TS 22.022 [33].
SIM_PUK_LOCK9Personalized SIM card PUK lock.

LockStatusResponse7+

Defines the personalized lock information.

System API: This is a system API.

System capability: SystemCapability.Telephony.CoreService

NameTypeMandatoryDescription
resultnumberYesOperation result.
remain?: numbernumberNoRemaining attempts (can be null).

LockInfo8+

Defines the personalized lock information.

System API: This is a system API.

System capability: SystemCapability.Telephony.CoreService

NameTypeMandatoryDescription
lockTypeLockTypeYesLock type.
passwordstringYesPassword.
stateLockStateYesLock state.

PersoLockInfo8+

Defines the personalized lock information.

System API: This is a system API.

System capability: SystemCapability.Telephony.CoreService

NameTypeMandatoryDescription
lockTypePersoLockTypeYesPersonalized lock type.
passwordstringYesPassword.

IccAccountInfo10+

ICC account information.

System capability: SystemCapability.Telephony.CoreService

NameTypeMandatoryDescription
simIdnumberYesSIM card ID.
slotIndexnumberYesCard slot ID.
isEsimbooleanYesWhether the SIM card is an eSim card.
isActivebooleanYesWhether the card is activated.
iccIdstringYesICCID number.
showNamestringYesSIM card display name.
showNumberstringYesSIM card display number.

OperatorConfig8+

Defines the carrier configuration.

System API: This is a system API.

System capability: SystemCapability.Telephony.CoreService

NameTypeMandatoryDescription
fieldstringYesField name.
valuestringYesField value.

DiallingNumbersInfo8+

Defines the contact number information.

System API: This is a system API.

System capability: SystemCapability.Telephony.CoreService

NameTypeMandatoryDescription
alphaTagstringYesTag.
numberstringYesCall transfer number.
recordNumbernumberYesRecord number.
pin2stringYesPIN 2.

ContactType8+

Enumerates contact types.

System API: This is a system API.

System capability: SystemCapability.Telephony.CoreService

NameValueDescription
GENERAL_CONTACT1Common contact number.
FIXED_DIALING2Fixed dialing number.

OperatorConfigKey9+

Enumerates carrier configuration keys.

System API: This is a system API.

System capability: SystemCapability.Telephony.CoreService

NameValueDescription
KEY_VOICE_MAIL_NUMBER_STRING"voice_mail_number_string"Voice mailbox number.
KEY_IMS_SWITCH_ON_BY_DEFAULT_BOOL"ims_switch_on_by_default_bool"Fixed dialing number.
KEY_HIDE_IMS_SWITCH_BOOL"hide_ims_switch_bool"Whether to hide the IMS switch.
KEY_VOLTE_SUPPORTED_BOOL"volte_supported_bool"Whether to support VoLTE.
KEY_NR_MODE_SUPPORTED_LIST_INT_ARRAY"nr_mode_supported_list_int_array"List of supported NR modes.
KEY_VOLTE_PROVISIONING_SUPPORTED_BOOL"volte_provisioning_supported_bool"Whether to support VoLTE provisioning.
KEY_SS_OVER_UT_SUPPORTED_BOOL"ss_over_ut_supported_bool"Whether SS over UT is supported.
KEY_IMS_GBA_REQUIRED_BOOL"ims_gba_required_bool"Whether GBA is required for IMS.
KEY_UT_PROVISIONING_SUPPORTED_BOOL"ut_provisioning_supported_bool"Whether to support UT provisioning.
KEY_IMS_PREFER_FOR_EMERGENCY_BOOL"ims_prefer_for_emergency_bool"IMS preferences for emergency.
KEY_CALL_WAITING_SERVICE_CLASS_INT"call_waiting_service_class_int"Call waiting service.
KEY_CALL_TRANSFER_VISIBILITY_BOOL"call_transfer_visibility_bool"Call transfer visibility.
KEY_IMS_CALL_DISCONNECT_REASON_INFO_MAPPING_STRING_ARRAY"ims_call_disconnect_reason_info_mapping_string_array"List of IMS call disconnection reasons.
KEY_FORCE_VOLTE_SWITCH_ON_BOOL"force_volte_switch_on_bool"Whether to forcibly turn on VoLTE.
KEY_ENABLE_OPERATOR_NAME_CUST_BOOL"enable_operator_name_cust_bool"Whether to display the carrier name.
KEY_OPERATOR_NAME_CUST_STRING"operator_name_cust_string"Carrier name.
KEY_SPN_DISPLAY_CONDITION_CUST_INT"spn_display_condition_cust_int"SPN display rule.
KEY_PNN_CUST_STRING_ARRAY"pnn_cust_string_array"PLMN name
KEY_OPL_CUST_STRING_ARRAY"opl_cust_string_array"PLMN information of the carrier.
KEY_EMERGENCY_CALL_STRING_ARRAY"emergency_call_string_array"Emergency call list.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/5ec6afe70ebe4a42bb9a8b47e4ff72fa