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));
    }

我可以在 4.0.x 中获得所有列名,但在 4.0.x 下只能获得 _id。我的代码怎么了?提前谢谢!

    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));
        } ...

上面的代码在 4.0.x 中运行良好,我猜数据库有一些差异?

@Anu,这是我的完整代码,如果发现有问题请告诉我:

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();
    }
}
4

2 回答 2

2

试试这个.....它对我有用......

   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));
         }   
于 2012-06-14T11:19:39.547 回答
1

不要忘记移动的位置Cursor

利用:

Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
while (c.moveToNext()) {
    Log.i(getClass().getName(), "retrieveCall(): " + c.getColumnName(i));
}
于 2012-06-14T10:27:06.783 回答