harmony 鸿蒙@ohos.telephony.sim (SIM卡管理)

2022-08-09 浏览 (1183)

@ohos.telephony.sim (SIM卡管理)

SIM卡管理模块提供了SIM卡管理的基础能力,包括获取指定卡槽SIM卡的名称、号码、ISO国家码、归属PLMN号、服务提供商名称、SIM卡状态、卡类型、是否插卡、是否激活、锁状态,设置指定卡槽SIM卡显示的名称、号码、锁状态,激活、禁用指定卡槽SIM卡,更改Pin密码,以及解锁指定卡槽SIM卡密码、SIM卡密码的解锁密码等。

说明:

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

导入模块

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

sim.isSimActive7+

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

获取指定卡槽SIM卡是否激活。使用callback异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<boolean>回调函数。返回指定卡槽是否激活,如果激活返回true。

示例:

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>

获取指定卡槽SIM卡是否激活。使用Promise异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

示例:

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

获取指定卡槽SIM卡是否激活。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
boolean返回指定卡槽是否激活,如果激活返回true。

示例:

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

获取默认语音业务的卡槽ID。使用callback异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
callbackAsyncCallback<number>回调函数。
- 0:卡槽1
- 1:卡槽2
- -1:未设置或服务不可用

示例:

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>

获取默认语音业务的卡槽ID。使用Promise异步回调。

系统能力:SystemCapability.Telephony.CoreService

返回值:

类型说明
Promise<number>以Promise形式返回默认语音业务的卡槽ID。
- 0:卡槽1
- 1:卡槽2
- -1:未设置或服务不可用

示例:

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

检查应用(调用者)是否已被授予运营商权限。使用callback异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<boolean>回调函数。 返回检查应用(调用者)是否已被授予运营商权限。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

示例:

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>

检查应用(调用者)是否已被授予运营商权限。使用Promise异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

示例:

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

获取指定卡槽SIM卡的ISO国家码。使用callback异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

示例:

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>

获取指定卡槽SIM卡的ISO国家码。使用Promise异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

示例:

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

获取指定卡槽SIM卡的ISO国家码。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

示例:

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

获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号。使用callback异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<string>回调函数。返回指定卡槽SIM卡的归属PLMN号。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

示例:

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>

获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号。使用Promise异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

示例:

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

获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
string返回获取指定卡槽SIM卡的归属PLMN号。

示例:

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

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

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<string>回调函数。返回指定卡槽SIM卡的SPN。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

示例:

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>

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

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

示例:

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

获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN)。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
string返回获取指定卡槽SIM卡的SPN。

示例:

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

获取指定卡槽的SIM卡状态。使用callback异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

示例:

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>

获取指定卡槽的SIM卡状态。使用Promise异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

示例:

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

获取指定卡槽的SIM卡状态。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
SimState返回获取指定卡槽的SIM卡状态。

示例:

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

获取指定卡槽SIM卡的卡类型。使用callback异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

示例:

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>

获取指定卡槽SIM卡的卡类型。使用Promise异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

示例:

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

获取指定卡槽SIM卡的卡类型。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
CardType返回指定卡槽SIM卡的卡类型。

示例:

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

获取指定卡槽SIM卡是否插卡。使用callback异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<boolean>回调返回指定卡槽是否插卡,如果插卡返回true。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

示例:

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>

获取指定卡槽SIM卡是否插卡。使用Promise异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

示例:

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

获取指定卡槽SIM卡是否插卡。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
boolean返回指定卡槽是否插卡,如果插卡返回true。

示例:

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

获取SIM卡帐户信息。使用callback异步回调。

说明:

如果没有GET_TELEPHONY_STATE权限,获取到的ICCID和号码信息为空。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<IccAccountInfo>回调函数。返回指定卡槽SIM卡的帐户信息。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

获取SIM卡帐户信息。使用Promise异步回调。

说明:

如果没有GET_TELEPHONY_STATE权限,获取到的ICCID和号码信息为空。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
Promise<IccAccountInfo>以Promise形式返回指定卡槽SIM卡的帐户信息。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取激活SIM卡帐户信息列表。使用callback异步回调。

说明:

如果没有GET_TELEPHONY_STATE权限,获取到的ICCID和号码信息为空。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
callbackAsyncCallback<Array<IccAccountInfo>>回调函数。返回激活SIM卡帐户信息列表。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

示例:

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>>;

获取激活SIM卡帐户信息列表。使用Promise异步回调。

说明:

如果没有GET_TELEPHONY_STATE权限,获取到的ICCID和号码信息为空。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

返回值:

类型说明
Promise<Array<IccAccountInfo>>以Promise形式返回激活卡槽SIM卡的帐户信息列表。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

示例:

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

设置默认语音业务的卡槽ID。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumberSIM卡槽ID:
- 0:卡槽1
- 1:卡槽2
- -1:清除默认配置
callbackAsyncCallback<void>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

设置默认语音业务的卡槽ID。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumberSIM卡槽ID:
- 0:卡槽1
- 1:卡槽2
- -1:清除默认配置

返回值:

类型说明
Promise<void>以Promise形式异步返回设置结果。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

设置指定卡槽SIM卡显示的名称。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
namestringSIM卡名称。
callbackAsyncCallback<void>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

设置指定卡槽SIM卡显示的名称。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
namestringSIM卡名称。

返回值:

类型说明
Promise<void>以Promise形式异步返回设置结果。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取指定卡槽SIM卡的名称。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<string>回调函数。返回指定卡槽SIM卡的名称。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

获取指定卡槽SIM卡的名称。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

设置指定卡槽SIM卡的号码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
numberstringSIM卡号码。
callbackAsyncCallback<void>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

设置指定卡槽SIM卡的号码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
numberstringSIM卡号码。

返回值:

类型说明
Promise<void>以Promise形式异步返回设置结果。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取指定卡槽SIM卡的号码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<string>回调函数。返回指定卡槽的号码。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

获取指定卡槽SIM卡的号码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
Promise<string>以Promise形式返回指定卡槽的号码。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

激活指定卡槽SIM卡。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<void>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

激活指定卡槽SIM卡。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
Promise<void>以Promise形式异步返回设置结果。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

禁用指定卡槽SIM卡。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<void>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

禁用指定卡槽SIM卡。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
Promise<void>以Promise形式异步返回设置结果。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

设置指定卡槽SIM卡的锁状态。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<LockStatusResponse>回调函数。
optionsLockInfo锁信息。
- lockType: LockType
- password: string
- state: LockState

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

设置指定卡槽SIM卡的锁状态。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
optionsLockInfo锁信息。
- lockType: LockType
- password: string
- state: LockState

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取指定卡槽SIM卡的锁状态。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<LockState>回调函数。
optionsLockType锁类型。
- 1: PIN锁
- 2: PIN2锁

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

获取指定卡槽SIM卡的锁状态。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
optionsLockType锁类型。
- 1: PIN锁
- 2: PIN2锁

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

更改Pin密码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<LockStatusResponse>回调函数。
newPinstring新密码。
oldPinstring旧密码。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>;

更改Pin密码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
newPinstring新密码。
oldPinstring旧密码。

返回值:

类型说明
Promise<LockStatusResponse>以Promise形式返回指定卡槽SIM卡的Pin是否成功。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

更改Pin2密码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<LockStatusResponse>回调函数。
newPin2string新密码。
oldPin2string旧密码。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

更改Pin2密码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
newPin2string新密码。
oldPin2string旧密码。

返回值:

类型说明
Promise<LockStatusResponse>以Promise形式返回指定卡槽SIM卡的Pin是否成功。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

解锁指定卡槽SIM卡密码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
pinstringSIM卡的密码。
callbackAsyncCallback<LockStatusResponse>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

解锁指定卡槽SIM卡密码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
pinstringSIM卡的密码。

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

解锁指定卡槽SIM卡密码的解锁密码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
newPinstring重置SIM卡的密码。
pukstringSIM卡密码的解锁密码。
callbackAsyncCallback<LockStatusResponse>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

解锁指定卡槽SIM卡密码的解锁密码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
newPinstring重置SIM卡的密码。
pukstringSIM卡密码的解锁密码。

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

解锁指定卡槽SIM卡密码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
pin2stringSIM卡的密码。
callbackAsyncCallback<LockStatusResponse>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

解锁指定卡槽SIM卡密码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
pin2stringSIM卡的密码。

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

解锁指定卡槽SIM卡密码的解锁密码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
newPin2string重置SIM卡的密码。
puk2stringSIM卡密码的解锁密码。
callbackAsyncCallback<LockStatusResponse>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

解锁指定卡槽SIM卡密码的解锁密码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
newPin2string重置SIM卡的密码。
puk2stringSIM卡密码的解锁密码。

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取卡槽数量。

系统能力:SystemCapability.Telephony.CoreService

返回值:

类型说明
number卡槽数量。

示例:

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

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

sim.getSimIccId7+

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

获取指定卡槽SIM卡的ICCID。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

获取指定卡槽SIM卡的ICCID。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取指定卡槽中SIM卡语音信箱的alpha标识符。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

获取指定卡槽中SIM卡语音信箱的alpha标识符。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取指定卡槽中SIM卡的语音信箱号。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

获取指定卡槽中SIM卡的语音信箱号。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
Promise<string>以Promise形式返回获取指定卡槽SIM卡的语音信箱号。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

设置语音邮件信息。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
mailNamestring邮件名字
mailNumberstring邮件号码
callbackAsyncCallback<void>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

设置语音邮件信息。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
mailNamestring邮件名字。
mailNumberstring邮件号码。

返回值:

类型说明
Promise<void>以Promise形式返回结果。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取指定卡槽中SIM卡的MSISDN。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_PHONE_NUMBERS

系统能力:SystemCapability.Telephony.CoreService

参数:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

获取指定卡槽中SIM卡的MSISDN。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_PHONE_NUMBERS

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取指定卡槽中SIM卡的组标识符级别1(GID1)。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

获取指定卡槽中SIM卡的组标识符级别1(GID1)。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
Promise<string>以Promise形式返回获取指定卡槽SIM卡的标识符级别1。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取国际移动用户识别码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

获取国际移动用户识别码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
Promise<string>以Promise形式返回获取的国际移动用户识别码。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取运营商配置。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
callbackAsyncCallback<Array<OperatorConfig>>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取运营商配置。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.GET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
Promise<Array<OperatorConfig>>以Promise形式返回运营商配置。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

查询SIM卡联系人号码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.READ_CONTACTS

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
typeContactType联系人类型。
- 1 : GENERAL_CONTACT
- 2 : FIXED_DIALING
callbackAsyncCallback<Array<DiallingNumbersInfo>>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

查询SIM卡联系人号码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.READ_CONTACTS

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
typeContactType联系人类型。
- 1 : GENERAL_CONTACT
- 2 : FIXED_DIALING

返回值:

类型说明
Promise<Array<DiallingNumbersInfo>>以Promise形式返回Icc拨号号码。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

添加SIM卡联系人号码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.WRITE_CONTACTS

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
typeContactType联系人类型。
- 1 : GENERAL_CONTACT
- 2 : FIXED_DIALING
diallingNumbersDiallingNumbersInfo拨号号码信息。
callbackAsyncCallback<void>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

添加SIM卡联系人号码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.WRITE_CONTACTS

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
typeContactType联系人类型。
- 1 : GENERAL_CONTACT
- 2 : FIXED_DIALING
diallingNumbersDiallingNumbersInfo拨号号码信息。

返回值:

类型说明
Promise<void>以Promise形式返回添加结果。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

删除SIM卡联系人号码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.WRITE_CONTACTS

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
typeContactType联系人类型。
- 1 : GENERAL_CONTACT
- 2 : FIXED_DIALING
diallingNumbersDiallingNumbersInfo拨号号码信息。
callbackAsyncCallback<void>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

删除SIM卡联系人号码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.WRITE_CONTACTS

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
typeContactType联系人类型。
- 1 : GENERAL_CONTACT
- 2 : FIXED_DIALING
diallingNumbersDiallingNumbersInfo拨号号码信息。

返回值:

类型说明
Promise<void>以Promise形式返回删除结果。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

更新SIM卡联系人号码。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.WRITE_CONTACTS

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
typeContactType联系人类型。
- 1 : GENERAL_CONTACT
- 2 : FIXED_DIALING
diallingNumbersDiallingNumbersInfo拨号号码信息。
callbackAsyncCallback<void>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

更新SIM卡联系人号码。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.WRITE_CONTACTS

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
typeContactType联系人类型。
- 1 : GENERAL_CONTACT
- 2 : FIXED_DIALING
diallingNumbersDiallingNumbersInfo拨号号码信息。

返回值:

类型说明
Promise<void>以Promise形式返回更新的结果。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

发送信封命令。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
cmdstring命令。
callbackAsyncCallback<void>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

发送信封命令。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
cmdstring命令。

返回值:

类型说明
Promise<void>以Promise形式返回发送结果。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

发送终端响应命令。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
cmdstring命令。
callbackAsyncCallback<void>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

发送终端响应命令。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
cmdstring命令。

返回值:

类型说明
Promise<void>以Promise形式返回发送结果。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

解锁SIM卡锁。使用callback异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
lockInfoPersoLockInfo定制锁类型信息。
callbackAsyncCallback<LockStatusResponse>回调函数。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

解锁SIM卡锁。使用Promise异步回调。

系统接口: 此接口为系统接口。

需要权限:ohos.permission.SET_TELEPHONY_STATE

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
slotIdnumber卡槽ID。
- 0:卡槽1
- 1:卡槽2
lockInfoPersoLockInfo定制锁类型信息。

返回值:

类型说明
Promise<LockStatusResponse>以Promise形式返回锁状态。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

获取指定卡槽中SIM卡的opkey。使用callback异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
801Capability not supported.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

示例:

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>

获取指定卡槽中SIM卡的opkey。使用Promise异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
801Capability not supported.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

示例:

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

获取指定卡槽中SIM卡的opkey。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
string返回指定卡槽中SIM卡的opkey。

示例:

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

获取指定卡槽中SIM卡的OpName。使用callback异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
801Capability not supported.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

示例:

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>

获取指定卡槽中SIM卡的OpName。使用Promise异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

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

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
401Parameter error.
801Capability not supported.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

示例:

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

获取指定卡槽中SIM卡的OpName。

系统能力:SystemCapability.Telephony.CoreService

参数:

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

返回值:

类型说明
string返回指定卡槽中SIM卡的OpName。

示例:

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

获取默认语音业务的SIM卡ID。使用callback异步回调。

系统能力:SystemCapability.Telephony.CoreService

参数:

参数名类型必填说明
callbackAsyncCallback<number>回调函数。
与SIM卡绑定,从1开始递增。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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>

获取默认语音业务的SIM卡ID。使用Promise异步回调。

系统能力:SystemCapability.Telephony.CoreService

返回值:

类型说明
Promise<number>以Promise形式返回默认语音业务的SIM卡ID。
与SIM卡绑定,从1开始递增。

错误码:

以下错误码的详细介绍请参见ohos.telephony(电话子系统)错误码

错误码ID错误信息
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.

示例:

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

SIM卡状态。

系统能力:SystemCapability.Telephony.CoreService

名称说明
SIM_STATE_UNKNOWN0SIM卡状态未知,即无法获取准确的状态。
SIM_STATE_NOT_PRESENT1表示SIM卡处于not present状态,即卡槽中没有插入SIM卡。
SIM_STATE_LOCKED2表示SIM卡处于locked状态,即SIM卡被PIN、PUK或网络锁锁定。
SIM_STATE_NOT_READY3表示SIM卡处于not ready状态,即SIM卡在位但无法正常工作。
SIM_STATE_READY4表示SIM卡处于ready状态,即SIM卡在位且工作正常。
SIM_STATE_LOADED5表示SIM卡处于loaded状态,即SIM卡在位且所有卡文件加载完毕。

CardType7+

卡类型。

系统能力:SystemCapability.Telephony.CoreService

名称说明
UNKNOWN_CARD-1未知类型。
SINGLE_MODE_SIM_CARD10单SIM卡。
SINGLE_MODE_USIM_CARD20单USIM卡。
SINGLE_MODE_RUIM_CARD30单RUIM卡。
DUAL_MODE_CG_CARD40双卡模式C+G。
CT_NATIONAL_ROAMING_CARD41中国电信内部漫游卡。
CU_DUAL_MODE_CARD42中国联通双模卡。
DUAL_MODE_TELECOM_LTE_CARD43双模式电信LTE卡。
DUAL_MODE_UG_CARD50双模式UG卡。
SINGLE_MODE_ISIM_CARD8+60单一ISIM卡类型。

LockType8+

锁类型。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.Telephony.CoreService

名称说明
PIN_LOCK1SIM卡密码锁。
FDN_LOCK2固定拨号锁。

LockState8+

锁状态。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.Telephony.CoreService

名称说明
LOCK_OFF0锁关闭状态
LOCK_ON1锁开启状态

PersoLockType8+

定制锁类型。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.Telephony.CoreService

名称说明
PN_PIN_LOCK0定制网络PIN锁(参照 3GPP TS 22.022 [33])。
PN_PUK_LOCK1定制网络PUk锁。
PU_PIN_LOCK2定制网络子集PIN锁(参照 3GPP TS 22.022 [33])。
PU_PUK_LOCK3定制网络子集PUK锁。
PP_PIN_LOCK4定制服务提供者PIN锁(参照 3GPP TS 22.022 [33])。
PP_PUK_LOCK5定制服务提供者PUK锁。
PC_PIN_LOCK6定制企业PIN锁(参照 3GPP TS 22.022 [33])。
PC_PUK_LOCK7定制企业Puk锁。
SIM_PIN_LOCK8定制SIM的PIN锁(参照 3GPP TS 22.022 [33])。
SIM_PUK_LOCK9定制SIM的PUK锁。

LockStatusResponse7+

锁状态响应。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.Telephony.CoreService

名称类型必填说明
resultnumber当前操作的结果。
remain?: numbernumber剩余次数(可以为空)。

LockInfo8+

锁状态响应。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.Telephony.CoreService

名称类型必填说明
lockTypeLockType锁类型。
passwordstring密码。
stateLockState锁状态。

PersoLockInfo8+

锁状态响应。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.Telephony.CoreService

名称类型必填说明
lockTypePersoLockType定制锁的类型。
passwordstring密码。

IccAccountInfo10+

Icc帐户信息。

系统能力:SystemCapability.Telephony.CoreService

名称类型必填说明
simIdnumberSIM卡ID。
slotIndexnumber卡槽ID。
isEsimboolean标记卡是否是eSim。
isActiveboolean卡是否被激活。
iccIdstringICCID号码。
showNamestringSIM卡显示名称。
showNumberstringSIM卡显示号码。

OperatorConfig8+

运营商配置。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.Telephony.CoreService

名称类型必填说明
fieldstring字段
valuestring

DiallingNumbersInfo8+

拨号号码信息。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.Telephony.CoreService

名称类型必填说明
alphaTagstring标签。
numberstring号码。
recordNumbernumber记录编号。
pin2stringpin2密码。

ContactType8+

联系人类型。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.Telephony.CoreService

名称说明
GENERAL_CONTACT1通用联系人。
FIXED_DIALING2固定拨号。

OperatorConfigKey9+

运营商配置键。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.Telephony.CoreService

名称说明
KEY_VOICE_MAIL_NUMBER_STRING"voice_mail_number_string"语音邮件号码。
KEY_IMS_SWITCH_ON_BY_DEFAULT_BOOL"ims_switch_on_by_default_bool"固定拨号。
KEY_HIDE_IMS_SWITCH_BOOL"hide_ims_switch_bool"是否隐藏ims开关。
KEY_VOLTE_SUPPORTED_BOOL"volte_supported_bool"是否支持volte模式。
KEY_NR_MODE_SUPPORTED_LIST_INT_ARRAY"nr_mode_supported_list_int_array"nr模式支持的列表。
KEY_VOLTE_PROVISIONING_SUPPORTED_BOOL"volte_provisioning_supported_bool"是否支持配置VOLTE。
KEY_SS_OVER_UT_SUPPORTED_BOOL"ss_over_ut_supported_bool"SS服务是否支持UT。
KEY_IMS_GBA_REQUIRED_BOOL"ims_gba_required_bool"IMS是否需要GBA。
KEY_UT_PROVISIONING_SUPPORTED_BOOL"ut_provisioning_supported_bool"是否支持UT配置。
KEY_IMS_PREFER_FOR_EMERGENCY_BOOL"ims_prefer_for_emergency_bool"IMS紧急首选项。
KEY_CALL_WAITING_SERVICE_CLASS_INT"call_waiting_service_class_int"呼叫等待服务。
KEY_CALL_TRANSFER_VISIBILITY_BOOL"call_transfer_visibility_bool"呼叫转移可见性。
KEY_IMS_CALL_DISCONNECT_REASON_INFO_MAPPING_STRING_ARRAY"ims_call_disconnect_reason_info_mapping_string_array"IMS呼叫结束原因列表。
KEY_FORCE_VOLTE_SWITCH_ON_BOOL"force_volte_switch_on_bool"强制VOLTE开关。
KEY_ENABLE_OPERATOR_NAME_CUST_BOOL"enable_operator_name_cust_bool"是否显示运营商名称。
KEY_OPERATOR_NAME_CUST_STRING"operator_name_cust_string"运营商名称。
KEY_SPN_DISPLAY_CONDITION_CUST_INT"spn_display_condition_cust_int"SPN显示规则。
KEY_PNN_CUST_STRING_ARRAY"pnn_cust_string_array"PLMN名称。
KEY_OPL_CUST_STRING_ARRAY"opl_cust_string_array"运营商PLMN信息。
KEY_EMERGENCY_CALL_STRING_ARRAY"emergency_call_string_array"紧急呼叫列表。

你可能感兴趣的鸿蒙文章

harmony 鸿蒙接口

harmony 鸿蒙系统公共事件定义(待停用)

harmony 鸿蒙系统公共事件定义

harmony 鸿蒙开发说明

harmony 鸿蒙企业设备管理概述(仅对系统应用开放)

harmony 鸿蒙BundleStatusCallback

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

harmony 鸿蒙@ohos.distributedBundle (分布式包管理)

harmony 鸿蒙@ohos.bundle (Bundle模块)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (企业设备管理扩展能力)

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