Search code examples
androidcalllog

Android call log reading


Hello guys I am facing a problem when I read the CallLog the values of the number are 0 and when I read for example the cached name its 2 here is my code and I put the permission

         String[] fields = {
    android.provider.CallLog.Calls.NUMBER, 
    android.provider.CallLog.Calls.TYPE,
    android.provider.CallLog.Calls.CACHED_NAME,
    android.provider.CallLog.Calls.CACHED_NUMBER_TYPE
    };
String order = android.provider.CallLog.Calls.DATE + " DESC"; 

Cursor c = getContentResolver().query(
    android.provider.CallLog.Calls.CONTENT_URI,
    fields,
    null,
    null,
    order
    );

if(c.moveToFirst()){


  do{

//the problem was here                //System.out.println(c.getColumnIndex(android.provider.CallLog.Calls.NUMBER)+" - - "); 

//the solution is :$
System.out.println(c.getString(c.getColumnIndex(android.provider.CallLog.Calls.NUMBER))+" - - "); 

  } while (c.moveToNext());

}

and I have read all the related questions on stackoverflow I figured it out so I will keep the question if any one faced it I was dump :S


Solution

  • Depends on phone, also not all/any columns are required to be filled in. Up to carrier/manufacturer/whomever else wants to write to the table. But yes the question fix would do it