zoukankan      html  css  js  c++  java
  • 获取android 刚发出去的短信

    import android.content.Context;
    import android.database.ContentObserver;
    import android.database.Cursor;
    import android.net.Uri;
    import android.os.Handler;
    import android.util.Log;
        public class ObserveSMSSend extends ContentObserver{
        private final String SMSSEND_TYPE="smsInfo";   

         private final String TYPE="send";     

        private static final String TAG ="SystemSens_sendsms";   

         private Context mcontext;       

       public ObserveSMSSend(Handler handler ,Context context) {
                    super(handler);
                    this.mcontext = context;
            }
         @Override
            public void onChange( boolean selfChange) {
            super.onChange(selfChange);                          

       Cursor cursor = this.mcontext.getContentResolver().query(Uri.parse("content://sms/outbox"),null, null, null, null);  
               while (cursor.moveToNext()){                        

             String address=cursor.getString(cursor.getColumnIndex("address"));               

             String msg=cursor.getString(cursor.getColumnIndex("body"));             

             Log.i("ReceiveSendSMS", address+":"+msg);       

            }
        }

    //* 在activity中添加 如下代码

        @Override    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       ObserveSMSSend content = new ObserveSMSSend(new Handler(), this);
              this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"), true, content);
        }

     

    ///注意 添加  androidmanifest中添加

    <uses-permission android:name="android.permission.READ_SMS"/>   <uses-permission android:name="android.permission.READ_CONTACTS"/>

    打开DDMS,用你的SDK 发一个短信 ,看看是systemout中有了。

     

    那个content://sms/outbox 可以改为 content://sms/inbox  就是收件箱,患有其他,自己找去。

  • 相关阅读:
    HDU 3401 Trade
    POJ 1151 Atlantis
    HDU 3415 Max Sum of MaxKsubsequence
    HDU 4234 Moving Points
    HDU 4258 Covered Walkway
    HDU 4391 Paint The Wall
    HDU 1199 Color the Ball
    HDU 4374 One hundred layer
    HDU 3507 Print Article
    GCC特性之__init修饰解析 kasalyn的专栏 博客频道 CSDN.NET
  • 原文地址:https://www.cnblogs.com/changefuture/p/2300971.html
Copyright © 2011-2022 走看看