我的要求类似于“ OneCalendar”应用程序,但用户只能在一个方向(“应用程序到帐户”)添加事件。
我在Calendar Provider上进行了研究,但这只是给我打电话的帐户,却没有明确的方式将事件推送到该帐户,
以下是我获取帐户的代码(这不是OneCalendar App的结果。它还显示Outlook,Apple日历帐户)
private List<CalendarAccount> getAccountCalendars() {
Cursor cur = null;
ContentResolver cr = getContentResolver();
Uri uri = Calendars.CONTENT_URI;
cur = cr.query(uri, EVENT_PROJECTION, "", null, null);
List<CalendarAccount> calendarAccounts = new ArrayList<>();
// Use the cursor to step through the returned records
while (cur.moveToNext()) {
long calID = 0;
String displayName = null;
String accountName = null;
String ownerName = null;
String accountType = null;
@ColorInt int color = 0;
// Get the field values
calID = cur.getLong(0);
displayName = cur.getString(2);
accountName = cur.getString(1);
accountType = cur.getString(3);
ownerName = cur.getString(6);
color = cur.getInt(7);
CalendarX calendar = new CalendarX(calID, displayName, color);
calendar.setAccountType(accountType);
calendar.setAccountOwner(ownerName);
CalendarAccount calendarAccount = new CalendarAccount(accountName);
int index = calendarAccounts.indexOf(calendarAccount);
if (index != -1) {
calendarAccount = calendarAccounts.get(index);
} else {
calendarAccounts.add(calendarAccount);
}
calendarAccount.getCalendars().add(calendar);
}
return calendarAccounts;
}
任何可能具有类似功能的帮助或资源库,将不胜感激。谢谢!