• Home
Name Date Size #Lines LOC

..--

AppScope/06-May-2025-3633

entry/06-May-2025-1,9121,735

hvigor/06-May-2025-2422

screenshots/device/06-May-2025-

.gitignoreD06-May-2025143 1211

README.mdD06-May-20251.1 KiB2413

README_zh.mdD06-May-20254.2 KiB7156

build-profile.json5D06-May-20251,019 4240

hvigorfile.tsD06-May-2025158 21

hvigorwD06-May-20252 KiB6228

hvigorw.batD06-May-20252 KiB7356

oh-package.json5D06-May-2025812 2625

ohosTest.mdD06-May-20251.1 KiB1412

README.md

1# SMS
2
3### Introduction
4
5This sample shows how to send SMS messages.
6
7### Usage
8
91. On the home page, click **Create Contact**. In the displayed dialog box, enter the contact name and phone number, and click **OK**. The contact is added to the contact list.
10
112. Click **Manage**. The button changes to **Cancel**, and the **x** sign is displayed on the contact list. Click the **x** sign if you want to delete a contact. Click **Cancel** if you want to quit, and the button changes back to **Manage**.
12
133. The **Send Message** icon is displayed on the right of each contact in the contact list. Click the icon to go to the page for sending SMS messages.
14
154. On the page for sending SMS messages, enter a message and click **Send** to send it.
16
17Note:
18- SMS messages can be successfully sent only when the required permission is granted and a SIM card is inserted. They are sent from the default SIM card.
19- Preset SMS messages are provided. Storage function is not available, and application data will be cleared each time you exit.
20
21### Constraints
22
23This sample can only be run on standard-system devices.
24

README_zh.md

1# 短信服务
2
3### 介绍
4
5本示例使用[@ohos.telephony.sms](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta5/zh-cn/application-dev/reference/apis/js-apis-sms.md) 接口展示了电话服务中发送短信的功能。
6
7### 效果预览
8|新建联系人|首页|短信页|
9|-------------|-----------|------------|
10|![](screenshots/device/create_contact.png)| ![](screenshots/device/save_contact.png)| ![](screenshots/device/send_message.png)|
11
12使用说明:
13
141. 首页点击**创建联系人**,弹框输入联系人姓名和电话,点击确定按钮后,联系人列表中添加该联系人;
152. 点击**管理**,该按钮变成**取消**,联系人列表出现删除x按钮,点击x按钮可删除联系人,点击**取消**,按钮变成**管理**;
163. 联系人列表中每个联系人右侧有**发送短信**图标按钮,点击该图标按钮跳转到发送短信页面;
174. 发送短信页面,输入短信点击向上箭头的**发送**按钮,可以发送短信;
185. 需授予短信发送权限且插入SIM卡才可成功发送短信,有预置短信内容,每次退出应用数据会清空,未添加存储功能,发送短信为默认卡发送。
19
20### 工程目录
21```
22entry/src/main/ets/
23|---pages
24|   |---Index.ets                           // 首页
25|   |---SendMessage.ets                     / 发送短信页
26|---common
27|   |---AddDialog.ets                       // 添加联系人
28|   |---TitleBar.ets                        // title
29|---model
30|   |---Contact.ets                         // 联系人数据结构
31|   |---DataSources.ets                     // 懒加载数据
32|   |---DataTimeUtil.ets                    // 日期工具
33|   |---Logger.ts                           // 日志工具
34|   |---Message.ets                         // 短信数据结构
35|   |---PermissionUtils.ets                 // 权限信息
36|   |---SmsModel.ets                        // 封装短信类
37```
38
39### 具体实现
40+ 发送短信功能在SmsModel中,源码参考 [SmsModel.ets](entry/src/main/ets/model/SmsModel.ets) :
41    + 发送短信:发送短信首先需要使用createMessage方法创建短信实例,然后获取基本参数,getDefaultSmsSlotId可以获取发短信默认卡槽id,getSmscAddr获取短信发送地址,然后调用sms.sendMessage方法发送短信。
42
43### 相关权限
44
45[ohos.permission.SEND_MESSAGES](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionsend_messages)
46
47[ohos.permission.SET_TELEPHONY_STATE](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionset_telephony_state)
48
49### 依赖
50
51不涉及。
52
53### 约束与限制
54
551. 本示例仅支持在标准系统上运行;
562. 本示例需要插入SIM卡,目前该功能仅支持部分机型;
573. 本示例已适配API version 9版本SDK,版本号:3.2.11.9;
584. 本示例涉及使用系统接口:getSmscAddr(),需要手动替换Full SDK 才能编译通过,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/faqs/full-sdk-switch-guide.md/);
595. 本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400, built on April 7, 2023)及以上版本才可编译运行;
606. 本示例所配置的权限ohos.permission.SEND_MESSAGESohos.permission.SET_TELEPHONY_STATEohos.permission.GET_TELEPHONY_STATE为system_basic级别(相关权限级别可通过[权限定义列表](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md) 查看),需要手动配置对应级别的权限签名(具体操作可查看[自动化签名方案](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/hapsigntool-overview.md/);
617. 本示例为预置应用,无需用户授权弹窗,授权方式为预置授权。
62
63### 下载
64如需单独下载本工程,执行如下命令:
65```
66git init
67git config core.sparsecheckout true
68echo code/SystemFeature/Telephony/Message > .git/info/sparse-checkout
69git remote add origin https://gitee.com/openharmony/applications_app_samples.git
70git pull origin master
71```