Deleting events from Calendar not being deleted

后端 未结 3 742
一整个雨季
一整个雨季 2021-02-05 03:36

I am trying to make my App add reminders to the user\'s Calendar. The code searches for the title and start date to check if the event already exists i

3条回答
  •  轮回少年
    2021-02-05 04:06

    You can also do something like this:

    private boolean isEventInCal(Context context, String id) {
        Uri event = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, Long.parseLong(id));
    
        Cursor cursor = context.getContentResolver().query(event, null, null, null, null);
        if (cursor != null && cursor.getCount() == 1) {
            //the event exists?
            if (cursor.moveToFirst() && !TextUtils.equals(cursor.getString(cursor.getColumnIndex("deleted")), "1")) {
    
                cursor.close();
                return true;
            } else {
                return false;
            }
        }
        return false;
    }
    

    It works on all the devices.

提交回复
热议问题