RealCalendarModule.java 文件源码

java
阅读 33 收藏 0 点赞 0 评论 0

项目:TDList 作者:
public static int deleteEvent(ContentResolver resolver,String eventTitle){
    Uri eventsUri;

    Cursor cursor;

    int noOfEventsDeleted=0;

    /**
     * Following are the columns that can be used in the selection part
     * String[] COLS={"calendar_id", "title", "description", "dtstart", "dtend","eventTimezone", "eventLocation"};
     */

    int osVersion = android.os.Build.VERSION.SDK_INT;
    if (osVersion <= 7) { //up-to Android 2.1
        eventsUri = Uri.parse("content://calendar/events");
        cursor = resolver.query(eventsUri, new String[]{ "_id" }, "Calendars._id=" + CALENDAR_ID + " and Calendars.title='"+eventTitle+"' and description='"+description+"'" , null, null);
    } else { //8 is Android 2.2 (Froyo) (http://developer.android.com/reference/android/os/Build.VERSION_CODES.html)
        eventsUri = Uri.parse("content://com.android.calendar/events");
        cursor = resolver.query(eventsUri, new String[]{ "_id" }, "calendar_id=" + CALENDAR_ID + " and title='"+eventTitle+"' and description='"+description+"'" , null, null);
    }


    while(cursor.moveToNext()) {
        long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
        noOfEventsDeleted+=resolver.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null);
        Log.d("RealCalendarModule","title="+eventTitle+", eventId"+eventId);
    }
    cursor.close();
    return noOfEventsDeleted;

}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号