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