微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我已按照此链接中的教程 – http://jimblackler.net/blog/?p=151&cpage=2#comment-52767来访问内部的android日历数据库(即使它没有得到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,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,sort);
        } catch (IllegalArgumentException e) {
            Log.w(DEBUG_TAG,"Failed to get provider at [" + calendars.toString()
                            + "]");
        }`

解决方法

如果需要查找定期事件,请使用Instances表.

查询它的URI是:

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

该表中的列列表是:

> _id – 此实例的ID
> event_id – 从中​​创建的事件
>开始 – 开始时间(毫秒)
> end – 结束时间(毫秒)
> startDay – 实例的开始日期
> endDay – 实例结束日
> startMinute – 午夜分钟(0..1440)
> endMinute – 从午夜开始的分钟

您还可以使用“事件”和“日历”表中的列.

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

例:

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐