获取未读电话的方法

来源:互联网 发布:apache fastcgi 配置 编辑:程序博客网 时间:2024/06/05 23:55

获取未读电话的方法1

 private int findNewCallCount(){    

                           Cursor csr = null;    

                           int missedCallCount = 0;  

                           try {    

                               csr = getContentResolver().query(Calls.CONTENT_URI,new String[]{Calls.NUMBER,Calls.TYPE,Calls.NEW},  

                                       null,null,Calls.DEFAULT_SORT_ORDER);    

                               if(null != csr){  

                                   while(csr.moveToNext()){  

                                       int type =csr.getInt(csr.getColumnIndex(Calls.TYPE));  

                                       switch (type){  

                                           caseCalls.MISSED_TYPE:  

                                               if(csr.getInt(csr.getColumnIndex(Calls.NEW))== 1){  

                                                   missedCallCount++;  

                                               }  

                                               break;  

                                 caseCalls.INCOMING_TYPE:  

                                               break;  

                                           case Calls.OUTGOING_TYPE:  

                                               break;  

                                       }  

                                   }  

                               }  

                           } catch (Exception e) {    

                               e.printStackTrace();    

                           } finally {    

                               csr.close();    

                           }    

                           return missedCallCount;//未读电话数目    

                       }


获取未读电话的方法2

   public int getUnknowMissedCallsNum(){

                   Cursorcur = null;

                   intunRead = 3;

                   intblack = unRead + 1;

                   try{

                            cur= getContentResolver().query(CallLog.Calls.CONTENT_URI, new String[]{CallLog.Calls.NUMBER, CallLog.Calls.CACHED_NAME,

                                               CallLog.Calls.DATE,CallLog.Calls.NEW }, "(type = "+ unRead + " AND new = 1)",null, "calls.date desc");// limit

                            //?distinct?

                            if(cur != null) {

                                     returncur.getCount();

                            }

                   }catch (SQLiteException ex) {

                            Log.d("SQLiteExceptionin getMissCallCount", ex.getMessage());

                   }finally {

                            if(cur != null && !cur.isClosed()) {

                                     cur.close();

                            }

                   }

                   return0;

         }