原文地址:http://lyp2002924.iteye.com/blog/487965
关键字: 短信 发送
1: android 的短信发送可以在模拟器中进行模拟出来。
如现在启动一模拟器id 号为5554,
运行cmd
telnet localhost 5554
输入help 可以看到很多用于模拟器中的功能命令
gsm call 134343434 // 便是呼叫当前模拟器命令
sms send 15555218135 Hello,this is a Message // 是向当前的模拟器发送短信息
2: 相关类:
android.telephony.gsm.SmsManager
android.telephony.gsm.SmsMessage
android.app.PendingIntent
android.widget.Toast
3:实现代码(节选)
String msg ="hello";
string number = "1234565678";
SmsManager sms = SmsManager.getDefault();
PendingIntent pi = PendingIntent.getBroadcast(Sms.this,0,new Intent(),0);
sms.sendTextMessage(number,null,msg,pi,null);
Toast.makeText(Sms.this,"send success",Toast.LENGHT_LONG).show();
4:代码解释
上述发送短信的代码很简单,但是其中的几个类函数并不好理解:
Toast.makeText 就是展示一个提示信息,这个比较容易理解;
PendingIntent 就是一个Intent 的描述,我们可以把这个描述交给别的程序,别的程序
根据这个描述在后面的别的时间做你安排做的事情,By giving a PendingIntent to another application,
you are granting it the right to perform the operation you have specified as if the other
application was yourself,就相当于你的代表了。本例中别的程序就是发送短信的程序,短信发送成功后要把intent 广播出去 。
函数sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)
前三个参数按照文档比较容易理解,
PendingIntent sentIntent 当短信发出时,成功的话sendIntent会把其内部的描述的intent广播出去,否则产生错误代码并通过android.app.PendingIntent.OnFinished
进行回调,这个参数最好不为空,否则会存在资源浪费的潜在问题;
deliveryIntent 是当消息已经传递给收信人后所进行的PendingIntent 广播。
查看PendingIntent 类可以看到许多的Send函数,就是PendingIntent在进行被赋予的相关的操作。
分享到:
相关推荐
android短信发送实例,基于android的短信发送实例,需要添加权限duan
Android短信发送功能实现技巧分享 Android短信发送功能实现技巧分享
利用android开发短信发送程序,实现两个模拟器之间发送信息,文章详见 http://blog.csdn.net/cndrip/article/details/7170830
【Android】短信应用——短信发送Demo 相关文章:http://blog.csdn.net/etzmico/article/details/6874775
android短信发送器
NULL 博文链接:https://ouyangfeng521.iteye.com/blog/1094857
Android发送短信程序,需要的可以下下来看看。
监控android短信发送状态的代码, 相当的不错哦!
简单的例子,实现短信发送。类似以前的砖头机。呵呵
A页面打开B页面,选中B的值,关闭B页面,并把B中选中的值返回A页面,短信发送器代码,导入ADT eclipse开发环境
在android模拟环境下,实现一个短信发送器
android 定时发送短信(新) android 手机定时发送短信程序,支持2.2以上版本。功能:即时发送短信,定时发送短信,取消定时发送,拨号,自动搜索联系人,此次修补上次出现的bug。
unity调用Android Api实现短信发送和震动功能
//短信发送成功给予提示 Toast.makeText( Sample_11_1.this, //上下文 "恭喜你,短信发送成功!", //提示内容 5000 //信息显示时间 ).show(); v.setEnabled(true);//短信发送完成后恢复...
1,跳转到系统或短信应用的发送界面。 2,直接调用系统的短信接口发送,该方法可以判断是否发送成功和对方是否接受。
一个关于Android短信助手的小程序。可以帮助初学者进一步理解Intent、开启08_开启activity获取返回值、Adapter的运用ListView的点击事件、Intent发送数据、Activity关闭返回到上一个Activity等知识。
android 短信发送 可直接部署使用
Android 实现短信发送 实现监听短信发送状态 对方是否已经接收到 并且保存至发件箱
android 定时发送短信源码
Android之发送短信的两种方式 1、调用系统短信接口直接发送短信 2、调起系统发短信功能 (并设置发送状态的监听)