免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1175 | 回复: 0
打印 上一主题 下一主题

Listen to incoming/outgoing SMS [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-03 17:01 |只看该作者 |倒序浏览

                                                                                                                                                                                                                                                                                1, Listen to incoming SMS
1.1, Prepare manifest file
     
         
              
                  
                     
                  
              
         
      
      
Remark: action android.provider.Telephony.SMS_RECEIVED is undocumented.
1.2, Parse SMS
    package org.apache.sms;  
   
    import android.content.BroadcastReceiver;  
    import android.content.Context;  
    import android.content.Intent;  
    import android.os.Bundle;  
    import android.telephony.gsm.SmsMessage;  
  
    public class SMSApp extends BroadcastReceiver
    {  
        private static final String LOG_TAG = "SMSApp";  
     
       /* package */
        static final String ACTION =  
               "android.provider.Telephony.SMS_RECEIVED";  
     
        public void onReceive(Context context, Intent intent)
        {  
            if (intent.getAction().equals(ACTION))
            {  
                Bundle bundle = intent.getExtras();
                if (bundle != null)
                {
                    Object[] pdus = (Object[]) bundle.get("pdus");
                    SmsMessage[] messages = new SmsMessage[pdus.length];
                    for (int i = 0; i   String strUriInbox = "content://sms/inbox";//SMS_INBOX:1
   String strUriFailed = "content://sms/failed";//SMS_FAILED:2
   String strUriQueued = "content://sms/queued";//SMS_QUEUED:3
   String strUriSent = "content://sms/sent";//SMS_SENT:4
   String strUriDraft = "content://sms/draft";//SMS_DRAFT:5
   String strUriOutbox = "content://sms/outbox";//SMS_OUTBOX:6
   String strUriUndelivered =
"content://sms/undelivered";//SMS_UNDELIVERED
   String strUriAll = "content://sms/all";//SMS_ALL
   String strUriConversations = "content://sms/conversations";//you
can delete one conversation by thread_id
   String strUriAll = "content://sms"//you can delete one message by _id
*/
String strUriInbox = "content://sms/inbox";
Uri uriSms = Uri.parse(strUriInbox);  //If you want to access all SMS, just replace the uri string to "content://sms/"
Cursor c = mContext.getContentResolver().query(uriSms, null, null, null, null);
while (c.moveToNext())
{
    try
    {
        //Read the contents of the SMS;
        for(int i; i
in AndroidManifest.xml
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/9577/showart_1850111.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP