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:com.commontime.plugin.notification.notification.NotificationWrapper.java
/** * Alarm manager for the application. */ private AlarmManager getAlarmMgr() { return (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); }
From source file:org.ohmage.reminders.notif.Notifier.java
private static void cancelAllAlarms(Context context, int trigId) { AlarmManager alarmMan = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, NotifReceiver.class).setAction(ACTION_EXPIRE_ALM); PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_NO_CREATE); if (pi != null) { alarmMan.cancel(pi);/* w w w . ja v a 2 s . co m*/ pi.cancel(); } i = new Intent(context, NotifReceiver.class).setAction(ACTION_REPEAT_ALM); pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_NO_CREATE); if (pi != null) { alarmMan.cancel(pi); pi.cancel(); } }
From source file:com.piusvelte.sonet.core.SonetService.java
@Override public void onCreate() { super.onCreate(); // handle version changes int currVer = 0; try {/*from w w w . j a v a2 s . c o m*/ currVer = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (!sp.contains(getString(R.string.key_version)) || (currVer > sp.getInt(getString(R.string.key_version), 0))) { sp.edit().putInt(getString(R.string.key_version), currVer).commit(); try { BackupManager.dataChanged(this); } catch (Throwable t) { Log.d(TAG, "backupagent not supported"); } } mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mConnectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); mSonetCrypto = SonetCrypto.getInstance(getApplicationContext()); // check the instant upload settings startService(Sonet.getPackageIntent(getApplicationContext(), SonetUploader.class)); }
From source file:com.ubergeek42.WeechatAndroid.service.RelayServiceBackbone.java
@Override public void onCreate() { if (DEBUG)//from ww w. j a v a 2s. c o m logger.debug("onCreate()"); super.onCreate(); prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); prefs.registerOnSharedPreferenceChangeListener(this); notificationManger = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // prepare handler that will run on a separate thread HandlerThread handler_thread = new HandlerThread("doge"); handler_thread.start(); thandler = new Handler(handler_thread.getLooper()); startForeground(NOTIFICATION_ID, buildNotification(null, "Tap to connect", null)); disconnected = false; already_had_intent = false; network_unavailable = false; // Prepare for dealing with SSL certs certmanager = new SSLHandler(new File(getDir("sslDir", Context.MODE_PRIVATE), "keystore.jks")); registerReceiver(connectivityActionReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); }
From source file:fr.paug.droidcon.service.SessionAlarmService.java
private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID);// w w w . j a v a 2 s.c om final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > sessionStart) { LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart); return; } // By default, sets alarm to go off at 10 minutes before session start time. If alarm // offset is provided, alarm is set to go off by that much time from now. long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionStart - MILLI_TEN_MINUTES; } else { alarmTime = currentTime + alarmOffset; } LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString()); final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. notifIntent.setData( new Uri.Builder().authority("fr.paug.droidcon").path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); LOGD(TAG, "-> Intent extra: session start " + sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); LOGD(TAG, "-> Intent extra: session end " + sessionEnd); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:com.embeddedlog.LightUpDroid.timer.TimerReceiver.java
private void updateNextTimesup(Context context) { TimerObj t = getNextRunningTimer(mTimers, false, Utils.getTimeNow()); long nextTimesup = (t == null) ? -1 : t.getTimesupTime(); int timerId = (t == null) ? -1 : t.mTimerId; Intent intent = new Intent(); intent.setAction(Timers.TIMES_UP);/* w w w. j av a 2 s. c om*/ intent.setClass(context, TimerReceiver.class); if (!mTimers.isEmpty()) { intent.putExtra(Timers.TIMER_INTENT_EXTRA, timerId); } AlarmManager mngr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent p = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); if (t != null) { if (Utils.isKitKatOrLater()) { mngr.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextTimesup, p); } else { mngr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextTimesup, p); } if (Timers.LOGGING) { Log.d(TAG, "Setting times up to " + nextTimesup); } } else { mngr.cancel(p); if (Timers.LOGGING) { Log.v(TAG, "no next times up"); } } }
From source file:com.androidinspain.deskclock.data.TimerNotificationBuilder.java
public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) { final Timer timer = unexpired.get(0); final int count = unexpired.size(); // Compute some values required below. final boolean running = timer.isRunning(); final Resources res = context.getResources(); final long base = getChronometerBase(timer); final String pname = context.getPackageName(); final List<Action> actions = new ArrayList<>(2); final CharSequence stateText; if (count == 1) { if (running) { // Single timer is running. if (TextUtils.isEmpty(timer.getLabel())) { stateText = res.getString(com.androidinspain.deskclock.R.string.timer_notification_label); } else { stateText = timer.getLabel(); }/*from ww w.ja v a 2 s .c o m*/ // Left button: Pause final Intent pause = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_PAUSE_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon1 = com.androidinspain.deskclock.R.drawable.ic_pause_24dp; final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.timer_pause); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Action.Builder(icon1, title1, intent1).build()); // Right Button: +1 Minute final Intent addMinute = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_ADD_MINUTE_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon2 = com.androidinspain.deskclock.R.drawable.ic_add_24dp; final CharSequence title2 = res.getText(com.androidinspain.deskclock.R.string.timer_plus_1_min); final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute); actions.add(new Action.Builder(icon2, title2, intent2).build()); } else { // Single timer is paused. stateText = res.getString(com.androidinspain.deskclock.R.string.timer_paused); // Left button: Start final Intent start = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_START_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon1 = com.androidinspain.deskclock.R.drawable.ic_start_24dp; final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.sw_resume_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Action.Builder(icon1, title1, intent1).build()); // Right Button: Reset final Intent reset = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_RESET_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon2 = com.androidinspain.deskclock.R.drawable.ic_reset_24dp; final CharSequence title2 = res.getText(com.androidinspain.deskclock.R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Action.Builder(icon2, title2, intent2).build()); } } else { if (running) { // At least one timer is running. stateText = res.getString(com.androidinspain.deskclock.R.string.timers_in_use, count); } else { // All timers are paused. stateText = res.getString(com.androidinspain.deskclock.R.string.timers_stopped, count); } final Intent reset = TimerService.createResetUnexpiredTimersIntent(context); @DrawableRes final int icon1 = com.androidinspain.deskclock.R.drawable.ic_reset_24dp; final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.timer_reset_all); final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset); actions.add(new Action.Builder(icon1, title1, intent1).build()); } // Intent to load the app and show the timer when the notification is tapped. final Intent showApp = new Intent(context, TimerService.class).setAction(TimerService.ACTION_SHOW_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()) .putExtra(Events.EXTRA_EVENT_LABEL, com.androidinspain.deskclock.R.string.label_notification); final PendingIntent pendingShowApp = PendingIntent.getService(context, REQUEST_CODE_UPCOMING, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); final Builder notification = new NotificationCompat.Builder(context).setOngoing(true).setLocalOnly(true) .setShowWhen(false).setAutoCancel(false).setContentIntent(pendingShowApp) .setPriority(Notification.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM) .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_timer) .setSortKey(nm.getTimerNotificationSortKey()).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setStyle(new NotificationCompat.DecoratedCustomViewStyle()) .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background)); for (Action action : actions) { notification.addAction(action); } if (Utils.isNOrLater()) { notification.setCustomContentView(buildChronometer(pname, base, running, stateText)) .setGroup(nm.getTimerNotificationGroupKey()); } else { final CharSequence contentTextPreN; if (count == 1) { contentTextPreN = TimerStringFormatter.formatTimeRemaining(context, timer.getRemainingTime(), false); } else if (running) { final String timeRemaining = TimerStringFormatter.formatTimeRemaining(context, timer.getRemainingTime(), false); contentTextPreN = context.getString(com.androidinspain.deskclock.R.string.next_timer_notif, timeRemaining); } else { contentTextPreN = context.getString(com.androidinspain.deskclock.R.string.all_timers_stopped_notif); } notification.setContentTitle(stateText).setContentText(contentTextPreN); final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final Intent updateNotification = TimerService.createUpdateNotificationIntent(context); final long remainingTime = timer.getRemainingTime(); if (timer.isRunning() && remainingTime > MINUTE_IN_MILLIS) { // Schedule a callback to update the time-sensitive information of the running timer final PendingIntent pi = PendingIntent.getService(context, REQUEST_CODE_UPCOMING, updateNotification, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); final long nextMinuteChange = remainingTime % MINUTE_IN_MILLIS; final long triggerTime = SystemClock.elapsedRealtime() + nextMinuteChange; TimerModel.schedulePendingIntent(am, triggerTime, pi); } else { // Cancel the update notification callback. final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE); if (pi != null) { am.cancel(pi); pi.cancel(); } } } return notification.build(); }
From source file:at.diamonddogs.util.CacheManager.java
/** * Turn on scheduled cache cleaning (cache will be cleaned even if app is * not running)/*from ww w .j a v a2s .c o m*/ * * @param context a {@link Context} */ public void enableScheduledCacheCleaner(Context context) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // @formatter:off am.setInexactRepeating(AlarmManager.RTC, Utils.getScheduledDate(Calendar.SUNDAY, 3, 0, 0).getTimeInMillis(), 7 * AlarmManager.INTERVAL_DAY, getAlarmIntent(context)); // @formatter:on Log.i(TAG, "Cache cleaning alarm has been set."); }
From source file:org.mozilla.gecko.updater.UpdateService.java
private void registerForUpdates(boolean isRetry) { Calendar lastAttempt = getLastAttemptDate(); Calendar now = new GregorianCalendar(TimeZone.getTimeZone("GMT")); int interval = getUpdateInterval(isRetry); if (lastAttempt == null || (now.getTimeInMillis() - lastAttempt.getTimeInMillis()) > interval) { // We've either never attempted an update, or we are passed the desired // time. Start an update now. Log.i(LOGTAG, "no update has ever been attempted, checking now"); startUpdate(0);/*from w w w . j a va 2 s.c o m*/ return; } AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (manager == null) return; PendingIntent pending = PendingIntent.getService(this, 0, new Intent(UpdateServiceHelper.ACTION_CHECK_FOR_UPDATE, null, this, UpdateService.class), PendingIntent.FLAG_UPDATE_CURRENT); manager.cancel(pending); lastAttempt.setTimeInMillis(lastAttempt.getTimeInMillis() + interval); Log.i(LOGTAG, "next update will be at: " + lastAttempt.getTime()); manager.set(AlarmManager.RTC_WAKEUP, lastAttempt.getTimeInMillis(), pending); }
From source file:com.drinviewer.droiddrinviewer.DrinViewerBroadcastReceiver.java
/** * Stops the alarm repeater after a disconnection from a WiFi network * // www .j a va 2 s . c o m * @param context The context to use */ private void stopAlarmRepeater(Context context) { /** * Sends a message to clean the host collection, and stop the DiscoverServerService * should be safe because this method gets called on WiFi disconnect */ Intent i = new Intent(context, this.getClass()); i.setAction(context.getResources().getString(R.string.broadcast_cleanhostcollection)); i.putExtra("stopservice", true); context.sendBroadcast(i); /** * Cancel the pending intent from the AlarmManager */ PendingIntent senderstop = PendingIntent.getBroadcast(context, 0, new Intent(context, this.getClass()), 0); // Get the alarm manager if (alarmManager == null) alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(senderstop); }