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

发布于 2025-01-13 19:39:38 字数 1620 浏览 1 评论 0原文

我正在尝试从我的 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 来实现在日历中设置提醒的相同过程吗?如果是的话,有什么好的教程或演练可以参考吗?

I'm trying to set reminders in calendar from my android application. I am able to set those reminders perfectly on google calendars using contentValues event and reminders. However to delete those events I need ID where it has been set. Somehow, I am able to save that ID while setting the reminder in shared preferences and then retrieve it later to delete that event.

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?

Also is there a way this same process of setting reminders in calendar can be achieved via google calendar api? If so is there any good tutorial or walkthrough that I can refer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2025-01-20 19:39:38

根据此处的文档,提醒没有/包含 ID,因此您无法直接访问这些内容。

目前,您可以将您的星标添加到已请求此功能的公共跟踪器

除了上述内容之外,我还发现了您可以尝试的第三方工具

As per the documentation here reminders do not have/include an ID so you can't access those directly.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文