效果图:

manifest.xml 文件中加入  <uses-permission android:name="android.permission.SEND_SMS"/>

<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">sms</string>
<string name="action_settings">Settings</string>
<string name="number">请输入手机号</string>
<string name="content">请输入文本</string>
<string name="button">发送</string>
<string name="success">短信发送成功!</string>
</resources>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/number" /> <EditText
android:id="@+id/numberText"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/content" /> <EditText
android:id="@+id/contentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minLines="3" /> <Button
android:id="@+id/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button" /> </LinearLayout>
package jk.sms;

import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.Menu;
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 Activity { private EditText NumberText;
private EditText ContentText; protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NumberText = (EditText) this.findViewById(R.id.numberText);
ContentText = (EditText) this.findViewById(R.id.contentText);
Button button = (Button) this.findViewById(R.id.Button);
button.setOnClickListener(new ButtonClickListener());
}
@SuppressLint("ShowToast")
private final class ButtonClickListener implements OnClickListener { public void onClick(View v) {
String number = NumberText.getText().toString();
String content = ContentText.getText().toString();
SmsManager manager = SmsManager.getDefault();
ArrayList<String> texts = manager.divideMessage(content); //超过规定长度后短信拆分
for (int i = 0; i < texts.size(); i++) {
manager.sendTextMessage(number, null, content, null, null);
}
Toast.makeText(MainActivity.this, R.string.success,
Toast.LENGTH_LONG);
}
} public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }

Android入门之简单短信发送器的更多相关文章

  1. Android实现简单短信发送器

    布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:to ...

  2. Android简易实战教程--第四话《最简单的短信发送器》

    首先配置一个布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...

  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模拟器打电话发短信的简单方法

    在开发android应用程序时,有时候需要测试一下向android手机拨打电话发送短信时该应用程序的反应.譬如编写一个广播接收器,来提示用户有短信收到或者处理短信,就需要向该手机发送短信来进行测试.这 ...

随机推荐

  1. Web用户控件

    用户控件是个什么东西?自定义的反复重用的控件集合 注意:创建好用户控件后,必须添加到其他web页中才能显示出来,不能直接作为一个网页来显示,因此也就不能设置用户控件为“起始页”. 用户控件与ASP.N ...

  2. JQuery - MD5加密

    效果: JS代码: 命名为任意名称,一般为:Jquery.md5.js /** * jQuery MD5 hash algorithm function * * <code> * Calc ...

  3. 用SignalR做类似QQ登录的应用

    原文:用SignalR做类似QQ登录的应用 首先通过NuGet下载signalr包 在工程下新建一个类,继承Hub public class DemoHub:Hub { public class Us ...

  4. SDUTOJ 1489 求二叉树的先序遍历

    <img src="http://img.blog.csdn.net/20141014212549703?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi ...

  5. badi增强

    对于根据事务代码查找对应的BADI,网上介绍的方法很多,但总结下来无非就两种方法,在此把它记录下来,方便以后自己查阅了. (1)通过SE24,输入CL_EXITHANDLER,然后在方法GET_INS ...

  6. CodeForces 371C Hamburgers

    B题又耽误时间了...人太挫了.... C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes i ...

  7. USM锐化之openCV实现,附赠调整对比度函数

    源地址:http://www.cnblogs.com/easymind223/archive/2012/07/03/2575277.html 常用Photoshop的玩家都知道Unsharp Mask ...

  8. Js实现select联动,option从数据库中读取

    待要实现的功能:页面有两个select下拉列表,从第一个select中选择后,在第二个select中出现对应的列表选择,再从第二个select中选择后,在一个text中显示对应的信息.两个select ...

  9. C# Http以文件的形式上传文件

    以下的是上传的方法: // <summary> /// 将本地文件上传到指定的服务器(HttpWebRequest方法) /// </summary> /// <para ...

  10. Android显示GIF图片

    今天我们研究一下怎样在Android手机上显示GIF动态图片 首先须要在src文件夹下新建一个自己定义的View.代码例如以下: </pre><pre name="code ...