Android实现短信发送器功能

1.短信界面

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:orientation="vertical" >
  5. <EditText
  6. android:layout_width="match_parent"
  7. android:layout_height="wrap_content"
  8. android:layout_marginTop="10dp"
  9. android:hint="请输入手机号"
  10. android:inputType="phone" />
  11. <EditText
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. android:layout_marginTop="10dp"
  15. android:hint="请输入短信内容"
  16. android:inputType="text"
  17. android:lines="5" />
  18. <Button
  19. android:layout_width="wrap_content"
  20. android:layout_height="wrap_content"
  21. android:layout_marginTop="10dp"
  22. android:onClick="sendSms"
  23. android:text="发送" />
  24. </LinearLayout>

2.业务逻辑

  1. public void sendSMS(View v) {
  2. // 1.取出手机号
  3. EditText et_input_num = (EditText) findViewById(R.id.et_input_num);
  4. // trim: 过滤用户输入的空格
  5. String num = et_input_num.getText().toString().trim();
  6. // 2. 取出用户输入的短信内容
  7. EditText et_input_content = (EditText) findViewById(R.id.et_input_content);
  8. String content = et_input_content.getText().toString().trim();
  9. // 3. 校验
  10. Pattern pattern = Pattern.compile("^1[3578]\\d{9}$");
  11. Matcher matcher = pattern.matcher(num);
  12. if (matcher.matches()) {
  13. if (content != null && !content.equals("")) {
  14. // 4. 校验成功,发送短信
  15. SmsManager smsManager = SmsManager.getDefault();
  16. smsManager.sendTextMessage(num, null, content, null, null);
  17. } else {
  18. Toast.makeText(this, "请检查输入的内容", Toast.LENGTH_LONG).show();
  19. }
  20. } else {
  21. Toast.makeText(this, "请检查手机号", Toast.LENGTH_LONG).show();
  22. }
  23. }

最后在在AndroidManifest.xml里面添加

<uses-permission android:name="android.permission.SEND_SMS  "/>

来自为知笔记(Wiz)

时间: 2024-08-09 22:01:43

Android实现短信发送器功能的相关文章

Android注册短信验证码功能

一.短信验证的效果是通过使用聚合数据的SDK实现的 ,效果如下: 二.根据前一段时间的博客中输了怎么注册!注册之后找到个人中心找到申请一个应用即可! 三.根据官方文档创建项目 官方文档API下载地址:http://yunpan.cn/cZwc6mum75yYx 访问密码 9f29 (包含了项目jar的导入操作) 四.调用SDK 第一步:创建并配置工程(具体方法参见工程配置部分的介绍): 第二步:在AndroidManifest中添加开发密钥.所需权限等信息: (1)在application中添加

Android(java)学习笔记99:android的短信发送器研究

1.第一种可以调用系统内部的短信程序. 之前我曾经出现过一个bug就是报错: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO dat=Tel:xxx }…… 这是因为我使用intent调用系统编辑短信服务参数没有设置好,后认真核对修改之后,改成如下的样子就没有问题了: 出现这个报错的原因是: 之前我调用Intent启动a

Android开发系列(二):短信发送器的实现

我们要实现的目标是:做一个短信发送器 界面: 因为要涉及到短信发送这种属于隐私的问题,所以我们要在AndroidManifest.xml中添加一行代码,来获得权限: <uses-permission android:name="android.permission.SEND_SMS"/> 然后,我们就要配置main.xml: <?xml version="1.0" encoding="utf-8"?> <Linear

Android实现电话拨号器和短信发送器

电话拨号器和短信发送器是Android初学者很好的练习项目,今天就找了两个写得很不错的例子学习下 电话拨号器 实现原理:用户输入电话号码,当点击拨打的时候,由监听对象捕获,监听对象通过文本控件获取到用户输入的电话号码,由于系统已经实现了电话拨号功能,所以我们只需要调用这个功能就可以了. 步骤: 1.界面布局 2.编写Activity 3.使用意图过滤器激活电话拨号功能 4.添加电话服务权限(用手机的电话服务,要在清单文件AndroidManifest.xml中添加电话服务权限) 如图所示这三个控

无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、短信发送器、Android 中各种布局(1)

1.Android是什么 手机设备的软件栈,包括一个完整的操作系统.中间件.关键的应用程序,底层是linux内核,安全管理.内存管理.进程管理.电源管理.硬件驱动 2.Dalvik VM 和 JVM 的比较 3.常见adb指令 platform-tools/adb.exe adb.exe : android debug bridge android调试桥 adb devices:列出所以连接的设备 adb kill-server :杀死adb调试桥 adb start-server :启动adb

初识安卓小程序(Android短信发送器)

首先,先创建一个安卓项目(我的版本是4.4.2的),名字为"短信发送器" 然后在res文件夹下找到layout文件夹,找到activity_main.xml或fragment_main.xml,在里面输入或拖拽按钮 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tool

Android学习笔记(2)——短信发送器

搬运自本人博客:http://www.xgezhang.com/android_sms.html 上一篇文章中我们学着写了一个电话拨号器,这里我们继续来写一个短信发送器. 同样的按一般app开发的步骤,首先先确定下UI界面,大致效果应该是这样: 那么界面要怎么完成了?这种布局可以采用线性布局来做,比较方便.这里还是采用的相对布局,先上xml文件: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2

Android实现简单短信发送器

布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height=

Android短信发送器

Xml代码: <?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/widget0" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.an