无法以编程方式从Android日历中读取重复发生的事件

Ani*_*ilV 7 android

我已按照此链接中的教程 - http://jimblackler.net/blog/?p=151&cpage=2#comment-52767访问内部安卓日历数据库(即使SDK未正式支持).它适用于除重复活动之外的所有条目.光标根本不会返回任何重复发生的事件.有人可以帮助我吗?以下是我的光标声明 -

    String[] projection = new String[] { "title", "description", "dtstart", "eventLocation" };
    String selection = "(calendar_id=" + calID + ")AND " + (now - window)
            + "<dtstart AND dtstart< " + (now + (window));
    String sortorder = "dtstart ASC";

    Cursor managedCursor = getCalendarManagedCursor(projection, selection,
            "events", sortorder);

    private Cursor getCalendarManagedCursor(String[] projection,
        String selection, String path, String sort) {
    Uri calendars = Uri.parse("content://calendar/" + path);
    Cursor managedCursor = null;
    try {
        managedCursor = getContentResolver().query(calendars, projection,
                selection, null, sort);
    } catch (IllegalArgumentException e) {
        Log.w(DEBUG_TAG,
                "Failed to get provider at [" + calendars.toString() + "]");
    }

    if (managedCursor == null) {
        // try again
        calendars = Uri.parse("content://com.android.calendar/" + path);
        try {
            managedCursor = getContentResolver().query(calendars,
                    projection, selection, null, sort);
        } catch (IllegalArgumentException e) {
            Log.w(DEBUG_TAG,
                    "Failed to get provider at [" + calendars.toString()
                            + "]");
        }`
Run Code Online (Sandbox Code Playgroud)

Mar*_*rot 16

Instances如果需要查找重复发生的事件,请使用该表.

查询它的URI是:

  • instances/when/*/* - 两次(毫秒)之间的所有实例
  • instances/whenbyday/*/* - 两次(天)之间的所有实例
  • instances/groupbyday/*/*- 相同whenbyday,但按开始日分组

该表中的列列表是:

  • _id - 此实例的ID
  • event_id - 它是从它创建的事件
  • begin - 开始时间(毫秒)
  • end - 结束时间(毫秒)
  • startDay - 实例的开始日期
  • endDay - 实例结束日
  • startMinute - 午夜(0..1440)
  • endMinute - 从午夜开始的几分钟

您还可以使用EventsCalendar表中的列.

您可以在链接的同一页面上看到一个示例:http://jimblackler.net/blog/?p = 151

例:

String[] projection = new String[] {
        "title", "description", "begin", "eventLocation"
};
String selection = "calendar_id = " + calID;
String path = "instances/when/" + (now - window) + "/" + (now + window);
String sortOrder = "begin DESC";
Cursor managedCursor = getCalendarManagedCursor(
        projection, selection, path, sortorder);
Run Code Online (Sandbox Code Playgroud)

编辑:谷歌似乎开始记录日历提供商.浏览到日历Providier | Google Developers了解更多信息.

  • 我会杀死一个代码片段来迭代重复的事件.以下是什么?`(现在 - 窗口)+"/"+(现在+窗口)`什么是现在和窗口?我甚至都看不到**getCalendarManagedCursor**来自哪里.简单阅读所有事件(包括最重要的RECURRING事件)的整个过程令人沮丧.大量的部分代码片段,伪代码和教程链接.最终,仍然无法显示反复发生的事件. (2认同)