List of usage examples for android.app AlarmManager ELAPSED_REALTIME
int ELAPSED_REALTIME
To view the source code for android.app AlarmManager ELAPSED_REALTIME.
Click Source Link
From source file:com.google.android.apps.muzei.sync.TaskQueueService.java
private void scheduleRetryArtworkDownload() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.schedule(new JobInfo.Builder(LOAD_ARTWORK_JOB_ID, new ComponentName(this, DownloadArtworkJobService.class)) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build()); } else {/*from ww w. jav a 2s.com*/ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); int reloadAttempt = sp.getInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, 0); sp.edit().putInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, reloadAttempt + 1).commit(); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); long retryTimeMillis = SystemClock.elapsedRealtime() + (1 << reloadAttempt) * 2000; am.set(AlarmManager.ELAPSED_REALTIME, retryTimeMillis, TaskQueueService.getArtworkDownloadRetryPendingIntent(this)); } }
From source file:com.sean.takeastand.alarmprocess.UnscheduledRepeatingAlarm.java
private void setAlarm(long triggerTime) { PendingIntent pendingIntent = createPendingIntent(mContext); AlarmManager am = ((AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE)); am.set(AlarmManager.ELAPSED_REALTIME, triggerTime, pendingIntent); }
From source file:com.appsaur.tarucassist.AlarmReceiver.java
public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification timein Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using initial notification time and repeat interval time mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, RepeatTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
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 w w w.ja va 2s . c o m*/ 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:de.hero.vertretungsplan.MainActivity.java
public static void setNewAlarm(Context context, boolean set, String interval) { Intent i = new Intent(context, de.hero.vertretungsplan.CheckForUpdates.class); PendingIntent pi = PendingIntent.getService(context, 0, i, 0); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.cancel(pi); // cancel any existing alarms Log.d("MainActivity", "cancelAlarm"); if (set) {/*from ww w . j a v a 2s. co m*/ long lngInterval; switch (interval) { case "1/2": lngInterval = AlarmManager.INTERVAL_HALF_HOUR; break; case "1": lngInterval = AlarmManager.INTERVAL_HOUR; break; case "6": lngInterval = AlarmManager.INTERVAL_HALF_DAY / 2; break; case "3": default: lngInterval = AlarmManager.INTERVAL_HOUR * 3; break; } Log.d("MainActivity", "setAlarm " + interval + " Stunden"); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR / 3, lngInterval, pi); // For debugging after 10 seconds // am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, // SystemClock.elapsedRealtime() + 25000 , // AlarmManager.INTERVAL_HOUR , pi); } }
From source file:org.fdroid.enigtext.service.KeyCachingService.java
private void startTimeoutIfAppropriate() { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); boolean timeoutEnabled = sharedPreferences .getBoolean(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_PREF, false); if ((activitiesRunning == 0) && (this.masterSecret != null) && timeoutEnabled && !isPassphraseDisabled()) { long timeoutMinutes = sharedPreferences .getInt(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_INTERVAL_PREF, 60 * 5); long timeoutMillis = timeoutMinutes * 60 * 1000; Log.w("KeyCachingService", "Starting timeout: " + timeoutMillis); AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE); alarmManager.cancel(pending);//from w w w . j ava 2 s .co m alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + timeoutMillis, pending); } }
From source file:com.securecomcode.text.service.KeyCachingService.java
private void startTimeoutIfAppropriate() { boolean timeoutEnabled = TextSecurePreferences.isPassphraseTimeoutEnabled(this); if ((activitiesRunning == 0) && (this.masterSecret != null) && timeoutEnabled && !TextSecurePreferences.isPasswordDisabled(this)) { long timeoutMinutes = TextSecurePreferences.getPassphraseTimeoutInterval(this); long timeoutMillis = timeoutMinutes * 60 * 1000; Log.w("KeyCachingService", "Starting timeout: " + timeoutMillis); AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE); alarmManager.cancel(pending);/*from w w w.j a v a 2 s.co m*/ alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + timeoutMillis, pending); } }
From source file:com.sean.takeastand.alarmprocess.ScheduledRepeatingAlarm.java
private void setAlarm(long triggerTime) { Calendar nextAlarmTime = Calendar.getInstance(); nextAlarmTime.add(Calendar.MINUTE, mCurrentAlarmSchedule.getFrequency()); if ((mCurrentAlarmSchedule.getEndTime()).before(nextAlarmTime)) { Utils.setRunningScheduledAlarm(mContext, -1); Log.i(TAG, mContext.getString(R.string.alarm_day_over)); Toast.makeText(mContext, "Scheduled reminders over", Toast.LENGTH_LONG).show(); Utils.setImageStatus(mContext, Constants.NO_ALARM_RUNNING); cancelAlarm();//ww w. j a v a2s. c o m endSessionAnalytics(); } else { PendingIntent pendingIntent = createPendingIntent(mContext, mCurrentAlarmSchedule); AlarmManager am = ((AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE)); am.set(AlarmManager.ELAPSED_REALTIME, triggerTime, pendingIntent); Utils.setRunningScheduledAlarm(mContext, mCurrentAlarmSchedule.getUID()); } }
From source file:de.ub0r.android.portaltimer.UpdateReceiver.java
private void schedNext(final Context context) { Log.d(TAG, "schedNext()"); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Log.d(TAG, "current: " + mNow); long t;/*w ww. j a v a 2 s . com*/ PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm.isScreenOn()) { t = mNow + 1000L; } else { t = mNextTarget - mNow; Log.d(TAG, "t: " + t); if (t < 0) { // IllegalState? t = 30000; } else if (t < 30000) { t = 5000; } else if (t < 60000) { t = 15000; } else { t = 30000; } Log.d(TAG, "t: " + t); long diff = mNextTarget - (mNow + t); diff = (diff / 5000) * 5000; Log.d(TAG, "diff: " + diff); if (diff == 0) { t = mNow + 5000; } else { t = mNextTarget - diff - 1000; } } Log.d(TAG, "next: " + t); long et; if (t - System.currentTimeMillis() < 100) { // IllegalState? et = 1000 + SystemClock.elapsedRealtime(); } else { et = t - System.currentTimeMillis() + SystemClock.elapsedRealtime(); } am.set(AlarmManager.ELAPSED_REALTIME, et, PendingIntent.getBroadcast(context, 0, new Intent(context, UpdateReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT)); }
From source file:com.android.transmart.services.PlaceCheckinService.java
/** * {@inheritDoc}//from w ww.jav a 2s . c o m * Perform a checkin the specified venue. If the checkin fails, add it to the queue and * set an alarm to retry. * * Query the checkin queue to see if there are pending checkins to be retried. */ @Override protected void onHandleIntent(Intent intent) { // Retrieve the details for the checkin to perform. String reference = intent.getStringExtra(LocationConstants.EXTRA_KEY_REFERENCE); String id = intent.getStringExtra(LocationConstants.EXTRA_KEY_ID); long timeStamp = intent.getLongExtra(LocationConstants.EXTRA_KEY_TIME_STAMP, 0); // Check if we're running in the foreground, if not, check if // we have permission to do background updates. boolean backgroundAllowed = cm.getBackgroundDataSetting(); boolean inBackground = sharedPreferences.getBoolean(LocationConstants.EXTRA_KEY_IN_BACKGROUND, true); if (reference != null && !backgroundAllowed && inBackground) { addToQueue(timeStamp, reference, id); return; } // Check to see if we are connected to a data network. NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); // If we're not connected then disable the retry Alarm, enable the Connectivity Changed Receiver // and add the new checkin directly to the queue. The Connectivity Changed Receiver will listen // for when we connect to a network and start this service to retry the checkins. if (!isConnected) { // No connection so no point triggering an alarm to retry until we're connected. alarmManager.cancel(retryQueuedCheckinsPendingIntent); // Enable the Connectivity Changed Receiver to listen for connection to a network // so we can commit the pending checkins. PackageManager pm = getPackageManager(); ComponentName connectivityReceiver = new ComponentName(this, ConnectivityChangedReceiver.class); pm.setComponentEnabledSetting(connectivityReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); // Add this checkin to the queue. addToQueue(timeStamp, reference, id); } else { // Execute the checkin. If it fails, add it to the retry queue. if (reference != null) { if (!checkin(timeStamp, reference, id)) addToQueue(timeStamp, reference, id); } // Retry the queued checkins. ArrayList<String> successfulCheckins = new ArrayList<String>(); Cursor queuedCheckins = contentResolver.query(QueuedCheckinsContentProvider.CONTENT_URI, null, null, null, null); try { // Retry each checkin. while (queuedCheckins.moveToNext()) { long queuedTimeStamp = queuedCheckins .getLong(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_TIME_STAMP)); String queuedReference = queuedCheckins .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_REFERENCE)); String queuedId = queuedCheckins .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_ID)); if (queuedReference == null || checkin(queuedTimeStamp, queuedReference, queuedId)) successfulCheckins.add(queuedReference); } // Delete the queued checkins that were successful. if (successfulCheckins.size() > 0) { StringBuilder sb = new StringBuilder("(" + QueuedCheckinsContentProvider.KEY_REFERENCE + "='" + successfulCheckins.get(0) + "'"); for (int i = 1; i < successfulCheckins.size(); i++) sb.append(" OR " + QueuedCheckinsContentProvider.KEY_REFERENCE + " = '" + successfulCheckins.get(i) + "'"); sb.append(")"); int deleteCount = contentResolver.delete(QueuedCheckinsContentProvider.CONTENT_URI, sb.toString(), null); Log.d(TAG, "Deleted: " + deleteCount); } // If there are still queued checkins then set a non-waking alarm to retry them. queuedCheckins.requery(); if (queuedCheckins.getCount() > 0) { long triggerAtTime = System.currentTimeMillis() + LocationConstants.CHECKIN_RETRY_INTERVAL; alarmManager.set(AlarmManager.ELAPSED_REALTIME, triggerAtTime, retryQueuedCheckinsPendingIntent); } else alarmManager.cancel(retryQueuedCheckinsPendingIntent); } finally { queuedCheckins.close(); } } }