I am making an app in which I want to get the call logs of all incoming, outgoing and missed calls. How can I do that?
private void getLastNumber() {
//this help you to get recent call
Uri contacts = CallLog.Calls.CONTENT_URI;
Cursor managedCursor = context.getContentResolver().query(contacts, null, null,
null, android.provider.CallLog.Calls.DATE + " DESC limit 1;");
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);
StringBuffer sb = new StringBuffer();
managedCursor.moveToNext();
String phNumber = managedCursor.getString(number);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
String callDayTime = new Date(Long.valueOf(callDate)).toString();
int callDuration = managedCursor.getInt(duration);
managedCursor.close();
int dircode = Integer.parseInt(callType);
sb.append("Phone Number:--- " + phNumber + " ,Call Date:--- " + callDayTime + " ,Call duration in sec :--- " + callDuration);
sb.append("\n----------------------------------");
Log.d("calllogs", "getLastNumber: "+"Phone Number:--- " + phNumber + " ,Call Date:--- " + callDayTime + " ,Call duration in sec :--- " + callDuration);
}