Update Calendar event - Android Android OS

Android examples for Android OS:Calendar Event

Description

Update Calendar event

Demo Code


import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Events;
import android.provider.CalendarContract.Reminders;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;

public class Main{
    /** The main/basic URI for the android events table */
    private static final Uri EVENT_URI = CalendarContract.Events.CONTENT_URI;
    /**/*from w  w w  .j ava  2s.c  o  m*/
     * Update event
     */
    public static void updateEvent(CalendarRequest crx) throws Exception {
        ContentResolver cr = crx.getContext().getContentResolver();
        ContentValues values = new ContentValues();
        values.put(Events.TITLE, crx.getTitle());
        values.put(Events.DESCRIPTION, crx.getDescription());
        values.put(Events.EVENT_LOCATION, crx.getLocation());
        String selection = "(" + Events._ID + " = ?)";
        String[] selectionArgs = new String[] { String.valueOf(crx
                .getEventID()) };
        cr.update(buildEventUri(crx.getAccountName()), values, selection,
                selectionArgs);
    }
    /** Builds the Uri for events (as a Sync Adapter) */
    private static Uri buildEventUri(String accountName) {
        return EVENT_URI
                .buildUpon()
                .appendQueryParameter(
                        CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                .appendQueryParameter(Calendars.ACCOUNT_NAME, accountName)
                .appendQueryParameter(Calendars.ACCOUNT_TYPE,
                        CalendarContract.ACCOUNT_TYPE_LOCAL).build();
    }
}

Related Tutorials