List of usage examples for android.app AlarmManager setAndAllowWhileIdle
public void setAndAllowWhileIdle(@AlarmType int type, long triggerAtMillis, PendingIntent operation)
From source file:com.kubotaku.android.code4kyoto5374.util.AlarmService.java
@TargetApi(Build.VERSION_CODES.M) private static void setupAlarmNew(Context context, PendingIntent intent, final long triggerAtMillis) { final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.setAndAllowWhileIdle(AlarmManager.RTC, triggerAtMillis, intent); }
From source file:com.commonsware.android.deepbg.PollReceiver.java
static void scheduleExactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) { Intent i = buildBaseIntent(ctxt).putExtra(EXTRA_PERIOD, period).putExtra(EXTRA_IS_DOWNLOAD, isDownload); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { Log.e("PollReceiver", "allow while idle"); alarms.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { alarms.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi); } else {/*w ww .j a v a 2s . c om*/ alarms.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi); } }
From source file:com.actinarium.nagbox.service.NagboxService.java
private void rescheduleAlarm() { AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Prepare pending intent. Setting, updating, or cancelling the alarm - we need it in either case Intent intent = new Intent(this, NagAlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); long nextTimestamp = NagboxDbOps.getClosestNagTimestamp(mDatabase); if (nextTimestamp == 0) { alarmManager.cancel(pendingIntent); } else {// www . ja v a2s . c o m // todo: deal with exact/inexact reminders later if (Build.VERSION.SDK_INT >= 23) { alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextTimestamp, pendingIntent); } else if (Build.VERSION.SDK_INT >= 19) { alarmManager.setWindow(AlarmManager.RTC_WAKEUP, nextTimestamp, ALARM_TOLERANCE, pendingIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, nextTimestamp, pendingIntent); } } }
From source file:com.crearo.gpslogger.GpsLoggingService.java
/** * Sets up the auto email timers based on user preferences. */// w w w .ja va 2 s. co m @TargetApi(23) public void setupAutoSendTimers() { LOG.debug("Setting up autosend timers. Auto Send Enabled - " + String.valueOf(preferenceHelper.isAutoSendEnabled()) + ", Auto Send Delay - " + String.valueOf(Session.getAutoSendDelay())); if (preferenceHelper.isAutoSendEnabled() && Session.getAutoSendDelay() > 0) { long triggerTime = System.currentTimeMillis() + (long) (Session.getAutoSendDelay() * 60 * 1000); alarmIntent = new Intent(this, AlarmReceiver.class); cancelAlarm(); PendingIntent sender = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); if (Systems.isDozing(this)) { am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, sender); } else { am.set(AlarmManager.RTC_WAKEUP, triggerTime, sender); } LOG.debug("Autosend alarm has been set"); } else { if (alarmIntent != null) { LOG.debug("alarmIntent was null, canceling alarm"); cancelAlarm(); } } }