3
    Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
    for (int i = 0; i < c.getColumnCount(); i++) {
        Log.i(getClass().getName(), "retrieveCall(): " + c.getColumnName(i));
    }

I can get all colume names in 4.0.x, but only got _id under 4.0.x. What 's the matter with my code? Thx in advance!

    Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
    for (int i = 0; i < c.getColumnCount(); i++) {
        Log.i(getClass().getName(), "retrieveCall(): " + c.getColumnName(i));
    }

    while (c.moveToNext()) {
        for (int i = 0; i < c.getColumnCount(); i++) {
            Log.i(getClass().getName(), "retrieveCall(): " + c.getColumnName(i) + " = " + c.getInt(i) + "/" + c.getString(i));
        } ...

code above works well in 4.0.x, I guess there are some differences of database?

@Anu, this is my complete code, please kindly tell me if you found somthing wrong:

private void retrieveCall()
{
    Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);

    if (c != null) {
        while (c.moveToNext()) {
            String number = c.getString(c.getColumnIndex("number"));
            String name = c.getString(c.getColumnIndex("name"));
            long date = c.getLong(c.getColumnIndex("date"));

            if (number.length() > 0) {
                LogDetail log = null;
                if (_callTable.containsKey(number)) {
                    log = (LogDetail) _callTable.get(number);
                    log.name = name;
                    log.date = date;
                    log.amount++;
                } else {
                    log = new LogDetail();
                    log.name = name;
                    log.date = date;
                    log.amount = 1;
                }
                _callTable.put(number, log);
            }
        }
        c.close();
    }
}
thecr0w
  • 2,148
  • 4
  • 33
  • 59

2 Answers2

2

try this ..... It worked for me...

   Cursor c1 = getContentResolver().query(CallLog.Calls.CONTENT_URI,null,null,null,null); 
  for(int i=0;i<c1.getColumnCount();i++){
    Log.i("Column name", ""+c1.getColumnName(i));
         }   
Anu
  • 552
  • 3
  • 9
  • even your code works fine... you donot need to include the while loop code only above code snippet will work – Anu Jun 14 '12 at 11:23
  • worked for you? I paste your code and run and print and got nothing but a single _id. is the bug of android? I tested those codes in 2.3.5: // ? { http://stackoverflow.com/questions/11031067/about-getcontentresolver-query-calllog Cursor c1 = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null); for (int i = 0; i < c1.getColumnCount(); i++) { Log.i("Column name test", "" + c1.getColumnName(i)); } // ? } – thecr0w Jun 16 '12 at 13:39
  • I 'm sorry, it 's the problem of my differentiation system. I use SQLite Manager to find that, the database name is not "contact.db" but "contact2.db"! Although ClearMaster still works fine, I think I should ignore it temporarily. – thecr0w Jun 18 '12 at 09:03
1

Don't forget to move the position of the Cursor

Use:

Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
while (c.moveToNext()) {
    Log.i(getClass().getName(), "retrieveCall(): " + c.getColumnName(i));
}
Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106
Ion Aalbers
  • 7,830
  • 3
  • 37
  • 50