布局:

<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. linux-exp 工具+小技巧

    # 工具篇 # pwntools ,gdb-peda ROPgadget-tool . EDB ## pwntools获取.安装和文档帮助 ## - pwntools: github可以搜索到 htt ...

  2. docker stop 与 docker kill的区别

    docker stop 与 docker kill 均可以将容器停掉,但二者究竟有什么区别呢?首先,摘录一下官网对这两个功能的描述: docker stop: Stop a running conta ...

  3. centos6.5 64bit 实现root开机自动登录X桌面

    vim /etc/gdm/custom.conf 修改daemon节点,添加如下内容: AutomaticLoginEnable=true AutomaticLogin=root 重启计算机. 完.

  4. PHP中关于 basename、dirname、pathinfo 详解

    basename(url)      返回路径中的文件名部分. dirname(url)       返回路径中的目录名称部分. pathinfo(url)      返回关于文件路径的信息. bas ...

  5. Oracle存储过程单步调试方法

    oracle存储过程单步调试的方法 1.在要调试的过程上单击test,如下图所示: 2.出现如下界面时单击最左上方的按钮:,如下图所示: 3.单击后呈现如下画面: 其中: 表示要停止test; 表示要 ...

  6. jquery ui 常用(一)(自动完成 | 标签页 | 折叠面板 | 带图标的按钮 | 日期选择器| )

    条件,引用3个文件 jquery-ui.min.css; jquery.min.js; jquery-ui.min.js. 一.自动完成 http://www.w3cschool.cc/jqueryu ...

  7. C++中new和delete来创建和释放动态数组

    在C++编程中,使用new创建数组然后用delete来释放. 一.创建并释放一维数组 #include<iostream> using namespace std; int main() ...

  8. List null

    List<String> list = new ArrayList<String>(); 不给list add,list也不为null 所以list判断有没有数据,只能用判断l ...

  9. c# 反射列子

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  10. jsp:和属性相关的方法,请求的转发,重定向

    jsp中与属性相关的方法: 方法: void setAttribute(String name, Object o): 设置属性 Object getAttribute(String name):获取 ...