开发学院手机开发Android 开发 Android sms 发送、接收及格式 阅读

Android sms 发送、接收及格式

 2010-03-09 15:44:00 来源:WEB开发网   
核心提示:Intent("SMS_DELIVERED"), 0);并注册接收器,根据getResultCode()来判断:Java代码registerReceiver(sendReceiver);registerReceiver(deliveredReceiver);registerReceiver(send
Intent("SMS_DELIVERED"), 0);

并注册接收器,根据getResultCode()来判断:

Java代码

registerReceiver(sendReceiver);

registerReceiver(deliveredReceiver);

registerReceiver(sendReceiver);

registerReceiver(deliveredReceiver);

三、 sms接收

根据接收时广播的android.provider.Telephony.SMS_RECEIVED的Intent.我们可以扩展一个BroadcastReceiver来接收sms.

传递的Intent包含pdus数据。相关代码如下:

Java代码

Bundle bundle = intent.getExtras();

Object[] pdus = (Object[]) bundle.get("pdus");

SmsMessage[] msgs = new SmsMessage[pdus.length];

for (int i = 0; i < pdus.length; i++) {

msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);

}

Bundle bundle = intent.getExtras();

Object[] pdus = (Object[]) bundle.get("pdus");

SmsMessage[] msgs = new SmsMessage[pdus.length];

for (int i = 0; i < pdus.length; i++) {

msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);

}

四、 采用ContentObserver监控短信数据库

上面方法三中并不能对sms进行更新和删除操作,要做这些操作需要用ContentObserver来监控短信数据库的变化来进行相关操作。

1. 短信数据库的ContentUri

Java代码

public final static String SMS_URI_ALL = "content://sms/"; //0

public final static String SMS_URI_INBOX = "content://sms/inbox";//1

public final static String SMS_URI_SEND = "content://sms/sent";//2

public final static String SMS_URI_DRAFT = "content://sms/draft";//3

public final static String SMS_URI_OUTBOX = "content://sms/outbox";//4

public final static String SMS_URI_FAILED = "content://sms/failed";//5

public final static String SMS_URI_QUEUED = "content://sms/queued";//6

public final static String SMS_URI_ALL = "content://sms/"; //0

public final static String SMS_URI_INBOX = "content://sms/inbox";//1

上一页  1 2 3 4  下一页

Tags:Android sms 发送

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接