List of usage examples for android.app AlarmManager cancel
public void cancel(OnAlarmListener listener)
From source file:de.appplant.cordova.plugin.notification.NotificationWrapper.java
/** * Cancel existing notification//from w ww . ja va 2s .c om */ public void cancel(String notificationId) { /* * Create an intent that looks similar, to the one that was registered * using add. Making sure the notification id in the action is the same. * Now we can search for such an intent using the 'getService' method * and cancel it. */ Intent intent = new Intent(context, receiver).setAction("" + notificationId); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); AlarmManager am = getAlarmManager(); NotificationManager nc = getNotificationManager(); am.cancel(pi); try { nc.cancel(Integer.parseInt(notificationId)); } catch (Exception e) { } unpersist(notificationId); }
From source file:ca.zadrox.dota2esportticker.service.UpdateMatchService.java
private void cancelAutoUpdate() { final Intent updateMatchIntent = new Intent(UpdateMatchService.ACTION_AUTO_UPDATE_MATCHES, null, this, UpdateMatchService.class); final Intent updateResultIntent = new Intent(UpdateMatchService.ACTION_UPDATE_RESULTS, null, this, UpdateMatchService.class); PendingIntent umi = PendingIntent.getService(this.getApplicationContext(), 0, updateMatchIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent uri = PendingIntent.getService(this.getApplicationContext(), 0, updateResultIntent, PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); am.cancel(umi); am.cancel(uri);//from w w w . j a va 2 s . c om }
From source file:at.diamonddogs.util.CacheManager.java
/** * Turn off scheduled cache cleaning/*from www . j a v a 2s . c om*/ * * @param context a {@link Context} */ public void disableScheduledCacheCleaner(Context context) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.cancel(getAlarmIntent(context)); Log.i(TAG, "Cache cleaning alarm has been disabled."); }
From source file:ca.zadrox.dota2esportticker.service.UpdateMatchService.java
private void scheduleAutoUpdates() { if (!PrefUtils.shouldAutoUpdate(this)) { return;/*from ww w .j a v a 2 s .c om*/ } final long currentTime = TimeUtils.getUTCTime(); final Intent updateMatchIntent = new Intent(UpdateMatchService.ACTION_AUTO_UPDATE_MATCHES, null, this, UpdateMatchService.class); final Intent updateResultIntent = new Intent(UpdateMatchService.ACTION_UPDATE_RESULTS, null, this, UpdateMatchService.class); final long matchUpdateTime = currentTime + (60000 * 60 * 12); final long resultUpdateTime = currentTime + (60000 * 60); PendingIntent umi = PendingIntent.getService(this.getApplicationContext(), 0, updateMatchIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent uri = PendingIntent.getService(this.getApplicationContext(), 0, updateResultIntent, PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); am.cancel(umi); am.cancel(uri); am.setInexactRepeating(AlarmManager.RTC, matchUpdateTime, AlarmManager.INTERVAL_HALF_DAY, umi); am.setInexactRepeating(AlarmManager.RTC, resultUpdateTime, AlarmManager.INTERVAL_HOUR, uri); }
From source file:com.google.android.apps.paco.NotificationCreator.java
private void createAlarmToCancelNotificationAtTimeout(Context context, NotificationHolder notificationHolder) { DateTime alarmTime = new DateTime(notificationHolder.getAlarmTime()); int timeoutMinutes = (int) (notificationHolder.getTimeoutMillis() / MILLIS_IN_MINUTE); DateTime timeoutTime = new DateTime(alarmTime).plusMinutes(timeoutMinutes); long elapsedDurationInMillis = timeoutTime.getMillis(); Log.i(PacoConstants.TAG,//from www. j a va 2 s. c o m "Creating cancel alarm to timeout notification for holder: " + notificationHolder.getId() + ". experiment = " + notificationHolder.getExperimentId() + ". alarmtime = " + new DateTime(alarmTime).toString() + " timing out in " + timeoutMinutes + " minutes"); Intent ultimateIntent = new Intent(context, AlarmReceiver.class); Uri uri = Uri.withAppendedPath(NotificationHolderColumns.CONTENT_URI, notificationHolder.getId().toString()); ultimateIntent.setData(uri); ultimateIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue()); PendingIntent intent = PendingIntent.getBroadcast(context.getApplicationContext(), 2, ultimateIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(intent); alarmManager.set(AlarmManager.RTC_WAKEUP, elapsedDurationInMillis, intent); }
From source file:com.google.android.apps.paco.NotificationCreator.java
private void createAlarmForSnooze(Context context, NotificationHolder notificationHolder) { DateTime alarmTime = new DateTime(notificationHolder.getAlarmTime()); Experiment experiment = experimentProviderUtil.getExperiment(notificationHolder.getExperimentId()); Integer snoozeTime = experiment.getSignalingMechanisms().get(0).getSnoozeTime(); int snoozeMinutes = snoozeTime / MILLIS_IN_MINUTE; DateTime timeoutMinutes = new DateTime(alarmTime).plusMinutes(snoozeMinutes); long snoozeDurationInMillis = timeoutMinutes.getMillis(); Log.i(PacoConstants.TAG,/*from w w w . jav a 2 s . co m*/ "Creating snooze alarm to resound notification for holder: " + notificationHolder.getId() + ". experiment = " + notificationHolder.getExperimentId() + ". alarmtime = " + new DateTime(alarmTime).toString() + " waking up from snooze in " + timeoutMinutes + " minutes"); Intent ultimateIntent = new Intent(context, AlarmReceiver.class); Uri uri = Uri.withAppendedPath(NotificationHolderColumns.CONTENT_URI, notificationHolder.getId().toString()); ultimateIntent.setData(uri); ultimateIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue()); ultimateIntent.putExtra(SNOOZE_REPEATER_EXTRA_KEY, true); PendingIntent intent = PendingIntent.getBroadcast(context.getApplicationContext(), 3, ultimateIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(intent); alarmManager.set(AlarmManager.RTC_WAKEUP, snoozeDurationInMillis, intent); }
From source file:no.firestorm.weathernotificatonservice.WeatherNotificationService.java
private void removeAlarm() { final PendingIntent pendingIntent = PendingIntent.getService(this, 0, new Intent(this, WeatherNotificationService.class), PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarm.cancel(pendingIntent); }
From source file:edu.mit.media.funf.configured.ConfiguredPipeline.java
private void cancelAlarm(String action) { Intent i = new Intent(this, getClass()); i.setAction(action);//from w w w. j av a 2 s. com PendingIntent pi = PendingIntent.getService(this, 0, i, PendingIntent.FLAG_NO_CREATE); if (pi != null) { AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.cancel(pi); } }
From source file:org.svij.taskwarriorapp.activities.TasksActivity.java
@Override protected void onResume() { super.onResume(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); long date_long = prefs.getLong("notifications_alarm_time", System.currentTimeMillis()); Intent myIntent = new Intent(this, NotificationService.class); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getService(this, 0, myIntent, 0); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date_long); alarmManager.cancel(pendingIntent); if (!calendar.getTime().before(new Date())) { alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24 * 60 * 60 * 1000, pendingIntent);/*from w w w .j av a2 s . co m*/ } setTitle(column + " (" + taskListFragment.getListView().getCount() + ")"); }
From source file:org.ametro.app.ApplicationEx.java
public void changeAlarmReceiverState(boolean enabled) { AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Intent intent = new Intent(this, AlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); alarmManager.cancel(pendingIntent); if (enabled) { long interval = (GlobalSettings.getUpdatePeriod(this) == 900) ? AlarmManager.INTERVAL_FIFTEEN_MINUTES : AlarmManager.INTERVAL_DAY; alarmManager.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis() + 1000 * 60 * 2, interval, pendingIntent);//from w w w . j a va 2 s. c o m } }