Android Call Log Analysis

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.