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="match_parent"
tools:context="com.example.msgSend.MainActivity"
tools:ignore="MergeRootFrame" > <TextView
android:id="@+id/tv_pleaseInputPhoneNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pleaseInputPhoneNum" /> <EditText
android:id="@+id/et_phoneNum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tv_pleaseInputPhoneNum"
android:layout_marginTop="14dp"
android:ems="10"
android:inputType="phone" /> <TextView
android:id="@+id/et_pleaseInputContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/et_phoneNum"
android:layout_marginTop="16dp"
android:text="@string/pleaseinputcontent" /> <EditText
android:id="@+id/et_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/et_pleaseInputContent"
android:layout_marginTop="26dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:ems="10"
android:lines="5" > </EditText> <Button
android:id="@+id/bt_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/et_content"
android:layout_below="@+id/et_content"
android:layout_marginTop="26dp"
android:text="@string/send" /> </RelativeLayout>
activity代码:
package com.example.msgSend; import java.util.List; import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.telephony.SmsManager;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast; public class MainActivity extends ActionBarActivity implements OnClickListener{ /** 电话号码 */
private EditText etPhoneNum; /** 短信内容 */
private EditText etContent; /** 发送按钮 */
private Button btSend; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //获得组件
etPhoneNum = (EditText)findViewById(R.id.et_phoneNum);
etContent = (EditText)findViewById(R.id.et_content);
btSend = (Button)findViewById(R.id.bt_send);
System.out.println("获取成功"); //注册点击事件
btSend.setOnClickListener(this);
} @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bt_send:
sendMessage();
break;
default:
break;
} }
//实现短信发送
private void sendMessage() {
String phoneNum = etPhoneNum.getText().toString();
String content = etContent.getText().toString(); //吐司提示
if (TextUtils.isEmpty(phoneNum) || TextUtils.isEmpty(content)) {
Toast.makeText(this, "手机号码和短信都不能为空", Toast.LENGTH_LONG).show();
return ;
} SmsManager smsManager = SmsManager.getDefault();
//短信是有长度限制的, 直接对内容进行分割
List<String> contents = smsManager.divideMessage(content);
//发送
for (String content1 : contents) {
smsManager.sendTextMessage(phoneNum, null, content1, null, null);
}
} }
效果:

Android实现简单短信发送器的更多相关文章
- Android入门之简单短信发送器
效果图: manifest.xml 文件中加入 <uses-permission android:name="android.permission.SEND_SMS"/&g ...
- Android学习4—短信发送器的实现
界面预览: 由图中可以看出,此APP需要的组件有:两个TextView,一个用于显示手机号码的标题,另一个用于显示短信内容的标题. ...
- Android实战--短信发送器
首先设计界面 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...
- 无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、短信发送器、Android 中各种布局(1)
1.Android是什么 手机设备的软件栈,包括一个完整的操作系统.中间件.关键的应用程序,底层是linux内核,安全管理.内存管理.进程管理.电源管理.硬件驱动 2.Dalvik VM 和 JVM ...
- android开发学习---开发一个简易的短信发送器
一.需求: 开发一个简易的短信发送器,输入:对方手机号码,短信内容,点击发送按钮,短信发送成功,对方手机成功收到短信. 其中要求短信内容过长时可以自动拆分,长度英文是160个英文,中文是70个,中英混 ...
- Android短信发送器_08
1.string xml代码 <?xml version="1.0" encoding="utf-8"?> <resources> &l ...
- 初识安卓小程序(Android短信发送器)
首先,先创建一个安卓项目(我的版本号是4.4.2的),名字为"短信发送器" 然后在res目录下找到layout目录,找到activity_main.xml或fragment_mai ...
- Android短信发送器(2)
在上一篇的<Android短信发送器>当中.发送功能并不完好.当发送内容超过限定字数时,短信就会发送失败,此时就须要推断内容是否超过限制,假设不超过限制.就直接发送,反之.则对其进行处理再 ...
- Android(java)学习笔记99:android的短信发送器研究
1.第一种可以调用系统内部的短信程序. 之前我曾经出现过一个bug就是报错: android.content.ActivityNotFoundException: No Activity found ...
随机推荐
- Http的常见问题
A: HTTP(超文本传输协议)是一个基于请求与响应模式的.无状态的.应用层的协议. B: 文件传输协议FTP.电子邮件传输协议SMTP.域名系统服务DNS.HTTP协议等都同是应用层协议. C:HT ...
- JQUERY解析XML IE8的兼容问题
var str="xml字符串"; alert($(str).find("Row").attr("Id")); 在IE8下,这段脚本无法运行 ...
- 【jQuery UI 1.8 The User Interface Library for jQuery】.学习笔记.7.Slider控件
默认slider的安装启用 为slider自定义风格 修改配置选项 创建一个垂直的slider 设置最大最小值,和默认值 启用多个 手柄 和 范围 slider内置的回调事件 slider的方法 这个 ...
- anroid 查看签名信息的方法
1.把app改成压缩文件 2.解压以后找到META-INF\CERT.RSA 3.在CMD命令行里面输入: keytool -printcert -file E:\META-INF\CERT.RS ...
- Quick-cocos2d-x v3.3 SocketTCP链接(转)
Quick-Cocos2d-x v3.3里面提供了两种长连接WebSockets.SocketTCP,这里说一下SocketTCP的用法. 1 2 3 local net = require(&quo ...
- 2016年11月2日 星期三 --出埃及记 Exodus 19:18
2016年11月2日 星期三 --出埃及记 Exodus 19:18 Mount Sinai was covered with smoke, because the LORD descended on ...
- 【Java】JDBC连接MySQL
JDBC连接MySQL 虽然在项目中通常用ORM的框架实现持久化.但经常因测试某些技术的需要,要写一个完整的JDBC查询数据库.写一个在这儿备份. 首先引入驱动包: <dependencies& ...
- 关于python的__name__理解
Python中,每个模块有个__name__属性,当模块是在自己文件下执行的,那么它的__name__属性是__main__,而当它被引入到别的模块中,那么在别的模块下(import模块名 可以引入一 ...
- Duilib中Webbrowser事件完善使其支持判断页面加载完毕
在多iframe的页面中,需要结合DISPID_DOCUMENTCOMPLETE和DISPID_NAVIGATECOMPLETE2两个事件判断页面是否加载完毕,而duilib中没有提供对DISPID_ ...
- SD卡驱动分析(一)
Android下的SD卡驱动与标准LINUX下的SD卡驱动好像没有太大的区别,这里就以高通的ANDROID 2.3以代表,来简要分析一下LINUX下SD卡驱动的写法.由于小弟的技术有限,分析的有错的地 ...