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