Example usage for android.app AlarmManager INTERVAL_HALF_DAY

List of usage examples for android.app AlarmManager INTERVAL_HALF_DAY

Introduction

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

Prototype

long INTERVAL_HALF_DAY

To view the source code for android.app AlarmManager INTERVAL_HALF_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:Main.java

private static long translateIntervalDesc(String intervalDesc) {
    switch (intervalDesc) {
    case "onceaminute":
        return 1000 * 60;
    case "onceahour":
        return AlarmManager.INTERVAL_HOUR;
    case "twiceaday":
        return AlarmManager.INTERVAL_HALF_DAY;
    case "onceaday":
        return AlarmManager.INTERVAL_DAY;
    case "onceaweek":
        return AlarmManager.INTERVAL_DAY * 7;
    default:/* w  ww .  j  a  v a  2  s.  co m*/
        return AlarmManager.INTERVAL_DAY;
    }
}

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

private void setUpdateInterval(int interval) {
    boolean enableUpdateCheck = true;
    switch (interval) {
    case 0:/*from w  w w . j a  va 2  s .  c o  m*/
        UpdateListener.interval = AlarmManager.INTERVAL_DAY;
        break;
    case 1:
        UpdateListener.interval = AlarmManager.INTERVAL_HALF_DAY;
        break;
    case 2:
        UpdateListener.interval = AlarmManager.INTERVAL_HOUR;
        break;
    case 3:
        enableUpdateCheck = false;
        break;
    }
    if (enableUpdateCheck) {
        SharedPreferences prefs = getSharedPreferences(LAST_INTERVAL, 0);
        prefs.edit().putLong(LAST_INTERVAL, UpdateListener.interval).apply();
        WakefulIntentService.cancelAlarms(this);
        WakefulIntentService.scheduleAlarms(new UpdateListener(), this, true);
    } else {
        SharedPreferences prefs = getSharedPreferences(LAST_INTERVAL, 0);
        prefs.edit().putLong(LAST_INTERVAL, 1).apply();
        com.Candy.ota.updater.ConnectivityReceiver.disableReceiver(this);
        WakefulIntentService.cancelAlarms(this);
    }
}

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

private void setUpdateInterval(int interval) {
    boolean enableUpdateCheck = true;
    switch (interval) {
    case 0:/*from   ww  w  .jav  a  2s.  c o  m*/
        UpdateListener.interval = AlarmManager.INTERVAL_DAY;
        break;
    case 1:
        UpdateListener.interval = AlarmManager.INTERVAL_HALF_DAY;
        break;
    case 2:
        UpdateListener.interval = AlarmManager.INTERVAL_HOUR;
        break;
    case 3:
        enableUpdateCheck = false;
        break;
    }
    if (enableUpdateCheck) {
        SharedPreferences prefs = getSharedPreferences(LAST_INTERVAL, 0);
        prefs.edit().putLong(LAST_INTERVAL, UpdateListener.interval).apply();
        WakefulIntentService.cancelAlarms(this);
        WakefulIntentService.scheduleAlarms(new UpdateListener(), this, true);
    } else {
        SharedPreferences prefs = getSharedPreferences(LAST_INTERVAL, 0);
        prefs.edit().putLong(LAST_INTERVAL, 1).apply();
        com.slim.ota.updater.ConnectivityReceiver.disableReceiver(this);
        WakefulIntentService.cancelAlarms(this);
    }
}

From source file:de.geeksfactory.opacclient.reminder.SyncAccountService.java

@Override
protected void doWakefulWork(Intent intent) {
    if (BuildConfig.DEBUG)
        Log.i(NAME, "SyncAccountService started");

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);

    if (!sp.getBoolean(SyncAccountAlarmListener.PREF_SYNC_SERVICE, false)) {
        if (BuildConfig.DEBUG)
            Log.i(NAME, "notifications are disabled");
        return;//from www.j a v  a  2  s.c o  m
    }

    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null) {
        if (!sp.getBoolean("notification_service_wifionly", false)
                || networkInfo.getType() == ConnectivityManager.TYPE_WIFI
                || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
            syncAccounts();
        } else {
            failed = true;
        }
    } else {
        failed = true;
    }

    if (BuildConfig.DEBUG) {
        Log.i(NAME, "SyncAccountService finished " + (failed ? " with errors" : " " + "successfully"));
    }

    long previousPeriod = sp.getLong(SyncAccountAlarmListener.PREF_SYNC_INTERVAL, 0);
    long newPeriod = failed ? AlarmManager.INTERVAL_HOUR : AlarmManager.INTERVAL_HALF_DAY;
    if (previousPeriod != newPeriod) {
        sp.edit().putLong(SyncAccountAlarmListener.PREF_SYNC_INTERVAL, newPeriod).apply();
        WakefulIntentService.cancelAlarms(this);
        WakefulIntentService.scheduleAlarms(SyncAccountAlarmListener.withOnePeriodBeforeStart(), this);
    }
}

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;/*from   ww  w .j  a v  a2  s .c  o 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: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) {/*w  w w  . j  a va2  s  .  c o 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: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   ww w  .j  a v  a  2s  . c om*/

    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: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  a v a 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) 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:com.Candy.ota.CandyOTA.java

private void setInitialUpdateInterval() {
    SharedPreferences prefs = this.getActivity().getSharedPreferences(LAST_INTERVAL, 0);
    long value = prefs.getLong(LAST_INTERVAL, 0);
    //set interval to 12h if user starts first time SlimOTA and it was not installed by system before
    //yes ask lazy tarak....he has this case ;)
    if (value == 0) {
        UpdateListener.interval = AlarmManager.INTERVAL_HALF_DAY;
        prefs.edit().putLong(LAST_INTERVAL, UpdateListener.interval).apply();
        WakefulIntentService.scheduleAlarms(new UpdateListener(), getActivity(), false);
    }/* w ww  .  j  av a 2 s .  c o m*/
}

From source file:com.near.chimerarevo.activities.MainActivity.java

@Override
public void onDestroy() {
    super.onDestroy();
    if (ImageLoader.getInstance().isInited()) {
        ImageLoader.getInstance().clearDiskCache();
        ImageLoader.getInstance().clearMemoryCache();
    }//from w ww  .  ja v  a 2s  .  c o m
    if (mHelper != null)
        mHelper.dispose();

    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("news_search_pref", true)) {
        Intent intent = new Intent(getApplicationContext(), NewsService.class);
        PendingIntent pintent = PendingIntent.getService(getApplicationContext(), 0, intent, 0);
        AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

        alarm.cancel(pintent);

        long delay;
        int sel = Integer.parseInt(
                PreferenceManager.getDefaultSharedPreferences(this).getString("notification_delay_pref", "0"));

        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);
    }
}