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

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?? screenshot1screenshot2

share|improve this question

This question had a bounty worth +50 reputation from Elizabeth that ended 18 secs ago. Grace period ends in 23 hours

This question has not received enough attention.


分享:
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.