Android - Alarm Manager and DST changes

31 Views Asked by At

I use an alarm manager to create repeating alarms (at a specific time) and exact alarms (at a time that changes from day to day).

The problem occurs when there's a DST start or finish:

  • For my repeating alarms, they can go for example from 8AM to 7AM and stay like this until the next DST change
  • For my exact alarms, since I reschedule them after each notification, the alarm of the DST change is wrong: the 28th of October, I had an alarm at 7AM (GMT+2), when the notification fired, I had to reschedule an alarm for the day after, the 29th at 6AM (GMT+1). But since I rescheduled it when the phone was still in GMT+2, it didn't work, because the notification fired at 7AM on the 29th.

I understood that the value in milliseconds that I use in the alarm methods is in UTC, so how can I deal with these changes (in repeating and in exact alarms)?

I created a BroadcastReceiver, but I don't think it fires all the time, and I didn't see it fire for the DST change.

Here's the receiver:

<receiver
    android:name=".TimeChangeReceiver" android:enabled="true" android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.TIME_SET" />
        <action android:name="android.intent.action.DATE_CHANGED" />
        <action android:name="android.intent.action.TIMEZONE_CHANGED" />
    </intent-filter>
</receiver>
public class TimeChangeReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, Intent intent) {
        setAllAlarms(context);
    }
}
0

There are 0 best solutions below