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:Main.java
private static long translateIntervalDesc(String intervalDesc) { switch (intervalDesc) { case "onceaminute": return 1000 * 60; case "onceahour": return AlarmManager.INTERVAL_HOUR; case "twiceaday": return AlarmManager.INTERVAL_HALF_DAY; case "onceaday": return AlarmManager.INTERVAL_DAY; case "onceaweek": return AlarmManager.INTERVAL_DAY * 7; default:/*www. j ava 2 s. c o m*/ return AlarmManager.INTERVAL_DAY; } }
From source file:com.licenta.android.licenseapp.alarm.AlarmReceiver.java
public static void setAlarm(Context context) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); /*//from w ww . jav a2 s. c om * If you don't have precise time requirements, use an inexact repeating alarm * the minimize the drain on the device battery. * * The call below specifies the alarm type, the trigger time, the interval at * which the alarm is fired, and the alarm's associated PendingIntent. * It uses the alarm type RTC_WAKEUP ("Real Time Clock" wake up), which wakes up * the device and triggers the alarm according to the time of the device's clock. * * Alternatively, you can use the alarm type ELAPSED_REALTIME_WAKEUP to trigger * an alarm based on how much time has elapsed since the device was booted. This * is the preferred choice if your alarm is based on elapsed time--for example, if * you simply want your alarm to fire every 60 minutes. You only need to use * RTC_WAKEUP if you want your alarm to fire at a particular date/time. Remember * that clock-based time may not translate well to other locales, and that your * app's behavior could be affected by the user changing the device's time setting. * */ // Wake up the device to fire the alarm in 30 minutes, and every 30 minutes // after that. long intervalMillis; String intervalVal = prefs.getString("repeat_interval", "0"); switch (intervalVal) { case "15": intervalMillis = AlarmManager.INTERVAL_FIFTEEN_MINUTES; break; case "30": intervalMillis = AlarmManager.INTERVAL_HALF_HOUR; break; case "60": intervalMillis = AlarmManager.INTERVAL_HOUR; break; default: intervalMillis = 0; break; } // for testing intervalMillis = 6000; alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + intervalMillis, intervalMillis, alarmIntent); prefs.edit().putBoolean(Constants.PREF_KEY_IS_ALARM_ON, true).apply(); Log.d(context.getClass().getName(), "Alarm started"); }
From source file:br.ajmarques.cordova.plugin.localnotification.Options.java
/** * Parst die bergebenen Eigenschaften./* w w w . j ava 2 s .c o m*/ */ public Options parse(JSONObject options) { String repeat = options.optString("repeat"); this.options = options; if (repeat.equalsIgnoreCase("hourly")) { interval = AlarmManager.INTERVAL_HOUR; } if (repeat.equalsIgnoreCase("daily")) { interval = AlarmManager.INTERVAL_DAY; } else if (repeat.equalsIgnoreCase("weekly")) { interval = AlarmManager.INTERVAL_DAY * 7; } else if (repeat.equalsIgnoreCase("monthly")) { interval = AlarmManager.INTERVAL_DAY * 31; // 31 days } else if (repeat.equalsIgnoreCase("yearly")) { interval = AlarmManager.INTERVAL_DAY * 365; } else { try { interval = Integer.parseInt(repeat) * 60000; } catch (Exception e) { } ; } return this; }
From source file:com.yeldi.yeldibazaar.UpdateService.java
public static void schedule(Context ctx) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); String sint = prefs.getString("updateInterval", "0"); int interval = Integer.parseInt(sint); Intent intent = new Intent(ctx, UpdateService.class); PendingIntent pending = PendingIntent.getService(ctx, 0, intent, 0); AlarmManager alarm = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); alarm.cancel(pending);//from w w w. j a va 2 s . c o m if (interval > 0) { alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 5000, AlarmManager.INTERVAL_HOUR, pending); Log.d("FDroid", "Update scheduler alarm set"); } else { Log.d("FDroid", "Update scheduler alarm not set"); } }
From source file:com.footprint.cordova.plugin.localnotification.Options.java
/** * Parses the given properties/* ww w . j a v a2 s .c o m*/ */ public Options parse(JSONObject options) { String repeat = options.optString("repeat"); this.options = options; if (repeat.equalsIgnoreCase("secondly")) { interval = 1000; } if (repeat.equalsIgnoreCase("minutely")) { interval = AlarmManager.INTERVAL_FIFTEEN_MINUTES / 15; } if (repeat.equalsIgnoreCase("hourly")) { interval = AlarmManager.INTERVAL_HOUR; } if (repeat.equalsIgnoreCase("daily")) { interval = AlarmManager.INTERVAL_DAY; } else if (repeat.equalsIgnoreCase("weekly")) { interval = AlarmManager.INTERVAL_DAY * 7; } else if (repeat.equalsIgnoreCase("monthly")) { interval = AlarmManager.INTERVAL_DAY * 31; // 31 days } else if (repeat.equalsIgnoreCase("yearly")) { interval = AlarmManager.INTERVAL_DAY * 365; } else { try { interval = Integer.parseInt(repeat) * 60000; } catch (Exception e) { } ; } return this; }
From source file:com.commontime.plugin.notification.notification.Options.java
/** * Parse repeat interval.//from www .j a v a2 s. c o m */ private void parseInterval() { String every = options.optString("every").toLowerCase(); if (every.isEmpty()) { interval = 0; } else if (every.equals("second")) { interval = 1000; } else if (every.equals("minute")) { interval = AlarmManager.INTERVAL_FIFTEEN_MINUTES / 15; } else if (every.equals("hour")) { interval = AlarmManager.INTERVAL_HOUR; } else if (every.equals("day")) { interval = AlarmManager.INTERVAL_DAY; } else if (every.equals("week")) { interval = AlarmManager.INTERVAL_DAY * 7; } else if (every.equals("month")) { interval = AlarmManager.INTERVAL_DAY * 31; } else if (every.equals("year")) { interval = AlarmManager.INTERVAL_DAY * 365; } else { try { interval = Integer.parseInt(every) * 60000; } catch (Exception e) { e.printStackTrace(); } } }
From source file:org.pixmob.freemobile.netstat.SyncService.java
public static void schedule(Context context, boolean enabled) { final Context appContext = context.getApplicationContext(); final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent syncIntent = PendingIntent.getService(appContext, 0, new Intent(appContext, SyncService.class), PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(syncIntent);/*from w w w .j a v a 2s . c o m*/ if (enabled) { // Set the sync period. long period = AlarmManager.INTERVAL_HOUR; final int syncErrors = context.getSharedPreferences(INTERNAL_SP_NAME, MODE_PRIVATE) .getInt(INTERNAL_SP_KEY_SYNC_ERRORS, 0); if (syncErrors != 0) { // When there was a sync error, the sync period is longer. period = AlarmManager.INTERVAL_HOUR * Math.min(syncErrors, MAX_SYNC_ERRORS); } // Add a random time to prevent concurrent requests for the server. final long fuzz = RANDOM.nextInt(1000 * 60 * 30); period += fuzz; if (DEBUG) { Log.d(TAG, "Scheduling synchronization: next in " + (period / 1000 / 60) + " minutes"); } final long syncTime = System.currentTimeMillis() + period; am.set(AlarmManager.RTC_WAKEUP, syncTime, syncIntent); } else { if (DEBUG) { Log.d(TAG, "Synchronization schedule canceled"); } } }
From source file:com.Candy.ota.settings.Settings.java
private void setUpdateInterval(int interval) { boolean enableUpdateCheck = true; switch (interval) { case 0://w w w . ja v a 2s. co m UpdateListener.interval = AlarmManager.INTERVAL_DAY; break; case 1: UpdateListener.interval = AlarmManager.INTERVAL_HALF_DAY; break; case 2: UpdateListener.interval = AlarmManager.INTERVAL_HOUR; break; case 3: enableUpdateCheck = false; break; } if (enableUpdateCheck) { SharedPreferences prefs = getSharedPreferences(LAST_INTERVAL, 0); prefs.edit().putLong(LAST_INTERVAL, UpdateListener.interval).apply(); WakefulIntentService.cancelAlarms(this); WakefulIntentService.scheduleAlarms(new UpdateListener(), this, true); } else { SharedPreferences prefs = getSharedPreferences(LAST_INTERVAL, 0); prefs.edit().putLong(LAST_INTERVAL, 1).apply(); com.Candy.ota.updater.ConnectivityReceiver.disableReceiver(this); WakefulIntentService.cancelAlarms(this); } }
From source file:com.slim.ota.settings.Settings.java
private void setUpdateInterval(int interval) { boolean enableUpdateCheck = true; switch (interval) { case 0:// w ww . j a v a 2 s. c o m UpdateListener.interval = AlarmManager.INTERVAL_DAY; break; case 1: UpdateListener.interval = AlarmManager.INTERVAL_HALF_DAY; break; case 2: UpdateListener.interval = AlarmManager.INTERVAL_HOUR; break; case 3: enableUpdateCheck = false; break; } if (enableUpdateCheck) { SharedPreferences prefs = getSharedPreferences(LAST_INTERVAL, 0); prefs.edit().putLong(LAST_INTERVAL, UpdateListener.interval).apply(); WakefulIntentService.cancelAlarms(this); WakefulIntentService.scheduleAlarms(new UpdateListener(), this, true); } else { SharedPreferences prefs = getSharedPreferences(LAST_INTERVAL, 0); prefs.edit().putLong(LAST_INTERVAL, 1).apply(); com.slim.ota.updater.ConnectivityReceiver.disableReceiver(this); WakefulIntentService.cancelAlarms(this); } }
From source file:org.pixmob.freemobile.netstat.SyncServiceTesting.java
public static void schedule(Context context, boolean enabled) { final Context appContext = context.getApplicationContext(); final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent syncIntent = PendingIntent.getService(appContext, 0, new Intent(appContext, SyncServiceTesting.class), PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(syncIntent);/*from ww w.j a va 2s. com*/ if (enabled) { // Set the sync period. long period = AlarmManager.INTERVAL_HOUR; final int syncErrors = context.getSharedPreferences(INTERNAL_SP_NAME, MODE_PRIVATE) .getInt(INTERNAL_SP_KEY_SYNC_ERRORS, 0); if (syncErrors != 0) { // When there was a sync error, the sync period is longer. period = AlarmManager.INTERVAL_HOUR * Math.min(syncErrors, MAX_SYNC_ERRORS); } // Add a random time to prevent concurrent requests for the server. final long fuzz = RANDOM.nextInt(1000 * 60 * 30); period += fuzz; if (DEBUG) { Log.d(TAG, "Scheduling synchronization: next in " + (period / 1000 / 60) + " minutes"); } final long syncTime = System.currentTimeMillis() + period; am.set(AlarmManager.RTC_WAKEUP, syncTime, syncIntent); } else { if (DEBUG) { Log.d(TAG, "Synchronization schedule canceled"); } } }