阅读所有使用CalendarContract今天的事件 - 安卓4.0+ [英] Reading all of today's events using CalendarContract - Android 4.0+

查看:838
本文介绍了阅读所有使用CalendarContract今天的事件 - 安卓4.0+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Android的新日历API来读取所有今天的日历事件。我很难找到合适的选择上的数据库查询返回的所有事件。似乎所有的经常性和全天的活动留出了选择。什么选择的args会允许我从日历API获得所有今天的事件?

I'm trying to use Android's new calendar API to read all of today's calendar events. I'm have trouble finding the right selection on the database query to return all of the events. It seems that all recurring and all day events are left out of the selection. What selection args would permit me to obtain all of today's events from the calendar api?

下面是我当前的尝试:

    Cursor cur = null;
    String selection = "((" + CalendarContract.Events.DTSTART
            + " >= ?) AND (" + CalendarContract.Events.DTEND + " <= ?))";
    Time t = new Time();
    t.setToNow();
    String dtStart = Long.toString(t.toMillis(false));
    t.set(59, 59, 23, t.monthDay, t.month, t.year);
    String dtEnd = Long.toString(t.toMillis(false));
    String[] selectionArgs = new String[] { dtStart, dtEnd };
    cur = c.getContentResolver().query(CalendarContract.Events.CONTENT_URI,
            null, selection, selectionArgs, null);

我不确定如何拓宽选择或增加它来获得经常性活动和全天事件。任何帮助将是AP preciated。

I am unsure of how to broaden the selection or adding to it to get the recurring events and all day events. Any help would be appreciated.

推荐答案

要获取所有事件的今天,包括经常性的事件,你需要使用的实例表,即

To get all events today, including recurring events, you need to use the Instances table, i.e.

Uri.Builder eventsUriBuilder = CalendarContract.Instances.CONTENT_URI
            .buildUpon();
ContentUris.appendId(eventsUriBuilder, timeNow);
ContentUris.appendId(eventsUriBuilder, endOfToday);
Uri eventsUri = eventsUriBuilder.build();
Cursor cursor = null;       
cursor = mContext.getContentResolver().query(eventsUri, columns, null, null, CalendarContract.Instances.DTSTART + " ASC");

请注意,您必须附加的时间限制到事件的URI,你不能排序任何其他方式。

Note that you must append the time constraints to the events uri, you cannot sort any other way.

为了包括所有的全天活动,以及,刚刚展开搜索到晚上11:59的previous夜间和上午12:00在今晚。

In order to include all day events as well, just expand the the search to 11:59PM the previous night and 12:00AM tonight.

这篇关于阅读所有使用CalendarContract今天的事件 - 安卓4.0+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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