• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.telephony.esim (eSIM Management)
2
3The **esim** module provides basic eSIM management capabilities, including checking whether a specified card slot supports the eSIM function.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 18. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9
10## Modules to Import
11
12```ts
13import { eSIM } from '@kit.TelephonyKit';
14```
15
16## eSIM.isSupported<sup>18+</sup>
17
18isSupported\(slotId: number\): boolean
19
20Checks whether the specified card slot supports the eSIM function.
21
22**System capability**: SystemCapability.Telephony.CoreService.Esim
23
24**Parameters**
25
26| Name| Type  | Mandatory| Description                                  |
27| ------ | ------ | ---- | -------------------------------------- |
28| slotId | number | Yes  | Card slot ID. <br>- **0**: card slot 1.<br>- **1**: card slot 2|
29
30**Returns**
31
32| Type                 | Description                              |
33| --------------------- | ---------------------------------- |
34| boolean | A boolean value indicating whether the specified card slot supports the eSIM function. The value **true** indicates that the card slot supports the eSIM function, and the value **false** indicates the opposite.|
35
36**Error codes**
37
38For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
39
40| ID             | Error Message                          |
41| --------------------- | ---------------------------------- |
42| 401 | Invalid parameter value.     |
43|3120001| Service connection failed. |
44|3120002| System internal error.     |
45
46**Example**
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
59Launches the download page for the user to add a single profile. This API uses a promise to return the result.
60
61**Required permissions**: ohos.permission.SET_TELEPHONY_ESIM_STATE_OPEN
62
63**System capability**: SystemCapability.Telephony.CoreService.Esim
64
65**Parameters**
66
67| Name| Type  | Mandatory| Description                                  |
68| ------ | ------ | ---- | -------------------------------------- |
69| profile | DownloadableProfile | Yes  | Profile that can be downloaded.|
70
71**Returns**
72
73| Type                 | Description                              |
74| --------------------- | ---------------------------------- |
75| Promise\<boolean\> | Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.|
76
77**Error codes**
78
79For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
80
81| ID             | Error Message                          |
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**Example**
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```
112
113## DownloadableProfile<sup>18+</sup>
114
115Defines a downloadable profile.
116
117**System capability**: SystemCapability.Telephony.CoreService.Esim
118
119| Name| Type| Mandatory| Description|
120| ----- | ----- | ----- | -----|
121| activationCode   | string             |  Yes | Activation code. For a profile that does not require an activation code, the value may be left empty.|
122| confirmationCode | string             |  No | Confirmation code.     |
123| carrierName      | string             |  No | Carrier name.   |
124| accessRules      | Array\<AccessRule> |  No | Access rule array.|
125