Jeet PRAJAPATI
Jeet PRAJAPATI

Reputation: 43

How To update Event of Calendar Programmatically in Android?

i am creating an android application in which i want to update existing Calendar event programmatic-ally. so please help me following is the code of update event

ContentResolver cr = getActivity().getContentResolver();
ContentValues values = new ContentValues();
values.put (Events.CALENDAR_ID, 1);
values.put (Events.TITLE, titles);
values.put (Events.DTSTART, dtstart);
values.put (Events.DTEND, dtend);
int count = cr.update (Events.CONTENT_URI, values, Events._ID+" = "+eventId, null);

its not working please give me suggestion to solve it thanks

Upvotes: 2

Views: 2386

Answers (1)

Arjun Prakash
Arjun Prakash

Reputation: 691

private int UpdateCalendarEntry(int entryID) {
    int iNumRowsUpdated = 0;

    ContentValues event = new ContentValues();

    event.put("title", "Changed Event Title");
    event.put("hasAlarm", 1); // 0 for false, 1 for true

    Uri eventsUri = Uri.parse(getCalendarUriBase()+"events");
    Uri eventUri = ContentUris.withAppendedId(eventsUri, entryID);

    iNumRowsUpdated = getContentResolver().update(eventUri, event, null,
            null);

    Log.i(DEBUG_TAG, "Updated " + iNumRowsUpdated + " calendar entry.");

    return iNumRowsUpdated;
}

Upvotes: 2

Related Questions