0

我想删除所有日历条目。我正在使用此查询来获取日历条目

Uri uri = Uri.parse("content://com.android.calendar/events");
cursor =  context.getContentResolver().query(uri, null, null,null, null);

但是游标每次都返回null。我也检查过 Uri uri = Uri.parse("content://calendar/events"); 但结果是一样的。

请帮忙。

提前致谢。

4

2 回答 2

0

问题是作为 URI 一部分的日历授权。在 API 级别 14 之前它不是标准化的。如果您的目标是 8 级及更高级别com.android.calendar,Google 的代码建议您这样做,但手机制造商可能会使用其他权限。在 API 8 之前,权限是公正的calendar(如上一个答案中使用的)。

还要记住授予写入用户日历的权​​限。

当您删除事件时,请记住同时删除它们的扩展属性、提醒和警报。以下是他们的路径:

private static final String calendarPath = "calendars";
private static final String eventsPath = "events";
private static final String remindersPath = "reminders";
private static final String calAlertsPath = "calendar_alerts";
private static final String eventsExtPropPath = "extendedproperties";

对于 API 级别 14,这是标准化的,您可以从以下位置获取 URI CalendarContract

    CalendarContract.Calendars.CONTENT_URI;
    CalendarContract.Events.CONTENT_URI;
    CalendarContract.Reminders.CONTENT_URI;
    CalendarContract.CalendarAlerts.CONTENT_URI;
    CalendarContract.ExtendedProperties.CONTENT_URI;
于 2012-10-22T14:02:56.817 回答
0

//试试这个请求android:minSdkVersion="7"

public void deleteAllCalendar(){
        Log.i(TAG, "In deleteAllCalendar()");
        String strUriEvents = "content://calendar/events";
        Uri uri_calendar = Uri.parse(strUriEvents);
        String str_column_name = "_id";
        String[] projection = {str_column_name};
        int columnIndex = 0;
        String str_id = "";
        Vector<String> vector_id = new Vector<String>();
        int delRow = 0;
        String where = "";
        try {
            Cursor cursor = cr.query(uri_calendar, projection, null, null, null);
            if(cursor.moveToFirst()){
                do{
                    columnIndex = cursor.getColumnIndex(str_column_name);
                    str_id = cursor.getString(columnIndex);
                    vector_id.add(str_id);
                }while(cursor.moveToNext());
            }
            cursor.close();
            for(int i=0; i<vector_id.size(); i++){
                str_id = vector_id.get(i);
                where = str_column_name+"="+str_id;
                delRow = cr.delete(uri_calendar, where, null);
                Log.i(TAG, "deleteAllCalendar(),delRow:"+delRow);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            Log.e(TAG, "deleteAllCalendar(),Exception");
            e.printStackTrace();
        }
        Log.i(TAG, "Out deleteAllCalendar()");
    }
于 2012-10-22T13:44:26.527 回答