Uninstall calendar software in android

I searched the Internet many times and many examples. I can successfully add an event to the calendar through my application, but I cannot delete this event programmatically. Here are the samples that I tried that I cannot get a successful result.

tokens [1] is the identifier of the event.
1)

Uri eventsUri = Uri.parse(getCalendarUriBase()+"events"); Uri eventUri = ContentUris.withAppendedId(eventsUri, Long.parseLong(tokens[1])); getContentResolver().delete(eventUri, null, null); 

2)

  ContentResolver cr = FlightOperationsCancelTicketFee.this.getContentResolver(); Uri EVENTS_URI = Uri.parse("content://com.android.calendar/" + "events"); deleteEvent(cr, EVENTS_URI, 1); private void deleteEvent(ContentResolver resolver, Uri eventsUri, int calendarId) { Cursor cursor; if (android.os.Build.VERSION.SDK_INT <= 7) { cursor = resolver.query(eventsUri, new String[]{ "_id" }, "Calendars_id=" + calendarId, null, null); } else { cursor = resolver.query(eventsUri, new String[]{ "_id" }, "calendar_id=" + calendarId, null, null); } while(cursor.moveToNext()) { long eventId = cursor.getLong(cursor.getColumnIndex("_id")); resolver.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null); } cursor.close(); } 

3)

  ContentResolver cr = getContentResolver(); String calUriString = "content://com.android.calendar/events"; Uri cal=Uri.parse(calUriString); String[] EVENT_PROJECTION=new String[]{"calendar_id","title","dtstart","_id"}; Uri eventsUri = Uri.parse(getCalendarUriBase()+"events"); Uri eventUri =ContentUris.withAppendedId(eventsUri, Long.parseLong(tokens[1])); String reminderUriString = "content://com.android.calendar/reminders"; Uri remUri =Uri.parse(reminderUriString); cr.delete(remUri, "event_id="+Commons.event_id, null); cr.delete(eventUri, null, null); 

4)

  Uri eventsUri = Uri.parse(getCalendarUriBase()+"events"); Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, Long.parseLong(tokens[1])); getContentResolver().delete(eventUri, null, null); 

None of the above actions work. I need help. Thanks .. Edit: I think I can not send the correct context, is there a way to save the context using general settings? However, it only stores the values โ€‹โ€‹of String and Int. Is there any other way to do something like this?

+4
source share
3 answers

Use this code, it worked for me:

  Uri deleteUri = null; deleteUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, Long.parseLong(String.valueOf(eventID))); int rows = getContentResolver().delete(deleteUri, null, null); Toast.makeText(this, "Event deleted", Toast.LENGTH_LONG).show(); 
+2
source

The best documentation on this subject is here: http://developer.android.com/guide/topics/providers/calendar-provider.html

But you basically do this from the book in (1).

My suggestion is to first make sure that you have the correct identifier, a second test on another device, etc. Also check if you can get the event again after deleting it.

0
source

You must add events to the calendar with different _id, since calander_id acts as a primary key. Therefore, if you want a particular record to be deleted, just give this identifier the delete command.

0
source

Source: https://habr.com/ru/post/1485622/


All Articles