Android Reading Call Log from Phone Programmatically

Here is the code to read all call log data (MISSED, OUTGOING, INCOMING) from android phone programmatically.

Permission in AndroidManifest.xml:
Add the READ_CONTACTS permission to your AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_CONTACTS" />

Code :

public static void getAllCallLogs(ContentResolver cr) {
    //reading all data in descending order according to DATE
    String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
    Uri callUri = Uri.parse("content://call_log/calls");
    Cursor cur = cr.query(callUri, null, null, null, strOrder);
    // loop through cursor
    while (cur.moveToNext()) {
     CallDataLog callLog = new CallDataLog();
     String callNumber = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
     String callName = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
     String callDate = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.DATE));
     String callType = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.TYPE));
     String isCallNew = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.NEW));
     String duration = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.DURATION));
     // process log data...
    }
}

7 comments :

  1. I want to use pin less calling with registered numbers but i also want to control my bill by viewing and tracking call history online from all registered numbers .

    ReplyDelete
  2. Hi, How can i get the last call details after call end in android

    ReplyDelete
  3. Hi,how can i get last 7days of call log history,i need query

    ReplyDelete
  4. Hi,how can i get last 7days of calllog history

    ReplyDelete
  5. how to get the call history of a particular contact??

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete

Your Comment and Question will help to make this blog better...