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:com.embeddedlog.LightUpDroid.timer.TimerReceiver.java
private void showCollapsedNotificationWithNext(final Context context, String title, String text, Long nextBroadcastTime) { Intent activityIntent = new Intent(context, DeskClock.class); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activityIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.TIMER_TAB_INDEX); PendingIntent pendingActivityIntent = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); showCollapsedNotification(context, title, text, Notification.PRIORITY_HIGH, pendingActivityIntent, IN_USE_NOTIFICATION_ID, false); if (nextBroadcastTime == null) { return;/* w w w .j a v a2 s . c om*/ } Intent nextBroadcast = new Intent(); nextBroadcast.setAction(Timers.NOTIF_IN_USE_SHOW); PendingIntent pendingNextBroadcast = PendingIntent.getBroadcast(context, 0, nextBroadcast, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Utils.isKitKatOrLater()) { alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } else { alarmManager.set(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } }
From source file:me.tatarka.support.internal.job.JobStore.java
private void markForBootSession(JobStatus jobStatus) { // Pending intents are cleared on reboot. Therefore, we can use one to mark that we haven't // rebooted yet. Intent intent = new Intent(mContext, JobSchedulerService.class).setAction(jobStatus.toShortString()); PendingIntent pendingIntent = PendingIntent.getService(mContext, jobStatus.getJobId(), intent, PendingIntent.FLAG_CANCEL_CURRENT); // Have the alarm manager hold on to our pending intent so it will still be there even if our app is killed. AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.ELAPSED_REALTIME, Long.MAX_VALUE, pendingIntent); }
From source file:com.sean.takeastand.alarmprocess.ScheduledRepeatingAlarm.java
@Override public void pause() { //Cancel previous PendingIntent pendingIntent = createPendingIntent(mContext, mCurrentAlarmSchedule); AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); am.cancel(pendingIntent);//from www . ja va 2 s .c om endAlarmService(); int totalPauseTime = Utils.getDefaultPauseAmount(mContext); long delayTimeInMillis = totalPauseTime * Constants.secondsInMinute * Constants.millisecondsInSecond; long triggerTime = SystemClock.elapsedRealtime() + delayTimeInMillis; PendingIntent pausePendingIntent = createPausePendingIntent(mContext, mCurrentAlarmSchedule); am.set(AlarmManager.ELAPSED_REALTIME, triggerTime, pausePendingIntent); Calendar pausedUntilTime = Calendar.getInstance(); pausedUntilTime.add(Calendar.MINUTE, Utils.getDefaultPauseAmount(mContext)); Utils.setPausedTime(pausedUntilTime, mContext); Utils.setImageStatus(mContext, Constants.SCHEDULE_PAUSED); }
From source file:org.opensilk.music.ui2.LauncherActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Timber.v("onActivityResult"); switch (requestCode) { case StartActivityForResult.APP_REQUEST_SETTINGS: switch (resultCode) { case ActivityResult.RESULT_RESTART_APP: // Hack to force a refresh for our activity for eg theme change AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); PendingIntent pi = PendingIntent.getActivity(this, 0, getBaseContext().getPackageManager() .getLaunchIntentForPackage(getBaseContext().getPackageName()), PendingIntent.FLAG_CANCEL_CURRENT); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 700, pi); finish();// www . ja v a 2 s. co m break; case ActivityResult.RESULT_RESTART_FULL: killServiceOnExit = true; onActivityResult(StartActivityForResult.APP_REQUEST_SETTINGS, ActivityResult.RESULT_RESTART_APP, data); break; } break; case StartActivityForResult.PLUGIN_REQUEST_LIBRARY: case StartActivityForResult.PLUGIN_REQUEST_SETTINGS: mBus.post(new ActivityResult(data, requestCode, resultCode)); break; default: super.onActivityResult(requestCode, resultCode, data); } }
From source file:fr.paug.droidcon.service.SessionAlarmService.java
private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID);//from w w w . j ava2 s . c o m final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > sessionStart) { LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart); return; } // By default, sets alarm to go off at 10 minutes before session start time. If alarm // offset is provided, alarm is set to go off by that much time from now. long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionStart - MILLI_TEN_MINUTES; } else { alarmTime = currentTime + alarmOffset; } LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString()); final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. notifIntent.setData( new Uri.Builder().authority("fr.paug.droidcon").path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); LOGD(TAG, "-> Intent extra: session start " + sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); LOGD(TAG, "-> Intent extra: session end " + sessionEnd); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:org.pixmob.freemobile.netstat.SyncServiceTesting.java
public static void schedule(Context context, boolean enabled) { final Context appContext = context.getApplicationContext(); final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent syncIntent = PendingIntent.getService(appContext, 0, new Intent(appContext, SyncServiceTesting.class), PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(syncIntent);//from w ww . j a v a 2s .com if (enabled) { // Set the sync period. long period = AlarmManager.INTERVAL_HOUR; final int syncErrors = context.getSharedPreferences(INTERNAL_SP_NAME, MODE_PRIVATE) .getInt(INTERNAL_SP_KEY_SYNC_ERRORS, 0); if (syncErrors != 0) { // When there was a sync error, the sync period is longer. period = AlarmManager.INTERVAL_HOUR * Math.min(syncErrors, MAX_SYNC_ERRORS); } // Add a random time to prevent concurrent requests for the server. final long fuzz = RANDOM.nextInt(1000 * 60 * 30); period += fuzz; if (DEBUG) { Log.d(TAG, "Scheduling synchronization: next in " + (period / 1000 / 60) + " minutes"); } final long syncTime = System.currentTimeMillis() + period; am.set(AlarmManager.RTC_WAKEUP, syncTime, syncIntent); } else { if (DEBUG) { Log.d(TAG, "Synchronization schedule canceled"); } } }
From source file:com.monkey.entonado.MainActivity.java
/** * OnResume// w ww . j a v a2 s . c o m * register the broadcast receiver with the intent values to be matched */ @Override protected void onResume() { super.onResume(); registerReceiver(mReceiver, mIntentFilter); CountDownTimer t = new CountDownTimer(1000, 500) { public void onTick(long millisUntilFinished) { } public void onFinish() { if (intentoConectar) { mostrarMensaje(mensajeConexion); intentoConectar = false; } else if (intentoEnviarLista) { String mensaje = ""; boolean entro = false; if (mensajeConexion == null) { mensaje = "Estas desconectado"; } else if (mensajeConexion.equals("desconectado")) { mensaje = "Estas desconectado"; } else if (mensajeConexion.equals("Estas conectado!")) { mensaje = "La lista ha sido enviada"; Intent in = new Intent(MainActivity.this, AlarmReciever.class); PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, in, PendingIntent.FLAG_ONE_SHOT); entro = true; System.out.println("puso alarma"); AlarmManager am = (AlarmManager) MainActivity.this.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000 * 60, pi); } else { mensaje = mensajeConexion; } if (!entro) mostrarMensaje(mensaje); intentoEnviarLista = false; } } }.start(); }
From source file:org.bwgz.quotation.service.QuotationService.java
@Override protected void onHandleIntent(Intent intent) { Log.d(TAG, String.format("onHandleIntent - intent: %s (%s)", intent, new Date().toString())); SharedPreferences preferences = getSharedPreferences(QuotationApplication.APPLICATION_PREFERENCES, Context.MODE_PRIVATE); long modified = preferences.getLong(QuotationApplication.APPLICATION_PREFERENCE_QUOTATION_PICKS_MODIFIED, 0);//from w ww .j a v a2s . c om if (modified + PICKS_PERIOD < System.currentTimeMillis()) { getContentResolver().delete(PickQuotation.CONTENT_URI, null, null); getContentResolver().delete(PickPerson.CONTENT_URI, null, null); getContentResolver().delete(PickSubject.CONTENT_URI, null, null); FreebaseIdLoader freebaseIdLoader = FreebaseIdLoader.getInstance(getApplicationContext()); List<Pick> quotationPicks = freebaseIdLoader.getRandomQuotationPicks(PICK_SIZE); List<Pick> authorPicks = freebaseIdLoader.getRandomAuthorPicks(PICK_SIZE); List<Pick> subjectPicks = freebaseIdLoader.getRandomSubjectPicks(PICK_SIZE); for (int i = 0; i < PICK_SIZE; i++) { getContentResolver() .query(PickQuotation.withAppendedId(quotationPicks.get(i).getId()), null, null, null, null) .close(); getContentResolver() .query(PickPerson.withAppendedId(authorPicks.get(i).getId()), null, null, null, null) .close(); getContentResolver() .query(PickSubject.withAppendedId(subjectPicks.get(i).getId()), null, null, null, null) .close(); } SharedPreferences.Editor editor = preferences.edit(); modified = System.currentTimeMillis(); editor.putLong(QuotationApplication.APPLICATION_PREFERENCE_QUOTATION_PICKS_MODIFIED, modified); editor.putLong(QuotationApplication.APPLICATION_PREFERENCE_PERSON_PICKS_MODIFIED, modified); editor.putLong(QuotationApplication.APPLICATION_PREFERENCE_SUBJECT_PICKS_MODIFIED, modified); editor.commit(); } AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, new Intent(this, QuotationAlarmReceiver.class), 0); alarmManager.cancel(alarmIntent); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, 2); calendar.set(Calendar.MINUTE, random.nextInt(60)); calendar.set(Calendar.SECOND, random.nextInt(60)); alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis() + PICKS_PERIOD, alarmIntent); LocalBroadcastManager.getInstance(this) .sendBroadcast(new Intent(BROADCAST_ACTION).putExtra(EXTENDED_DATA_STATUS, true)); }
From source file:com.android.deskclock.timer.TimerReceiver.java
private void showCollapsedNotificationWithNext(final Context context, String title, String text, Long nextBroadcastTime) { LogUtils.d(TAG, "showCollapsedNotificationWithNext nextBroadcastTime: %d", nextBroadcastTime); Intent activityIntent = new Intent(context, DeskClock.class); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activityIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.TIMER_TAB_INDEX); PendingIntent pendingActivityIntent = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); showCollapsedNotification(context, title, text, NotificationCompat.PRIORITY_HIGH, pendingActivityIntent, IN_USE_NOTIFICATION_ID, false); if (nextBroadcastTime == null) { return;/*from w w w. ja va2s . c o m*/ } Intent nextBroadcast = new Intent(); nextBroadcast.setAction(Timers.NOTIF_IN_USE_SHOW); PendingIntent pendingNextBroadcast = PendingIntent.getBroadcast(context, 0, nextBroadcast, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Utils.isKitKatOrLater()) { alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } else { alarmManager.set(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } }
From source file:org.jamienicol.episodes.AutoRefreshHelper.java
public void rescheduleAlarm() { NetworkStateReceiver.disable(context); final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final Intent intent = new Intent(context, AutoRefreshHelper.Service.class); final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0); if (getAutoRefreshEnabled() && getAutoRefreshPeriod() != 0) { final long alarmTime = getPrevAutoRefreshTime() + getAutoRefreshPeriod(); Log.i(TAG, String.format("Scheduling auto refresh alarm for %d.", alarmTime)); alarmManager.set(AlarmManager.RTC, alarmTime, pendingIntent); } else {//from w ww. ja va2s.c om Log.i(TAG, "Cancelling auto refresh alarm."); alarmManager.cancel(pendingIntent); } }