CalendarContract Events : bad id inserted, Calendar corrupted in Android

让人想犯罪 __ 提交于 2020-01-16 05:52:01

问题


I made a mistake on testing insert Events using CalendarContract.

I set my own _ID in a Events insert.

values.put(Events._ID, "156498713465");

Now, all my new events are created with a bad id (for exemple -535191590).

When I click to the event in the Google Calendar Application, it crash.

I have the same error as this thread : Calendar corrupted in Android

I tried to delete all bad events :

activity.getContentResolver().delete(Events.CONTENT_URI, Events._ID + " > ? ", 
new String[] { "10000" });

But when a new events are inserted, a bad id is generated.

My question is : Where can I reset the Events Id sequence ?

Thanks, Regards


回答1:


Don't set the id; the following will do what you want:

ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();

values.put (Events.CALENDAR_ID, Long.toString(newCalendarId));
values.put (Events.DTSTART, dtStart);
values.put (Events.DTEND, dtEnd);
values.put (Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
values.put (Events.TITLE, title);
Uri uri = cr.insert (Events.CONTENT_URI, values); 

// The returned uri will contain the eventId assigned by Events.


来源:https://stackoverflow.com/questions/20104817/calendarcontract-events-bad-id-inserted-calendar-corrupted-in-android

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