SIM卡管理

说明:

本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

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

sim.isSimActive7+

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

获取指定卡槽SIM卡是否激活,使用callback方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2
callback AsyncCallback<boolean> 回调函数。

示例:

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

sim.isSimActive7+

isSimActive(slotId: number): Promise<boolean>

获取指定卡槽SIM卡是否激活,使用Promise方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2

返回值:

类型 说明
Promise<boolean> 以Promise形式返回指定卡槽是否激活,如果激活返回true。

示例:

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

sim.getDefaultVoiceSlotId7+

getDefaultVoiceSlotId(callback: AsyncCallback<number>): void

获取默认语音业务的卡槽ID,使用callback方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
callback AsyncCallback<number> 回调函数。

示例:

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

sim.getDefaultVoiceSlotId7+

getDefaultVoiceSlotId(): Promise<number>

获取默认语音业务的卡槽ID,使用Promise方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

返回值:

类型 说明
Promise<number> 以Promise形式返回默认语音业务的卡槽ID。

示例:

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

sim.hasOperatorPrivileges7+

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

检查应用(调用者)是否已被授予运营商权限,使用callback方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2
callback AsyncCallback<boolean> 回调函数。

示例:

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

sim.hasOperatorPrivileges7+

hasOperatorPrivileges(slotId: number): Promise<boolean>

检查应用(调用者)是否已被授予运营商权限,使用Promise方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2

返回值:

类型 说明
Promise<boolean> 以Promise形式返回检查应用(调用者)是否已被授予运营商权限。

示例:

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

sim.getISOCountryCodeForSim

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

获取指定卡槽SIM卡的ISO国家码,使用callback方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2
callback AsyncCallback<string> 回调函数。返回国家码,例如:CN(中国)。

示例:

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

sim.getISOCountryCodeForSim

getISOCountryCodeForSim(slotId: number): Promise<string>

获取指定卡槽SIM卡的ISO国家码,使用Promise方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2

返回值:

类型 说明
Promise<string> 以Promise形式返回获取指定卡槽SIM卡的ISO国家码,例如:CN(中国)。

示例:

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

sim.getSimOperatorNumeric

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

获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号,使用callback方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2
callback AsyncCallback<string> 回调函数。

示例:

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

sim.getSimOperatorNumeric

getSimOperatorNumeric(slotId: number): Promise<string>

获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号,使用Promise方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2

返回值:

类型 说明
Promise<string> 以Promise形式返回获取指定卡槽SIM卡的归属PLMN号。

示例:

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

sim.getSimSpn

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

获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN),使用callback方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2
callback AsyncCallback<string> 回调函数。

示例:

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

sim.getSimSpn

getSimSpn(slotId: number): Promise<string>

获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN),使用Promise方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2

返回值:

类型 说明
Promise<string> 以Promise形式返回获取指定卡槽SIM卡的SPN。

示例:

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

sim.getSimState

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

获取指定卡槽的SIM卡状态,使用callback方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2
callback AsyncCallback<SimState> 回调函数。参考SimState

示例:

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

sim.getSimState

getSimState(slotId: number): Promise<SimState>

获取指定卡槽的SIM卡状态,使用Promise方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2

返回值:

类型 说明
Promise<SimState> 以Promise形式返回获取指定卡槽的SIM卡状态。

示例:

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

sim.getCardType7+

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

获取指定卡槽SIM卡的卡类型,使用callback方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2
callback AsyncCallback<CardType> 回调函数。

示例:

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

sim.getCardType7+

getCardType(slotId: number): Promise<CardType>

获取指定卡槽SIM卡的卡类型,使用Promise方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2

返回值:

类型 说明
Promise<CardType> 以Promise形式返回指定卡槽SIM卡的卡类型。

示例:

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

sim.hasSimCard7+

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

获取指定卡槽SIM卡是否插卡,使用callback方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2
callback AsyncCallback<boolean> 回调函数。

示例:

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

sim.hasSimCard7+

hasSimCard(slotId: number): Promise<boolean>

获取指定卡槽SIM卡是否插卡,使用Promise方式作为异步方法。

系统能力:SystemCapability.Communication.CoreService

参数:

参数名 类型 必填 说明
slotId number 卡槽ID。
- 0:卡槽1
- 1:卡槽2

返回值:

类型 说明
Promise<boolean> 以Promise形式返回指定卡槽是否插卡,如果插卡返回true。

示例:

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

sim.getMaxSimCount7+

getMaxSimCount(): number

获取卡槽数量。

系统能力:SystemCapability.Communication.CoreService

返回值:

类型 说明
number 卡槽数量。

示例:

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

SimState

SIM卡状态。

系统能力:以下各项对应的系统能力均为SystemCapability.Telephony.CoreService。

名称 说明
SIM_STATE_UNKNOWN 0 SIM卡状态未知,即无法获取准确的状态。
SIM_STATE_NOT_PRESENT 1 表示SIM卡处于not present状态,即卡槽中没有插入SIM卡。
SIM_STATE_LOCKED 2 表示SIM卡处于locked状态,即SIM卡被PIN、PUK或网络锁锁定。
SIM_STATE_NOT_READY 3 表示SIM卡处于not ready状态,即SIM卡在位但无法正常工作。
SIM_STATE_READY 4 表示SIM卡处于ready状态,即SIM卡在位且工作正常。
SIM_STATE_LOADED 5 表示SIM卡处于loaded状态,即SIM卡在位且所有卡文件加载完毕。

CardType7+

卡类型。

系统能力:以下各项对应的系统能力均为SystemCapability.Telephony.CoreService。

名称 说明
UNKNOWN_CARD -1 未知类型
SINGLE_MODE_SIM_CARD 10 单SIM卡
SINGLE_MODE_USIM_CARD 20 单USIM卡
SINGLE_MODE_RUIM_CARD 30 单RUIM卡
DUAL_MODE_CG_CARD 40 双卡模式C+G
CT_NATIONAL_ROAMING_CARD 41 中国电信内部漫游卡
CU_DUAL_MODE_CARD 42 中国联通双模卡
DUAL_MODE_TELECOM_LTE_CARD 43 双模式电信LTE卡
DUAL_MODE_UG_CARD 50 双模式UG卡
SINGLE_MODE_ISIM_CARD8+ 60 单一ISIM卡类型