These examples are for version <= 2.1;
first; find out which calendars exist
Cursor cursor = cr.query(Uri.parse("content://calendar/calendars"), new String[]{ "_id", "displayname" }, null, null, null); cursor.moveToFirst(); String[] CalNames = new String[cursor.getCount()]; int[] CalIds = new int[cursor.getCount()]; for (int i = 0; i < CalNames.length; i++) { CalIds[i] = cursor.getInt(0); CalNames[i] = cursor.getString(1); cursor.moveToNext(); } cursor.close();
Receiving all events, and a specific event is performed by specifying a range
ContentResolver contentResolver = getContentResolver() ;
Uri.Builder builder = Uri.parse(getCalendarUriBase() + "/instances/when").buildUpon(); long now = new Date().getTime(); ContentUris.appendId(builder, now - DateUtils.MILLIS_PER_DAY*10000); ContentUris.appendId(builder, now + DateUtils.MILLIS_PER_DAY * 10000);
and then say that you want to register the event ID from the calendar with ID = 1
Cursor eventCursor = contentResolver.query(builder.build(), new String[] { "event_id"}, "Calendars._id=" + 1, null, "startDay ASC, startMinute ASC"); // For a full list of available columns see http://tinyurl.com/yfbg76w while (eventCursor.moveToNext()) { String uid2 = eventCursor.getString(0); Log.v("eventID : ", uid2); }
bbaja42
source share