Example usage for android.app AlarmManager INTERVAL_DAY

List of usage examples for android.app AlarmManager INTERVAL_DAY

Introduction

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

Prototype

long INTERVAL_DAY

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

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.phonemetra.account.util.AccountUtils.java

public static void scheduleAccountPing(Context context, Intent intent) {
    if (Account.DEBUG)
        Log.d(TAG,//from  w  ww .  j a  va2 s.  c  om
                "Scheduling Account ping, starting = "
                        + new Timestamp(SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY)
                        + " interval (" + AlarmManager.INTERVAL_DAY + ")");
    PendingIntent reRegisterPendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
            SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY, AlarmManager.INTERVAL_DAY,
            reRegisterPendingIntent);
}

From source file:com.Candy.ota.settings.Settings.java

private int getUpdateInterval() {
    SharedPreferences prefs = getSharedPreferences(LAST_INTERVAL, 0);
    long value = prefs.getLong(LAST_INTERVAL, 0);
    int settingsValue;
    if (value == AlarmManager.INTERVAL_DAY) {
        settingsValue = 0;/*  ww  w .  j a va 2 s.  co m*/
    } else if (value == AlarmManager.INTERVAL_HALF_DAY || value == 0) {
        settingsValue = 1;
    } else if (value == AlarmManager.INTERVAL_HOUR) {
        settingsValue = 2;
    } else {
        settingsValue = 3;
    }
    return settingsValue;
}

From source file:jieehd.villain.updater.VillainUpdater.java

public void setRepeatingAlarm() {
    AlarmManager am;//from w  w  w .  j av  a  2s . c o  m
    am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(this, checkInBackground.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (3 * AlarmManager.INTERVAL_DAY),
            pendingIntent);
}

From source file:dess15proj5.fau.cs.osr_amos.mobiletimerecording.ui.MainActivity.java

/**
 * This method is used to initialize an alarm manager for this app. If the alarm is triggered, the app will check
 * whether it has to send a notification to the user reminding him to record for today.
 *
 * methodtype initialization method//from   ww  w. java 2s.  c  o  m
 */
private void setUpAlarmForNotifications() {
    Intent intent = new Intent(this, RecordingAlarmReceiver.class);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, AccountingNotification.ALARM_ID, intent, 0);

    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.set(Calendar.HOUR_OF_DAY, 20);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);

    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            pendingIntent);
}

From source file:com.concentricsky.android.khanacademy.app.HomeActivity.java

private void setupRepeatingLibraryUpdateAlarm() {
    Log.d(LOG_TAG, "setupRepeatingLibraryUpdateAlarm");
    AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);

    Intent intent = new Intent(getApplicationContext(), KADataService.class);
    intent.setAction(ACTION_LIBRARY_UPDATE);
    PendingIntent existing = PendingIntent.getService(getApplicationContext(),
            REQUEST_CODE_RECURRING_LIBRARY_UPDATE, intent, PendingIntent.FLAG_NO_CREATE);
    boolean alreadyScheduled = existing != null;

    if (!alreadyScheduled) {
        // Initial delay.
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.SECOND, UPDATE_DELAY_FROM_FIRST_RUN);

        // Schedule the alarm.
        PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(),
                REQUEST_CODE_RECURRING_LIBRARY_UPDATE, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        Log.d(LOG_TAG, "(re)setting alarm");
        am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
                pendingIntent);/*from   ww w .j av  a2  s  . c  om*/
    }
}

From source file:com.near.chimerarevo.fragments.SettingsFragment.java

private void setAlarm(int sel, boolean isEnabled) {
    Intent intent = new Intent(getActivity().getApplicationContext(), NewsService.class);
    PendingIntent pintent = PendingIntent.getService(getActivity().getApplicationContext(), 0, intent, 0);
    AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);

    alarm.cancel(pintent);/*from   w ww  . j av  a  2 s .  co m*/

    if (isEnabled) {
        long delay;
        switch (sel) {
        case 0:
            delay = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
            break;
        case 1:
            delay = AlarmManager.INTERVAL_HALF_HOUR;
            break;
        case 2:
            delay = AlarmManager.INTERVAL_HOUR;
            break;
        case 3:
            delay = 2 * AlarmManager.INTERVAL_HOUR;
            break;
        case 4:
            delay = 3 * AlarmManager.INTERVAL_HOUR;
            break;
        case 5:
            delay = 6 * AlarmManager.INTERVAL_HOUR;
            break;
        case 6:
            delay = AlarmManager.INTERVAL_HALF_DAY;
            break;
        case 7:
            delay = AlarmManager.INTERVAL_DAY;
            break;
        default:
            delay = AlarmManager.INTERVAL_HOUR;
            break;
        }

        alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.uptimeMillis(), delay, pintent);
    }
}

From source file:ca.etsmtl.applets.etsmobile.NewsListActivity.java

private void setAlarm() {
    final Intent toAlarm = new Intent(this, NewsAlarmReceiver.class);
    final PendingIntent toDownload = PendingIntent.getBroadcast(this, 0, toAlarm,
            PendingIntent.FLAG_CANCEL_CURRENT);
    final AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    final Calendar updateTime = Calendar.getInstance();
    updateTime.setTimeZone(TimeZone.getTimeZone("GMT"));

    updateTime.set(Calendar.HOUR_OF_DAY, 6);
    updateTime.set(Calendar.MINUTE, 00);
    alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            toDownload);/*from  w w w. j a va  2 s. co  m*/

    updateTime.set(Calendar.HOUR_OF_DAY, 12);
    alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            toDownload);

    updateTime.set(Calendar.HOUR_OF_DAY, 18);
    alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            toDownload);
}

From source file:de.schildbach.wallet.service.BlockchainService.java

public static void scheduleStart(final WalletApplication application) {
    final Configuration config = application.getConfiguration();
    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/*from   w w w .  j  av  a 2 s  .  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) application.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent alarmIntent = PendingIntent.getService(application, 0,
            new Intent(application, BlockchainService.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.svij.taskwarriorapp.TasksActivity.java

@Override
protected void onResume() {
    super.onResume();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    long date_long = prefs.getLong("notifications_alarm_time", System.currentTimeMillis());

    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent i = new Intent(this, NotificationService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date_long);

    if (!calendar.getTime().before(new Date())) {
        am.cancel(pi);/*  w  w w.  ja  v  a 2 s.com*/
        am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                calendar.getTimeInMillis() + AlarmManager.INTERVAL_DAY, pi);
    }

}

From source file:org.ametro.app.ApplicationEx.java

public void changeAlarmReceiverState(boolean enabled) {
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent intent = new Intent(this, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
    alarmManager.cancel(pendingIntent);//w ww .ja v a 2  s  . c o  m
    if (enabled) {
        long interval = (GlobalSettings.getUpdatePeriod(this) == 900) ? AlarmManager.INTERVAL_FIFTEEN_MINUTES
                : AlarmManager.INTERVAL_DAY;
        alarmManager.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis() + 1000 * 60 * 2, interval,
                pendingIntent);
    }
}