Android之短信发送器
来源:互联网 发布:stm32f103 flash编程 编辑:程序博客网 时间:2024/05/01 10:03
效果图:
界面布局:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <!--显示控件-->
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/moblie"
- />
- <!--文本框按钮-->
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/moblie"
- />
- <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>
接着是资源文件strings.xml
import java.util.List;import android.app.Activity;import android.os.Bundle;import android.telephony.SmsManager;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class SmsActivity extends Activity { private EditText mobileText; //定义文本框 定义成员变量,就可以直接调用 private EditText contentText; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mobileText = (EditText)this.findViewById(R.id.mobile); contentText = (EditText)this.findViewById(R.id.content); Button button =(Button)this.findViewById(R.id.button);//按钮不需要在很多地方引用,所以就键个点击事件就搞定了,后面不需要引用 button.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){ String mobile = mobileText.getText().toString(); String content = contentText.getText().toString(); SmsManager smsManager = SmsManager.getDefault(); //当信息长度超过120个字符,分多次发送 if(content.length() > 120){ List<String> contents = smsManager.divideMessage(content); for(String sms : contents){//使用增强for循环 迭代短信内容 sms : contents smsManager.sendTextMessage(mobile,null,sms,null, null); } }else{ smsManager.sendTextMessage(mobile,null,content,null,null); }//采用吐西方式提示用户发送成功 Toast.makeText(SmsActivity.this, R.string.info, Toast.LENGTH_LONG).show(); //吐丝 //Toast是一种提供给用户简洁信息的视图 } }); }}
添加短信服务权限:
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="cn.itcast.action"
- android:versionCode="1"
- android:versionName="1.0">
- 略....
- <uses-sdk android:minSdkVersion="8" />
- <!-- 短信服务权限 -->
- <uses-permission android:name="android.permission.SEND_SMS" />
- </manifest>
---------------------------------------------------------------------------------------
smsManager.sendTextMessage(destinationAddress, scAddress, text, sentIntent, deliveryIntent)
如果不用,后面两个可以为null
--destinationAddress 目标电话号码,收报地址
-- ScAddress 通讯录 服务商的短信中心号码(例如中国移动的短信中心号码),测试可以不填。
-- sentIntent:发送(短信) -->中国移动 --> 中国移动发送失败 --> 返回发送成功或失败信号(广播出去) --> 后续处理 即,这个意图包装了短信发送状态的信息
-- deliveryIntent: 广播(短信)接收器 即:这个意图包装了短信是否被对方收到的状态信息(供应商已经发送成功,但是对方没有收到)。//delivery 交付
- Android之短信发送器
- Android之短信发送器
- Android之短信发送器
- android 之短信发送
- Android入门之简单短信发送器
- Android学习之短信发送器
- Android开发案例之短信发送器
- Android之制作短信发送器
- Android短信发送器
- android 短信发送器
- android短信发送器
- Android短信发送器
- android短信发送器
- android 短信发送器
- Android短信发送器
- Android -- 短信发送器
- android 短信发送器
- Android短信发送器
- ASP.NET学习笔记[4] - 无法分析从服务器在通过调用 Response.Write()
- 【Cortex-M0】4 ARM微微控制器的指令集
- 基于Socket的通信机制-有连接通信方式:多线程通信
- Android图形系统分析与移植--六、framebuffer研究
- VS2010与SVN
- Android之短信发送器
- 好的软件人员一生必看的六十本书
- Android开发实例详解之IMF(Android SDK Sample—SoftKeyboard)
- 电脑中TCP/IP协议设置
- 使用RVM在ubuntu下安装ruby&rails
- C#中使用try...catch...是否会影响程序性能
- [C#新手入门 六] 如何高效的将excel导入sqlserver?
- 【Cortex-M0】5 ARM C语言编程
- 焊接工具