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
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.
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.
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
...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With