来源: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:权限添加:

<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
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:代码解释
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在进行被赋予的相关的操作。

更多相关文章

  1. Android 完全退出应用程序实现代码
  2. 设置Android程序图标
  3. Android应用程序内存优化
  4. Android 开发入门问题集:启动模拟器、安装卸载apk、项目调试、导
  5. Android利用程序实现GPS的打开或关闭
  6. Android App程序运行过程 ActivityThread.main()------>详解系列

随机推荐

  1. Tabhost中Activity绑定Service
  2. Android音乐播放器开发小记——项目简介
  3. android EditText 的键盘弹出(不弹出)坑爹
  4. Android - 修改最小SDK版本(minSdkVersio
  5. apk重签名之re-sign.jar重签名
  6. Android 8.1 中Systemui中的常见修改(八)Sy
  7. Android平台上面输入法遮挡问题-android:
  8. 第一章 开始启程,你的第一行Android代码
  9. Android属性之build.prop生成过程分析
  10. Android中bindService的使用及Service生