Http://stackoverflow.com/questions/6786666/how-do-i-access-call-log-for-android
Http://android2011dev.blogspot.in/2011/08/get-android-phone-call-historylog.html
How does I access call log for Android?
Http://developer.android.com/reference/android/provider/CallLog.Calls.html
First you need to give the permission-to-read call logs from the device.
<uses-permission android:name= "Android.permission.READ_CONTACTS"/>
Now with this method to get the recent call logs Getcalldetails ()
Private voidgetcalldetails () {StringBuffer sb=NewStringBuffer (); Cursor Managedcursor= Managedquery (CallLog.Calls.CONTENT_URI,NULL,NULL,NULL,NULL); intNumber =Managedcursor.getcolumnindex (CallLog.Calls.NUMBER); intType =Managedcursor.getcolumnindex (CallLog.Calls.TYPE); intDate =Managedcursor.getcolumnindex (CallLog.Calls.DATE); intDuration =Managedcursor.getcolumnindex (CallLog.Calls.DURATION); Sb.append ("Call Details:"); while(Managedcursor.movetonext ()) {String Phnumber=managedcursor.getstring (number); String CallType=managedcursor.getstring (type); String calldate=managedcursor.getstring (date); Date Calldaytime=NewDate (long.valueof (calldate)); String callduration=managedcursor.getstring (duration); String dir=NULL; intDircode =Integer.parseint (CallType); Switch(dircode) { CaseCallLog.Calls.OUTGOING_TYPE:dir= "outgoing"; Break; CaseCallLog.Calls.INCOMING_TYPE:dir= "INCOMING"; Break; CaseCallLog.Calls.MISSED_TYPE:dir= "MISSED"; Break; } sb.append ("\nphone Number:---" +phnumber + "\ncall Type:---" +dir+ "\ncall Date:---" +calldaytime+ "\ n
Call duration in SEC:---"+Callduration);
Sb.append ("\ n----------------------------------");
} Managedcursor.close (); Call.settext (SB);}
Private StaticString getcalldetails (context context) {StringBuffer StringBuffer=NewStringBuffer (); Cursor Cursor=context.getcontentresolver (). Query (CallLog.Calls.CONTENT_URI,NULL,NULL,NULL, CallLog.Calls.DATE + "DESC"); intNumber =Cursor.getcolumnindex (CallLog.Calls.NUMBER); intType =Cursor.getcolumnindex (CallLog.Calls.TYPE); intDate =Cursor.getcolumnindex (CallLog.Calls.DATE); intDuration =Cursor.getcolumnindex (CallLog.Calls.DURATION); while(Cursor.movetonext ()) {String Phnumber=cursor.getstring (number); String CallType=cursor.getstring (type); String calldate=cursor.getstring (date); Date Calldaytime=NewDate (long.valueof (calldate)); String callduration=cursor.getstring (duration); String dir=NULL; intDircode =Integer.parseint (CallType); Switch(dircode) { CaseCallLog.Calls.OUTGOING_TYPE:dir= "outgoing"; Break; CaseCallLog.Calls.INCOMING_TYPE:dir= "INCOMING"; Break; CaseCallLog.Calls.MISSED_TYPE:dir= "MISSED"; Break; } stringbuffer.append ("\nphone Number:---" + phnumber + "\ncall Type:---" + dir + "\ncall Date:---" +Calldaytime+ "\ncall duration in SEC:---" +callduration); Stringbuffer.append ("\ n----------------------------------"); } cursor.close (); returnstringbuffer.tostring ();}
Android Call Log Analysis