在 Android 日历中插入重复事件

发布于 2024-12-23 22:05:34 字数 1211 浏览 0 评论 0原文

我有一个无法解决的问题。我设法将我的事件插入我的 Android 日历中,但我想让它们重复出现。例如生日。我希望他们每年重复一次。我有这个代码:

    final ContentResolver cr = ctx.getContentResolver();
    ContentValues cv = new ContentValues();
    cv.put("calendar_id", calIds[0]);
    cv.put("title", title);

    cv.put("rrule", "FREQ=YEARLY");
    cv.put("description", comment );
    Calendar start = Calendar.getInstance();
    start.set(2012, 0, 2, 8, 0, 0);

    Calendar end = Calendar.getInstance();
    end.set(2012, 0, 2, 9, 0, 0);

    long startTime = start.getTimeInMillis();       
    long endTime = end.getTimeInMillis();

    cv.put("dtstart", startTime);
    cv.put("dtend", endTime);
    //Insertion on the events of the calendar
    cr.insert(Uri.parse("content://com.android.calendar/events"), cv);

它插入我的事件,但它不会重复发生。我的意思是,我的活动出现在 2012 年 1 月 2 日,但 2013 年 1 月 2 日没有出现,2014 年也没有出现,依此类推。所以我在手机上打开我的日历并尝试编辑我的事件,我看到我应该选择它的发生的地方,它显示“2012 年 1 月 2 日”而不是“1 月 2 日”,如果要自定义的话应该如此我的活动来自我的手机。另一方面,如果我尝试从手机手动添加事件,它工作得很好(我的意思是我可以添加每年发生的事件)。 我注意到的另一件事是,如果我更改年份,例如我输入 2010 年而不是 2012 年,它会每年插入我的事件,直到我当前的日期。更准确地说,它在 2010 年 1 月 2 日插入一个事件,在 2011 年 2 月插入另一个事件,并在 2012 年 1 月 2 日停止(今天是 2012 年 1 月 2 日),在此日期之后,不再插入该日期的事件。 有人遇到过此类问题吗?欢迎任何帮助。谢谢你!

I have an issue that I can't solve. I managed to insert my events into my android calendar but I want to make them recurring. For birthdays for example. I want them to repeat yearly. I have this code :

    final ContentResolver cr = ctx.getContentResolver();
    ContentValues cv = new ContentValues();
    cv.put("calendar_id", calIds[0]);
    cv.put("title", title);

    cv.put("rrule", "FREQ=YEARLY");
    cv.put("description", comment );
    Calendar start = Calendar.getInstance();
    start.set(2012, 0, 2, 8, 0, 0);

    Calendar end = Calendar.getInstance();
    end.set(2012, 0, 2, 9, 0, 0);

    long startTime = start.getTimeInMillis();       
    long endTime = end.getTimeInMillis();

    cv.put("dtstart", startTime);
    cv.put("dtend", endTime);
    //Insertion on the events of the calendar
    cr.insert(Uri.parse("content://com.android.calendar/events"), cv);

It inserts my event but it doesn't do it recurring. I mean that my event appears on 2jan2012 but on 2jan2013 doesn't and neither does in 2014 and so on. So I opened my calendar on the phone and tried to edit my event and I saw that where I should select the occurence of it, there it shows "on 2 january 2012" not "on 2 january" as it should if it were to customize my event from my phone. On the other hand, if I try to add an event manually from my phone it works just fine( I mean I can add an event that occurs yearly).
Another thing that I have noticed is that if I change the year, for example I put 2010 instead of 2012 it inserts my events yearly until my current date. To be more precise, it inserts an event on 2jan2010, another for 2jan2011 and for 2jan2012 it stops(today is 2nd january 2012) and after this date there are no more events inserted for this date.
Has anyone experienced this type of problem? Any help is welcomed. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以酷 2024-12-30 22:05:34

听起来,您尝试添加的任何事件在当前日期之后都不会重复发生。

使用日历,手动插入具有特定标题(例如“测试”)的每年/每月/每周事件,该事件在当前日期之后重复出现。然后编写一个简单的方法来读取日历中当前的事件。检查标题“Test”并记录该事件的 ContentValues 内容 - 看看是否可以发现任何差异。

From what it sounds like, any events that you try to add doesn't recur past the current date.

Using the Calendar, manually insert a Yearly/Monthly/Weekly event with a specific title such as "Test", that recurs past the current date. Then write a simple method that reads in events currently in your Calendar. Check for the title "Test" and log the contents of the ContentValues for that event - see if you can spot any differences.

若水微香 2024-12-30 22:05:34

当它是重复事件时,在 ContentValues 中放置“duration”而不是“dtend”。

请参阅https://stackoverflow.com/a/13839548/3629966

Put 'duration' instead of 'dtend' in ContentValues when it's a recurring event.

Refer to https://stackoverflow.com/a/13839548/3629966

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文