界面布局:

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. 在mac安装numpy matplotlib scipy

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #fffff ...

  2. cetos6 安装samba共享文件夹

    yum方式安装 yum install samba 修改配置文件 vim /etc/samba/smb.conf [global] comment = global workgroup = QFpay ...

  3. sqlite创建数据库并创建一个表

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...

  4. in_array 判断的一些见解

    我个人见解in_array的判断是== 并不是===  证明如下: $arr=(array_merge(range(1, 9),range('a', 'z'),range('A', 'Z')));$m ...

  5. linux 目录及文件的命名规则、ls操作

    linux 命名: 1 不超过255个字符 2 严格区分大小写 3 除/外,其他的字符都是合法的 注意:1)避免文件名首字符使用+ - .(避免和隐藏文件混淆) 2)避免文件名使用空格,制表符以及@# ...

  6. QT枚举类型与字符串类型相互转换

    在QT中将枚举类型注册(QT_Q_ENUM或QT_Q_FLAG)后,就可以利用QT的元对象进行枚举类型与字符串类型转换了. 代码示例: #include <QtCore/QMetaEnum> ...

  7. 关于ASCII,Unicode和UTF-8

    自己也不是很明白这些编码,百度了一下,整理出来与大家分享分享,在此感谢作者. 先说说这些编码 ANSI:最早的时候计算机ASCII码只能表示256个符号(含控制符号),这个字符集表示英文字母足够,其中 ...

  8. 关于STM32的IO口速率问题

    输入模式可以不用配置速度,但是输出模式必须确定最大输出频率.当STM32的GPIO端口设置为输出模式时,有三种速度可以选择:2MHz.10MHz和50MHz,这个速度是指I/O口驱动电路的速度,是用来 ...

  9. 老司机的奇怪noip模拟T2-huangyueying

    2. 黄月英(huangyueying.cpp/c/pas )[问题描述]xpp 每天研究天文学研究哲学,对于人生又有一些我们完全无法理解的思考.在某天无聊学术之后, xpp 打开了 http://w ...

  10. 【转】cookie和session的区别

    原作者:施杨(施杨's Think out)出处:http://shiyangxt.cnblogs.com ************** 本文版权归原作者和博客园共有,欢迎转载,转载请保留该申明 ** ...