界面布局:

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. js检测对象中是否存在某个属性

    1.使用in关键字.该方法可以判断对象的自有属性和继承来的属性是否存在. 2.使用对象的hasOwnProperty()方法.该方法只能判断自有属性是否存在,对于继承属性会返回false. 3.用un ...

  2. C#模板打印功能-模板为WPS或Excel

    //---WPS----- using EtApp = ET; using System.Reflection; using System.Runtime.InteropServices; using ...

  3. yii2.0单文件上传和多文件上传

    yii2文件上传使用到yii2自带的文件上传类UploadFIle,以及对应的模型规则,这里分别介绍单文件上传和多文件上传: yii2单个文件上传: 上传步奏,先创建上传表单模型model(包含验证规 ...

  4. hdfs格式化hadoop namenode -format错误

    在对HDFS格式化,执行hadoop namenode -format命令时,出现未知的主机名的问题,异常信息如下所示: [shirdrn@localhost bin]$ hadoop namenod ...

  5. 淘淘商城_day10_课堂笔记

    今日大纲 Dubbo入门学习 使用dubbo优化单点登录系统 系统间服务调用方式 浏览器直接访问 浏览器发起请求,通过ajax或jsonp方式请求: Httpclient方式 系统与系统之间通过Htt ...

  6. 投票项目-bootstrap

    <script id="src" type="text/tmpl"> //script标签的type写成这个,浏览器会认为他不是javascript ...

  7. jQuery进行简单验证的正则表达式

    下面都是一些比较常用简单的验证,像那些特殊的复杂的情况这里不进行考虑 1.验证电话号码或者手机号码 ? 1 2 3 4 5 6 7 8 9 10 /**  * 验证电话号码(手机号码+电话号码)  * ...

  8. Dokan官方说明文档

    Dokan 库Copyright(c) Hiroki Asakawa http://dokan-dev.net/en 什么是Dokan库================================ ...

  9. 浙大pat 1029题解

    1029. Median (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given an incre ...

  10. soj 2543 完全二叉树

    1000. 完全二叉树     Total: 338 Accepted: 81                 Time Limit: 1sec    Memory Limit:256MB Descr ...