List of usage examples for android.app AlarmManager set
public void set(@AlarmType int type, long triggerAtMillis, PendingIntent operation)
Schedule an alarm.
From source file:uk.bowdlerize.service.CensorCensusService.java
private void onProbeFinish() { AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Intent i = new Intent(CensorCensusService.this, CensorCensusService.class); i.putExtra(API.EXTRA_POLL, true);// www .j a v a 2 s. co m PendingIntent pi = PendingIntent.getService(CensorCensusService.this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); //If we are polling lets set our next tick if (getSharedPreferences(MainActivity.class.getSimpleName(), Context.MODE_PRIVATE) .getInt(API.SETTINGS_GCM_PREFERENCE, API.SETTINGS_GCM_FULL) == API.SETTINGS_GCM_DISABLED) { am.cancel(pi); // cancel any existing alarms //TODO Setback to 60000 long repeat = (long) (getPreferences(CensorCensusService.this).getInt(API.SETTINGS_FREQUENCY, 1) * 60000);//60000 or 5000 Log.e("onProbeFinish", Long.toString(repeat)); Log.e("onProbeFinish", " - "); Log.e("onProbeFinish", " - "); Log.e("onProbeFinish", " - "); am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + repeat, pi); } else { Log.e("onProbeFinish", "Cancel everything!"); Log.e("onProbeFinish", " - "); Log.e("onProbeFinish", " - "); Log.e("onProbeFinish", " - "); am.cancel(pi); // cancel any existing alarms stopSelf(); } }
From source file:com.negaheno.android.NotificationsController.java
private void scheduleNotificationDelay(boolean onlineReason) { try {/*from ww w. j a va2 s . c o m*/ FileLog.e("tmessages", "delay notification start"); AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationDelay.class), 0); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); if (onlineReason) { alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 3 * 1000, pintent); } else { alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 500, pintent); } } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.negaheno.android.NotificationsController.java
private void scheduleNotificationRepeat() { try {/*from w w w.j a v a 2 s. com*/ AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); int minutes = preferences.getInt("repeat_messages", 60); if (minutes > 0 && personal_count > 0) { alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + minutes * 60 * 1000, pintent); } else { alarm.cancel(pintent); } } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:org.vshgap.android.NotificationsController.java
private void scheduleNotificationDelay(boolean onlineReason) { try {//from ww w.j a va 2 s . c om FileLog.e("tmessages", "delay notification start, onlineReason = " + onlineReason); AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationDelay.class), 0); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); if (onlineReason) { alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 3 * 1000, pintent); } else { alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000, pintent); } } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:org.proninyaroslav.libretorrent.services.TorrentTaskService.java
@Override public void onTaskRemoved(Intent rootIntent) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { Intent restartServiceIntent = new Intent(getApplicationContext(), this.getClass()); restartServiceIntent.setPackage(getPackageName()); PendingIntent restartServicePendingIntent = PendingIntent.getService(getApplicationContext(), 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT); AlarmManager alarmService = (AlarmManager) getApplicationContext() .getSystemService(Context.ALARM_SERVICE); alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePendingIntent); }/*from ww w.j a v a 2s . c o m*/ }
From source file:com.zld.ui.ZldNewActivity.java
/** * ?Service???//from ww w .j a v a2 s . c o m * * @param intent 1 * @param bundle 2 * @param action 3 */ private void serIntent(Intent intent, Bundle bundle, String action) { intent.setClass(ZldNewActivity.this, HomeExitPageService.class); bundle.putString(INTENT_KEY, action); intent.putExtras(bundle); PendingIntent sender = PendingIntent.getService(ZldNewActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), sender); }
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private void setTriggerAlwaysAlarm(int trigId, String trigDesc) { cancelTriggerAlwaysAlarm(trigId);/*w w w. j av a 2s .c o m*/ LocTrigDesc desc = new LocTrigDesc(); if (!desc.loadString(trigDesc)) { return; } if (!desc.shouldTriggerAlways()) { return; } Log.v(TAG, "LocTrigService: Setting trigger always alarm(" + trigId + ", " + trigDesc + ")"); Calendar target = Calendar.getInstance(); target.set(Calendar.HOUR_OF_DAY, desc.getEndTime().getHour()); target.set(Calendar.MINUTE, desc.getEndTime().getMinute()); target.set(Calendar.SECOND, 0); LocationTrigger locTrig = new LocationTrigger(); if (locTrig.hasTriggeredToday(this, trigId)) { target.add(Calendar.DAY_OF_YEAR, 1); } else if (System.currentTimeMillis() >= target.getTimeInMillis()) { target.add(Calendar.DAY_OF_YEAR, 1); } Intent i = createTriggerAlwaysAlarmIntent(trigId); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE); Log.v(TAG, "LocTrigService: Calculated target time: " + target.getTime().toString()); long alarmTime = target.getTimeInMillis(); /* Convert the alarm time to elapsed real time. * If we dont do this, a time change in the system might * set off all the alarms and a trigger might go off before * we get a chance to cancel it */ long elapsedRT = alarmTime - System.currentTimeMillis(); if (elapsedRT <= 0) { Log.v(TAG, "LocTrigService: negative elapsed realtime - " + "alarm not setting: " + trigId); return; } Log.v(TAG, "LocTrigService: Setting alarm for " + elapsedRT + " millis into the future"); alarmMan.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + elapsedRT, pi); }
From source file:org.ohmage.triggers.types.location.LocTrigService.java
private void setTriggerAlwaysAlarm(int trigId, String trigDesc) { cancelTriggerAlwaysAlarm(trigId);//from w ww .ja va 2s . c om LocTrigDesc desc = new LocTrigDesc(); if (!desc.loadString(trigDesc)) { return; } if (!desc.shouldTriggerAlways()) { return; } Log.i(DEBUG_TAG, "LocTrigService: Setting trigger always alarm(" + trigId + ", " + trigDesc + ")"); Calendar target = Calendar.getInstance(); target.set(Calendar.HOUR_OF_DAY, desc.getEndTime().getHour()); target.set(Calendar.MINUTE, desc.getEndTime().getMinute()); target.set(Calendar.SECOND, 0); LocationTrigger locTrig = new LocationTrigger(); if (locTrig.hasTriggeredToday(this, trigId)) { target.add(Calendar.DAY_OF_YEAR, 1); } else if (System.currentTimeMillis() >= target.getTimeInMillis()) { target.add(Calendar.DAY_OF_YEAR, 1); } Intent i = createTriggerAlwaysAlarmIntent(trigId); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE); Log.i(DEBUG_TAG, "LocTrigService: Calculated target time: " + target.getTime().toString()); long alarmTime = target.getTimeInMillis(); /* Convert the alarm time to elapsed real time. * If we dont do this, a time change in the system might * set off all the alarms and a trigger might go off before * we get a chance to cancel it */ long elapsedRT = alarmTime - System.currentTimeMillis(); if (elapsedRT <= 0) { Log.i(DEBUG_TAG, "LocTrigService: negative elapsed realtime - " + "alarm not setting: " + trigId); return; } Log.i(DEBUG_TAG, "LocTrigService: Setting alarm for " + elapsedRT + " millis into the future"); alarmMan.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + elapsedRT, pi); }
From source file:com.android.exchange.ExchangeService.java
private void setAlarm(long id, long millis) { synchronized (mPendingIntents) { PendingIntent pi = mPendingIntents.get(id); if (pi == null) { Intent i = new Intent(this, MailboxAlarmReceiver.class); i.putExtra("mailbox", id); i.setData(Uri.parse("Box" + id)); pi = PendingIntent.getBroadcast(this, 0, i, 0); mPendingIntents.put(id, pi); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + millis, pi); //log("+Alarm set for " + alarmOwner(id) + ", " + millis/1000 + "s"); }/* w w w . j av a 2s. com*/ } }
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 {/*w w w .j a v a2s. com*/ 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; }