Search code examples
androidcalllog

Android: Get CallLog History from a certain contact


I query the CallLog.Calls provider in order to retrieve a list of calls from a certain contact, based on the contact's display name. In particular, I use this query:

String selection = CallLog.Calls.CACHED_NAME + "= ?";       
String dispName = dataCollector.getDisplayName();
Cursor callCursor = 
    cr.query(callLogUri, callLogProjection, selection, 
              new String[] {dispName},CallLog.Calls.DATE + " DESC");

The dataCollector object is used to hold information from queries based on a given contact id. The problem is that this code only returns one call for the given contact. I can't understand why. Any clues?


Solution

  • int i=0;
    while(cursor.moveToNext())
    {       
    Sring id = cursor.getString(cursor.getColumnIndex(CallLog.Calls._ID));
    numbersTemp[i]=cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
    valuesTemp[i]=cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
    i++;
    }