在我的应用程序中,我使用此代码获取所有通话记录。它会返回我的Android手机中的所有通话记录。

public class CallLogHelper {

    public static Cursor getAllCallLogs(ContentResolver cr) {
        // reading all data in descending order according to DATE
        String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
        Uri callUri = Uri.parse("content://call_log/calls");
        Cursor curCallLogs = cr.query(callUri, null, null, null, strOrder);
        return curCallLogs;
    }

    public static void insertPlaceholderCall(ContentResolver contentResolver,
            String name, String number) {
        ContentValues values = new ContentValues();
        values.put(CallLog.Calls.NUMBER, number);
        values.put(CallLog.Calls.DATE, System.currentTimeMillis());
        values.put(CallLog.Calls.DURATION, 0);
        values.put(CallLog.Calls.TYPE, CallLog.Calls.OUTGOING_TYPE);
        values.put(CallLog.Calls.NEW, 1);
        values.put(CallLog.Calls.CACHED_NAME, name);
        values.put(CallLog.Calls.CACHED_NUMBER_TYPE, 0);
        values.put(CallLog.Calls.CACHED_NUMBER_LABEL, "");
        Log.d("Call Log", "Inserting call log placeholder for " + number);
        contentResolver.insert(CallLog.Calls.CONTENT_URI, values);
    }

}

但我的问题是,我想从特定的日期获取通话记录,而不是所有的通话记录。我不知道如何使用查询从特定日期获取调用日志。
帮帮我谢谢

最佳答案

        String[] strFields = {
                android.provider.CallLog.Calls.NUMBER,
                android.provider.CallLog.Calls.TYPE,
                android.provider.CallLog.Calls.CACHED_NAME,
                android.provider.CallLog.Calls.DATE,
                android.provider.CallLog.Calls.DURATION,

                };

        // Defines a string to contain the selection clause
        String mSelectionClause = android.provider.CallLog.Calls.DATE+ " >= ?";

        // Initializes an array to contain selection arguments
        String[] mSelectionArgs = { createDate(2013,1,1).toString() };

        Cursor mCallCursor = currentContext.getContentResolver().query(
                android.provider.CallLog.Calls.CONTENT_URI,
                strFields,
                mSelectionClause,
                mSelectionArgs,
                null
                );

        return mCallCursor;

public static Long createDate(int year, int month, int day)
{
    Calendar calendar = Calendar.getInstance();

    calendar.set(year, month, day);

    return calendar.getTimeInMillis();

}

08-16 13:10