I try to read out all existing calendars.
I want have a HashMap with all titles, accounts in it. Can somebody help me please? This is my try. In the LogCat I see all calendars.
public HashMap<String, String> readCalendar(Context context) {
String[] EVENT_PROJECTION = new String[] {
Calendars.ACCOUNT_NAME,
Calendars.CALENDAR_DISPLAY_NAME
};
Cursor managedCursor = null;
HashMap<String, String> calendars = new HashMap<String, String>();
Uri calendarUri = CalendarContract.Calendars.CONTENT_URI;
ContentResolver cr = context.getContentResolver();
managedCursor = cr.query(calendarUri, EVENT_PROJECTION, null, null, null);
if (managedCursor != null && managedCursor.moveToFirst()) {
do {
// here I see all accounts and names in the LogCat
for (int i = 0; i < managedCursor.getColumnCount(); i++) {
Log.i(LOG_TAG, managedCursor.getColumnName(i) + "="
+ managedCursor.getString(i));
}
String title = managedCursor.xxxxxx; // I don't know how
String account = managedCursor.xxxxx; // I don't know how
calendars.put(title, account);
} while (managedCursor.moveToNext());
managedCursor.close();
} else {
Log.i(LOG_TAG, "No Calendars");
}
return calendars;
}
It seems you are looking for column names in the Calendars table. They are described in the API (the Calendar Columns section). The calls might look like this (if these are columns you want):