我在Marshmellow設備中使用以下代碼以事件編程方式將事件添加到日曆,但它不起作用。任何想法?我無法在日曆應用中看到此事件。以編程方式將事件添加到日曆
long startMillis = 0;
long endMillis = 0;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = null, endDate = null;
try{
startDate = simpleDateFormat.parse("2017-05-01 01:30:00");
startMillis = startDate.getTime();
endDate = simpleDateFormat.parse("2017-05-01 03:30:00");
endMillis = endDate.getTime();
}catch (ParseException e){
e.printStackTrace();
}
ContentResolver cr = this.getContentResolver();
ContentValues values = new ContentValues();
TimeZone timeZone = TimeZone.getDefault();
values.put(CalendarContract.Events.DTSTART, startMillis);
values.put(CalendarContract.Events.DTEND, endMillis);
values.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());
values.put(CalendarContract.Events.TITLE, "Hello Title");
values.put(CalendarContract.Events.DESCRIPTION, "Add events to Calendar");
values.put(CalendarContract.Events.CALENDAR_ID, 879);
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
PS:它的工作原理,如果只有一個Gmail帳戶與日曆應用程序同步。
任何錯誤,你越來越?閱讀此[回答](http://stackoverflow.com/questions/34959858/add-event-and-reminder-not-working-in-6-0-mahmahmallow) – Piyush
@Piyush沒有erros。 – Aniruddha
閱讀我分享的鏈接 – Piyush