2012-10-31 52 views
7

我想獲得所有Call-Logs excluding SMS但我得到一個合併列表。Calllogs返回所有日誌調用以及短信日誌,我怎樣才能過濾只有通話記錄?

我該如何過濾通話記錄才能撥打電話?

我正在使用以下代碼。

String[] strFields = { 
      android.provider.CallLog.Calls.NUMBER, 
      android.provider.CallLog.Calls.TYPE, 
      android.provider.CallLog.Calls.CACHED_NAME, 
      android.provider.CallLog.Calls.CACHED_NUMBER_TYPE, 
      android.provider.CallLog.Calls.DATE 
}; 
String strOrder = android.provider.CallLog.Calls.DATE + " DESC"; 

Uri calluri = Uri.parse("content://call_log/calls"); 
Cursor mCallCursor = getContentResolver().query(
      calluri, 
      strFields, 
      null, 
      null, 
      strOrder 
); 

我正在使用Samsung Note 2進行測試。

+0

我也有同樣的問題。不知道這是三星的錯誤還是變種。 – Tushar

回答

0

我在兩個三星設備上都有同樣的問題。研究這個問題表明它是如何處理Android日誌的問題,它合併它們。顯然這是不正確和不一致的行爲。請注意,短信不能通過通話記錄API刪除,但它可以通過通話記錄API來檢索。

0

CallLog.Calls提供澄清,接收,傳出和錯過的功能。所有類型的CallLog.Calls也可以獲得其他記錄。

見下面的代碼:

光標managedCursor = getActivity()getContentResolver()的查詢(CallLog.Calls.CONTENT_URI,NULL,NULL,NULL,NULL); int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER); int name = managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME); int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE); int date = managedCursor.getColumnIndex(CallLog.Calls.DATE); int newcall = managedCursor.getColumnIndex(CallLog.Calls.NEW); int callduration = managedCursor.getColumnIndex(CallLog.Calls.DURATION); int id = managedCursor.getColumnIndex(CallLog.Calls._ID);

 while (managedCursor.moveToNext()) { 
      callNumber = managedCursor.getString(number); 
      callName = managedCursor.getString(name); 
      callType = managedCursor.getString(type); 
      callDate = managedCursor.getString(date); 
      isCallNew = managedCursor.getString(newcall); 
      Date callDayTime = new Date(Long.valueOf(callDate)); 
      duration = managedCursor.getString(callduration); 
      contactId = managedCursor.getString(id); 

     // process log data... 
       Log.i("Call Name-----", callNumber); 
       String cType = null; 

       int cTypeCode = Integer.parseInt(callType); 

       switch(cTypeCode) 
        { 
          case CallLog.Calls.OUTGOING_TYPE: 
          cType = "OUTGOING"; 
          break; 

          case CallLog.Calls.INCOMING_TYPE: 
          cType= "INCOMING"; 
          break; 

          case CallLog.Calls.MISSED_TYPE: 
          cType = "MISSED"; 
          break; 

        } 
相關問題