List of usage examples for android.app AlarmManager cancel
public void cancel(OnAlarmListener listener)
From source file:net.networksaremadeofstring.rhybudd.ZenossPoller.java
private void PollerCheck() { AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Intent Poller = new Intent(this, ZenossPoller.class); if (settings.getBoolean("AllowBackgroundService", true)) { //Log.i("PollerCheck","Background scanning enabled!"); Notifications.SendStickyNotification(this); Poller.putExtra("events", true); PendingIntent Monitoring = PendingIntent.getService(this, 0, Poller, PendingIntent.FLAG_UPDATE_CURRENT);//PendingIntent.FLAG_UPDATE_CURRENT am.cancel(Monitoring); try {//from w w w.ja v a2s. co m am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, (long) 0, Long.parseLong(settings.getString("BackgroundServiceDelay", "60")) * 1000, Monitoring); } catch (Exception e) { am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, (long) 0, 60000, Monitoring); BugSenseHandler.sendExceptionMessage("ZenossPoller", "PollerCheck", e); } } else { //Log.i("PollerCheck","Background scanning disabled!"); Poller.putExtra("events", true); PendingIntent Monitoring = PendingIntent.getService(this, 0, Poller, PendingIntent.FLAG_UPDATE_CURRENT);//PendingIntent.FLAG_UPDATE_CURRENT am.cancel(Monitoring); mNM.cancel(Notifications.NOTIFICATION_POLLED_STICKY); } /*if(settings.getBoolean("refreshCache", true)) { //Log.i("PollerCheck","Background cache refresh enabled!"); Poller.putExtra("refreshCache", true); PendingIntent CacheRefresh = PendingIntent.getService(this, 1, Poller, PendingIntent.FLAG_UPDATE_CURRENT); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 10000, AlarmManager.INTERVAL_HOUR, CacheRefresh); } else { //Log.i("PollerCheck","Background cache refresh disabled!"); Poller.putExtra("refreshCache", true); PendingIntent CacheRefresh = PendingIntent.getService(this, 1, Poller, PendingIntent.FLAG_UPDATE_CURRENT); am.cancel(CacheRefresh); }*/ //We use a SyncAdapter now like good citizens try { if (settings.getBoolean("refreshCache", true)) { Poller.putExtra("refreshCache", true); PendingIntent CacheRefresh = PendingIntent.getService(this, 1, Poller, PendingIntent.FLAG_UPDATE_CURRENT); am.cancel(CacheRefresh); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("refreshCache", false); editor.commit(); } } catch (Exception e) { e.printStackTrace(); BugSenseHandler.sendExceptionMessage("ZenossPoller", "cancel refresh cache poller", e); } }
From source file:net.easysol.dsb.web_protector.antiphishing.AntiphishingController.java
public void stopWebAnalyzerService() { if (this.webAnalyzerListener != null) { this.webAnalyzerListener.onWebAnalyzerOff(); }// w w w . j a v a 2 s.c o m Log.i("SERVICE", "Stoping web protector"); AlarmManager alarmManager = (AlarmManager) this.myContext .getSystemService(NotificationCompatApi24.CATEGORY_ALARM); Intent service = new Intent(this.myContext, WebAnalyzerService.class); PendingIntent op = PendingIntent.getService(this.myContext, WebProtectorPreferences.REQUEST_CODE_WEB_PROTECTOR, service, 0); op.cancel(); alarmManager.cancel(op); this.myContext.stopService(service); }
From source file:de.incoherent.suseconferenceclient.tasks.CheckForUpdatesTask.java
@Override protected Long doInBackground(Void... params) { String kUrl = "https://conference.opensuse.org/osem/api/v1/conferences/gRNyOIsTbvCfJY5ENYovBA"; if (kUrl.length() <= 0) return 0l; String updatesUrl = mConference.getUrl() + "/updates.json"; int lastUpdateRevision = mDb.getLastUpdateValue(mConference.getSqlId()); int revisionLevel = lastUpdateRevision; try {//from w ww . ja v a 2 s .c o m JSONObject updateReply = HTTPWrapper.get(updatesUrl); if (updateReply == null) return 0l; int newLevel = updateReply.getInt("revision"); if (newLevel > revisionLevel) { long id = mConference.getSqlId(); // Cache favorites and alerts List<String> favoriteGuids = mDb.getFavoriteGuids(id); List<Event> alerts = mDb.getAlertEvents(id); List<String> alertGuids = new ArrayList<String>(); // Now cancel all of the outstanding alerts, in case // a talk has been moved AlarmManager manager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); for (Event e : alerts) { alertGuids.add("\"" + e.getGuid() + "\""); Log.d("SUSEConferences", "Removing an alert for " + e.getTitle()); Intent intent = new Intent(mContext, AlarmReceiver.class); intent.putExtras(ScheduleDetailsActivity.generateAlarmIntentBundle(mContext, e)); PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, intent.getStringExtra("intentId").hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT); manager.cancel(pendingIntent); pendingIntent.cancel(); } // Now clear the DB mDb.clearDatabase(id); // Download schedule ConferenceCacher cacher = new ConferenceCacher(new ConferenceCacherProgressListener() { @Override public void progress(String progress) { publishProgress(progress); } }); long val = cacher.cacheConference(mConference, mDb); mErrorMessage = cacher.getLastError(); if (val == -1) { mDb.setConferenceAsCached(id, 0); } else { mDb.setLastUpdateValue(id, newLevel); mDb.toggleEventsInMySchedule(favoriteGuids); mDb.toggleEventAlerts(alertGuids); alerts = mDb.getAlertEvents(id); // ... And re-create the alerts, if they are in the future Date currentDate = new Date(); for (Event e : alerts) { if (currentDate.after(e.getDate())) continue; Log.d("SUSEConferences", "Adding an alert for " + e.getTitle()); alertGuids.add("\"" + e.getGuid() + "\""); Intent intent = new Intent(mContext, AlarmReceiver.class); intent.putExtras(ScheduleDetailsActivity.generateAlarmIntentBundle(mContext, e)); PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, intent.getStringExtra("intentId").hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT); manager.set(AlarmManager.RTC_WAKEUP, e.getDate().getTime() - 300000, pendingIntent); } } return val; } else { return 0l; } } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java
/** * Called when download has been completed. * @param content content.//from ww w . ja va 2s .c o m */ void onDownloadComplete(CapptainReachInteractiveContent content) { /* Cancel alarm */ Intent intent = new Intent(INTENT_ACTION_DOWNLOAD_TIMEOUT); intent.setPackage(mContext.getPackageName()); int requestCode = (int) content.getLocalId(); PendingIntent operation = PendingIntent.getBroadcast(mContext, requestCode, intent, 0); AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(operation); /* Update notification if not too late e.g. notification not yet dismissed */ notifyPendingContent(content); }
From source file:at.vcity.androidimsocket.services.IMService.java
@Override public void onDestroy() { try {//from w w w . ja v a 2s . c om unregisterReceiver(alarmReceiver); } catch (IllegalArgumentException e) { } AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, IMService.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarm.cancel(pintent); Log.i("IMService is being destroyed", "..."); // super.onDestroy(); }
From source file:com.android.deskclock.alarms.AlarmStateManager.java
/** * Used in L and later devices where "next alarm" is stored in the Alarm Manager. *//*from w w w. j a va2 s . com*/ @TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void updateNextAlarmInAlarmManager(Context context, AlarmInstance nextAlarm) { // Sets a surrogate alarm with alarm manager that provides the AlarmClockInfo for the // alarm that is going to fire next. The operation is constructed such that it is ignored // by AlarmStateManager. AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); int flags = nextAlarm == null ? PendingIntent.FLAG_NO_CREATE : 0; PendingIntent operation = PendingIntent.getBroadcast(context, 0 /* requestCode */, AlarmStateManager.createIndicatorIntent(context), flags); if (nextAlarm != null) { long alarmTime = nextAlarm.getAlarmTime().getTimeInMillis(); // Create an intent that can be used to show or edit details of the next alarm. PendingIntent viewIntent = PendingIntent.getActivity(context, nextAlarm.hashCode(), AlarmNotifications.createViewAlarmIntent(context, nextAlarm), PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager.AlarmClockInfo info = new AlarmManager.AlarmClockInfo(alarmTime, viewIntent); alarmManager.setAlarmClock(info, operation); } else if (operation != null) { alarmManager.cancel(operation); } }
From source file:indrora.atomic.irc.IRCService.java
/** * On Destroy/* w w w. j av a2 s .c o m*/ */ @Override public void onDestroy() { // Make sure our notification is gone. if (foreground) { stopForegroundCompat(R.string.app_name); } AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); synchronized (alarmIntentsLock) { for (PendingIntent pendingRIntent : alarmIntents.values()) { am.cancel(pendingRIntent); } for (ReconnectReceiver receiver : alarmReceivers.values()) { unregisterReceiver(receiver); } alarmIntents.clear(); alarmIntents = null; alarmReceivers.clear(); alarmReceivers = null; } unregisterReceiver(_netTransitionHandler); }
From source file:org.apps8os.motivator.ui.MainActivity.java
/** * Set the notifications for the first time. After this, the notifications are controlled from the settings activity. *///from ww w. j av a2s .c o m public void setNotifications() { // Set up notifying user to answer to the mood question // The time to notify the user Calendar notificationTime = Calendar.getInstance(); notificationTime.set(Calendar.MINUTE, 0); notificationTime.set(Calendar.SECOND, 0); // An alarm manager for scheduling notifications AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Set the notification to repeat over the given time at notificationTime Intent notificationIntent = new Intent(this, NotificationService.class); notificationIntent.putExtra(NotificationService.NOTIFICATION_TYPE, NotificationService.NOTIFICATION_MOOD); PendingIntent pendingNotificationIntent = PendingIntent.getService(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.cancel(pendingNotificationIntent); if (notificationTime.get(Calendar.HOUR_OF_DAY) >= 10) { notificationTime.add(Calendar.DATE, 1); } notificationTime.set(Calendar.HOUR_OF_DAY, 10); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingNotificationIntent); /** Commented out for now, setting different times for the notifications. if (mTimeToNotify == getString(R.string.in_the_morning_value)) { if (notificationTime.get(Calendar.HOUR_OF_DAY) >= 10) { notificationTime.add(Calendar.DATE, 1); } notificationTime.set(Calendar.HOUR_OF_DAY, 10); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingNotificationIntent); } else if (mTimeToNotify == getString(R.string.morning_and_evening_value)) { if (notificationTime.get(Calendar.HOUR_OF_DAY) >= 10 && notificationTime.get(Calendar.HOUR_OF_DAY) < 22) { notificationTime.set(Calendar.HOUR_OF_DAY, 22); } else if (notificationTime.get(Calendar.HOUR_OF_DAY) < 10) { notificationTime.set(Calendar.HOUR_OF_DAY, 10); } else { notificationTime.add(Calendar.DATE, 1); notificationTime.set(Calendar.HOUR_OF_DAY, 10); } alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(), AlarmManager.INTERVAL_HALF_DAY, pendingNotificationIntent); } else if (mTimeToNotify == getString(R.string.every_hour_value)) { notificationTime.add(Calendar.HOUR_OF_DAY, 1); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(), AlarmManager.INTERVAL_HOUR, pendingNotificationIntent); } **/ }
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 ww.j a va 2s.c o m 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:se.oort.clockify.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);//from w ww .j av a2 s.c o m 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(LOG_TAG, "Setting times up to " + nextTimesup); } } else { mngr.cancel(p); if (Timers.LOGGING) { Log.v(LOG_TAG, "no next times up"); } } }