List of usage examples for android.app AlarmManager setInexactRepeating
public void setInexactRepeating(@AlarmType int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)
From source file:info.papdt.blacklight.support.Utility.java
public static void startServiceAlarm(Context context, Class<?> service, long interval) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, service); PendingIntent p = PendingIntent.getService(context, REQUEST_CODE, i, PendingIntent.FLAG_CANCEL_CURRENT); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, interval, p); }
From source file:de.hero.vertretungsplan.MainActivity.java
public static void setNewAlarm(Context context, boolean set, String interval) { Intent i = new Intent(context, de.hero.vertretungsplan.CheckForUpdates.class); PendingIntent pi = PendingIntent.getService(context, 0, i, 0); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.cancel(pi); // cancel any existing alarms Log.d("MainActivity", "cancelAlarm"); if (set) {/*from w w w . j av a 2 s.c om*/ long lngInterval; switch (interval) { case "1/2": lngInterval = AlarmManager.INTERVAL_HALF_HOUR; break; case "1": lngInterval = AlarmManager.INTERVAL_HOUR; break; case "6": lngInterval = AlarmManager.INTERVAL_HALF_DAY / 2; break; case "3": default: lngInterval = AlarmManager.INTERVAL_HOUR * 3; break; } Log.d("MainActivity", "setAlarm " + interval + " Stunden"); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR / 3, lngInterval, pi); // For debugging after 10 seconds // am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, // SystemClock.elapsedRealtime() + 25000 , // AlarmManager.INTERVAL_HOUR , pi); } }
From source file:nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver.java
public AlarmReceiver() { Context context = GBApplication.getContext(); Intent intent = new Intent("DAILY_ALARM"); intent.setPackage(BuildConfig.APPLICATION_ID); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, new Intent("DAILY_ALARM"), 0); AlarmManager am = (AlarmManager) (context.getSystemService(Context.ALARM_SERVICE)); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + 10000, AlarmManager.INTERVAL_DAY, pendingIntent); }
From source file:edu.mit.media.realityanalysis.fieldtest.MainPipeline.java
@Override public void onCreate() { super.onCreate(); String password = getDataPassword(this); // If the user hasn't logged in yet, we need to stop the service // NOTE: this currently doesn't work properly because we're just using the default password (changeme) if (password == null || password == "") { Intent loginIntent = new Intent(this, LoginActivity.class); startActivity(loginIntent);/* ww w.j a v a 2s . c om*/ this.stopSelf(); } else { setEncryptionPassword(getDataPassword(this).toCharArray()); } //Setup the notification service to run periodically Intent notificationIntent = new Intent(this, NotificationService.class); PendingIntent notificationPendingIntent = PendingIntent.getService(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), AlarmManager.INTERVAL_HALF_HOUR, notificationPendingIntent); }
From source file:de.schildbach.wallet.service.BlockchainService.java
public static void scheduleStart(final WalletApplication application) { final Configuration config = application.getConfiguration(); final long lastUsedAgo = config.getLastUsedAgo(); // apply some backoff final long alarmInterval; if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS) alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES; else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS) alarmInterval = AlarmManager.INTERVAL_HALF_DAY; else// ww w. j a va 2 s . co m alarmInterval = AlarmManager.INTERVAL_DAY; log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes", lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS); final AlarmManager alarmManager = (AlarmManager) application.getSystemService(Context.ALARM_SERVICE); final PendingIntent alarmIntent = PendingIntent.getService(application, 0, new Intent(application, BlockchainService.class), 0); alarmManager.cancel(alarmIntent); // workaround for no inexact set() before KitKat final long now = System.currentTimeMillis(); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY, alarmIntent); }
From source file:dess15proj5.fau.cs.osr_amos.mobiletimerecording.ui.MainActivity.java
/** * This method is used to initialize an alarm manager for this app. If the alarm is triggered, the app will check * whether it has to send a notification to the user reminding him to record for today. * * methodtype initialization method/* ww w .j a va 2 s .c om*/ */ private void setUpAlarmForNotifications() { Intent intent = new Intent(this, RecordingAlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, AccountingNotification.ALARM_ID, intent, 0); Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.set(Calendar.HOUR_OF_DAY, 20); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); }
From source file:net.peterkuterna.android.apps.devoxxfrsched.service.CfpSyncManager.java
/** * Set up the alarm./*from w w w . j a va 2s. co m*/ * * @param trigger * when the alarm should first trigger in milliseconds. */ public void setSyncAlarm(long trigger) { Log.d(TAG, "Setting up sync alarm"); final Context context = getContext(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final boolean doBackgroundUpdates = prefs.getBoolean(SettingsActivity.KEY_BACKGROUND_UPDATES, true); if (doBackgroundUpdates) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pi = getAlarmPendingIntent(); if (pi == null) { pi = createAlarmPendingIntent(); } am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + trigger, INTERVAL, pi); } }
From source file:org.kegbot.app.service.CheckinService.java
private void registerAlarm() { unregisterAlarm();/* w ww.j a va2 s. c om*/ Log.d(TAG, "Registering alarm."); final Intent intent = getCheckinIntent(this); mPendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); final AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); final long nextCheckin = SystemClock.elapsedRealtime() + CHECKIN_INTERVAL_MILLIS; alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextCheckin, CHECKIN_INTERVAL_MILLIS, mPendingIntent); }
From source file:com.gmail.at.faint545.fragments.QueueFragment.java
private void setRecurringAlarm() { if (getRemote().getRefreshInterval() != -1) { updateTime = Calendar.getInstance(); updateTime.setTimeZone(TimeZone.getTimeZone("GMT")); updateTime.set(Calendar.MINUTE, 1); Intent downloader = new Intent(getActivity(), AlarmReciever.class); downloader.putExtra("url", getRemote().buildURL()); downloader.putExtra("api", getRemote().getApiKey()); downloader.putExtra("messenger", new Messenger(handler)); PendingIntent recurringDownload = PendingIntent.getBroadcast(getActivity(), 0, downloader, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarms = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE); alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), getRemote().getRefreshInterval(), recurringDownload); } else {/*from ww w . j a v a2 s. c o m*/ downloadQueue(null); } }
From source file:de.hero.vertretungsplan.CheckForAppUpdate.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { boolean setTimer = intent.getBooleanExtra("setTimer", false); boolean checkNow = intent.getBooleanExtra("checkNow", false); Intent i = new Intent(this, de.hero.vertretungsplan.CheckForAppUpdate.class); i.putExtra("checkNow", true); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.cancel(pi);/* ww w.j a v a 2 s. c o m*/ Log.d("CheckForAppUpdate", "Alarm canceled"); if (setTimer) { long lngInterval = AlarmManager.INTERVAL_DAY * 7; Log.d("CheckForAppUpdate", "Alarm set"); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY * 6, lngInterval, pi); //For debugging: after 10 seconds //am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 25000 , AlarmManager.INTERVAL_HOUR , pi); } if (checkNow) { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) { try { new HtmlWorkAppUpdate(this).execute(new URI(getString(R.string.htmlAdresseAktuelleVersion))); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return START_NOT_STICKY; }