'RRULE in android
I am trying to set weekly monday reminder in calendar at 9 a.m. Following is the code
final int[] preTimings = {9, 12, 18};
Calendar calendar = Calendar.getInstance(Locale.getDefault());
ContentValues newEvent = new ContentValues();
int month = calendar.get(Calendar.MONTH);
int date = calendar.get(Calendar.DATE);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DATE, date);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
for(int i = 0; i < preTimings.length; i++{
calendar.set(Calendar.HOUR_OF_DAY, preTimings[i]);
long timeInMillis = calendar.getTimeInMillis();
newEvent.put(CalendarContract.Events.CALENDAR_ID, 1);
newEvent.put(CalendarContract.Events.TITLE, preTitle[i]);
newEvent.put(CalendarContract.Events.DTSTART, timeInMillis);
newEvent.put(CalendarContract.Events.DTEND, timeInMillis + 60000);
newEvent.put(CalendarContract.Events.RRULE, "FREQ=WEEKLY;BYDAY=MO");
newEvent.put(CalendarContract.Events.HAS_ALARM, true);
newEvent.put(CalendarContract.Events.EVENT_TIMEZONE, "GMT-05:30");
So this program is setting the 12 p.m and 6 p.m correctly on Mondays every week but for some reason it is setting the 9 a.m on Tuesdays every week. I don't know what is wrong over here. I even tried converting the timeInMillis in an online calculator to know what is the result, but they are correct.
Solution 1:[1]
So the issue was on the last line, even though i have specifically declared the timezone, it was setting it incorrectly.
So instead of
newEvent.put(CalendarContract.Events.EVENT_TIMEZONE, "GMT-05:30");
It should be
newEvent.put(CalendarContract.Events.EVENT_TIMEZONE, String.valueOf(TimeZone.getTimeZone("UTC")));
Still no idea why it worked for times 11 a.m and above. Kinda weird
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aagam Shah |
