界面布局:

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" > <TextView
android:id="@+id/phonenumber_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/phonenumber" /> <EditText
android:id="@+id/phonenumber_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/phonenumber_text"
android:inputType="phone" >
</EditText> <TextView
android:id="@+id/phonenumber_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/phonenumber_edit"
android:text="@string/phonenumber" /> <EditText
android:id="@+id/message_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/phonenumber_text2"
android:lines="5" /> <Button
android:id="@+id/call_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/message_edit"
android:onClick="callphone"
android:text="call" /> </RelativeLayout>

java代码:

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
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; import java.util.ArrayList; public class SendMessage extends Activity implements OnClickListener { private EditText phonenumber_edit;
private EditText content_eidt;
private Button Send_button;
private String content ;
private String phoneNumber; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
}
/**
*
* @Title: initViews
* @Description: TODO(初始化布局文件)
* @param 设定文件
* @return void 返回类型
* @throws
*/
private void initViews() {
phonenumber_edit = (EditText)findViewById(R.id.phonenumber_edit);
content_eidt = (EditText)findViewById(R.id.message_edit);
Send_button = (Button)findViewById(R.id.call_button);
Send_button.setOnClickListener(this);
}
/**
*
* @Name onClick
* @Description TODO(按钮单击事件处理)
* @param v
* @see android.view.View.OnClickListener#onClick(android.view.View)
* @Date 2013-12-8 下午10:28:30
*
*/
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
switch (v.getId()) {
//打你发送短信按钮
case R.id.call_button:
//取得短信内容
content = content_eidt.getText().toString().trim();
//取得手机号码
phoneNumber = phonenumber_edit.getText().toString().trim();
//判断字符是否为空
if(TextUtils.isEmpty(content)||TextUtils.isEmpty(phoneNumber)){
Toast.makeText(getApplicationContext(), "请输入内容", Toast.LENGTH_LONG).show();
return;
}
//短信发送
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> contents = smsManager.divideMessage(content);
for (String string : contents) {
smsManager.sendTextMessage(phoneNumber, null, string, null, null);
}
Toast.makeText(getApplicationContext(), "短信已经发送", Toast.LENGTH_LONG).show();
break; default:
break;
} }
}

权限设置:

   <!-- 发送短信权限的权限 -->
<uses-permission android:name="android.permission.SEND_SMS" />

android基础知识点复习之短信发送的更多相关文章

  1. Android短彩信源码解析-短信发送流程(三)

    3.短信pdu的压缩与封装 相关文章: ------------------------------------------------------------- 1.短信发送上层逻辑 2.短信发送f ...

  2. Android短彩信源码解析-短信发送流程(二)

    转载请注明出处:http://blog.csdn.net/droyon/article/details/11699935 2,短彩信发送framework逻辑 短信在SmsSingleRecipien ...

  3. Android系统应用Mms之Sms短信发送流程(Mms应用部分)二

    1. 新建一条短信, 在发送短信之前, 首先创建的是一个会话Conversation, 以后所有与该接收人(一个或多个接收人)的消息交互, 都在该会话Conversation中. ComposeMes ...

  4. Android中实现短信发送的一种方式

    SendSmsActivity.java: package com.test.smsmangerdemo.sendsmsactivity; import android.support.v7.app. ...

  5. Android Sms短信发送

    界面布局: 具体代码: private void sendSms() { // 获取电话号码和短信内容 String number = number1.getText().toString(); St ...

  6. C#利用Web Service实现短信发送(转)

    通过编程方式实现短信息的发送对很多人来说是一件比较烦杂的事情,目前一般的解决方法是通过计算机和手机的连线,通过可对手机编程的语言编写相关的手机短信息程序来实现,而这种方法对于一般人来说是很难达到的,因 ...

  7. Android手机上监听短信的两种方式

    Android手机上监听短信有两种方式: 1. 接受系统的短信广播,操作短信内容. 优点:操作方便,适合简单的短信应用. 缺点:来信会在状态栏显示通知信息. AndroidManifest.xml: ...

  8. Android 解决双卡双待手机解析短信异常

    开发中,难免会遇到各种各样的适配问题,尤其是经过深度修改定制过的系统,有的无论是软硬件上都有很大的区别,这里不得不提到一种奇葩的机型,没错,那就是双卡双待的手机(比如XT800, A60, S8600 ...

  9. 短信发送接口被恶意访问的网络攻击事件(三)定位恶意IP的日志分析脚本

    前言 承接前文<短信发送接口被恶意访问的网络攻击事件(二)肉搏战-阻止恶意请求>,文中有讲到一个定位非法IP的shell脚本,现在就来公布一下吧,并没有什么技术难度,只是当时花了些时间去写 ...

随机推荐

  1. lumen框架

    1,获取配置 app(); 说明:app()返回的是全局唯一的application对象,该对象的原型是Laravel\Lumen\Application 加载配置文件(config/app.php) ...

  2. GitHub上优秀的ThirdParty

    仅为个人记录. 1.SwiftyJSON GitHub地址:https://github.com/SwiftyJSON/SwiftyJSON 2.CryptoSwift GitHub地址:https: ...

  3. hexo常用命令笔记

    hexo npm install -g hexo npm update -g hexo hexo init 常用 hexo n == hexo new "a new post" 新 ...

  4. ensp实战之防火墙安全转发策略

    本次实验用防火墙是USG6000V,拓扑图如下: 步骤一: 按上面配好PC1.2.3以及WWW服务器的IP地址.子网掩码以及网关: 步骤二: 进入防火墙的CLI命令模式下,按一下命令配置: 配置各个接 ...

  5. CodeForces 700A As Fast As Possible

    要保证总时间最短,因为总时间计的是最后一个人到达的时间,也就是最后一个人要求尽快到达,也就是说我们要让最后一个人乘车时间尽量多.再仔细想想可以发现每个人的乘车时间和走路时间都是一样的. 因此,可以二分 ...

  6. HDU 3127 WHUgirls

    二维完全背包,理解似乎还不够全面,过几天回来再看看这题. #include<cstdio> #include<cstring> #include<cmath> #i ...

  7. 整屏滚动效果 jquery.fullPage.js插件+CSS3实现

    最近很流行整屏滚动的效果,无论是在PC端还是移动端,本人也借机学习了一下,主要通过jquery.funnPage.js插件+CSS3实现效果. 本人做的效果: PC端:http://demo.qpdi ...

  8. [妙味JS基础]第八课:return、定时器基础

    知识点总结 return 1)函数名+括号 = return 返回值 2)所有的函数默认的返回值 = 未定义 3)return后面的代码不执行 arguments  =>为实参的集合,当参数个数 ...

  9. emoji图像转码解码 存入数据库

    public String emojiConvert1(String str) throws UnsupportedEncodingException { String patternString = ...

  10. Django中使用Bootstrap

    一.在Django中引用Bootstrap模版 1.首先下载bootsrtap代码(http://v3.bootcss.com/getting-started/#download),并将下载后的文件放 ...