1# @ohos.telephony.esim (eSIM卡管理) 2 3eSIM卡管理模块提供了eSIM卡管理的基础能力,包括获取指定卡槽是否支持eSIM功能,如果支持则允许用户添加单个配置文件。 4 5> **说明:** 6> 7> 本模块首批接口从API version 18开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9 10## 导入模块 11 12```ts 13import { eSIM } from '@kit.TelephonyKit'; 14``` 15 16## eSIM.isSupported<sup>18+</sup> 17 18isSupported\(slotId: number\): boolean 19 20获取指定卡槽是否支持eSIM功能。 21 22**系统能力**:SystemCapability.Telephony.CoreService.Esim 23 24**参数:** 25 26| 参数名 | 类型 | 必填 | 说明 | 27| ------ | ------ | ---- | -------------------------------------- | 28| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1。<br/>- 1:卡槽2。 | 29 30**返回值:** 31 32| 类型 | 说明 | 33| --------------------- | ---------------------------------- | 34| boolean | 返回指定卡槽是否支持eSIM功能,如果支持返回true。 | 35 36**错误码:** 37 38以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。 39 40| 错误码ID | 错误信息 | 41| --------------------- | ---------------------------------- | 42| 401 | Invalid parameter value. | 43|3120001| Service connection failed. | 44|3120002| System internal error. | 45 46**示例:** 47 48```ts 49import { eSIM } from '@kit.TelephonyKit'; 50 51let isSupported: boolean = eSIM.isSupported(0); 52console.log(`the esim is Supported:` + isSupported); 53``` 54 55## eSIM.addProfile<sup>18+</sup> 56 57addProfile\(profile: DownloadableProfile\): Promise\<boolean\> 58 59通过该接口拉起下载界面,允许用户添加单个配置文件。使用Promise异步回调。 60 61**需要权限**:ohos.permission.SET_TELEPHONY_ESIM_STATE_OPEN 62 63**系统能力**:SystemCapability.Telephony.CoreService.Esim 64 65**参数:** 66 67| 参数名 | 类型 | 必填 | 说明 | 68| ------ | ------ | ---- | -------------------------------------- | 69| profile | DownloadableProfile | 是 | 可下载的配置文件信息。 | 70 71**返回值:** 72 73| 类型 | 说明 | 74| --------------------- | ---------------------------------- | 75| Promise\<boolean\> | 以Promise形式返回最终用户添加单个配置文件的结果。返回true为成功,false为失败。 | 76 77**错误码:** 78 79以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。 80 81| 错误码ID | 错误信息 | 82| --------------------- | ---------------------------------- | 83| 201 | Permission denied. | 84| 401 | Invalid parameter value. | 85| 801 | Capability not supported. | 86|3120001| Service connection failed. | 87|3120002| System internal error. | 88 89**示例:** 90 91```ts 92import { BusinessError } from '@kit.BasicServicesKit'; 93import { eSIM } from '@kit.TelephonyKit'; 94 95let profile: eSIM.DownloadableProfile = { 96 activationCode:'1', 97 confirmationCode:'1', 98 carrierName:'test', 99 accessRules:[{ 100 certificateHashHexStr:'test', 101 packageName:'com.example.testcoreservice', 102 accessType:0 103 }] 104}; 105 106eSIM.addProfile(profile).then(() => { 107 console.log(`addProfile invoking succeeded.`); 108}).catch((err: BusinessError) => { 109 console.error(`addProfile, promise: err->${JSON.stringify(err)}`); 110}); 111```