List of usage examples for android.app AlarmManager cancel
public void cancel(OnAlarmListener listener)
From source file:org.svij.taskwarriorapp.TasksActivity.java
@Override protected void onResume() { super.onResume(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); long date_long = prefs.getLong("notifications_alarm_time", System.currentTimeMillis()); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Intent i = new Intent(this, NotificationService.class); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date_long); if (!calendar.getTime().before(new Date())) { am.cancel(pi); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), calendar.getTimeInMillis() + AlarmManager.INTERVAL_DAY, pi); }/* w w w .j av a2s. c o m*/ }
From source file:com.near.chimerarevo.activities.MainActivity.java
@Override public void onDestroy() { super.onDestroy(); if (ImageLoader.getInstance().isInited()) { ImageLoader.getInstance().clearDiskCache(); ImageLoader.getInstance().clearMemoryCache(); }//from w w w . j a v a 2 s . co m if (mHelper != null) mHelper.dispose(); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("news_search_pref", true)) { Intent intent = new Intent(getApplicationContext(), NewsService.class); PendingIntent pintent = PendingIntent.getService(getApplicationContext(), 0, intent, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarm.cancel(pintent); long delay; int sel = Integer.parseInt( PreferenceManager.getDefaultSharedPreferences(this).getString("notification_delay_pref", "0")); switch (sel) { case 0: delay = AlarmManager.INTERVAL_FIFTEEN_MINUTES; break; case 1: delay = AlarmManager.INTERVAL_HALF_HOUR; break; case 2: delay = AlarmManager.INTERVAL_HOUR; break; case 3: delay = 2 * AlarmManager.INTERVAL_HOUR; break; case 4: delay = 3 * AlarmManager.INTERVAL_HOUR; break; case 5: delay = 6 * AlarmManager.INTERVAL_HOUR; break; case 6: delay = AlarmManager.INTERVAL_HALF_DAY; break; case 7: delay = AlarmManager.INTERVAL_DAY; break; default: delay = AlarmManager.INTERVAL_HOUR; break; } alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.uptimeMillis(), delay, pintent); } }
From source file:org.chromium.chrome.browser.physicalweb.UrlManager.java
private void cancelClearNotificationAlarm() { PendingIntent pendingIntent = createClearNotificationAlarmIntent(); AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent); }
From source file:com.pacoapp.paco.triggering.NotificationCreator.java
@SuppressLint("NewApi") 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.info("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);//from ww w. j a v a 2 s .co m 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); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, elapsedDurationInMillis, intent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, elapsedDurationInMillis, intent); } }
From source file:com.klinker.android.twitter.activities.MainActivity.java
@Override public void onStart() { super.onStart(); MainActivity.isPopup = false;// w w w .ja va2 s . c om Log.v("talon_starting", "main activity starting"); sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0); // check for night mode switching int theme = AppSettings.getCurrentTheme(sharedPrefs); if (!getWindow().hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY) || sharedPrefs.getBoolean("launcher_frag_switch", false) || (theme != settings.theme && !settings.addonTheme)) { sharedPrefs.edit().putBoolean("launcher_frag_switch", false).putBoolean("dont_refresh", true).commit(); AppSettings.invalidate(); Log.v("talon_theme", "no action bar overlay found, recreating"); finish(); overridePendingTransition(0, 0); startActivity(getRestartIntent()); overridePendingTransition(0, 0); MainActivity.caughtstarting = true; // return so that it doesn't start the background refresh, that is what caused the dups. sharedPrefs.edit().putBoolean("dont_refresh_on_start", true).commit(); return; } else { sharedPrefs.edit().putBoolean("dont_refresh", false).putBoolean("should_refresh", true).commit(); } if (DrawerActivity.settings.pushNotifications) { if (!TalonPullNotificationService.isRunning) { context.startService(new Intent(context, TalonPullNotificationService.class)); } } else { context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE")); } // cancel the alarm to start the catchup service AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getService(context, 236, new Intent(context, CatchupPull.class), 0); am.cancel(pendingIntent); // cancel the old one, then start the new one in 1 min // clear the pull unread sharedPrefs.edit().putInt("pull_unread", 0).commit(); // will only run when debugging new Handler().postDelayed(new Runnable() { @Override public void run() { NotificationUtils.sendTestNotification(MainActivity.this); } }, 1000); }
From source file:org.yaaic.irc.IRCService.java
/** * Check status of service//w ww .j av a 2 s .c om */ public void checkServiceStatus() { boolean shutDown = true; List<Server> servers = Yaaic.getInstance().getServers(); for (final Server server : servers) { if (server.isDisconnected() && !server.mayReconnect()) { int serverId = server.getId(); synchronized (this) { IRCConnection connection = connections.get(serverId); if (connection != null) { connection.dispose(); } connections.remove(serverId); } synchronized (alarmIntentsLock) { // XXX: alarmIntents can be null PendingIntent pendingRIntent = alarmIntents.get(serverId); if (pendingRIntent != null) { AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.cancel(pendingRIntent); alarmIntents.remove(serverId); } ReconnectReceiver receiver = alarmReceivers.get(serverId); if (receiver != null) { unregisterReceiver(receiver); alarmReceivers.remove(serverId); } } } else { shutDown = false; } } if (shutDown) { foreground = false; stopForegroundCompat(R.string.app_name); stopSelf(); } }
From source file:me.tatarka.support.internal.job.JobStore.java
private void unmarkForBootSession(JobStatus jobStatus) { Intent intent = new Intent(mContext, JobSchedulerService.class).setAction(jobStatus.toShortString()); PendingIntent pendingIntent = PendingIntent.getService(mContext, jobStatus.getJobId(), intent, PendingIntent.FLAG_NO_CREATE); if (pendingIntent != null) { AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); am.cancel(pendingIntent); pendingIntent.cancel();/*from ww w. j a va 2 s . co m*/ } }
From source file:com.pacoapp.paco.triggering.NotificationCreator.java
@SuppressLint("NewApi") private void createAlarmForSnooze(Context context, NotificationHolder notificationHolder) { DateTime alarmTime = new DateTime(notificationHolder.getAlarmTime()); Experiment experiment = experimentProviderUtil .getExperimentByServerId(notificationHolder.getExperimentId()); Integer snoozeTime = notificationHolder.getSnoozeTime(); if (snoozeTime == null) { snoozeTime = DEFAULT_SNOOZE_10_MINUTES; }/*from ww w. ja v a2 s.c om*/ int snoozeMinutes = snoozeTime / MILLIS_IN_MINUTE; DateTime timeoutMinutes = new DateTime(alarmTime).plusMinutes(snoozeMinutes); long snoozeDurationInMillis = timeoutMinutes.getMillis(); Log.info("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); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, snoozeDurationInMillis, intent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, snoozeDurationInMillis, intent); } }
From source file:com.klinker.android.twitter.ui.MainActivity.java
@Override public void onStart() { super.onStart(); MainActivity.isPopup = false;//from ww w . ja v a 2s . c o m Log.v("talon_starting", "main activity starting"); sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); // check for night mode switching int theme = AppSettings.getCurrentTheme(sharedPrefs); if (!getWindow().hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY) || sharedPrefs.getBoolean("launcher_frag_switch", false) || (theme != settings.theme && !settings.addonTheme)) { sharedPrefs.edit().putBoolean("launcher_frag_switch", false).putBoolean("dont_refresh", true).commit(); AppSettings.invalidate(); Log.v("talon_theme", "no action bar overlay found, recreating"); finish(); overridePendingTransition(0, 0); startActivity(getRestartIntent()); overridePendingTransition(0, 0); MainActivity.caughtstarting = true; // return so that it doesn't start the background refresh, that is what caused the dups. sharedPrefs.edit().putBoolean("dont_refresh_on_start", true).commit(); return; } else { sharedPrefs.edit().putBoolean("dont_refresh", false).putBoolean("should_refresh", true).commit(); } if (DrawerActivity.settings.pushNotifications) { if (!TalonPullNotificationService.isRunning) { context.startService(new Intent(context, TalonPullNotificationService.class)); } } else { context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE")); } // cancel the alarm to start the catchup service AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getService(context, 236, new Intent(context, CatchupPull.class), 0); am.cancel(pendingIntent); // cancel the old one, then start the new one in 1 min // clear the pull unread sharedPrefs.edit().putInt("pull_unread", 0).commit(); UpdateUtils.checkUpdate(this); /*new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(1000); } catch (Exception e) { } NotificationUtils.refreshNotification(context); } }).start();*/ }
From source file:org.kaoriha.phonegap.plugins.releasenotification.Notifier.java
public void stop() { AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(ctx, Receiver.class); PendingIntent pi = PendingIntent.getBroadcast(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); am.cancel(pi); }