'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. 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?



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yancy Godoy