Вопрос

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

Это было полезно?

Решение

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.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top