Is it possible to remove the Android calendar event

后端 未结 4 1757
渐次进展
渐次进展 2021-01-28 00:14

I am using the Android calendar. How can I remove a calendar event using code? Is it possible?

For clarification, I would like to mention that I don\'t want a sync proce

4条回答
  •  忘了有多久
    2021-01-28 01:02

    A short way:

    Uri eventUri = Uri.parse("content://calendar/events");  // or "content://com.android.calendar/events" 
    
    
    Cursor cursor = contentResolver.query(eventUri, new String[]{"_id"}, "calendar_id = " + calendarId, null, null); // calendar_id can change in new versions 
    
    while(cursor.moveToNext()) {
        Uri deleteUri = ContentUris.withAppendedId(eventUri, cursor.getInt(0));
    
        contentResolver.delete(deleteUri, null, null);
    }
    

提交回复
热议问题