Example usage for android.app AlarmManager INTERVAL_FIFTEEN_MINUTES

List of usage examples for android.app AlarmManager INTERVAL_FIFTEEN_MINUTES

Introduction

In this page you can find the example usage for android.app AlarmManager INTERVAL_FIFTEEN_MINUTES.

Prototype

long INTERVAL_FIFTEEN_MINUTES

To view the source code for android.app AlarmManager INTERVAL_FIFTEEN_MINUTES.

Click Source Link

Document

Available inexact recurrence interval recognized by #setInexactRepeating(int,long,long,PendingIntent) when running on Android prior to API 19.

Usage

From source file:com.psiphon3.psiphonlibrary.UpgradeChecker.java

/**
 * Creates the periodic alarm used to check for updates. Can be called unconditionally; it
 * handles cases when the alarm is already created.
 * @param appContext The application context.
 *//*ww w .  j av a  2s .c  o  m*/
private static void createAlarm(Context appContext) {
    if (!allowedToSelfUpgrade(appContext)) {
        // Don't waste resources with an alarm if we can't possibly self-upgrade.
        log(appContext, R.string.upgrade_checker_no_alarm_no_selfupgrading, MyLog.Sensitivity.NOT_SENSITIVE,
                Log.WARN);
        return;
    }

    Intent intent = new Intent(appContext, UpgradeChecker.class);
    intent.setAction(ALARM_INTENT_ACTION);

    boolean alarmExists = (PendingIntent.getBroadcast(appContext, ALARM_INTENT_REQUEST_CODE, intent,
            PendingIntent.FLAG_NO_CREATE) != null);

    if (alarmExists) {
        log(appContext, R.string.upgrade_checker_alarm_exists, MyLog.Sensitivity.NOT_SENSITIVE, Log.WARN);
        return;
    }

    log(appContext, R.string.upgrade_checker_creating_alarm, MyLog.Sensitivity.NOT_SENSITIVE, Log.WARN);

    PendingIntent alarmIntent = PendingIntent.getBroadcast(appContext, ALARM_INTENT_REQUEST_CODE, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmMgr = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE);
    alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_FIFTEEN_MINUTES,
            AlarmManager.INTERVAL_HALF_DAY, alarmIntent);
}

From source file:com.example.feedback.ActivityFeedback.java

/**
 * Set broadcast receiver of type FeedbackBroadcastReceiver and create an alarm to test internet
 * connection repeatedly until feedback is sent.
 *
 * @param   context  application context of calling activity
 *///from www.  j a va2s. co m
public void setAlarm(Context context) {
    intent = new Intent(this, FeedbackBroadcastReceiver.class);
    pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarm.cancel(pending);
    // Set alarm to start immediately and repeat every fifteen minutes, approximately.
    alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(),
            AlarmManager.INTERVAL_FIFTEEN_MINUTES, pending);
}

From source file:de.schildbach.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context));
    final long lastUsedAgo = config.getLastUsedAgo();

    // apply some backoff
    final long alarmInterval;
    if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS)
        alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
    else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
        alarmInterval = AlarmManager.INTERVAL_HALF_DAY;
    else/*  w  ww . jav a 2s.  co  m*/
        alarmInterval = AlarmManager.INTERVAL_DAY;

    log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes",
            lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS);

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent alarmIntent = PendingIntent.getService(context, 0,
            new Intent(context, BlockchainServiceImpl.class), 0);
    alarmManager.cancel(alarmIntent);

    // workaround for no inexact set() before KitKat
    final long now = System.currentTimeMillis();
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY,
            alarmIntent);
}

From source file:de.langerhans.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(@Nonnull final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context));
    final long lastUsedAgo = config.getLastUsedAgo();

    // apply some backoff
    final long alarmInterval;
    if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS)
        alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
    else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
        alarmInterval = AlarmManager.INTERVAL_HALF_DAY;
    else/*w  w  w.ja  va 2s  .  c  o  m*/
        alarmInterval = AlarmManager.INTERVAL_DAY;

    log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes",
            lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS);

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final Intent startIntent = new Intent(context, AutosyncReceiver.class);
    startIntent.setAction("de.langerhans.wallet.AUTOSYNC_ACTION");
    final PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, startIntent, 0);
    alarmManager.cancel(alarmIntent);

    // workaround for no inexact set() before KitKat
    final long now = System.currentTimeMillis();
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY,
            alarmIntent);
}

From source file:biz.wiz.android.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(@Nonnull final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context));
    final long lastUsedAgo = config.getLastUsedAgo();

    // apply some backoff
    final long alarmInterval;
    if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS)
        alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
    else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
        alarmInterval = AlarmManager.INTERVAL_HALF_DAY;
    else//  w ww .  j  a  v  a2 s  .  c  om
        alarmInterval = AlarmManager.INTERVAL_DAY;

    log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes",
            lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS);

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent alarmIntent = PendingIntent.getService(context, 0,
            new Intent(context, BlockchainServiceImpl.class), 0);
    alarmManager.cancel(alarmIntent);

    // workaround for no inexact set() before KitKat
    final long now = System.currentTimeMillis();
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY,
            alarmIntent);
}

From source file:org.hopestarter.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context),
            context.getResources());//from w  w  w  . j  a v a 2 s  . com
    final long lastUsedAgo = config.getLastUsedAgo();

    // apply some backoff
    final long alarmInterval;
    if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS)
        alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
    else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
        alarmInterval = AlarmManager.INTERVAL_HALF_DAY;
    else
        alarmInterval = AlarmManager.INTERVAL_DAY;

    log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes",
            lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS);

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent alarmIntent = PendingIntent.getService(context, 0,
            new Intent(context, BlockchainServiceImpl.class), 0);
    alarmManager.cancel(alarmIntent);

    // workaround for no inexact set() before KitKat
    final long now = System.currentTimeMillis();
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY,
            alarmIntent);
}

From source file:com.matthewmitchell.peercoin_android_wallet.WalletApplication.java

public void scheduleStartBlockchainService() {

    final WalletApplication wa = this;

    this.setOnLoadedCallback(new Runnable() {

        @Override/*from w  w w .j a  v a 2  s  . c  om*/
        public void run() {

            final long lastUsedAgo = config.getLastUsedAgo();

            // apply some backoff
            final long alarmInterval;
            if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS)
                alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
            else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
                alarmInterval = AlarmManager.INTERVAL_HALF_DAY;
            else
                alarmInterval = AlarmManager.INTERVAL_DAY;

            log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes",
                    lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS);
            assertTrue(config != null);
            final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
            final PendingIntent alarmIntent = PendingIntent.getService(wa, 0,
                    new Intent(wa, BlockchainServiceImpl.class), 0);
            alarmManager.cancel(alarmIntent);

            // workaround for no inexact set() before KitKat
            final long now = System.currentTimeMillis();
            alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval,
                    AlarmManager.INTERVAL_DAY, alarmIntent);

        }

    });

}