zoukankan      html  css  js  c++  java
  • Android 获取未读短信未接电话数目

    引用:http://blog.csdn.net/zhuangxujun/article/details/7035430

    1. <pre name="code" class="java"></pre><pre name="code" class="java"><pre name="code" class="java">if (mIntentReceiver == null) {  
    2.   
    3.   
    4.             mIntentReceiver = new MissedCallIntentReceiver();  
    5.             final IntentFilter myFilter = new IntentFilter();  
    6.                     myFilter.addAction("com.android.phone.NotificationMgr.MissedCall_intent");  
    7.             getApplicationContext().registerReceiver(mIntentReceiver, myFilter);  
    8.   
    9.   
    10.                 }  
    11.                 getApplicationContext().getContentResolver().registerContentObserver(Uri.parse("content://mms-sms/"), true,   
    12.                                                                                             new newMmsContentObserver(getApplicationContext(),   myHandler)); </pre><br>  
    13. <pre></pre>  
    14. <pre name="code" class="java"private  class MissedCallIntentReceiver extends BroadcastReceiver {</pre><pre name="code" class="java">                @Override  
    15.         public void onReceive(Context context, Intent intent) {  
    16.                        missedCallCount=intent.getIntExtra(MISSECALL_EXTRA, 0);//未接电话数目  
    17.                        
    18.         }  
    19.     }  
    20.   
    21.   
    22.     private void findNewSmsCount(Context ctx){  
    23.         Cursor  csr = null;  
    24.         try {  
    25.             csr = getApplicationContext().getContentResolver().query(Uri.parse("content://sms"), null,"type = 1 and read = 0"nullnull);  
    26.         } catch (Exception e) {  
    27.              e.printStackTrace();  
    28.         } finally {  
    29.              csr.close();  
    30.         }  
    31.         newSmsCount=csr.getCount(); //未读短信数目  
    32.         Log.v(TAG,"newSmsCount="+newSmsCount);  
    33.     }  
    34.   
    35.     private void findNewMmsCount(Context ctx){  
    36.         Cursor  csr = null;  
    37.         try {  
    38.              csr = getApplicationContext().getContentResolver().query(Uri.parse("content://mms/inbox"), null,  
    39.                       "read = 0"nullnull);  
    40.         } catch (Exception e) {  
    41.              e.printStackTrace();  
    42.         } finally {  
    43.              csr.close();  
    44.         }  
    45.          newMmsCount=csr.getCount();//未读彩信数目  
    46.     }  
    47. //监控短信,彩信数目变化  
    48.     public class newMmsContentObserver extends ContentObserver{  
    49.         private Context ctx;         
    50.      
    51.         public newMmsContentObserver(Context context, Handler handler) {       
    52.             super(handler);       
    53.             ctx = context;       
    54.         }       
    55.   
    56.     @Override      
    57.     public void onChange(boolean selfChange){     
    58.         Log.v(TAG,"newMmsContentObserver onChange:");  
    59.         newMmsCount=0;      
    60.     newSmsCount=0;          
    61.         findNewMmsCount(ctx);  
    62.     findNewSmsCount(ctx);  
    63.          
    64.        }  
    65.      }</pre><br>  
    66. <br>  
    67. <pre></pre>  
    68. <br>  
    69. <span style="font-size:18px; color:#ff0000"><strong>用于获取未读短信未接电话数目</strong></span><br>  
    70.        
    71.   
    72. </pre>  
  • 相关阅读:
    013.ES6 -对象字面量增强型写法
    012. ES6
    011. ES6 语法
    10. 9. Vue 计算属性的setter和getter 以及 计算属性的缓存讲解
    4. Spring MVC 数据响应方式
    3. SpringMVC 组件解析
    9. Vue 计算属性
    【洛谷 2984】给巧克力
    【洛谷 1821】捉迷藏 Hide and Seek
    【洛谷 1821】银牛派对Silver Cow Party
  • 原文地址:https://www.cnblogs.com/sode/p/2886655.html
Copyright © 2011-2022 走看看