SendSmsActivity.java:

package com.test.smsmangerdemo.sendsmsactivity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.app.PendingIntent;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast; /**
*发送短信实例
*/ public class SendSmsActivity extends AppCompatActivity {
EditText phone, content;
Button send; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_send_sms);
//获取 SMSManger管理器
final SmsManager smsManager = SmsManager.getDefault();
//初始化控件
phone = (EditText) findViewById(R.id.et_phone);
content = (EditText) findViewById(R.id.et_content);
send = (Button) findViewById(R.id.btn_send); send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { //创建一个 android.app.PendingIntent 对象
PendingIntent pi = PendingIntent.getActivity(SendSmsActivity.this, 0, new Intent(), 0); //发送短信
smsManager.sendTextMessage(phone.getText().toString(), null, content.getText().toString(),
pi, null); //提示短信发送完成
Toast.makeText(SendSmsActivity.this, "短信发送完成", Toast.LENGTH_SHORT).show();
}
});
}
}

AndroidMainfest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.smsmangerdemo.sendsmsactivity" >
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".SendSmsActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>

activity_send_sms.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
tools:context="com.test.smsmangerdemo.sendsmsactivity.SendSmsActivity"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="收件人"/> <EditText
android:id="@+id/et_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"/>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发送内容"/> <EditText
android:id="@+id/et_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="top"
android:lines="5"
android:text="你好"/>
</LinearLayout> <Button
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发送"
android:id="@+id/btn_send"
/>
</LinearLayout>

实现效果:

最新文章

  1. 数据复制与AA双活(1)
  2. regsvr32的使用
  3. LeetCode----326. Power of Three(Java)
  4. 免费Gif图片录制工具
  5. 迁移应用数据库到MySQL Database on Azure
  6. ifram一些常用的知识点
  7. Light OJ 1064 - Throwing Dice
  8. Saiku如何固定查询结果table的表头和首列
  9. solr-geohsah 按照距离搜索分组
  10. Hibernate从零开始的反向工程
  11. Property list types and their various representations
  12. mintUI配合vue2.0,webpack,vue-cli脚手架从零搭建
  13. Ajax相关——get请求和post请求的区别
  14. AngularJS进阶(二十一)Angularjs中scope与rootscope区别及联系
  15. list对象中根据两个参数过滤数据
  16. 关于管理,你可能一直有 3 个误解zz
  17. 整合SPRING CLOUD云服务架构 - 企业分布式微服务云架构构建
  18. 将百度编辑器ueditor用在easyui中
  19. Eclipse svn 中文转成英文
  20. 手把手教你搭建nuget服务器

热门文章

  1. 【Spring】16、注解事务 @Transactional
  2. JavaWeb学习日记----XML的解析
  3. Python 部分系统类的常用方法整理
  4. oracle中row_number() over()
  5. mybatis 自动生成文件配置
  6. Android联系人列表实现
  7. 我写的.net相关的文章
  8. mysql的数据类型和字段属性
  9. 钉钉扫码登录web网站
  10. SQL Server如何定位自定义标量函数被那个SQL调用次数最多浅析