这是我为检索事件而实现的:
if (Integer.parseInt(Build.VERSION.SDK) >= 8 || Integer.parseInt(Build.VERSION.SDK) <= 13 ) {
uri = "content://com.android.calendar/events";
CALENDAR_URI = Uri.parse(uri);
} else if(Integer.parseInt(Build.VERSION.SDK) >= 14){
CALENDAR_URI = CalendarContract.Events.CONTENT_URI;
}
else {
uri = "content://calendar/events";
CALENDAR_URI = Uri.parse(uri);
}
Cursor cursors = context.getContentResolver().query(CALENDAR_URI, new String[]{ "_id", "title", "description", "dtstart", "dtend", "eventLocation" },
null,null, null);
cursors.moveToFirst();
String[] CalNames = new String[cursors.getCount()];
int[] CalIds = new int[cursors.getCount()];
for (int i = 0; i < CalNames.length; i++) {
CalIds[i] = cursors.getInt(0);
CalNames[i] = "Event"+cursors.getInt(0)+": \nTitle: "+ cursors.getString(1)+"\nDescription: "+cursors.getString(2)+"\nStart Date: "+new Date(cursors.getLong(3))+"\nEnd Date : "+new Date(cursors.getLong(4))+"\nLocation : "+cursors.getString(5);
Date mDate = new Date(cursors.getLong(3));
Date nDate = new Date(cursors.getLong(4));
long mTime = mDate.getTime();
long lTime = nDate.getTime();
if(stTime <= mTime && enTime >= lTime){
String eid = cursors.getString(0);
int eID = Integer.parseInt(eid);
String desc = cursors.getString(2);
String title = cursors.getString(1);
在这种情况下,你的stTime将是你的dtstart,而enTime将是你的dtend.