在Android上删除日历活动

时间:2013-12-31 10:16:01

标签: android android-layout android-intent calendar android-contentprovider

我已经参考这个问题实现了android Calendar事件 - How to add calendar events in Android?

以下是我用于向日历添加新事件的代码

public void onClick(View v) {
    // TODO Auto-generated method stub

    String date = etMyTextB.getText().toString();
    String time = "9:00 am";
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");

    try {
        Date dt = df.parse(date + " " + time);
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(System.currentTimeMillis());
        cal.clear();
        cal.setTime(dt);            

        Intent calIntent = new Intent(Intent.ACTION_EDIT);
        calIntent.setType("vnd.android.cursor.item/event");

        calIntent.putExtra("beginTime", cal.getTimeInMillis());
        calIntent.putExtra("allDay", true);
        calIntent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
        calIntent.putExtra("title", "Revenue Licence Renewal Date");
        startActivity(calIntent);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

我没有使用Content Providers因为我需要Android 2.x.x的支持。我的问题是如何以程序方式删除使用上述代码添加的事件?

1 个答案:

答案 0 :(得分:1)

检查此链接并告诉我这是否有效:

http://android-codes-examples.blogspot.com.es/2011/02/insertion-and-deletion-of-calendar.html

希望它有所帮助!