【问题标题】:How to delete a calendar entry?如何删除日历条目?
【发布时间】:2009-09-24 15:18:21
【问题描述】:

我正在尝试实现我的第一个 android 程序。它应该编写日历条目(我知道,这不是开始编写 Andorid 的最佳任务)。

我试过了:

Uri CALENDAR_URI = Uri.parse("content://calendar/events");
ContentResolver cr = getContentResolver();
cr.delete(CALENDAR_URI, null, null); // Delete all
cr.delete(CALENDAR_URI, "calendar_id=1", null); // Delete all in default calendar
cr.delete(CALENDAR_URI, "_id=1", null); // Delete specific entry

没有任何效果。我得到一个“无法删除该 URL”。

插入日历条目很简单:

ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", this.title);
values.put("allDay", this.allDay);
values.put("dtstart", this.dtstart.toMillis(false));
values.put("dtend", this.dtend.toMillis(false));
values.put("description", this.description);
values.put("eventLocation", this.eventLocation);
values.put("visibility", this.visibility);
values.put("hasAlarm", this.hasAlarm);

cr.insert(CALENDAR_URI, values);

根据我的插入方法访问日历有效。

谢谢,亚瑟!

【问题讨论】:

    标签: android calendar


    【解决方案1】:

    好的,我没有尝试过的一件事:

    Uri CALENDAR_URI = Uri.parse("content://calendar/events");
    int id = 1; // calendar entry ID
    Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id);
    cr.delete(uri, null, null);
    

    这就是我所缺少的:

    Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id);
    

    应该指向 content://calendar/events/1

    现在我的日历是空的:-)

    【讨论】:

      【解决方案2】:

      从用户日历中删除内容的正确方法是使用适当的 GData API 并将其从 Google 日历中删除。操作日历应用程序的内容提供者——正如您正在尝试做的那样——不是公共 API 的一部分。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      相关资源
      最近更新 更多