Search code examples
androidloggingcall

Open Android call log inside my activity


I do not know if this is possible to achieve:

I am developing and android app for the place I work at. The user is will not be able to use anything else but the app.

The problem that I am facing is that I need to get a call log for the user to see the missed calls, I was planning to use the OS call log screen, but I want to know if I can open that call


Solution

  • To open the standard Android call log

    enter image description here

    Fire a Calls.CONTENT_TYPE intent:

    Intent i = new Intent();
    i.setAction(Intent.ACTION_VIEW);
    i.setType(CallLog.Calls.CONTENT_TYPE);
    startActivity(i);           
    


    To programmatically get call log records from database (e.g. to populate your own UI):


    Cursor cur = managedQuery(CallLog.Calls.CONTENT_URI, null, null, null, null);
    int numberInd = cur.getColumnIndex(CallLog.Calls.NUMBER);
    int typeInd = cur.getColumnIndex(CallLog.Calls.TYPE);
    int dateInd = cur.getColumnIndex(CallLog.Calls.DATE);
    int durationInd = cur.getColumnIndex(CallLog.Calls.DURATION);
    
    while (cur.moveToNext()) {
         String number = cur.getString(numberInd);
         String type = cur.getString(typeInd);
         String date = cur.getString(dateInd);
         String duration = cur.getString(durationInd);
         int callCode = Integer.parseInt(type);
         // callCode can be OUTGOING_TYPE, INCOMING_TYPE or MISSED_TYPE
    
         .........
    }
    


    And in both cases you will need a READ_CALL_LOG permission