title: AlarmManager: how to schedule a daily alarm and deal with time changes
body: <p>I need to set up an alarm daily at a given hour. I'm programming the alarm using <code>AlarmManager.RTC_WAKEUP</code>, so it uses the system time as reference. I'm setting the alarm to first execute at the desired hour, then to repeat daily:</p>
  
  <pre><code>    alarmManager.setRepeating(
          AlarmManager.RTC_WAKEUP,
          getTimestampToday("12:00"),
          AlarmManager.INTERVAL_DAY,
          pendingIntent
      );
  </code></pre>
  
  <p>The <code>getTimestampToday</code> method returns a long timestamp for today at the desired hour. It does so by obtaining the local date for today, then setting the desired hour, finally converting it back to a timestamp (which is UTC based).</p>
  
  <p>The problem here is the alarm should work according to the local time. So if the time changed after the alarm is scheduled (for instance, DST time change, or the user goes to a different country, or he changes the date, time or timezone manually), then the alarm will fire at the wrong local time the next time.</p>
  
  <p>Example:</p>
  
  <ol>
  <li>Alarm set to first fire at 8:00 AM, repeat daily (meaning 86400 seconds of interval).</li>
  <li>That night, an automatic DST time change happens at 3:00 AM, shifts the clock back to 2:00 AM.</li>
  <li>Next morning, the alarm fires at 7:00 AM, which is wrong.   </li>
  </ol>
  
  <p>The app is meant to be running for long periods of time (it is a kiosk app for corporate use only). I'm re-scheduling the alarms when the app starts, but this does not solve my problem, because the app can run for days without being restarted. I need to detect when the time changes to schedule the alarms again according to the new local time.</p>
  
  <p>I'm using this receiver:</p>
  
  <pre><code>    &lt;receiver android:name="foo.bar.receivers.TimeChangeReceiver" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.ACTION_TIMEZONE_CHANGED" /&gt;
              &lt;action android:name="android.intent.action.ACTION_TIME_CHANGED" /&gt;
              &lt;action android:name="android.intent.action.DATE_CHANGED"&gt;&lt;/action&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p>It detects the date change, but does not work with time changes nor time zone changes. (Tested it on a tablet running OS 4.0.3). It is really odd, because I can clearly see the events being broadcasted in logcat.</p>
  
  <p>So my questions:</p>
  
  <ul>
  <li>Why are the <code>ACTION_TIMEZONE_CHANGED</code> and <code>ACTION_TIME_CHANGED</code> events not being received by my BroadcastReceiver, and how could I solve it.</li>
  <li>Would these intents detect a DST time change as well?</li>
  <li>If not possible, is there a better approach to program alarms at local times and deal with time changes?</li>
  </ul>
  
  <p>Thanks in advance.</p>