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