![](/img/trans.png)
[英]Can I write events to Google Calendar from my android application?
[英]Is there any way to delete events from google calendar from android application
我正在嘗試通過我的 android 應用程序在日歷中設置提醒。 我可以使用 contentValues 事件和提醒在谷歌日歷上完美地設置這些提醒。 但是,要刪除這些事件,我需要在已設置的位置設置 ID。 不知何故,我能夠在共享首選項中設置提醒時保存該 ID,然后稍后檢索它以刪除該事件。
ContentValues event = new ContentValues();
event.put(CalendarContract.Events.CALENDAR_ID,calendarId); //calendarId = 3 is the calendar id of my google account in current phone
event.put(CalendarContract.Events.TITLE,"Test");
event.put(CalendarContract.Events.DESCRIPTION,"TEST");
event.put(CalendarContract.Events.DTSTART,System.currentTimeMillis() + 300000);
event.put(CalendarContract.Events.DTEND,System.currentTimeMillis() + 305000);
event.put(CalendarContract.Events.HAS_ALARM,true);
event.put(CalendarContract.Events.EVENT_TIMEZONE, "UTC+05:30");
Uri uri = getContentResolver().insert(CalendarContract.Events.CONTENT_URI, event);
long eventId = Long.parseLong(uri.getLastPathSegment()); //event id to be saved in shared preferences, retrieved later to delete this reminder
ContentValues reminder = new ContentValues();
reminder.put(CalendarContract.Reminders.EVENT_ID, eventId);
reminder.put(CalendarContract.Reminders.MINUTES,1);
reminder.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
getContentResolver().insert(CalendarContract.Reminders.CONTENT_URI,reminder);
Toast.makeText(this, "Check Calendar", Toast.LENGTH_SHORT).show();
但是,如果用戶卸載應用程序,這些提醒不會被刪除,因為共享首選項將在卸載時被刪除。 如果用戶切換到新手機,同樣的問題會再次出現。 那么有沒有辦法檢索日歷中設置的提醒的ID?
還有一種方法可以通過谷歌日歷 api 實現在日歷中設置提醒的相同過程嗎? 如果是這樣,我可以參考任何好的教程或演練嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.