1

I am bit new to calendar. Can anybody suggest me how to get events (eg. birthday/meetings reminder) from default calendar (not google calendar or any other only default calendar) and display it in listview/recyclerview in our application?

psiyumm
  • 6,437
  • 3
  • 29
  • 50
Vikash Kumar
  • 395
  • 5
  • 17

1 Answers1

0

This SO question describes reading and writing to the calendar. The key information you need to read the calendar(s) is:

Uri uri = CalendarContract.Calendars.CONTENT_URI;
String[] projection = new String[] {
   CalendarContract.Calendars._ID,
   CalendarContract.Calendars.ACCOUNT_NAME,
   CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
   CalendarContract.Calendars.NAME,
   CalendarContract.Calendars.CALENDAR_COLOR
};

Cursor calendarCursor = managedQuery(uri, projection, null, null, null);

Then you need to extract the data from the cursor:

ArrayList<String> ids = new ArrayList<String>();
try {
        if (cursor.getCount() > 0) {
            while (cursor.moveToNext()) {
                String id= cursor.getString(0);
                calendars.add(id);  
            }
        }
    } catch (AssertionError ex) { /*TODO: log exception and bail*/ }

Then you have the ids and need to query each one for events. This is described in the accepted answer to this SO question. Also this github repository has a solution. Most of these approaches only work on versions of Android greater than 4.2.

Community
  • 1
  • 1
hack_on
  • 2,532
  • 4
  • 26
  • 30