How To update Event of Calendar Programmatically in Android?

江枫思渺然 提交于 2019-12-11 02:54:30

问题


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


回答1:


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;
}


来源:https://stackoverflow.com/questions/29507396/how-to-update-event-of-calendar-programmatically-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!