在Google日历Android中添加从开始日期到结束日期之间的所有日期的事件 [英] Adding Events for all days between start date and end date in google calendar Android

查看:142
本文介绍了在Google日历Android中添加从开始日期到结束日期之间的所有日期的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google日历Android中为开始日期和结束日期之间的所有天添加活动.我想每3个月剩余一次,直到结束日期. 这是我的功能

Adding Events for all days between start date and end date in google calendar Android. i want remainder every 3 months till end date. This is my function

    public void addEvent1(Context ctx, String title){
            SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy");
            SimpleDateFormat df3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", java.util.Locale.getDefault());
            Date Startdate = null;
            Date Enddate =null;
            String dtStart = date.getText().toString();
            try {
                Startdate = df2.parse(dtStart);
                Enddate = df2.parse(stringMaturityDate);
                Log.v("SDate: ",""+ df3.format(Startdate));
                Log.v("EDate: ",""+ df3.format(Enddate));
            } catch(ParseException e){
                e.printStackTrace();
            }
            Calendar cali = Calendar.getInstance();
            cali.setTime(Startdate);


            Calendar cali2 = Calendar.getInstance();
            cali2.setTime(Enddate);

            SimpleDateFormat yyyymmdd = new SimpleDateFormat("yyyyMMdd");
            Calendar dt = Calendar.getInstance();


            dt.setTime(Enddate);

            String dtUntill = yyyymmdd.format(dt.getTime());

            ContentResolver contentResolver = ctx.getContentResolver();

            ContentValues calEvent = new ContentValues();
            calEvent.put(CalendarContract.Events.CALENDAR_ID, 1); // XXX pick)
            calEvent.put(CalendarContract.Events.TITLE, title);
            calEvent.put(CalendarContract.Events.RRULE, "FREQ=MONTHLY;INTERVAL=3;UNTIL=" + dtUntill);
            calEvent.put(CalendarContract.Events.DTSTART, cali.getTimeInMillis());
            calEvent.put(CalendarContract.Events.DTEND, cali2.getTimeInMillis());

            calEvent.put(CalendarContract.Events.EVENT_TIMEZONE, "" + java.util.Locale.getDefault());



            Uri uri = contentResolver.insert(CalendarContract.Events.CONTENT_URI, calEvent);


                int id = Integer.parseInt(uri.getLastPathSegment());
               Toast.makeText(ctx, "Created Calendar Event " + id,
                       Toast.LENGTH_SHORT).show();
 ContentValues reminders = new ContentValues();
        reminders.put(CalendarContract.Reminders.EVENT_ID, id);
        reminders.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
        reminders.put(CalendarContract.Reminders.MINUTES, 10);

        Uri uri1 = contentResolver.insert(CalendarContract.Reminders.CONTENT_URI, reminders);
        }

此功能每天都会添加事件.如何删除它.我只需要余数,我的代码有什么问题吗?

this function adds events every day. How to remove that. I need only remainder.Is there any anything wrong in my code??

推荐答案

如果我正确阅读了所有内容,则您希望每棵树月进行一整天的日历项目.您是否尝试添加此行?

If I read everything correctly you want a calendar item every tree months for one full day. Have you tried adding this line?

contentValues.put(CalendarContract.EXTRA_EVENT_ALL_DAY, true);

并已将一个日历项目的结束日期更改为当前年末,而这应该是当前项目的结束日期. DTEND是当前项目的结尾DURATION是重现模式的结尾.

And changed the end date of one calendar item is currrently set to the end of the year while this should be the end date of the current item. DTEND is the end of the current item DURATION is the end of the reoccuring patern.

如果我理解错误的问题,请给我详细说明.对于CalenderContracts中的所有选项,请检查此链接.

If I understood the problem wrong please give me a detailed description. For all options in the CalenderContracts check this link.

您希望每天进行日历约会,但每三个月提醒用户一次.对于您的代码,当前无法实现此操作,因为您要为每个具有该ID的日历项添加提醒(因此每天).我能想到的唯一简单的解决方案是创建一个单独的约会,并使用另一个ID,您每三个月重复一次,并附带一个提醒和一个不同的ID.当前无法为某些具有相同ID的事件和不具有相同ID的事件设置警报.

You want a calendar appointment for each day but remind the user every three months. With your code this is not currently possible as you are adding a reminder for every calender item with that id (so for every day). Only easy solution what I can think of is creating a separate appointment with an other id that you repeat every three months with an reminder and a different id. It is not currently possible to set an alarm for some events with the same id and some not.

这篇关于在Google日历Android中添加从开始日期到结束日期之间的所有日期的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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