新建一个Android项目sns。

在String.xml添加文字

<resources>

<stringname="app_name">Sns发送短信</string>

<stringname="hello">Hello World, MainActivity!</string>

<stringname="number">输入手机号</string>

<stringname="content">请输入短信内容</string>

<stringname="button">发送</string>

<stringname="success">发送完成</string>

</resources>

设置界面main.xml

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical">

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/number"/>

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@+id/number"/>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/content"/>

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:minLines="3"

android:id="@+id/content"/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

 android:text="@string/button"

android:id="@+id/button"/>

</LinearLayout>

设置按钮点击事件

public
class
MainActivity extends Activity {

private EditTextnumberText;

private EditTextcontentText;

@Override

public
void
onCreate(BundlesavedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

numberText = (EditText)this.findViewById(R.id.number);

contentText = (EditText)this.findViewById(R.id.content);

Button button = (Button) this.findViewById(R.id.button);

button.setOnClickListener(new ButtonClckListener());

}

private
final class
ButtonClckListenerimplements View.OnClickListener{

public
void
onClick(View v){

String number = numberText.getText().toString();

String content = contentText.getText().toString();

SmsManager manager =SmsManager.getDefault();

ArrayList<String> texts =manager.divideMessage(content);

for (String text : texts) {

// 后两个参数 sentIntent, deliveryIntent(发送状态,是否收到短信状态

manager.sendTextMessage(number, null, text,null,
null);

}

Toast.makeText(MainActivity.this, R.string.success, Toast.LENGTH_LONG).show();

}

}

}

发送成功的三种通知

1.      状态栏通知

2.      对话框通知

3.          吐西(Toast)(弹出发送成功,一秒自动消失)

设置权限

发送短信要设置权限,我们在sdk在docs→index.html

这里可以看到所有的权限搜索send sms可以看到发短信的权限

可以找到

然后可以在manifest申请权限(manifest节点下)

<uses-permissionandroid:name="android.permission.BROADCAST_SMS"/>

安装应用测试

给另外一台模拟器发送短信。

发送成功的Toast效果

code :链接:http://pan.baidu.com/s/1eQzU5s2 密码:70pd

学习笔记7-Android短信发送器的更多相关文章

  1. Android(java)学习笔记86:案例短信发送器

    1.一般我们第一步都是先创建这个main.xml布局文件,这是良好的习惯: <?xml version="1.0" encoding="utf-8"?&g ...

  2. Android(java)学习笔记69:短信发送器

    1. 一般我们第一步都是先创建这个main.xml布局文件,这是良好的习惯: <?xml version="1.0" encoding="utf-8"?& ...

  3. Android短信发送器(2)

    在上一篇的<Android短信发送器>当中.发送功能并不完好.当发送内容超过限定字数时,短信就会发送失败,此时就须要推断内容是否超过限制,假设不超过限制.就直接发送,反之.则对其进行处理再 ...

  4. Android短信发送器_08

    1.string xml代码 <?xml version="1.0" encoding="utf-8"?> <resources> &l ...

  5. 初识安卓小程序(Android短信发送器)

    首先,先创建一个安卓项目(我的版本号是4.4.2的),名字为"短信发送器" 然后在res目录下找到layout目录,找到activity_main.xml或fragment_mai ...

  6. Android学习笔记_2_发送短信

    1.首先需要在AndroidManifest.xml文件中加入发送短信的权限 <uses-permission android:name="android.permission.SEN ...

  7. [android] 短信发送器

    /*****************2016年4月23日 更新********************************/ 知乎:什么是 7 位元的字符? 英文字符难道不是 8 bit 是一个字 ...

  8. android短信发送器源代码

    Activity类: import java.util.List;import android.app.Activity;import android.app.PendingIntent;import ...

  9. android开发学习---开发一个简易的短信发送器

    一.需求: 开发一个简易的短信发送器,输入:对方手机号码,短信内容,点击发送按钮,短信发送成功,对方手机成功收到短信. 其中要求短信内容过长时可以自动拆分,长度英文是160个英文,中文是70个,中英混 ...

  10. 无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、短信发送器、Android 中各种布局(1)

    1.Android是什么 手机设备的软件栈,包括一个完整的操作系统.中间件.关键的应用程序,底层是linux内核,安全管理.内存管理.进程管理.电源管理.硬件驱动 2.Dalvik VM 和 JVM ...

随机推荐

  1. java实现生产者/消费者的三种方式

    package com.wenki.thread; import java.util.LinkedList; import java.util.concurrent.LinkedBlockingQue ...

  2. es6新增

    首先要说let,他是只在代码块中执行的变量,例如: {    let a = 10;    var b = 1;}console.log(a);//definedconsole.log(b);//1 ...

  3. web项目部署到阿里云服务器步骤

    http://www.cnblogs.com/qq3111901846/p/6178855.html http://blog.csdn.net/liona_koukou/article/details ...

  4. 利用Runtime实现简单的字典转模型

    前言 我们都知道,开发中会有这么一个过程,就是将服务器返回的数据转换成我们自己定义的模型对象.当然服务器返回的数据结构有xml类型的,也有json类型的.本文只讨论json格式的. 大家在项目中一般是 ...

  5. width:100vh有感而发

    在看一个网页的代码是看到 width:100vh  纳尼...这这我怎么没有见过,这是个什么属性,随之有看到 min-height:calc(100vh + 51px);这尼玛又是怎么用的.... 感 ...

  6. JAX-RPC 与 JAX-WS 的比较

    引言 Web 服务已经出现很久了.首先是 SOAP,但 SOAP 仅描述消息的情况,然后是 WSDL,WSDL 并不会告诉您如何使用 Java™ 编写 Web 服务.在这种情况下,JAX-RPC 1. ...

  7. 解决IE6下select显示在弹出框上问题

    利用定位position:absolute;z-index:1;和iframe[z-index:-1]来解决此问题,最好根据需要加上: border='0' frameborder='0' scrol ...

  8. vue.js-路由

    1:编写router.js   import Router from "vue-router" import Vue from "vue" import rou ...

  9. SpringMVC 教程 - Handler Method

    原文链接:https://www.codemore.top/cates/Backend/post/2018-04-21/spring-mvc-handler-methods 由注解@RequestMa ...

  10. asp.net使用session完成: 从哪个页面进入登录页面,登录成功还回到那个页面

    1.在Login.aspx页面Load中加入 if (!IsPostBack && Request.UrlReferrer != null) {      Session[ " ...