To get call history programmatically first add read conact permission in Manifest file :
<uses-permission android:name="android.permission.READ_CONTACTS" />
Create xml file. Add the below code in xml file :
<Linearlayout android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<Textview android:id="@+id/call"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</Textview>
</Linearlayout>
Now call the getCallDetails() method in java class :
private void getCallDetails() {
StringBuffer sb = new StringBuffer();
Cursor managedCursor = managedQuery( CallLog.Calls.CONTENT_URI,null, null,null, null);
int number = managedCursor.getColumnIndex( CallLog.Calls.NUMBER );
int type = managedCursor.getColumnIndex( CallLog.Calls.TYPE );
int date = managedCursor.getColumnIndex( CallLog.Calls.DATE);
int duration = 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 = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString( duration );
String dir = null;
int dircode = Integer.parseInt( callType );
switch( dircode ) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
sb.append( "\nPhone Number:--- "+phNumber +" \nCall Type:--- "+dir+" \nCall Date:--- "+callDayTime+" \nCall duration in sec :--- "+callDuration );
sb.append("\n----------------------------------");
}
managedCursor.close();
call.setText(sb);
}
Using this application user can access his call history. It show call number,call type i.e. incoming/outgoing/missed call, call date-time and call duration.
Here is the output where user can see all details :
<uses-permission android:name="android.permission.READ_CONTACTS" />
Create xml file. Add the below code in xml file :
<Linearlayout android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<Textview android:id="@+id/call"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</Textview>
</Linearlayout>
Now call the getCallDetails() method in java class :
private void getCallDetails() {
StringBuffer sb = new StringBuffer();
Cursor managedCursor = managedQuery( CallLog.Calls.CONTENT_URI,null, null,null, null);
int number = managedCursor.getColumnIndex( CallLog.Calls.NUMBER );
int type = managedCursor.getColumnIndex( CallLog.Calls.TYPE );
int date = managedCursor.getColumnIndex( CallLog.Calls.DATE);
int duration = 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 = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString( duration );
String dir = null;
int dircode = Integer.parseInt( callType );
switch( dircode ) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
sb.append( "\nPhone Number:--- "+phNumber +" \nCall Type:--- "+dir+" \nCall Date:--- "+callDayTime+" \nCall duration in sec :--- "+callDuration );
sb.append("\n----------------------------------");
}
managedCursor.close();
call.setText(sb);
}
Using this application user can access his call history. It show call number,call type i.e. incoming/outgoing/missed call, call date-time and call duration.
Here is the output where user can see all details :
72 comments:
Thank you very much for such an nice tutorial. It was of great help to me. But it gets stopped unexpectedly. I am knew to android And don't know how to fix it.
i copied your code and did exactly what you said. Imported all the required packages. I don't see any mistake :(
I am using android 2.2 SDK 8.
Sara have you initialized xml and text view in your activity class before calling getCallDetails() method. Add below source in onCreate() method :
setContentView(R.layout.main);
call = (TextView)findViewById(R.id.call);
getCallDetails();
Thanks for your prompt reply. yeah i have initialized the xml and textview :(
I have figured it out! and i am quite ashamed of the mistake i made. I missed one line in xml :(
I am really sorry for bothering you. It is an excellent tutorial and it works fine. :) thank u
still iam getting response as unexpected close
hello, I really found this tutorial efficient. I would want to know if I wish to sort the call logs to only outgoing international and local calls what do i need done? or what is the code i need?
Iam trying to get my call log for all my calls for both my phones
It worked well ,thanks a lot
error in using managedQuery()
The method managedQuery(Uri, null, null, null, null) is undefined for the type CallRecord
error in managedQuery()
I have been visiting various blogs for India call unlimited. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards
send me complete code of Get Android phone call history/log programmatically" at virampurohit@gmail.com
Very useful tutorial, Thank you very much.
all the force close errors are because we are just copying the code.
there is an error in XML code Provide
he has written "Textview" instead of "TextView" i mean v should be capital
Thank you very much for such an nice tutorial.
But managedQuery is Deprecated.
is there another solution?
Hi its really a nice tutorial i have visited many sites but not find an exact example.I have an error will you please help me i cannot able to resolve the managedQuery its giving me an error CallLog.Call also not resolved have any solution please help ....!
The above will not work. We need 2 permissions for this. Add the following permissions in the manifest file:
i have pasted the code correctly n i added the menifest file and call = (TextView)findViewById(R.id.call);
getCallDetails(); in oncreate() method bt i found error in last line call.setText(sb);
how i resolve this?
call.setText(sb.toString());
Hello Sir
can you please give me the code for retrieving the call summary(total no of incoming calls,outgoing calls,how many are local calls,std calls etc)same for sms summary how many sms are sent local,std etc.Sir i'm new to android and i have to submit my app please help me sir as soon as possible.
Thank You.
Thank you very much for the cod sir.... Can you plz give me the code for accessing sms details like, sender, receiver, time, date, content etc.
Below is the link of my posts where you can get information about how to read both incoming and outgoing SMS content programmatically.
http://android2011dev.blogspot.in/2013/10/incoming-sms-details.html
http://android2011dev.blogspot.in/2013/10/outgoing-sms-details.html
In the manifest file change to:
android:targetSdkVersion="10"
then the code will run
i dont know exactly why, i think its compatibility, someone can explain it?? because if targetSdkVersion="18" for example, the app crashes
Great tutorial..Thnxs alot..:)
hi, when i write this code in eclipse cross out managedCursor
do you know why?
it run well in emulator but not in mobile
hello, i m getting an error of unfortunately, calllog has stopped both on mobile as well as emulator.
please help to sort it out.
hello, i m getting an error unfortunately, callog stopped both on emulator as well as phone.please help to sort it out
hi,
thank you for thos mus information. .... you are showing call time also.. but for me i didn't get time ... why please help me..
Thank you
Thank you very much for the cod sir.... Can you plz give me the code for accessing backup of call log details like, sender, receiver, time, date, etc.
very useful post. send me complete project of Get Android phone call history/log programmatically" to kchands93@gmail.com
hi, any one help me is it possible to get call cost also?if possible,How to get the call cost.
sir it showing only 4,5 call details how we can get all call logs details
hi...Im trying to get the call cost details,Im getting the cost per minute details from the user,but still error occured. if anyone plz help me...by using this how to know call cost.
can we forward this call log history to another phone as a message
hi i want to store all these logs in sqlite database i m new to android can any body helps me plzzz
how do i convert time in 12 hr format
Hi, thanks for this great tutorial, but my problem is that i only get the missed calls. can you please help me.
Change the order in the last lines of code if you don't want the system to crash after sometime.
The correct order will be
call.setText(sb); managedCursor.close();
Thanks for sharing the information.
regards, Calling Card
hi, i know its a stupid question but still i want t know can i get all the conversation of call .
Thanks.
use this permission this code i get it thank you very match very use fully tutorial
use this permission
How to get call logs for particular SIM if the phone has DUAL SIM
Thanks for the post. I'm using Android Studio 1.3.1 and a Nexus 5 API 22 emulator and receive a permission issue.
Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.CallLogProvider from ProcessRecord{39b0a8ec 2019:test.com.testapp/u0a57} (pid=2019, uid=10057) requires android.permission.READ_CALL_LOG or android.permission.WRITE_CALL_LOG
I believe my manifest sets the correct permissions. Any ideas?
<application
Thanks in advance.
I changed some things and it worked for me.
1st: The is misspelled, it is written "Linearlayout".
2nd: The is misspelled, it is written "Textview".
3rd: For the java.lang.SecurityException: Permission Denial you should add
.
Also a good tip: instead of you should use so that
you can scroll through all the calls.
The tags from my previous post were banned so i republish:
1st: The "LinearLayout" is misspelled, it is written "Linearlayout".
2nd: The "TextView" is misspelled, it is written "Textview".
3rd: For the java.lang.SecurityException: Permission Denial you should add
'uses-permission android:name="android.permission.READ_CALL_LOG"'
Also a good tip: instead of "LinearLayout" you should use "ScrollView" so that
you can scroll through all the calls.
sir how to get current date call log history plz tell me
I am not able to resolve Calls
Can anyone please help me?
hi how to track last received or dialled or missed cal im getting call history but how to get last call alone
how to retrieve only todays incomming calls call summary in android
Hi jyo243 filter your calls details array current date = your calls details array(date)
get only incoming call
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- " + dir + " \nCall Date:--- " + callDayTime + " \nCall duration in sec :--- " + callDuration);
sb.append("\n----------------------------------");
miss_cal.setText(sb);
break;
How can I get the Contact Name too??
Hello sir, i want to send the call log details to an email. I request you sir to provide the complete java code for this program.
gracias for this article
Searching for this one.
Some times i too posts on my blog https://www.droidblogger.com
managedQuery is depreciated for api 23. I am not able to resolve it. Any opinion?
guys plz answer how to make it work
unexpected close error please tell me . there is an error in methoud calling. please help
Is it possible to get carrier name also in incoming call detail
Nice information.. Thanks for sharing..
Digital marketing services in pune
Great stuff...I have come across very many sites, but none that are so accurate and so regularly updated. Thanks for your efforts and keep up the good work new android phones Please keep share
Hello Dear,
The blog was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents.
You can also get Track & Monitor Employee Calls History | Call Log App - Callmonitor.app
Call History App - Find the best call monitor app for track & monitor employees inbound and outbound calls history, get valuable insight to boost your company with us! Download now app.
Visit Now - https://callmonitor.app/
how to replace Textview to Listview. I make Listview but get an error. please solve this error
Call.setText(sb.toString()+""); error in setText.
Uri allCalls = Uri.parse("content://call_log/calls");
Cursor c = managedQuery(allCalls, null, null, null, null);
String num= c.getString(c.getColumnIndex(CallLog.Calls.NUMBER));// for number
String name= c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME));// for name
String duration = c.getString(c.getColumnIndex(CallLog.Calls.DURATION));// for duration
int type = Integer.parseInt(c.getString(c.getColumnIndex(CallLog.Calls.TYPE)));// for call type, Incoming or out going.
call.setText(sb); showing error..
Accelmove Dynamics has an extraordinary and fast-growing technical team of engineers and R&D members who seamlessly combine advanced analytical thinking , design thinking and bring in Problem solving functionalities under one roof . We work on identifying challenges and implementing the best solutions in this real world, wherever robots could fit into.
https://accelmove.com/
NIL
Post a Comment