views:

405

answers:

3

Hi all!

I'm trying to implement my first android Program. It should write calendar entries (I know, not the best task to begin programming Andorid).

I've tried:

Uri CALENDAR_URI = Uri.parse("content://calendar/events");
ContentResolver cr = getContentResolver();
cr.delete(CALENDAR_URI, null, null); // Delete all
cr.delete(CALENDAR_URI, "calendar_id=1", null); // Delete all in default calendar
cr.delete(CALENDAR_URI, "_id=1", null); // Delete specific entry

Nothing worked. I allays get a "cannot delete that URL".

Inserting an Calendar Entry was simple:

ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", this.title);
values.put("allDay", this.allDay);
values.put("dtstart", this.dtstart.toMillis(false));
values.put("dtend", this.dtend.toMillis(false));
values.put("description", this.description);
values.put("eventLocation", this.eventLocation);
values.put("visibility", this.visibility);
values.put("hasAlarm", this.hasAlarm);

cr.insert(CALENDAR_URI, values);

According to my insert method accessing the calendar worked.

Thanks, Arthur!

+1  A: 

The right way to delete things out of a user's calendar is to use the appropriate GData APIs and delete it from their Google Calendar. Manipulating the Calendar application's content provider -- as you are trying to do -- is not part of the public API.

CommonsWare
I've also read about it. I want to implement something like described in this question: http://stackoverflow.com/questions/846942/is-there-a-way-to-access-the-calendars-entries-without-using-gdata-java-client
Arthur
+2  A: 

OK, one thing I didn't try:

Uri CALENDAR_URI = Uri.parse("content://calendar/events");
int id = 1; // calendar entry ID
Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id);
cr.delete(uri, null, null);

This is what I was missing:

Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id);

should lead to content://calendar/events/1

Now my Calendar is empty :-)

Arthur
A: 

can u plz share the complete code to delete specific rows. Thanks

parul
This is the complete code. Only the deceleration of CALENDER_URI was not copied from the question
Arthur
Thanks for ur prompt answer.this is the code i'm trying to add:: Uri CALENDAR_URI = Uri.parse("content://calendar/events"); ContentResolver cr = mContext.getContentResolver();int id = 1; // calendar entry ID Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id); cr.delete(uri, null, null); but donno wat is "ContentUris"?thnx..
parul