filter.addAction(ACTION_MIDNIGHT);
registerReceiver(mIntentReceiver, filter);
+ // Listen for updates to weather data
+ Uri weatherNotificationUri = new Uri.Builder()
+ .scheme(android.content.ContentResolver.SCHEME_CONTENT)
+ .authority(WEATHER_CONTENT_AUTHORITY)
+ .path(WEATHER_CONTENT_PATH)
+ .build();
+ getContentResolver().registerContentObserver(
+ weatherNotificationUri, true, mContentObserver);
+
+ // Elaborate mechanism to find out when the day rolls over
Calendar today = Calendar.getInstance();
+ today.set(Calendar.HOUR_OF_DAY, 0);
+ today.set(Calendar.MINUTE, 0);
+ today.set(Calendar.SECOND, 0);
today.add(Calendar.DATE, 1);
+ long alarmTimeUTC = today.getTimeInMillis() + today.get(Calendar.ZONE_OFFSET);
mMidnightIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_MIDNIGHT), 0);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
- am.setRepeating(AlarmManager.RTC, today.getTimeInMillis(), AlarmManager.INTERVAL_DAY, mMidnightIntent);
+ am.setRepeating(AlarmManager.RTC, alarmTimeUTC, AlarmManager.INTERVAL_DAY, mMidnightIntent);
+ if (DEBUG) Log.d(LOG_TAG, "set repeating midnight event at "
+ + alarmTimeUTC + " repeating every "
+ + AlarmManager.INTERVAL_DAY + " with intent: " + mMidnightIntent);
// un-dim when resuming
mDimmed = false;