How to get Call Log data of the last one hour only?

Viewed 19

I want to access call log of only the past one hour so how can i implement these, I have successfully accessed all calllog's but I only want to access the past one hour call log data only? is it possible?

my code to get all Calllog's

public void getCallDetails() {
        ContentResolver cr = getContentResolver();
        Cursor cursorCallLogs = cr.query(CallLog.Calls.CONTENT_URI,
                PROJECTION, null, null, CallLog.Calls.DATE + " DESC");
        if (cursorCallLogs != null) {
            try {
                final int nameIndex = cursorCallLogs.getColumnIndex(CallLog.Calls.CACHED_NAME);
                final int numberIndex = cursorCallLogs.getColumnIndex(CallLog.Calls.NUMBER);
                final int durationIndex = cursorCallLogs.getColumnIndex(CallLog.Calls.DURATION);
                final int TypeIndex = cursorCallLogs.getColumnIndex(CallLog.Calls.TYPE);
                final int DateIndex = cursorCallLogs.getColumnIndex(CallLog.Calls.DATE);

                String name, number, duration, type;

                String dir = null;
                while (cursorCallLogs.moveToNext()) {
                    name = cursorCallLogs.getString(nameIndex);
                    number = cursorCallLogs.getString(numberIndex);
                    duration = cursorCallLogs.getString(durationIndex);
                    type = cursorCallLogs.getString(TypeIndex);
                    Date date = new Date(cursorCallLogs.getLong(DateIndex));

                    int dircode = Integer.parseInt(type);
                    switch (dircode) {
                        case CallLog.Calls.OUTGOING_TYPE:
                            dir = "OUTGOING";
                            break;
                        case CallLog.Calls.INCOMING_TYPE:
                            dir = "INCOMING";
                            break;

                        case CallLog.Calls.MISSED_TYPE:
                            dir = "MISSED";
                            break;
                    }
                  
                }
            } finally {
                cursorCallLogs.close();
            }
        }
    }
0 Answers
Related