Deleting events from Calendar not being deleted

主宰稳场 提交于 2019-12-03 01:16:22

If its not a URI problem,

Can you try to include in the selection string

AND (deleted != 1)

so the selection string becomes,

String selection = "((" + "calendar_id" + " = 1) AND ("
    + "title" + " LIKE '"+name+"') AND ("
    + "dtstart" + " = "+String.valueOf(c.getTimeInMillis())+") AND ( deleted != 1 ) )";

Occasionally, the CalendarDB takes sometime for the events to be removed. But the 'deleted' COLUMN will be marked as '1' indicating that they will be deleted soon. The reason for the delay maybe the calendar is waiting to be synced

p.s: Try using this tool -- http://www.cellobject.net/Tools/CellObjectSQLiteXMLBrowser.aspx to visualize the Calendar DB. Please check for the 'deleted' and 'dirty' columns in the db

Different versions of android use different URI paths for looking up calendar data. For example, you could use the following constants for android 2.1 and 2.2:

private static final String URI_VERSION_2_1 = "content://calendar/events";
private static final String URI_VERSION_2_2 = "content://com.android.calendar/events";

In 4.0 an different method is preferred:

http://android-developers.blogspot.com/2011/10/ics-and-non-public-apis.html http://developer.android.com/reference/android/provider/CalendarContract.Events.html

There is a good chance that the Galaxy S3 has at least Android 4.0 on it. This change may account for the code working on an S1, but not an S3.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!