List of usage examples for android.app AlarmManager INTERVAL_HOUR
long INTERVAL_HOUR
To view the source code for android.app AlarmManager INTERVAL_HOUR.
Click Source Link
From source file:ca.zadrox.dota2esportticker.service.UpdateMatchService.java
private void scheduleAutoUpdates() { if (!PrefUtils.shouldAutoUpdate(this)) { return;/*from w w w. ja va 2 s .c o m*/ } final long currentTime = TimeUtils.getUTCTime(); final Intent updateMatchIntent = new Intent(UpdateMatchService.ACTION_AUTO_UPDATE_MATCHES, null, this, UpdateMatchService.class); final Intent updateResultIntent = new Intent(UpdateMatchService.ACTION_UPDATE_RESULTS, null, this, UpdateMatchService.class); final long matchUpdateTime = currentTime + (60000 * 60 * 12); final long resultUpdateTime = currentTime + (60000 * 60); PendingIntent umi = PendingIntent.getService(this.getApplicationContext(), 0, updateMatchIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent uri = PendingIntent.getService(this.getApplicationContext(), 0, updateResultIntent, PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); am.cancel(umi); am.cancel(uri); am.setInexactRepeating(AlarmManager.RTC, matchUpdateTime, AlarmManager.INTERVAL_HALF_DAY, umi); am.setInexactRepeating(AlarmManager.RTC, resultUpdateTime, AlarmManager.INTERVAL_HOUR, uri); }
From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java
public static long setUpdateAlarm(Context context, boolean initial) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent alarmintent = new Intent(context, AlarmReceiver.class); alarmintent.setAction(AlarmReceiver.ALARM_UPDATE); PendingIntent pendingintent = PendingIntent.getBroadcast(context, 0, alarmintent, 0); MyApp.LogDebug(LOG_TAG, "set update alarm"); long next_fetch; long interval; Time t = new Time(); t.setToNow();/* w ww. j av a 2 s. co m*/ long now = t.toMillis(true); if ((now >= MyApp.first_day_start) && (now < MyApp.last_day_end)) { interval = 2 * AlarmManager.INTERVAL_HOUR; next_fetch = now + interval; } else if (now >= MyApp.last_day_end) { MyApp.LogDebug(LOG_TAG, "cancel alarm post congress"); alarmManager.cancel(pendingintent); return 0; } else { interval = AlarmManager.INTERVAL_DAY; next_fetch = now + interval; } if ((now < MyApp.first_day_start) && ((now + AlarmManager.INTERVAL_DAY) >= MyApp.first_day_start)) { next_fetch = MyApp.first_day_start; interval = 2 * AlarmManager.INTERVAL_HOUR; if (!initial) { MyApp.LogDebug(LOG_TAG, "update alarm to interval " + interval + ", next in " + (next_fetch - now)); alarmManager.cancel(pendingintent); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, next_fetch, interval, pendingintent); } } if (initial) { MyApp.LogDebug(LOG_TAG, "set initial alarm to interval " + interval + ", next in " + (next_fetch - now)); alarmManager.cancel(pendingintent); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, next_fetch, interval, pendingintent); } return interval; }
From source file:io.indy.drone.activity.StrikeListActivity.java
private void setupAlarm() { // check a SharedPreferences variable to see if we've already setup an inexact alarm // otherwise the time until the next alarm will reset every time StrikeListActivity // is used.// w w w. j a v a 2 s .c o m // var: time that the alarm was last triggered // if this was 2-3 hours ago the alarm was cancelled and requires a reset boolean requireAlarm = false; Date today = new Date(); SharedPreferences settings = getSharedPreferences(ScheduledService.PREFS_FILENAME, 0); String alarmSetAt = settings.getString(ScheduledService.ALARM_SET_AT, ""); if (alarmSetAt.isEmpty()) { // first time of running // don't check the server straight away since the db // might still be populating from the local json file // // startService(new Intent(this, ScheduledService.class)); ifd("no alarm prefs found, assuming first time run, setting alarm"); requireAlarm = true; } else { ifd("alarmSetAt = " + alarmSetAt); Date d = DateFormatHelper.parseSQLiteDateString(alarmSetAt); long diffMs = today.getTime() - d.getTime(); long threeHours = 1000 * 60 * 60 * 3; if (diffMs > threeHours) { ifd("alarm was set more than 3 hours ago, and so requires a reset"); requireAlarm = true; } } if (!requireAlarm) { ifd("no need to set an alarm from StrikeListActivity"); return; } Intent intent = new Intent(this, ScheduledService.class); pi = PendingIntent.getService(this, 0, intent, 0); am = (AlarmManager) (this.getSystemService(Context.ALARM_SERVICE)); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HOUR, AlarmManager.INTERVAL_HOUR, pi); ifd("set alarm"); SharedPreferences.Editor editor = settings.edit(); editor.putString(ScheduledService.ALARM_SET_AT, DateFormatHelper.dateToSQLite(today)); editor.commit(); ifd("updated ALARM_SET_AT shared preference"); }