简体   繁体   English

有没有办法从 android 应用程序中删除谷歌日历中的事件

[英]Is there any way to delete events from google calendar from android application

I'm trying to set reminders in calendar from my android application.我正在尝试通过我的 android 应用程序在日历中设置提醒。 I am able to set those reminders perfectly on google calendars using contentValues event and reminders.我可以使用 contentValues 事件和提醒在谷歌日历上完美地设置这些提醒。 However to delete those events I need ID where it has been set.但是,要删除这些事件,我需要在已设置的位置设置 ID。 Somehow, I am able to save that ID while setting the reminder in shared preferences and then retrieve it later to delete that event.不知何故,我能够在共享首选项中设置提醒时保存该 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();

However if the user uninstalls the application those reminders wont get deleted as the shared preferences will be erased upon uninstallation.但是,如果用户卸载应用程序,这些提醒不会被删除,因为共享首选项将在卸载时被删除。 And if user switches to new phone, again the same issue will arise.如果用户切换到新手机,同样的问题会再次出现。 So is there a way to retrieve the IDs of the reminders set in calendar?那么有没有办法检索日历中设置的提醒的ID?

Also is there a way this same process of setting reminders in calendar can be achieved via google calendar api?还有一种方法可以通过谷歌日历 api 实现在日历中设置提醒的相同过程吗? If so is there any good tutorial or walkthrough that I can refer?如果是这样,我可以参考任何好的教程或演练吗?

As per the documentation here reminders do not have/include an ID so you can't access those directly.根据 此处的文档,提醒没有/包含 ID,因此您无法直接访问它们。

At the moment you can add your star to this Public Tracker where this feature has been requested.目前,您可以将您的星标添加到已请求此功能的公共追踪器

Aside from the above I found this third party tool you could try.除了上述之外,我还发现了您可以尝试的第三方工具

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM