我正在创建一个Android应用程序,我希望以编程方式更新现有的Calendar事件。所以请帮帮我 以下是更新事件的代码
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);
它不起作用请给我建议解决它 感谢
答案 0 :(得分:2)
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;
}