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);
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.
If I understood the problem wrong please give me a detailed description. For all options in the CalenderContracts check this link.
EDIT:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With