List of usage examples for android.app AlarmManager setInexactRepeating
public void setInexactRepeating(@AlarmType int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)
From source file:com.chintans.venturebox.util.Utils.java
public static void setAlarm(Context context, long time, boolean trigger, boolean isRom) { Intent i = new Intent(context, NotificationAlarm.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pi = PendingIntent.getBroadcast(context, isRom ? ROM_ALARM_ID : GAPPS_ALARM_ID, i, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.cancel(pi);// w w w.j a v a 2 s . co m if (time > 0) { am.setInexactRepeating(AlarmManager.RTC_WAKEUP, trigger ? 0 : time, time, pi); } }
From source file:cn.apputest.ctria.service.UploadFailRecordService.java
public static void setServiceAlarm(Context context) { Log.i("ServiceUtil-AlarmManager", "invokeTimerPOIService wac called.."); PendingIntent alarmSender = null;//ww w .ja v a2 s . c o m Intent startIntent = new Intent(context, UploadFailRecordService.class); startIntent.setAction(Constants.POI_SERVICE_ACTION); try { alarmSender = PendingIntent.getService(context, 0, startIntent, PendingIntent.FLAG_UPDATE_CURRENT); } catch (Exception e) { Log.i("ServiceUtil-AlarmManager", "failed to start " + e.toString()); } AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), Constants.ELAPSED_TIME_F, alarmSender); }
From source file:Main.java
public static void setTimerReceiver(Context context, int repeat_time, Class<?> class_name) { AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intentReceiver = new Intent(context, class_name); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intentReceiver, PendingIntent.FLAG_CANCEL_CURRENT); Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, repeat_time / 1000); // InexactRepeating allows Android to optimize the energy consumption alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), repeat_time, pendingIntent); }
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);// w w w . j a v a2 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.twentyoneechoes.borges.util.Utils.java
public static void scheduleLibraryUpdateService(Context context) { if (isAlarmAlreadySet(context)) return;/* w w w .j av a 2 s . c o m*/ AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, LibraryUpdateService.class); PendingIntent alarmIntent = PendingIntent.getService(context, LIBRARY_UPDATE_REQUEST_CODE, intent, 0); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, AlarmManager.INTERVAL_HALF_HOUR, AlarmManager.INTERVAL_HALF_HOUR, alarmIntent); }
From source file:com.jerrellmardis.amphitheatre.util.Utils.java
public static void scheduleLibraryUpdateService(Context context) { Log.d("amp:Utils", "Checking if alarm is already set: " + isAlarmAlreadySet(context, LibraryUpdateService.class)); //And now/*from www . ja va2 s . co m*/ Log.d("amp:Utils", "Start rechecking the library"); Intent intent = new Intent(context, LibraryUpdateService.class); intent.putExtra("ALARM", true); /*context.startService(intent);*/ if (isAlarmAlreadySet(context, LibraryUpdateService.class)) return; AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); //Intent intent = ... PendingIntent alarmIntent = PendingIntent.getService(context, LIBRARY_UPDATE_REQUEST_CODE, intent, 0); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, AlarmManager.INTERVAL_HALF_HOUR, AlarmManager.INTERVAL_HOUR * 3, //Every three hours seems sufficient alarmIntent); }
From source file:com.jerrellmardis.amphitheatre.util.Utils.java
public static void scheduleRecommendations(Context context) { Log.d("amp:Utils", "Checking if alarm is already set: " + isAlarmAlreadySet(context, RecommendationsService.class)); //And now/*from ww w . ja va 2 s . c om*/ Log.d("amp:Utils", "Start rechecking the recommendations"); Intent intent = new Intent(context, RecommendationsService.class); intent.putExtra("ALARM", true); /*context.startService(intent);*/ if (isAlarmAlreadySet(context, RecommendationsService.class)) return; AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); //Intent intent = ... PendingIntent alarmIntent = PendingIntent.getService(context, LIBRARY_UPDATE_REQUEST_CODE, intent, 0); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 5000, AlarmManager.INTERVAL_HALF_HOUR, //Every half hour seems sufficient alarmIntent); }
From source file:com.psiphon3.psiphonlibrary.UpgradeChecker.java
/** * Creates the periodic alarm used to check for updates. Can be called unconditionally; it * handles cases when the alarm is already created. * @param appContext The application context. *//*from ww w .ja v a 2 s.c om*/ private static void createAlarm(Context appContext) { if (!allowedToSelfUpgrade(appContext)) { // Don't waste resources with an alarm if we can't possibly self-upgrade. log(appContext, R.string.upgrade_checker_no_alarm_no_selfupgrading, MyLog.Sensitivity.NOT_SENSITIVE, Log.WARN); return; } Intent intent = new Intent(appContext, UpgradeChecker.class); intent.setAction(ALARM_INTENT_ACTION); boolean alarmExists = (PendingIntent.getBroadcast(appContext, ALARM_INTENT_REQUEST_CODE, intent, PendingIntent.FLAG_NO_CREATE) != null); if (alarmExists) { log(appContext, R.string.upgrade_checker_alarm_exists, MyLog.Sensitivity.NOT_SENSITIVE, Log.WARN); return; } log(appContext, R.string.upgrade_checker_creating_alarm, MyLog.Sensitivity.NOT_SENSITIVE, Log.WARN); PendingIntent alarmIntent = PendingIntent.getBroadcast(appContext, ALARM_INTENT_REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmMgr = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_FIFTEEN_MINUTES, AlarmManager.INTERVAL_HALF_DAY, alarmIntent); }
From source file:de.wikilab.android.friendica01.Max.java
public static void runTimer(Context c) { Log.i("Friendica", "try runTimer"); if (piTimerNotifications != null) return;//www .j a v a 2s.c o m AlarmManager a = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE); piTimerNotifications = PendingIntent.getService(c, 1, new Intent(c, NotificationCheckerService.class), 0); a.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, AlarmManager.INTERVAL_FIFTEEN_MINUTES, piTimerNotifications); Toast.makeText(c, "Friendica: Notif. check timer run", Toast.LENGTH_SHORT).show(); Log.i("Friendica", "done runTimer"); }
From source file:com.jtechme.apphub.UpdateService.java
public static void schedule(Context ctx) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "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);/* ww w . jav a 2s.co m*/ if (interval > 0) { alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 5000, AlarmManager.INTERVAL_HOUR, pending); Utils.debugLog(TAG, "Update scheduler alarm set"); } else { Utils.debugLog(TAG, "Update scheduler alarm not set"); } }