布局:

<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实现简单短信发送器的更多相关文章

  1. Android入门之简单短信发送器

    效果图: manifest.xml 文件中加入  <uses-permission android:name="android.permission.SEND_SMS"/&g ...

  2. Android学习4—短信发送器的实现

    界面预览: 由图中可以看出,此APP需要的组件有:两个TextView,一个用于显示手机号码的标题,另一个用于显示短信内容的标题.                                    ...

  3. Android实战--短信发送器

    首先设计界面 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...

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

    1.Android是什么 手机设备的软件栈,包括一个完整的操作系统.中间件.关键的应用程序,底层是linux内核,安全管理.内存管理.进程管理.电源管理.硬件驱动 2.Dalvik VM 和 JVM ...

  5. android开发学习---开发一个简易的短信发送器

    一.需求: 开发一个简易的短信发送器,输入:对方手机号码,短信内容,点击发送按钮,短信发送成功,对方手机成功收到短信. 其中要求短信内容过长时可以自动拆分,长度英文是160个英文,中文是70个,中英混 ...

  6. Android短信发送器_08

    1.string xml代码 <?xml version="1.0" encoding="utf-8"?> <resources> &l ...

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

    首先,先创建一个安卓项目(我的版本号是4.4.2的),名字为"短信发送器" 然后在res目录下找到layout目录,找到activity_main.xml或fragment_mai ...

  8. Android短信发送器(2)

    在上一篇的<Android短信发送器>当中.发送功能并不完好.当发送内容超过限定字数时,短信就会发送失败,此时就须要推断内容是否超过限制,假设不超过限制.就直接发送,反之.则对其进行处理再 ...

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

    1.第一种可以调用系统内部的短信程序. 之前我曾经出现过一个bug就是报错: android.content.ActivityNotFoundException: No Activity found ...

随机推荐

  1. 给文件加ip访问限制

    获取IP: function getIP(){ return isset($_SERVER['HTTP_X_FORWARDED_FOR'])? $_SERVER['HTTP_X_FORWARDED_F ...

  2. JS和CSS的多浏览器兼容(3)

    3.Javascript的浏览器兼容性问题 3.1 集合类对象问题说明:IE下,可以使用()或[]获取集合类对象; Safari及Chrome下,只能使用[]获取集合类对象. 解决方法:统一使用[]获 ...

  3. fedora 20 yum出错

    需要利用linux做项目,所以在win10装了vmvare 以及 fedora,据说这个linux比较稳定.. 1.系统装好以后,需要先把terminal调处理,这才符合程序猿的习惯嘛,具体方法如下 ...

  4. “wsimport -keep ”生成客户端报错“Use of SOAP Encoding is not supported.”

    本来想用 “wsimport -keep ” 生成客户端,结果报错“Use of SOAP Encoding is not supported.” 应该是缺jar包, 闲麻烦就发现了百度经验上的 这个 ...

  5. Linux hrtimer分析(一)

    http://blog.csdn.net/angle_birds/article/details/17375883 本文分析了Linux2.6.29中hrtimer的实现. Linux2.6中实现了一 ...

  6. css不同浏览器兼容性调试 --- 转自: [http://wo.115.com/?ct=detail&id=31733&bid=1018841]

    css不同浏览器兼容性调试 IE6.0,IE7.0与Firefox的CSS兼容性问题1.DOCTYPE 影响 CSS 处理 2.FF: div 设置 margin-left, margin-right ...

  7. JQuery知识快览之一—选择器

    阅读指导:本文参考最新的1.10.2版写成,针对用得比较多的1.4版,所有1.5版之后的函数都会注明哪一版新增.对于熟悉1.4版想学1.10版的请直接搜索"新增". JQuery是 ...

  8. Currency Exchange 分类: POJ 2015-07-14 16:20 10人阅读 评论(0) 收藏

    Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22180 Accepted: 8015 De ...

  9. eclipse alt+/ 无效时,如何设置 《转》

    一般情况下alt+/有代码提示作用,还有代码提示的快捷代码也不是alt+/,因此要恢复代码提示用alt+/.需要做两件事. 在 Window - Preferences - General - Key ...

  10. WPF中父子窗口的层次关系

    关于子窗体的层级关系总结一下哈,希望能对大家有些帮助 假设有这样两个窗体:RootWindow,SubWindow,在RootWindow中引发某事件而显示SubWindow 1,如果弹出窗体(比如S ...