List of usage examples for android.content Context ALARM_SERVICE
String ALARM_SERVICE
To view the source code for android.content Context ALARM_SERVICE.
Click Source Link
From source file:Main.java
public static synchronized long setBroadcastAlarm(Context context, Intent intent, long timeInterval, int identifier) { final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent pi = PendingIntent.getBroadcast(context, identifier, intent, PendingIntent.FLAG_CANCEL_CURRENT); return setUpAlarm(am, pi, timeInterval); }
From source file:net.kourlas.voipms_sms.receivers.SynchronizationIntervalReceiver.java
public static void setupSynchronizationInterval(Context applicationContext) { Preferences preferences = Preferences.getInstance(applicationContext); AlarmManager alarmManager = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(applicationContext, SynchronizationIntervalReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(applicationContext, 0, intent, 0); alarmManager.cancel(pendingIntent);/*from ww w. j a va2s .c o m*/ long syncInterval = preferences.getSyncInterval() * (24 * 60 * 60 * 1000); if (syncInterval != 0) { long nextSyncTime = preferences.getLastCompleteSyncTime() + syncInterval; long now = System.currentTimeMillis(); if (nextSyncTime <= now) { Database.getInstance(applicationContext).synchronize(false, false, null); nextSyncTime = now + syncInterval; } alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, nextSyncTime, syncInterval, pendingIntent); } }
From source file:Main.java
public static <T extends BroadcastReceiver> void scheduleUpdate(Context context, Class<T> clazz) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, clazz); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Random random = new Random(System.currentTimeMillis()); long offset = random.nextLong() % (12 * 60 * 60 * 1000); long interval = (24 * 60 * 60 * 1000) + offset; String prefKey = "pref_scheduled_monitor_config_update_" + clazz.getCanonicalName(); long scheduledTime = preferences.getLong(prefKey, -1); if (scheduledTime == -1) { context.sendBroadcast(intent);//from www . j a va2 s . co m } if (scheduledTime <= System.currentTimeMillis()) { context.sendBroadcast(intent); scheduledTime = System.currentTimeMillis() + interval; preferences.edit().putLong(prefKey, scheduledTime).commit(); Log.w("PeriodicActionUtils", "Scheduling for all new time: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); } else { Log.w("PeriodicActionUtils", "Scheduling for time found in preferences: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); } am.cancel(sender); am.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender); Log.w("PeriodicActionUtils", "Scheduled for: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); }
From source file:com.commonsware.android.wakecast.PollReceiver.java
static void scheduleAlarms(Context ctxt) { AlarmManager mgr = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(ctxt, PollReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + INITIAL_DELAY, PERIOD, pi);//from ww w . j av a 2 s . c om }
From source file:com.tealeaf.PushBroadcastReceiver.java
public static void scheduleNext(Context context, int timeout) { TeaLeafOptions options = new TeaLeafOptions(context); String appID = options.getAppID(); logger.log("{push} Scheduling the next push for", timeout); Intent intent = new Intent("com.tealeaf.CHECK_PUSH_SERVER"); intent.putExtra("appID", appID); AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); scheduledIntent = PendingIntent.getBroadcast(context, 0, intent, 0); alarms.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (timeout * 1000), scheduledIntent); }
From source file:MainActivity.java
public void setAlarm(View view) { Intent intentToFire = new Intent(getApplicationContext(), AlarmBroadcastReceiver.class); intentToFire.setAction(AlarmBroadcastReceiver.ACTION_ALARM); PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intentToFire, 0); AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); long thirtyMinutes = SystemClock.elapsedRealtime() + 30 * 1000; alarmManager.set(AlarmManager.ELAPSED_REALTIME, thirtyMinutes, alarmIntent); //alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, thirtyMinutes, AlarmManager.INTERVAL_HALF_HOUR, alarmIntent); }
From source file:com.meiste.greg.ptw.RaceAlarm.java
@SuppressLint("NewApi") public static void set(final Context context) { final Race race = Race.getNext(context, true, true); if (!alarm_set && (race != null)) { Util.log("Setting race alarm for race " + race.getId()); final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final Intent intent = new Intent(context, RaceAlarm.class); intent.putExtra(RACE_ID, race.getId()); final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { am.setExact(AlarmManager.RTC_WAKEUP, race.getStartTimestamp(), pendingIntent); } else {//from w ww . j av a 2 s . c o m am.set(AlarmManager.RTC_WAKEUP, race.getStartTimestamp(), pendingIntent); } alarm_set = true; } else { Util.log("Not setting race alarm: alarm_set=" + alarm_set); } }
From source file:com.tealeaf.PushBroadcastReceiver.java
public static void disableNotifications(Context context) { if (scheduledIntent != null) { AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarms.cancel(scheduledIntent);// www .j a va 2s.c om scheduledIntent = null; } }
From source file:com.cryart.sabbathschool.util.SSNotification.java
public static void setRepeatingNotification(Context context) { AlarmManager _SSAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent _SSNotificationIntent = new Intent(context, SSBroadcastReceiver.class); PendingIntent _SSAlarmIntent = PendingIntent.getBroadcast(context, 0, _SSNotificationIntent, 0); Calendar _SSNotificationTime = Calendar.getInstance(); SharedPreferences ssPreferences = PreferenceManager.getDefaultSharedPreferences(context); String ss_settings_notification_time = ssPreferences.getString( SSConstants.SS_SETTINGS_NOTIFICATION_TIME_KEY, SSConstants.SS_SETTINGS_NOTIFICATION_TIME_DEFAULT_VALUE); _SSNotificationTime.set(Calendar.HOUR_OF_DAY, SSHelper.parseHourFromString(ss_settings_notification_time, SSConstants.SS_NOTIFICATION_TIME_SETTINGS_FORMAT)); _SSNotificationTime.set(Calendar.MINUTE, SSHelper.parseMinuteFromString(ss_settings_notification_time, SSConstants.SS_NOTIFICATION_TIME_SETTINGS_FORMAT)); _SSNotificationTime.set(Calendar.SECOND, 0); _SSAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, _SSNotificationTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, _SSAlarmIntent); }
From source file:net.callmeike.android.alarmscheduler.scheduler.AlarmScheduler.java
public static void startSampleTask(Context ctxt) { int interval = ctxt.getResources().getInteger(R.integer.sample_task_interval); ((AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE)).setInexactRepeating( AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 100, interval * MS_PER_MINUTE, getTaskIntent(ctxt, SAMPLE_TASK)); Log.d(TAG, "sample task started"); }