• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SIM卡管理
2
3### 介绍
4
5本示例使用[sim](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-telephony-kit/js-apis-sim.md)相关接口,展示了电话服务中SIM卡相关功能,包含SIM卡的服务提供商、ISO国家码、归属PLMN号信息,以及默认语音卡功能。
6
7### 效果预览
8
9|主页|
10|--------------------------------|
11|![](screenshots/devices/main.png)|
12
13使用说明:
14
151.若SIM卡槽1插入SIM卡则SIM卡1区域显示为蓝色,否则默认为白色。
16
172.点击SIM卡1区域,弹窗显示SIM卡1的相关信息,再次点击面板消失。
18
193.默认拨号的SIM卡其按钮背景色为蓝色,目前只展示默认拨号的SIM卡,更改默认拨号卡功能暂不支持。
20
214.呼叫转移界面功能暂不支持,故点击按钮无实际操作。
22
23### 工程目录
24```
25entry/src/main/ets/
26|---common
27|   |---CallView.ets                    // 呼叫
28|   |---InfoView.ets                    // 信息
29|   |---Show.ets                        // 展示
30|   |---ShowView.ets                    // 展示页面
31|   |---SimView.ets                     // sim页面
32|---entryability
33|   |---EntryAbility.ts
34|---model
35|   |---AbilityContextController.ts     // 弹窗
36|   |---Logger.ts                       // 日志工具
37|---pages
38|   |---Index.ets                       // 首页
39```
40### 具体实现
41
42* 该示例主要通过hasSimCard方法获取指定卡槽SIM卡是否插卡,getSimState方法获取指定卡槽的SIM卡状态,SimState方法判断SIM卡状态,isSimActive方法获取指定卡槽SIM卡是否激活,getSimSpn方法获取指定卡槽SIM卡的服务提供商名称,getISOCountryCodeForSim方法获取指定卡槽SIM卡的ISO国家码,getSimOperatorNumeric方法获取指定卡槽SIM卡的归属PLMN号,getDefaultVoiceSlotId方法获取默认语音业务的卡槽ID等开发电话服务的相关功能。
43* 源码链接:[InfoView.ets](entry/src/main/ets/common/InfoView.ets),[ShowView.ets](entry/src/main/ets/common/ShowView.ets),[SimView.ets](entry/src/main/ets/common/SimView.ets)
44* 接口参考:[@ohos.telephony.sim](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-telephony-kit/js-apis-sim.md)
45
46### 相关权限
47
48电话权限:[ohos.permission.GET_TELEPHONY_STATE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_telephony_state)
49
50### 依赖
51
52不涉及。
53
54### 约束与限制
55
561.本示例暂不支持双卡功能,且需要插入SIM卡,目前该功能仅支持部分机型。
57
582.本示例仅支持在标准系统上运行。
59
603.本示例已适配API version 9版本SDK,版本号:3.2.11.9。
61
624.本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400, built on April 7, 2023)及以上版本才可编译运行。
63
645.本示例所配置的权限ohos.permission.GET_TELEPHONY_STATE为system_basic级别(相关权限级别可通过[权限定义列表](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md)查看),需要手动配置对应级别的权限签名(具体操作可查看[自动化签名方案](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/hapsigntool-overview.md)65
66### 下载
67
68如需单独下载本工程,执行如下命令:
69```
70git init
71git config core.sparsecheckout true
72echo code/BasicFeature/Telephony/SimManager/ > .git/info/sparse-checkout
73git remote add origin https://gitee.com/openharmony/applications_app_samples.git
74git pull origin master
75
76```