List of usage examples for android.app AlarmManager cancel
public void cancel(OnAlarmListener listener)
From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java
private void cancelNextDayAlarm() { AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(mDateChangePendingIntent); }
From source file:edu.rit.csh.androidwebnews.RecentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); newsgroupListMenu = new NewsgroupListMenu(this); newsgroupListMenu.checkEnabled();//w ww . j a v a 2 s.c o m dialog = new InvalidApiKeyDialog(this); connectionDialog = new ConnectionExceptionDialog(this); ftd = new FirstTimeDialog(this); setContentView(R.layout.activity_recent); rf = (RecentFragment) getSupportFragmentManager().findFragmentById(R.id.recent_fragment); if (!sharedPref.getBoolean("first_time", true)) { hc.getNewest(true); if (!sharedPref.getString("newsgroups_json_string", "").equals("")) { newsgroupListMenu .update(hc.getNewsGroupFromString(sharedPref.getString("newsgroups_json_string", ""))); hc.startUnreadCountTask(); } else { hc.getNewsGroups(); } Intent intent = new Intent(this, UpdaterService.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // if the run service is selected, an alarm is started to repeat over given time if (sharedPref.getBoolean("run_service", false)) { String timeString = sharedPref.getString("time_between_checks", "15"); int time = 15; if (!timeString.equals("")) { time = Integer.valueOf(timeString); } alarm.cancel(pintent); alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), time * 60000, pintent); } else { alarm.cancel(pintent); } } else { ftd.show(); SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean("first_time", false); editor.commit(); } setTitle("Recent Posts"); }
From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java
@Override public void cancelNotifications_(JSONArray notificationIds) { Log.d(C.TAG, "LocalNotificationsBackend.cancelNotifications_: "); Editor editor = mPrefs.edit();//from w w w .j av a 2 s . c o m AlarmManager am = (AlarmManager) mContext.getSystemService(Service.ALARM_SERVICE); NotificationManager nm = (NotificationManager) mContext.getSystemService(Service.NOTIFICATION_SERVICE); for (int i = 0, max = notificationIds.length(); i < max; i++) { int id = notificationIds.optInt(i); String idString = Integer.toString(id); PendingIntent pendingIntent = createPendingIntentForSchedule(idString); am.cancel(pendingIntent); nm.cancel(NOTIFICATION_MASK | id); String key = PREFS_PREFIX + idString; editor.remove(key); } editor.commit(); }
From source file:org.numixproject.hermes.irc.IRCService.java
/** * Check status of service//from w ww .j av a 2 s . c o m */ public void checkServiceStatus() { boolean shutDown = true; ArrayList<Server> mServers = Hermes.getInstance().getServersAsArrayList(); int mSize = mServers.size(); Server server; for (int i = 0; i < mSize; i++) { server = mServers.get(i); 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:com.example.cody.tapwater.activities.MainActivity.java
@Override public void onResume() { super.onResume(); System.out.println("Alarm manager setup"); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); String prompts = prefs.getString("prompts", "5"); String beginStr = prefs.getString("begin_time", ""); String endStr = prefs.getString("end_time", ""); Calendar beginCal = Calendar.getInstance(); Calendar endCal = Calendar.getInstance(); try {/*from w w w . j av a2s . com*/ beginCal.setTime(sdf.parse(beginStr)); endCal.setTime(sdf.parse(endStr)); } catch (ParseException e) { e.printStackTrace(); } long interval = notificationIntervalCalculation(Integer.valueOf(prompts), beginCal, endCal); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Intent i = new Intent(context, NotificationService.class); PendingIntent pi = PendingIntent.getService(context, 0, i, 0); am.cancel(pi); // by my own convention, minutes <= 0 means notifications are disabled if (interval > 0) { am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + interval, interval, pi); } }
From source file:com.google.android.apps.muzei.api.MuzeiArtSource.java
private void clearUpdateAlarm() { AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.cancel(getHandleNextCommandPendingIntent(this)); }
From source file:org.yaaic.irc.IRCService.java
/** * On Destroy//from w w w . j av a 2s. 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; } }
From source file:com.poloure.simplerss.FeedsActivity.java
private void setServiceIntent(int state) { // Load the ManageFeedsRefresh boolean value from settings. SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); if (!pref.getBoolean("refreshing_enabled", false) && ALARM_SERVICE_START == state) { return;//from ww w . ja v a2 s . c o m } // Create intent, turn into pending intent, and get the alarm manager. Intent intent = new Intent(this, ServiceUpdate.class); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); // Depending on the state string, start or stop the service. if (ALARM_SERVICE_START == state) { String intervalString = pref.getString("refresh_interval", "120"); long interval = Long.parseLong(intervalString) * MINUTE_VALUE; long next = System.currentTimeMillis() + interval; am.setRepeating(AlarmManager.RTC_WAKEUP, next, interval, pendingIntent); } else if (ALARM_SERVICE_STOP == state) { am.cancel(pendingIntent); } }
From source file:at.ac.uniklu.mobile.sportal.service.MutingService.java
/** * Turns OFF automatic ringtone muting during courses. */// w ww. java 2 s. c om private void turnOff() { Log.d(TAG, "turnOff()"); Analytics.onEvent(Analytics.EVENT_MUTINGSERVICE_OFF); // if the phone is currently in a muting period, turn the ringtone back on before turning off the service SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); if (Preferences.isMutingPeriod(preferences)) { MutingUtils.ringtoneTurnOn(this); Preferences.setMutingPeriod(preferences, false); } // remove eventually existing user notification removeNotification(Studentportal.NOTIFICATION_MS_INFO); // cancel an eventually existing pending alarm and the beloging intent as well (otherwise isRunning would always return true) AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Intent alarmIntent = new Intent(this, OnAlarmReceiver.class).putExtra(ACTION, ACTION_NONE); PendingIntent pendingAlarmIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.cancel(pendingAlarmIntent); pendingAlarmIntent.cancel(); // cancel an eventually exisiting location broadcast receiver LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Intent locationIntent = new Intent("at.ac.uniklu.mobile.sportal.LOCATION_UPDATE"); PendingIntent pendingLocationIntent = PendingIntent.getBroadcast(this, 0, locationIntent, PendingIntent.FLAG_UPDATE_CURRENT); locationManager.removeUpdates(pendingLocationIntent); pendingLocationIntent.cancel(); if (isRunning()) { Log.e(TAG, "COULD NOT TURN OFF"); } }
From source file:org.restcomm.app.qoslib.Services.TrackingManager.java
public void startCoverageTracking() { bTracking = true;/*from w w w . j a va2s . co m*/ this.owner.keepAwake(true, true); AlarmManager alarmMgr = (AlarmManager) owner.getSystemService(Service.ALARM_SERVICE); Intent intent = new Intent(IntentHandler.ACTION_TRACKING_5MINUTE); PendingIntent alarm = PendingIntent.getBroadcast(owner, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); alarmMgr.cancel(alarm); //trackingExpires = System.currentTimeMillis() + (numFiveMinutePeriods) * 5L * 60L * 1000L; //PreferenceManager.getDefaultSharedPreferences(owner).edit().putLong(PreferenceKeys.Miscellaneous.TRACKING_EXPIRES, trackingExpires).commit(); long expiresTime = System.currentTimeMillis() + (durMinutes * 60 - trackingElapsed) * 1000; PreferenceManager.getDefaultSharedPreferences(owner).edit() .putLong(PreferenceKeys.Miscellaneous.ENGINEER_MODE_EXPIRES_TIME, expiresTime).commit(); long delay = 0; if (durMinutes == 0) // continuous tracking { //trackingExpires = 0; // store a tracking expiry date of 10 million seconds from now //PreferenceManager.getDefaultSharedPreferences(owner).edit().putLong(PreferenceKeys.Miscellaneous.TRACKING_EXPIRES, System.currentTimeMillis()+10000000000l).commit(); PreferenceManager.getDefaultSharedPreferences(owner).edit() .putLong(PreferenceKeys.Miscellaneous.ENGINEER_MODE_EXPIRES_TIME, System.currentTimeMillis()) .commit(); } LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "startTracking", "durationMinutes=" + durMinutes + ",covInterval=" + coverageInterval + ",SpeedInterval=" + speedtestInterval + ",videoInterval=" + videoInterval); delay = 5L * 60L * 1000L; alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000, delay, alarm); }