我想查询CallLog数据库并根据指定的日期返回一些调用。例如,我希望能够从给定日期获取数据,即9月1日至今。
我通过调用:
查询数据库 Date d = new Date();
String strOrder = android.provider.CallLog.Calls.DATE + " > " + d.toString();
/* Query the CallLog Content Provider */
/*Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null,
null, null, strOrder);*/
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
Log.d(TAG, "Did not have permissions.");
return;
}
Cursor managedCursor = this.getContentResolver().query(CallLog.Calls.CONTENT_URI, null,
null, null, strOrder);
这给了我一个错误,但没有启动活动。
答案 0 :(得分:0)
由于您没有指定您收到的错误,我只能给您一个在我的代码中有效的示例:
String query = "( " + CallLog.Calls.DATE + " >= " + from +
" AND " + CallLog.Calls.DATE + " <= " + to + ")";
Cursor callsCursor = context.getContentResolver().query(
CallLog.Calls.CONTENT_URI,
null,
query,
null,
null,
CallLog.Calls.DATE + " DESC");
if (callsCursor != null) {
while (callsCursor.moveToNext()) {
String number = callsCursor.getString(callsCursor.getColumnIndex(CallLog.Calls.NUMBER));
int type = callsCursor.getInt(callsCursor.getColumnIndex(CallLog.Calls.TYPE));
long date = callsCursor.getLong(callsCursor.getColumnIndex(CallLog.Calls.DATE));
int duration = callsCursor.getInt(callsCursor.getColumnIndex(CallLog.Calls.DURATION));
// the rest of your code goes here
}
}
希望有所帮助