我尝试读出所有现有的日历。
我想要一个包含所有标题和帐户的 HashMap。有人可以帮我吗?这是我的尝试。在 LogCat 中,我看到了所有日历。
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;
}