无法读取的android日历编程周期性事件 [英] Cannot read recurring events from android calendar programmatically

查看:224
本文介绍了无法读取的android日历编程周期性事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照该链接的教程 - <一个href="http://jimblackler.net/blog/?p=151&cpage=2#comment-52767">http://jimblackler.net/blog/?p=151&cpage=2#comment-52767访问内部机器人日历数据库(即使它不正式由SDK支持)。它适用于所有项目,除了经常性的事件。光标根本不返回任何经常性的事件。有人可以帮助我在这里。以下是我的游标声明 -

 的String []投影=新的String [] {标题,说明,DTSTART,eventLocation};
    串选择=(CALENDAR_ID =+的calid +)和+(现在 - 窗口)
            +&LT; D​​TSTART和DTSTART&LT;+(现+(窗口));
    字符串排序顺序=DTSTART ASC;

    光标managedCursor = getCalendarManagedCursor(投影,选择,
            事件,排序顺序);

    私人光标getCalendarManagedCursor(字符串[]投影,
        串选择,路径字符串,字符串排序){
    乌里日历= Uri.parse(内容://日历/+路径);
    光标managedCursor = NULL;
    尝试 {
        managedCursor = getContentResolver()查询(日历,投影,
                选择,空,排序);
    }赶上(抛出:IllegalArgumentException E){
        Log.w(DEBUG_TAG,
                无法获得供应商的[+ calendars.toString()+]);
    }

    如果(managedCursor == NULL){
        // 再试一次
        日历= Uri.parse(内容://com.android.calendar/+路径);
        尝试 {
            managedCursor = getContentResolver()查询(日历,
                    投影,选择,空,排序);
        }赶上(抛出:IllegalArgumentException E){
            Log.w(DEBUG_TAG,
                    无法获得供应商的[+ calendars.toString()
                            +]);
        }`
 

解决方案

使用了实例表,如果你需要查找重复事件。

这些URI查询它是:

  • 实例/时/ * / * - 之间的所有情况下的两倍(毫秒)
  • 实例/ whenbyday / * / * - 两次之间的所有实例(天)
  • 实例/ groupbyday / * / * - 同 whenbyday ,而是由开始日期进行分组

在该表中的列的列表是:

  • _id - 该实例的ID
  • EVENT_ID - 事件它是从创建
  • 开始 - 开始时间(毫秒)
  • 结束 - 结束时间(毫秒)
  • 朝九特派 - 启动实例的一天
  • endday指定 - 实例的结束日
  • startMinute - 自午夜分钟(0..1440)
  • endMinute - 分钟从午夜开始

您还可以使用列从活动日历表。

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

例如:

 的String []投影=新的String [] {
        标题,说明,开始,eventLocation
};
串选择=CALENDAR_ID =+的calid;
字符串路径=实例/时/+(现在 - 窗)+/+(NOW +窗口);
字符串排序顺序=开始DESC;
光标managedCursor = getCalendarManagedCursor(
        投影,选择,路径,排序顺序);
 


编辑:看来谷歌传开来记录日历提供商。浏览到日历Providier |谷歌开发者了解更多信息。

I have followed the tutorial in this link - http://jimblackler.net/blog/?p=151&cpage=2#comment-52767 to access the internal android calendar database (even though it is not officially supported by the SDK). It works for all entries except for recurring events. The cursor does not return any recurring events at all. Can someone help me here. Following is my cursor declaration -

    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()
                            + "]");
        }`

解决方案

Use the Instances table if you need to locate recurring events.

The URIs for querying it are:

  • instances/when/*/* - All instances between two times (milliseconds)
  • instances/whenbyday/*/* - All instances between two times (days)
  • instances/groupbyday/*/* - Same as whenbyday, but grouped by the start day

The list of columns in that table are:

  • _id - The ID of this instance
  • event_id - The event it was created from
  • begin - Begin time (milliseconds)
  • end - End time (milliseconds)
  • startDay - Start day of instance
  • endDay - End day of instance
  • startMinute - Minutes since midnight (0..1440)
  • endMinute - Minutes since midnight

You can also use the columns from the Events and Calendar tables.

You can see an example on the same page that you linked: http://jimblackler.net/blog/?p=151

Example:

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);


Edit: It seems Google got around to document the Calendar Provider. Browse to Calendar Providier | Google Developers for more information.

这篇关于无法读取的android日历编程周期性事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆