SIM卡管理

2024-01-23 16:38 更新

SIM卡管理模塊提供了SIM卡管理的基礎(chǔ)能力,包括獲取指定卡槽SIM卡的名稱、號碼、ISO國家碼、歸屬PLMN號、服務(wù)提供商名稱、SIM卡狀態(tài)、卡類型、是否插卡、是否激活、鎖狀態(tài),設(shè)置指定卡槽SIM卡顯示的名稱、號碼、鎖狀態(tài),激活、禁用指定卡槽SIM卡,更改Pin密碼,以及解鎖指定卡槽SIM卡密碼、SIM卡密碼的解鎖密碼等。

說明

本模塊首批接口從API version 6開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。

導(dǎo)入模塊

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

sim.isSimActive7+

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

獲取指定卡槽SIM卡是否激活。使用callback異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

callback

AsyncCallback<boolean>

回調(diào)函數(shù)。

示例:

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

sim.isSimActive7+

isSimActive(slotId: number): Promise<boolean>

獲取指定卡槽SIM卡是否激活。使用Promise異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

返回值:

類型

說明

Promise<boolean>

以Promise形式返回指定卡槽是否激活,如果激活返回true。

示例:

  1. let promise = sim.isSimActive(0);
  2. promise.then(data => {
  3. console.log(`isSimActive success, promise: data->${JSON.stringify(data)}`);
  4. }).catch(err => {
  5. console.log(`isSimActive failed, promise: err->${JSON.stringify(err)}`);
  6. });

sim.getDefaultVoiceSlotId7+

getDefaultVoiceSlotId(callback: AsyncCallback<number>): void

獲取默認(rèn)語音業(yè)務(wù)的卡槽ID。使用callback異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

callback

AsyncCallback<number>

回調(diào)函數(shù)。

示例:

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

sim.getDefaultVoiceSlotId7+

getDefaultVoiceSlotId(): Promise<number>

獲取默認(rèn)語音業(yè)務(wù)的卡槽ID。使用Promise異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

返回值:

類型

說明

Promise<number>

以Promise形式返回默認(rèn)語音業(yè)務(wù)的卡槽ID。

示例:

  1. let promise = sim.getDefaultVoiceSlotId();
  2. promise.then(data => {
  3. console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`);
  4. }).catch(err => {
  5. console.log(`getDefaultVoiceSlotId failed, promise: err->${JSON.stringify(err)}`);
  6. });

sim.hasOperatorPrivileges7+

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

檢查應(yīng)用(調(diào)用者)是否已被授予運(yùn)營商權(quán)限。使用callback異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

callback

AsyncCallback<boolean>

回調(diào)函數(shù)。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

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

sim.hasOperatorPrivileges7+

hasOperatorPrivileges(slotId: number): Promise<boolean>

檢查應(yīng)用(調(diào)用者)是否已被授予運(yùn)營商權(quán)限。使用Promise異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

返回值:

類型

說明

Promise<boolean>

以Promise形式返回檢查應(yīng)用(調(diào)用者)是否已被授予運(yùn)營商權(quán)限。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

  1. let promise = sim.hasOperatorPrivileges(0);
  2. promise.then(data => {
  3. console.log(`hasOperatorPrivileges success, promise: data->${JSON.stringify(data)}`);
  4. }).catch(err => {
  5. console.log(`hasOperatorPrivileges failed, promise: err->${JSON.stringify(err)}`);
  6. });

sim.getISOCountryCodeForSim

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

獲取指定卡槽SIM卡的ISO國家碼。使用callback異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

callback

AsyncCallback<string>

回調(diào)函數(shù)。返回國家碼,例如:CN(中國)。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

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

sim.getISOCountryCodeForSim

getISOCountryCodeForSim(slotId: number): Promise<string>

獲取指定卡槽SIM卡的ISO國家碼。使用Promise異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

返回值:

類型

說明

Promise<string>

以Promise形式返回獲取指定卡槽SIM卡的ISO國家碼,例如:CN(中國)。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

  1. let promise = sim.getISOCountryCodeForSim(0);
  2. promise.then(data => {
  3. console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`);
  4. }).catch(err => {
  5. console.log(`getISOCountryCodeForSim failed, promise: err->${JSON.stringify(err)}`);
  6. });

sim.getSimOperatorNumeric

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

獲取指定卡槽SIM卡的歸屬PLMN(Public Land Mobile Network)號。使用callback異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

callback

AsyncCallback<string>

回調(diào)函數(shù)。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

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

sim.getSimOperatorNumeric

getSimOperatorNumeric(slotId: number): Promise<string>

獲取指定卡槽SIM卡的歸屬PLMN(Public Land Mobile Network)號。使用Promise異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

返回值:

類型

說明

Promise<string>

以Promise形式返回獲取指定卡槽SIM卡的歸屬PLMN號。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

  1. let promise = sim.getSimOperatorNumeric(0);
  2. promise.then(data => {
  3. console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`);
  4. }).catch(err => {
  5. console.log(`getSimOperatorNumeric failed, promise: err->${JSON.stringify(err)}`);
  6. });

sim.getSimSpn

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

獲取指定卡槽SIM卡的服務(wù)提供商名稱(Service Provider Name,SPN)。使用callback異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

callback

AsyncCallback<string>

回調(diào)函數(shù)。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

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

sim.getSimSpn

getSimSpn(slotId: number): Promise<string>

獲取指定卡槽SIM卡的服務(wù)提供商名稱(Service Provider Name,SPN)。使用Promise異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

返回值:

類型

說明

Promise<string>

以Promise形式返回獲取指定卡槽SIM卡的SPN。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

  1. let promise = sim.getSimSpn(0);
  2. promise.then(data => {
  3. console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`);
  4. }).catch(err => {
  5. console.log(`getSimSpn failed, promise: err->${JSON.stringify(err)}`);
  6. });

sim.getSimState

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

獲取指定卡槽的SIM卡狀態(tài)。使用callback異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

callback

AsyncCallback<SimState>

回調(diào)函數(shù)。參考SimState。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

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

sim.getSimState

getSimState(slotId: number): Promise<SimState>

獲取指定卡槽的SIM卡狀態(tài)。使用Promise異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

返回值:

類型

說明

Promise<SimState>

以Promise形式返回獲取指定卡槽的SIM卡狀態(tài)。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

  1. let promise = sim.getSimState(0);
  2. promise.then(data => {
  3. console.log(`getSimState success, promise: data->${JSON.stringify(data)}`);
  4. }).catch(err => {
  5. console.log(`getSimState failed, promise: err->${JSON.stringify(err)}`);
  6. });

sim.getCardType7+

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

獲取指定卡槽SIM卡的卡類型。使用callback異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

callback

AsyncCallback<CardType>

回調(diào)函數(shù)。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

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

sim.getCardType7+

getCardType(slotId: number): Promise<CardType>

獲取指定卡槽SIM卡的卡類型。使用Promise異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

返回值:

類型

說明

Promise<CardType>

以Promise形式返回指定卡槽SIM卡的卡類型。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

  1. let promise = sim.getCardType(0);
  2. promise.then(data => {
  3. console.log(`getCardType success, promise: data->${JSON.stringify(data)}`);
  4. }).catch(err => {
  5. console.log(`getCardType failed, promise: err->${JSON.stringify(err)}`);
  6. });

sim.hasSimCard7+

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

獲取指定卡槽SIM卡是否插卡。使用callback異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

callback

AsyncCallback<boolean>

回調(diào)函數(shù)。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

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

sim.hasSimCard7+

hasSimCard(slotId: number): Promise<boolean>

獲取指定卡槽SIM卡是否插卡。使用Promise異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

返回值:

類型

說明

Promise<boolean>

以Promise形式返回指定卡槽是否插卡,如果插卡返回true。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

  1. let promise = sim.hasSimCard(0);
  2. promise.then(data => {
  3. console.log(`hasSimCard success, promise: data->${JSON.stringify(data)}`);
  4. }).catch(err => {
  5. console.log(`hasSimCard failed, promise: err->${JSON.stringify(err)}`);
  6. });

sim.getMaxSimCount7+

getMaxSimCount(): number

獲取卡槽數(shù)量。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

返回值:

類型

說明

number

卡槽數(shù)量。

示例:

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

sim.getOpKey9+

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

獲取指定卡槽中SIM卡的opkey。使用callback異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

callback

AsyncCallback<string>

回調(diào)函數(shù)。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

801

Capability not supported.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

  1. try {
  2. sim.getOpKey(0, (err, data) => {
  3. if (err) {
  4. console.log("getOpKey failed, err: " + JSON.stringify(err));
  5. } else {
  6. console.log('getOpKey successfully, data: ' + JSON.stringify(data));
  7. }
  8. });
  9. } catch (err) {
  10. console.log("getOpKey err: " + JSON.stringify(err));
  11. }

sim.getOpKey9+

getOpKey(slotId: number): Promise<string>

獲取指定卡槽中SIM卡的opkey。使用Promise異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

返回值:

類型

說明

Promise<string>

以Promise形式返回指定卡槽中SIM卡的opkey。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

801

Capability not supported.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

  1. try {
  2. let data = sim.getOpKey(0);
  3. console.log(`getOpKey success, promise: data->${JSON.stringify(data)}`);
  4. } catch (error) {
  5. console.log(`getOpKey failed, promise: err->${JSON.stringify(error)}`);
  6. }

sim.getOpName9+

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

獲取指定卡槽中SIM卡的OpName。使用callback異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

callback

AsyncCallback<string>

回調(diào)函數(shù)。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

801

Capability not supported.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

  1. try {
  2. sim.getOpName(0, (err, data) => {
  3. if (err) {
  4. console.log("getOpName failed, err: " + JSON.stringify(err));
  5. } else {
  6. console.log('getOpName successfully, data: ' + JSON.stringify(data));
  7. }
  8. });
  9. } catch (err) {
  10. console.log("getOpName err: " + JSON.stringify(err));
  11. }

sim.getOpName9+

getOpName(slotId: number): Promise<string>

獲取指定卡槽中SIM卡的OpName。使用Promise異步回調(diào)。

系統(tǒng)能力:SystemCapability.Telephony.CoreService

參數(shù):

參數(shù)名

類型

必填

說明

slotId

number

卡槽ID。

- 0:卡槽1

- 1:卡槽2

返回值:

類型

說明

Promise<string>

以Promise形式返回指定卡槽中SIM卡的OpName。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請參見ohos.telephony(電話子系統(tǒng))錯(cuò)誤碼錯(cuò)誤碼。

錯(cuò)誤碼ID

錯(cuò)誤信息

401

Parameter error.

801

Capability not supported.

8300001

Invalid parameter value.

8300002

Operation failed. Cannot connect to service.

8300003

System internal error.

8300004

Do not have sim card.

8300999

Unknown error code.

示例:

  1. try {
  2. let data = sim.getOpName(0);
  3. console.log(`getOpName success, promise: data->${JSON.stringify(data)}`);
  4. } catch (error) {
  5. console.log(`getOpName failed, promise: err->${JSON.stringify(error)}`);
  6. }

SimState

SIM卡狀態(tài)。

系統(tǒng)能力:以下各項(xiàng)對應(yīng)的系統(tǒng)能力均為SystemCapability.Telephony.CoreService。

名稱

說明

SIM_STATE_UNKNOWN

0

SIM卡狀態(tài)未知,即無法獲取準(zhǔn)確的狀態(tài)。

SIM_STATE_NOT_PRESENT

1

表示SIM卡處于not present狀態(tài),即卡槽中沒有插入SIM卡。

SIM_STATE_LOCKED

2

表示SIM卡處于locked狀態(tài),即SIM卡被PIN、PUK或網(wǎng)絡(luò)鎖鎖定。

SIM_STATE_NOT_READY

3

表示SIM卡處于not ready狀態(tài),即SIM卡在位但無法正常工作。

SIM_STATE_READY

4

表示SIM卡處于ready狀態(tài),即SIM卡在位且工作正常。

SIM_STATE_LOADED

5

表示SIM卡處于loaded狀態(tài),即SIM卡在位且所有卡文件加載完畢。

CardType7+

卡類型。

系統(tǒng)能力:以下各項(xiàng)對應(yīng)的系統(tǒng)能力均為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

中國電信內(nèi)部漫游卡。

CU_DUAL_MODE_CARD

42

中國聯(lián)通雙???。

DUAL_MODE_TELECOM_LTE_CARD

43

雙模式電信LTE卡。

DUAL_MODE_UG_CARD

50

雙模式UG卡。

SINGLE_MODE_ISIM_CARD8+

60

單一ISIM卡類型。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號