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>

实现效果:

Android中实现短信发送的一种方式的更多相关文章

  1. Android中H5和Native交互的两种方式

    Android中H5和Native交互的两种方式:http://www.jianshu.com/p/bcb5d8582d92 注意事项: 1.android给h5页面注入一个对象(WZApp),这个对 ...

  2. Java中实现短信发送

    最近跟着做公司的项目偶然接触到的,顺势把这个给记录下来,给自己梳理一下. 采用引入第三方工具的方式,网上查了半天,发现简单的实现方式便是注册一个中国网建的账号,新建账号的时候会附带赠几条免费短信,彩信 ...

  3. laravel中实现短信发送验证码

    前段时间想实现一个短信验证码的功能,但是卡了很长时间. 首先我用的是阿里云的短信服务业务,其首次接入流程如下: 在阿里云上开通短信服务后需要做的: 1,申请签名  2,申请模板   3,创建Acces ...

  4. Android中读取短信信息

    Android中读取的短信文件有 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 /**  * 所有的短信  */ public static final Strin ...

  5. android 中管理短信

    为了看代码方便,一边在网上google资料,一边看Android java 源代码. 偶然发现了一个类MmsSmsDatabaseHelper.java,原来android将所有的短信信息都存入了mm ...

  6. 暴力清除Android中的短信

    有些短信程序有bug,当短信(特别是彩信)没有接收完整,或者是一些异常情况下,你会收到一条短信但是看不到或者看不了. 此时郁闷的事情就来了,系统会提醒你还有1条未读短信,但是你满世界都找不到这条短信. ...

  7. Android 网格布局短信发送界面

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

  8. Android中服务的生命周期与两种方式的区别

    服务的生命周期跟Activity的生命周期类似.但是生命周期甚至比你关注服务如何创建和销毁更重要,因为服务能够在用户不知情的情况下在后台运行. 服务的生命周期---从创建到销毁---可以被分为以下两个 ...

  9. Android开发之短信验证码示例

    在说Android中的短信验证码这个知识点前,我们首先来了解下聚合数据 聚合数据介绍 聚合数据是一家国内最大的基础数据API提供商,专业从事互联网数据服务.免费提供从天气查询.空气质量.地图坐标到金融 ...

随机推荐

  1. git merge 和 git merge --no-ff的区别

    git merge –no-ff 可以保存你之前的分支历史.能够更好的查看 merge历史,以及branch 状态. git merge 则不会显示 feature,只保留单条分支记录. 比如:我当前 ...

  2. Laravel日志

    大家在使用 Log::info() 会让日志全部记录默认在 storage/logs/laravel.log 文件里,文件大了查找起来就比较麻烦.那么我可不可以单独记录在一个日志文件里呢? 只需在你的 ...

  3. 【Java每日一题】20170322

    20170321问题解析请点击今日问题下方的“[Java每日一题]20170322”查看(问题解析在公众号首发,公众号ID:weknow619) package Mar2017; public cla ...

  4. VirtualBox VM启用3D加速

    默认情况下,是不支持 DX3D的, 我们运行 dxdiag 看到的情况如下: 安装时也提示需要安全模式下才能安装 VirtualBox 必须在Windows安全模式下才能成功安装3D加速驱动。 重启系 ...

  5. Tri Tiling(hdu1143)

    Tri Tiling Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. (一):C++分布式实时应用框架----整体介绍

    C++分布式实时应用框架 (Cpp Distributed Real-time Application Framework) 版权声明:本文版权及所用技术归属smartguys团队所有,对于抄袭,非经 ...

  7. hash 和pushState,replaceState

    hash 要点: 1.不会向后台发请求:#是用来指导浏览器动作的,对服务器端完全无用. 2.用来跳转到页面的指定位置:   为网页位置指定标识符,有两个方法.一是使用锚点,比如<a name=& ...

  8. CPU 实用工具

    系统版本:CentOS 7.4 top 17:49:04 // 当前时间 up 3:55 // 系统运行时间,格式为时:分 2 users // 当前登录用户数 load average // 三个值 ...

  9. SQL Server: Datetime,Datetime2

    select CONVERT(nvarchar(50), '2018-10-10 10:13:32.000', 126) select convert(nvarchar(MAX), '2018-10- ...

  10. [HTML/CSS]浮动的那点事儿

    元素是怎样浮动 元素的水平方向浮动,意味着元素只能左右移动而不能上下移动. 一个浮动元素会尽量向左或向右移动,直到它的外边缘碰到包含框或另一个浮动框的边框为止. 浮动元素之后的元素将围绕它. 浮动元素 ...