0
我正在開發一個android應用程序,它使用ContentResolver以編程方式將一些事件添加到用戶的默認日曆。Android日曆自定義事件顏色不斷變爲默認(藍色)
我也根據事件的類型設置事件的顏色(在我的情況下:假日綠色,工作日紅色)。這工作正常,但幾分鐘後所有的自定義着色變成藍色(默認谷歌日曆事件顏色)。我使用Nexus 5X進行調試。任何想法如何解決這個問題?
截圖: 以前
後
代碼:
// add work day event
if (DateFrom > today.getTimeInMillis() && WorkType == '0') {
ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, DateFrom);
values.put(CalendarContract.Events.DTEND, DateTo);
values.put(CalendarContract.Events.TITLE, Team + " (Id: " + Id + ")");
values.put(CalendarContract.Events.DESCRIPTION, "Work Day.");
values.put(CalendarContract.Events.CALENDAR_ID, DEFAULT_CALENDAR_ID);
values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().toString());
values.put(CalendarContract.Events.EVENT_COLOR, Color.RED);
Uri eventUri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
}
// add day off event
if (DateFrom > today.getTimeInMillis() && WorkType == '2' && IsApproved != null && IsApproved.equals("true")) {
ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.ALL_DAY, 1);
values.put(CalendarContract.Events.DTSTART, DateFrom + 3600000);
values.put(CalendarContract.Events.DURATION, "P23H");
values.put(CalendarContract.Events.TITLE, "Day Off!" + " (Id: " + Id + ")");
values.put(CalendarContract.Events.DESCRIPTION, "Day Off");
values.put(CalendarContract.Events.EVENT_COLOR, Color.GREEN);
values.put(CalendarContract.Events.CALENDAR_ID, DEFAULT_CALENDAR_ID);
values.put(CalendarContract.Events.HAS_ALARM, false);
values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().toString());
Uri eventUri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
}