CallLog.Calls 提供澄清、来电、去电和未接电话的功能。所有类型的 CallLog.Calls 也获取其他记录。
见下面的代码:
游标 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;
}