簡體   English   中英

有沒有辦法從 android 應用程序中刪除谷歌日歷中的事件

[英]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 實現在日歷中設置提醒的相同過程嗎? 如果是這樣,我可以參考任何好的教程或演練嗎?

根據 此處的文檔,提醒沒有/包含 ID,因此您無法直接訪問它們。

目前,您可以將您的星標添加到已請求此功能的公共追蹤器

除了上述之外,我還發現了您可以嘗試的第三方工具

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM