Java Code Examples for android.app.PendingIntent#cancel()
The following examples show how to use
android.app.PendingIntent#cancel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventPreferencesAlarmClock.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
void removeAlarm(Context context) { try { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { Intent intent = new Intent(); intent.setAction(PhoneProfilesService.ACTION_ALARM_CLOCK_EVENT_END_BROADCAST_RECEIVER); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, (int) _event._id, intent, PendingIntent.FLAG_NO_CREATE); if (pendingIntent != null) { //PPApplication.logE("EventPreferencesAlarmClock.removeAlarm", "alarm found"); alarmManager.cancel(pendingIntent); pendingIntent.cancel(); } } } catch (Exception e) { PPApplication.recordException(e); } PhoneProfilesService.cancelWork(ElapsedAlarmsWorker.ELAPSED_ALARMS_ALARM_CLOCK_SENSOR_TAG_WORK+"_" + (int) _event._id); }
Example 2
Source File: StartEventNotificationBroadcastReceiver.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
static void removeAlarm(Event event, Context context) { try { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { //Intent intent = new Intent(_context, StartEventNotificationBroadcastReceiver.class); Intent intent = new Intent(); intent.setAction(PhoneProfilesService.ACTION_START_EVENT_NOTIFICATION_BROADCAST_RECEIVER); //intent.setClass(context, StartEventNotificationBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, (int) event._id, intent, PendingIntent.FLAG_NO_CREATE); if (pendingIntent != null) { //PPApplication.logE("StartEventNotificationBroadcastReceiver.removeAlarm", "alarm found"); alarmManager.cancel(pendingIntent); pendingIntent.cancel(); } } } catch (Exception e) { PPApplication.recordException(e); } PhoneProfilesService.cancelWork(ElapsedAlarmsWorker.ELAPSED_ALARMS_START_EVENT_NOTIFICATION_TAG_WORK+"_"+(int)event._id); PPApplication.elapsedAlarmsStartEventNotificationWork.remove(ElapsedAlarmsWorker.ELAPSED_ALARMS_START_EVENT_NOTIFICATION_TAG_WORK+"_"+(int)event._id); //PPApplication.logE("[HANDLER] StartEventNotificationBroadcastReceiver.removeAlarm", "removed"); }
Example 3
Source File: NotificationService.java From good-weather with GNU General Public License v3.0 | 6 votes |
public static void setNotificationServiceAlarm(Context context, boolean isNotificationEnable) { Intent intent = NotificationService.newIntent(context); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); String intervalPref = AppPreference.getInterval(context); long intervalMillis = Utils.intervalMillisForAlarm(intervalPref); if (isNotificationEnable) { alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + intervalMillis, intervalMillis, pendingIntent); } else { alarmManager.cancel(pendingIntent); pendingIntent.cancel(); } }
Example 4
Source File: EventPreferencesSMS.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
void removeAlarm(Context context) { try { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { //Intent intent = new Intent(context, SMSEventEndBroadcastReceiver.class); Intent intent = new Intent(); intent.setAction(PhoneProfilesService.ACTION_SMS_EVENT_END_BROADCAST_RECEIVER); //intent.setClass(context, SMSEventEndBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, (int) _event._id, intent, PendingIntent.FLAG_NO_CREATE); if (pendingIntent != null) { //PPApplication.logE("EventPreferencesSMS.removeAlarm", "alarm found"); alarmManager.cancel(pendingIntent); pendingIntent.cancel(); } } } catch (Exception e) { PPApplication.recordException(e); } PhoneProfilesService.cancelWork(ElapsedAlarmsWorker.ELAPSED_ALARMS_SMS_EVENT_SENSOR_TAG_WORK+"_" + (int) _event._id); }
Example 5
Source File: EventPreferencesNotification.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
private void removeAlarm(Context context) { try { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { //Intent intent = new Intent(context, NotificationEventEndBroadcastReceiver.class); Intent intent = new Intent(); intent.setAction(PhoneProfilesService.ACTION_NOTIFICATION_EVENT_END_BROADCAST_RECEIVER); //intent.setClass(context, NotificationEventEndBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, (int) _event._id, intent, PendingIntent.FLAG_NO_CREATE); if (pendingIntent != null) { //PPApplication.logE("EventPreferencesNotification.removeAlarm", "alarm found"); alarmManager.cancel(pendingIntent); pendingIntent.cancel(); } } } catch (Exception e) { PPApplication.recordException(e); } PhoneProfilesService.cancelWork(ElapsedAlarmsWorker.ELAPSED_ALARMS_NOTIFICATION_EVENT_SENSOR_TAG_WORK+"_" + (int) _event._id); }
Example 6
Source File: EventPreferencesNFC.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
void removeAlarm(Context context) { try { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { //Intent intent = new Intent(context, NFCEventEndBroadcastReceiver.class); Intent intent = new Intent(); intent.setAction(PhoneProfilesService.ACTION_NFC_EVENT_END_BROADCAST_RECEIVER); //intent.setClass(context, NFCEventEndBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, (int) _event._id, intent, PendingIntent.FLAG_NO_CREATE); if (pendingIntent != null) { //PPApplication.logE("EventPreferencesNFC.removeAlarm", "alarm found"); alarmManager.cancel(pendingIntent); pendingIntent.cancel(); } } } catch (Exception e) { PPApplication.recordException(e); } PhoneProfilesService.cancelWork(ElapsedAlarmsWorker.ELAPSED_ALARMS_NFC_EVENT_SENSOR_TAG_WORK+"_" + (int) _event._id); }
Example 7
Source File: NotificationScheduler.java From Muslim-Athkar-Islamic-Reminders with MIT License | 6 votes |
public static void cancelReminder(Context context,Class<?> cls) { // Disable a receiver ComponentName receiver = new ComponentName(context, cls); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); Intent intent1 = new Intent(context, cls); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, DAILY_REMINDER_REQUEST_CODE, intent1, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE); if (am != null) { am.cancel(pendingIntent); pendingIntent.cancel(); } }
Example 8
Source File: RetryManager.java From OPFPush with Apache License 2.0 | 6 votes |
private void cancelRetry(@NonNull final String providerName, @NonNull final Operation operation, @NonNull final String action) { reset(providerName, operation); retryProvidersActions.remove(new Pair<>(providerName, action)); if (retryProvidersActions.isEmpty()) { unregisterConnectivityChangeReceiver(); } final Intent intent = new Intent(appContext, RetryBroadcastReceiver.class); intent.setAction(action); final PendingIntent pendingIntent = PendingIntent .getBroadcast(appContext, providerName.hashCode(), intent, 0); alarmManager.cancel(pendingIntent); pendingIntent.cancel(); }
Example 9
Source File: AsyncTimersTableUpdateHandler.java From ClockPlus with GNU General Public License v3.0 | 6 votes |
private void cancelAlarm(Timer timer, boolean removeNotification) { // Cancel the alarm scheduled. If one was never scheduled, does nothing. AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE); PendingIntent pi = createTimesUpIntent(timer); // Now can't be null am.cancel(pi); pi.cancel(); if (removeNotification) { TimerNotificationService.cancelNotification(getContext(), timer.getId()); } // Won't do anything if not actually started // This was actually a problem for successive Timers. We actually don't need to // manually stop the service in many cases. See usages of TimerController.stop(). // getContext().stopService(new Intent(getContext(), TimerRingtoneService.class)); // TODO: Do we need to finish TimesUpActivity? }
Example 10
Source File: OmahaClient.java From delion with Apache License 2.0 | 5 votes |
/** * Cancels the alarm that launches this service. It will be replaced when Chrome next resumes. */ private void cancelRepeatingAlarm() { Intent requestIntent = createRegisterRequestIntent(this); PendingIntent pendingIntent = PendingIntent.getService(this, 0, requestIntent, PendingIntent.FLAG_NO_CREATE); // Setting FLAG_NO_CREATE forces Android to return an already existing PendingIntent. // Here it would be the one that was used to create the existing alarm (if it exists). // If the pendingIntent is null, it is likely that no alarm was created. if (pendingIntent != null) { AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.cancel(pendingIntent); pendingIntent.cancel(); } }
Example 11
Source File: UpodsApplication.java From uPods-android with Apache License 2.0 | 5 votes |
public static void setAlarmManagerTasks(Context context) { try { if (ProfileManager.getInstance().getSubscribedPodcasts().size() == 0) { return; } AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, NetworkTasksService.class); intent.setAction(NetworkTasksService.ACTION_CHECK_FOR_NEW_EPISODS); PendingIntent alarmIntent = PendingIntent.getService(context, CHECK_NEW_EPISODS_INTENT_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); if (SettingsManager.getInstace().getBooleanSettingsValue(SettingsManager.JS_NOTIFY_EPISODES)) { long interval = SettingsManager.getInstace().getIntSettingsValue(SettingsManager.JS_PODCASTS_UPDATE_TIME); //interval = TimeUnit.MINUTES.toMillis(60); alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), interval, alarmIntent); Logger.printInfo(TAG, "Alarm managers - Episods check for updates task added"); } else { alarmIntent.cancel(); alarmMgr.cancel(alarmIntent); Logger.printInfo(TAG, "Alarm managers - Episods check for updates task canceled"); } } catch (Exception e) { Logger.printInfo(TAG, "Alarm managers - can't set alarm manager"); e.printStackTrace(); } }
Example 12
Source File: RunApplicationWithDelayBroadcastReceiver.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
static void removeDelayAlarm(Context context, String runApplicationData) { int requestCode = hashData(runApplicationData); try { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { Context _context = context; if (PhoneProfilesService.getInstance() != null) _context = PhoneProfilesService.getInstance(); //Intent intent = new Intent(_context, RunApplicationWithDelayBroadcastReceiver.class); Intent intent = new Intent(); intent.setAction(PhoneProfilesService.ACTION_RUN_APPLICATION_DELAY_BROADCAST_RECEIVER); //intent.setClass(context, RunApplicationWithDelayBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(_context, requestCode, intent, PendingIntent.FLAG_NO_CREATE); if (pendingIntent != null) { //PPApplication.logE("RunApplicationWithDelayBroadcastReceiver.removeDelayAlarm", "alarm found"); alarmManager.cancel(pendingIntent); pendingIntent.cancel(); } } } catch (Exception e) { PPApplication.recordException(e); } PhoneProfilesService.cancelWork(ElapsedAlarmsWorker.ELAPSED_ALARMS_RUN_APPLICATION_WITH_DELAY_TAG_WORK+"_"+requestCode); PPApplication.elapsedAlarmsRunApplicationWithDelayWork.remove(ElapsedAlarmsWorker.ELAPSED_ALARMS_RUN_APPLICATION_WITH_DELAY_TAG_WORK+"_"+requestCode); //PPApplication.logE("[HANDLER] RunApplicationWithDelayBroadcastReceiver.removeAlarm", "removed"); }
Example 13
Source File: ClockService.java From ToDoList with Apache License 2.0 | 5 votes |
private void cancelNotification() { Intent intent = ClockActivity.newIntent(getApplicationContext()); PendingIntent pi = PendingIntent .getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_NO_CREATE); pi.cancel(); getNotificationManager().cancel(NOTIFICATION_ID); }
Example 14
Source File: ReminderReceiver.java From privacy-friendly-shopping-list with Apache License 2.0 | 5 votes |
public void cancelAlarm(Context context, Intent i, String listId) { // If the alarm has been set, cancel it. alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pi = PendingIntent.getService(context, Integer.parseInt(listId), i, PendingIntent.FLAG_CANCEL_CURRENT); pi.cancel(); alarmMgr.cancel(pi); }
Example 15
Source File: KcaService.java From kcanotify_h5-master with GNU General Public License v3.0 | 5 votes |
private void processDockingSpeedup(int dockId) { KcaApiData.updateShipHpFull(KcaDocking.getShipId(dockId)); KcaDocking.setShipId(dockId, 0); KcaDocking.setCompleteTime(dockId, -1); PendingIntent pendingIntent = PendingIntent.getService( getApplicationContext(), getNotificationId(NOTI_DOCK, dockId), new Intent(getApplicationContext(), KcaAlarmService.class), PendingIntent.FLAG_UPDATE_CURRENT ); pendingIntent.cancel(); alarmManager.cancel(pendingIntent); }
Example 16
Source File: AlarmSyncScheduler.java From aptoide-client-v8 with GNU General Public License v3.0 | 4 votes |
@Override public void cancel(String syncId) { final PendingIntent pendingIntent = getPendingIntent(buildIntent(syncId, false)); alarmManager.cancel(pendingIntent); pendingIntent.cancel(); syncStorage.remove(syncId); }
Example 17
Source File: Scopes.java From deagle with Apache License 2.0 | 4 votes |
@Override public boolean unmark(@NonNull final String tag) { final PendingIntent mark = PendingIntent.getBroadcast(mContext, 0, makeIntent(tag), FLAG_NO_CREATE); if (mark == null) return false; mark.cancel(); return true; }
Example 18
Source File: CGMWidget.java From NightWidget with GNU General Public License v2.0 | 4 votes |
@Override public void onDeleted(Context context, int[] AppWidgetIds){ log.info("onDeleted"); SharedPreferences settings = context.getSharedPreferences("widget_prefs", 0); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIDs = appWidgetManager .getAppWidgetIds(new ComponentName(context, CGMWidget.class)); if (appWidgetIDs.length > 0) { log.info("DISABLE Length "+appWidgetIDs.length); String key = String.format(Locale.US,"appwidget%d_configured", appWidgetIDs[0]); settings.edit().remove("widget_ops_"+appWidgetIDs[0]).commit(); settings.edit().remove("widget_configuring_"+appWidgetIDs[0]).commit(); if (settings.contains(key)) settings.edit().remove(key).commit(); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); // Perform this loop procedure for each App Widget that belongs to this provider SharedPreferences.Editor editor= prefs.edit(); editor.putBoolean("widgetEnabled", false); editor.remove("widget_uuid"); editor.commit(); final AlarmManager m = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (service == null){ log.info("ISNULL!!!!"); }else m.cancel(service); final Intent in = new Intent(context, CGMWidgetUpdater.class); int i = 100; boolean alarmUp = (PendingIntent.getService(context, 27, in, PendingIntent.FLAG_NO_CREATE) != null); while (alarmUp && i > 0){ log.warn("I AM KILLING SERVICES " +i); i--; PendingIntent pI = PendingIntent.getService(context, 27, in, PendingIntent.FLAG_NO_CREATE); if (pI != null) pI.cancel(); m.cancel(PendingIntent.getService(context, 27, in, PendingIntent.FLAG_NO_CREATE)); alarmUp = (PendingIntent.getService(context, 27, in, PendingIntent.FLAG_NO_CREATE) != null); service = null; } log.warn("I HAVE KILLED SERVICES "); mHandlerWatchService.removeCallbacks(mWatchAction); }
Example 19
Source File: AlarmController.java From ClockPlus with GNU General Public License v3.0 | 4 votes |
/** * Cancel the alarm. This does NOT check if you previously scheduled the alarm. * @param rescheduleIfRecurring True if the alarm should be rescheduled after cancelling. * This param will only be considered if the alarm has recurrence * and is enabled. */ public void cancelAlarm(Alarm alarm, boolean showSnackbar, boolean rescheduleIfRecurring) { Log.d(TAG, "Cancelling alarm " + alarm); AlarmManager am = (AlarmManager) mAppContext.getSystemService(Context.ALARM_SERVICE); PendingIntent pi = alarmIntent(alarm, true); if (pi != null) { am.cancel(pi); pi.cancel(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Remove alarm in the status bar Intent alarmChanged = new Intent("android.intent.action.ALARM_CHANGED"); alarmChanged.putExtra("alarmSet", false/*enabled*/); mAppContext.sendBroadcast(alarmChanged); } } pi = notifyUpcomingAlarmIntent(alarm, true); if (pi != null) { am.cancel(pi); pi.cancel(); } // Does nothing if it's not posted. removeUpcomingAlarmNotification(alarm); final int hoursToNotifyInAdvance = AlarmPreferences.hoursBeforeUpcoming(mAppContext); // ------------------------------------------------------------------------------------ // TOneverDO: Place block after making value changes to the alarm. if ((hoursToNotifyInAdvance > 0 && showSnackbar // TODO: Consider showing the snackbar for non-upcoming alarms too; // then, we can remove these checks. && alarm.ringsWithinHours(hoursToNotifyInAdvance)) || alarm.isSnoozed()) { long time = alarm.isSnoozed() ? alarm.snoozingUntil() : alarm.ringsAt(); String msg = mAppContext.getString(R.string.upcoming_alarm_dismissed, formatTime(mAppContext, time)); showSnackbar(msg); } // ------------------------------------------------------------------------------------ if (alarm.isSnoozed()) { alarm.stopSnoozing(); } if (!alarm.hasRecurrence()) { alarm.setEnabled(false); } else if (alarm.isEnabled() && rescheduleIfRecurring) { if (alarm.ringsWithinHours(hoursToNotifyInAdvance)) { // Still upcoming today, so wait until the normal ring time // passes before rescheduling the alarm. alarm.ignoreUpcomingRingTime(true); // Useful only for VH binding Intent intent = new Intent(mAppContext, PendingAlarmScheduler.class) .putExtra(PendingAlarmScheduler.EXTRA_ALARM_ID, alarm.getId()); pi = PendingIntent.getBroadcast(mAppContext, alarm.getIntId(), intent, FLAG_CANCEL_CURRENT); am.set(AlarmManager.RTC_WAKEUP, alarm.ringsAt(), pi); } else { scheduleAlarm(alarm, false); } } save(alarm); // If service is not running, nothing happens mAppContext.stopService(new Intent(mAppContext, AlarmRingtoneService.class)); }
Example 20
Source File: KcaService.java From kcanotify_h5-master with GNU General Public License v3.0 | 4 votes |
private void processDockingInfo(boolean reset_flag) { int dockId, shipId, state; long completeTime; JsonArray data = KcaDocking.getDockData(); if (data == null) return; for (int i = 0; i < data.size(); i++) { JsonObject ndockData = data.get(i).getAsJsonObject(); state = ndockData.get("api_state").getAsInt(); int nid = getNotificationId(NOTI_DOCK, i); Intent deleteIntent = new Intent(this, KcaAlarmService.class).setAction(DELETE_ACTION.concat(String.valueOf(nid))); startService(deleteIntent); if (state != -1) { dockId = ndockData.get("api_id").getAsInt() - 1; shipId = ndockData.get("api_ship_id").getAsInt(); completeTime = ndockData.get("api_complete_time").getAsLong(); Intent aIntent = new Intent(getApplicationContext(), KcaAlarmService.class); if (KcaDocking.getCompleteTime(dockId) != -1) { if (KcaDocking.getShipId(dockId) != shipId || reset_flag) { PendingIntent pendingIntent = PendingIntent.getService( getApplicationContext(), getNotificationId(NOTI_DOCK, dockId), new Intent(getApplicationContext(), KcaAlarmService.class), PendingIntent.FLAG_UPDATE_CURRENT ); pendingIntent.cancel(); alarmManager.cancel(pendingIntent); if (shipId != 0) setDockingAlarm(dockId, shipId, completeTime, aIntent); KcaDocking.setShipId(dockId, shipId); } KcaDocking.setCompleteTime(dockId, completeTime); } else { if (state == 1) { setDockingAlarm(dockId, shipId, completeTime, aIntent); KcaDocking.setShipId(dockId, shipId); KcaDocking.setCompleteTime(dockId, completeTime); } } } } }