允许用户删除以编程方式插入的事件android

时间:2014-06-06 01:44:11

标签: android events calendar

我有这种方法以编程方式添加日历事件:

@SuppressLint("NewApi") private void Insert event (){
    long calID = 3;
    long startMillis = 0; 
    long endMillis = 0;     
    Calendar beginTime = Calendar.getInstance();
    beginTime.set(2014, 5, 10, 12, 00);
    startMillis = beginTime.getTimeInMillis();
    Calendar endTime = Calendar.getInstance();
    endTime.set(2014, 5, 10, 13, 00);
    endMillis = endTime.getTimeInMillis();

    ContentResolver cr = getContentResolver();
    ContentValues values = new ContentValues();
    values.put(Events.DTSTART, startMillis);
    values.put(Events.DTEND, endMillis);
    values.put(Events.ALL_DAY, true);
    values.put(Events.TITLE, "Title");
    values.put(Events.DESCRIPTION, "Description");
    values.put(Events.CALENDAR_ID, calID);
    values.put(Events.EVENT_LOCATION, "MyLocation");
    values.put(Events.EVENT_TIMEZONE, "America/Los_Angeles"); //Montevideo
    values.put(Events.GUESTS_CAN_MODIFY, true);
    Uri uri = cr.insert(Events.CONTENT_URI, values);        
}

但是如果我进入日历应用程序,我就无法删除该事件。我需要从事件值更改为让用户删除事件吗?

1 个答案:

答案 0 :(得分:1)

问题是下一行

long calID = 3;

该日历ID来自不允许我删除事件的日历(来自hotmail的同步日历)。只需将该行更改为:

long calID = 1;

就是这样