Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove and Update existing Calendar Event

I am following this gist, to insert event into Calendar

How do I update existing Calendar Event, which i have inserted earlier using below code:

public void addToCalender() throws ParseException {

        ......

        ContentValues event = new ContentValues();
        event.put(CalendarContract.Events.CALENDAR_ID, calendarId[0]);
        event.put(CalendarContract.Events.TITLE, "Event Title");
        event.put(CalendarContract.Events.DESCRIPTION, "Event Description");
        event.put(CalendarContract.Events.EVENT_LOCATION, "Eevnt Location");
        event.put(CalendarContract.Events.DTSTART, startCalTime);
        event.put(CalendarContract.Events.DTEND, endCalTime);
        event.put(CalendarContract.Events.STATUS, 1);
        event.put(CalendarContract.Events.HAS_ALARM, 1);
        event.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());

        Uri insertEventUri = AddEventActivity.this.getContentResolver().insert(
                eventsUri, event);

        ContentValues reminders = new ContentValues();
        reminders.put(Reminders.EVENT_ID,
                Long.parseLong(insertEventUri.getLastPathSegment()));
        reminders.put(Reminders.METHOD, Reminders.METHOD_ALERT);
        reminders.put(Reminders.MINUTES, 10);

        AddEventActivity.this.getContentResolver().insert(remainderUri, reminders);
    }

I would like to know, How do I :

1. Remove existing event

2. Update existing event
like image 658
Oreo Avatar asked Jul 07 '15 09:07

Oreo


People also ask

Does deleting a calendar event delete it for everyone?

Tip: To delete an event, right-click the event. Then, click Delete. After you delete an event, it may take awhile before it's removed from people's calendars. If you delete an event that you don't own, for the event to remove from everyone's calendars, the event owner may need to delete the event.

How do I edit an event in Apple calendar?

Edit an event Change event details: Tap the event, tap Edit near the top right, then in the event details, tap a setting to change it, or tap in a field to type new information.


2 Answers

Here is how you can modify an event. Let's say its ID is eventID:

public void updateEvent(int eventID)
{
    ContentResolver cr = context.getContentResolver();
    Uri eventUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventID);
    ContentValues event = new ContentValues();
    event.put(CalendarContract.Events.TITLE, "new title");
    event.put(CalendarContract.Events.DESCRIPTION, "My cool event!");
    cr.update(eventUri, event, null, null);
}

To remove an event, you have two possibilities:

If you are a standard application: Use the previous code and replace all the event.put by this one:

event.put(CalendarContract.Events.DELETED, 1);

If you are the SyncAdapter of the calendar and want a real deletion (The previous method just says that the event should be deleted and the one that follows must be used once the calendar is being synced :

public deleteEvent(Uri eventUri)
{
    cr.delete(event, null, null);
}

Where eventUri is the Uri of the event obtained as shown previously from the event ID.

For all of the previous methods, if you get an exception about not being in a sync adapter, you can use this:

public static Uri asSyncAdapter(Uri uri, String account, String accountType)
{
    return uri.buildUpon()
            .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, account)
            .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, accountType)
            .build();
}

I hope this will help you.

Source: personnal code + http://developer.android.com/guide/topics/providers/calendar-provider.html

like image 147
minoru Avatar answered Sep 17 '22 19:09

minoru


...
Outlook in fact seems to respond to the rules defined in RFC 2446

In summary you have to specify

METHOD:REQUEST and ORGANIZER:xxxxxxxx

...
Please read the original answer by Tom Carter.

like image 22
UiMVbJHjZepHhMFVyvjl hcCABJpad Avatar answered Sep 19 '22 19:09

UiMVbJHjZepHhMFVyvjl hcCABJpad