I want to get recently completed phone call details of android phone and after getting those details I want to start my new activity of my personal app when phone call has been completed . Basically i want to get phone call details before this details placed into directory/database of android phone.How to get this?
Asked
Active
Viewed 1,958 times
1 Answers
4
First you need to give the permission to read call logs from the device.
<uses-permission android:name="android.permission.READ_CONTACTS" />
Now use this method to get the recent call logs getCallDetails()
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);
}
Hope it will hemp you out for your need.

Rushabh Patel
- 3,052
- 4
- 26
- 58
-
I have just displayed all call logs in a single textview but you can modify code as per your need. :-) – Rushabh Patel Jul 08 '13 at 05:43
-
2Rushabh ,this code gives me call details except recent call.I mean ,i want details of phone call which is just complete and its data has not been saved into directory/database yet.I want to make call log activity which shows dialog box after completion of phone call to asking for logging mechanism of my own app.so this code does not gives me that recently completed phone call detail,do you have any solution for this? – Vishal V Jul 08 '13 at 05:50
-
I agree with @VishalV , this is not answer i can understand what did you except, did you find any answers? – FGH Jul 21 '20 at 17:32