Android: programmatically added event time is changed on daylight savings - android

When I add recurring event in android calendar programmatically it is changed by one hour when daylight savings time begin. It adds one hour at the end of March and subtracts one hour at the end of October.
So if I create an event that occurs every day at 8:00 am, at the end of Mart it will be shifted and will start at 9:00 am. It's like this until the end of October. At the end of October it shifts back and until the end of March it's at 8:00 am again.
To mention that the event has Events.EVENT_TIMEZONE and Events.EVENT_END_TIMEZONE set, and the calendar this event belongs to has Calendars.CALENDAR_TIME_ZONE set. All of these 3 are set to the same timezone.

I found the solution. The problem is that I added the time zone in format GMT+0100. I have to add time zones if format Europe/London.

Related

set repeated reminder that repeats every month

I am taking two dates from the user in my android code. I want to set reminder for every month which are in between those two dates.
If first date is : 1st jan 2015 and other date is 1st Feb 2016 then I want to set reminder for the 1st day every month in between these two dates. I tried using alarm manager but couldnt able to repeat alarm. Please help. thank you
One method might be to have your alarm receiver set the next alarm when it is called (e.g. it activates on 1 Jan 2015 and sets the next one for 1 Feb 2015), so you're always setting one ahead.
First you'll need to create 2 Calendar objects to store the dates to store the dates set by the user. Then proceed by either creating pending intents for each date in a for loop by incrementing the value of month. Assign all the pending intents to your AlarmManager and fire them with FLAG_ONE_SHOT.
Please provide your code so we could better understand your problem.

How to Handle repeated calendar event in android

I want to handle repeated Google calender events for changing phone mode to silent/general . Normal one time events are work properly but in the case of repeated events i can't get the ending date and time. Only get an predefined Ending time(Thu, 1 Jan 5:30:00 IST 1970). How to over come this problem.?
In CalendarContract, it is defined that for recurring event DTEND(end time) is null, but DURATION is defined.
Please refer to http://developer.android.com/reference/android/provider/CalendarContract.Events.html

android calendar event yearly repeating recurrence rule

I'm trying to add event in the calendar programatically. I want the event to repeat yearly, every first Monday in February for example. The rule I'm using is this:
FREQ=YEARLY;BYDAY=1MO;BYMONTH=2;INTERVAL=1;COUNT=11;
The problem is: if I create the event with starting date in January and set it to repeat every January, then it works fine.
But, If i create the event with starting date in other month other than February, and set it to repeat by the same rule, the event won't repeat on Monday but on some other day. That day is different depending in which month is the starting day of the event. It seems like it counts number of day because on the leap year the day is changed by one.
UPDATE:
I noticed that if I create an event as mentioned above the following happens: If I create the event for example in February and set to be repeated in March, the rule gets the number of days in month from the moth where the DTSTART of the event is set (February). So, if I create an event in February and set it to be repeated the last day in March it will be repeated every 28th March or 29th on leap years (instead of 31st as expected).
Another example: I create event with DTSTART in January 2013 and set it to be repeated every first Monday in February. It creates the event on the date in February 2013 that corresponds to the first Monday in January 2013, in this case that is 7th February (because 7th January is first Monday in January 2013). Every next year the event will be repeated on the first Thursday of February.
When adding the event DTSTART must be in the same month as the first occurrence of the event to avoid unwanted side effects
can you give more details in terms of what you have and what you expect:
BEGIN:VCALENDAR
PRODID:byhand
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:20130205T090000Z
UID:SO_14702482_2b
SUMMARY:SO_14702482_2b
DTSTART:20130104T090000Z
RRULE:FREQ=YEARLY;BYDAY=1MO;BYMONTH=2;INTERVAL=1;COUNT=11;
END:VEVENT
END:VCALENDAR
will occur (tested on 2 different platforms) #09h00Z on:
20130104,20130204,20140203, 20150202,20160201, 20170206,...
while
BEGIN:VCALENDAR
PRODID:byhand
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:20130205T090000Z
UID:SO_14702482_1b
SUMMARY:SO_14702482_1b
DTSTART:20130204T090000Z
RRULE:FREQ=YEARLY;BYDAY=1MO;BYMONTH=2;INTERVAL=1;COUNT=11;
END:VEVENT
END:VCALENDAR
will occur (here also tested) #09h00Z on:
20130204, 20140203, 20150202,20160201, 20170206,...
the main difference being that as RFC5545 specified, DTSTART is part of the occurences.

What does "-04:00" in Google Calendar's Event.Datetime mean?

No matter how I change the time zone of an Event in Google Calendar, there's always a "-04:00" string trailing behind the Start and End's DateTime attribute when pulled using the Google Calendar API on Android. What I do is I create an Event from the web and view the results on an Android emulator.
For example:
If I create an Event whose time zone is in Toronto, Canada (FYI, which is the Calendar's time zone), it will show
"dateTime" : "2012-04-25T10:00:00.000-04:00",
If I change it to Taipei, Taiwan, it will show
"dateTime" : "2012-04-24T22:00:00.000-04:00",
The hours change automatically, which is great for implementation, but what does that "-04:00" stand for? (FYI, Toronto's time zone is "GMT-05:00")
It's the UTC offset, telling you which time zone the event's time is being expressed in. That's probably coming from the time zone setting of the calendar. Toronto is currently at UTC-4:00, meaning it's four hours behind the UTC clock. So when you moved the event to Taipei, you kept it at the same local time (10 AM on the 25th), but the API expresses it in Toronto hours; i.e. the event will happen when it's 10 PM on the 24th in Toronto.
Toronto's time zone is GMT-5:00 (UTC and GMT are roughly equivalent) because without daylight savings, that's the offset. The API knows that Toronto is currently on daylight savings, though, and changes the offset accordingly.
It's also worth noting that this date/time format is ISO 8601 and is the usual way of representing time in APIs.

Repeat scheduled tasks on selected days in Android sdk alarm manager

I have tried to do this without bothering the experts and have read numerous threads here and on other sites. It is clearly my brain not understanding what needs to be done in order for this to work.
My goal is that the app allows the user to enter a time and one or more days in a week. All of the GUI side and storing of the dates and times I have done, however to get the alarm manager to repeat, lets say every Monday at 14:00 and then can send at 14:02 . I have used the java Calendar object to hold the times and days of the week or even used date and day of the week of the month. These are then , as needed, converted to milliseconds for it to be read in by the alarm manager.
I then have used either the alarm manager set or set repeat methods to repeat the event. All I am able to do is get it to occur once and then if I change the emulator date and time to another Monday nothing happens.
The GUI holds the hours and minutes in required variables and then these are used against the calendar objects.
The alarm manager calls a broadcast receiver for the event to occur.
Please can someone simply give an example on how to set specific days such as Monday , Wednesday Friday. I know that separate alarm managers are needed for each day and at the moment I have just focused on Monday as my main test.
Links viewed:
How can i Repeat the Alarm in android for only Monday, Tuesday and Friday
How to repeat the alarm for "n" days at a particular time
how to repeat alarm after 1 day in android
Managed to figure this out now and so follows my answer:
The following code calculates the remaining days between now and the day needed for the scheduled task. the variable whichday is passed via parameter from the method this code belongs to. In the understanding of this whichday represents days of the week 1 through to 7 where 1 is Sunday , 2 is Monday and so .
//This gets the current day of the week as of TODAY / NOW
int checkcurrentday = getcurtime.get(Calendar.DAY_OF_WEEK);
// This calculates the days between now and the day needed which is represented by whichday.
int numberofdays = Calendar.SATURDAY + whichday - checkcurrentday;
//Now add NOT set the difference of the days to your Calendar object
tMondayOn.add(Calendar.DATE, numberofdays);
Well, you need to first use the Java Calendar API (or Joda!) to figure out when the next monday is. Set the alarm to to that time in milliseconds then use setRepeating and pass in a long that represents the interval of one week.

Categories

Resources