Calllogs returning all logs calls as well as sms logs, how can i filter only call logs?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 04:06:23

问题


I am trying to get all the Call-Logs excluding SMS but i get a merged list.

How can i filter call logs for calls only?

I am using following code.

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
);

I am using Samsung Note 2 for testing.


回答1:


I have the same issue on both of my samsung devices. Researching this issue indicates it is problem with how samsung handles the android logs, it merges them. Obviously this is incorrect and inconsistent behavior. Note, an sms message cannot be deleted through the call log api, yet it can be retrieved through the call log api.




回答2:


CallLog.Calls provides feature to clarify, Incomming, Outgoing and Missed. All type of CallLog.Calls where its get other records also.

See below code:

Cursor managedCursor = getActivity().getContentResolver().query( 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;

                     }


来源:https://stackoverflow.com/questions/13161461/calllogs-returning-all-logs-calls-as-well-as-sms-logs-how-can-i-filter-only-cal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!