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.daiv.android.twitter.services.TrimDataService.java

public void setNextTrim(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    long now = new Date().getTime();
    long alarm = now + AlarmManager.INTERVAL_DAY;

    Log.v("alarm_date", "auto trim " + new Date(alarm).toString());

    PendingIntent pendingIntent = PendingIntent.getService(context, TRIM_ID,
            new Intent(context, TrimDataService.class), 0);

    am.set(AlarmManager.RTC_WAKEUP, alarm, pendingIntent);
}

From source file:com.footprint.cordova.plugin.localnotification.Options.java

/**
 * Parses the given properties//from  w w w.ja v a2s. c  o  m
 */
public Options parse(JSONObject options) {
    String repeat = options.optString("repeat");

    this.options = options;

    if (repeat.equalsIgnoreCase("secondly")) {
        interval = 1000;
    }
    if (repeat.equalsIgnoreCase("minutely")) {
        interval = AlarmManager.INTERVAL_FIFTEEN_MINUTES / 15;
    }
    if (repeat.equalsIgnoreCase("hourly")) {
        interval = AlarmManager.INTERVAL_HOUR;
    }
    if (repeat.equalsIgnoreCase("daily")) {
        interval = AlarmManager.INTERVAL_DAY;
    } else if (repeat.equalsIgnoreCase("weekly")) {
        interval = AlarmManager.INTERVAL_DAY * 7;
    } else if (repeat.equalsIgnoreCase("monthly")) {
        interval = AlarmManager.INTERVAL_DAY * 31; // 31 days
    } else if (repeat.equalsIgnoreCase("yearly")) {
        interval = AlarmManager.INTERVAL_DAY * 365;
    } else {
        try {
            interval = Integer.parseInt(repeat) * 60000;
        } catch (Exception e) {
        }
        ;
    }

    return this;
}

From source file:de.hero.vertretungsplan.CheckForAppUpdate.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    boolean setTimer = intent.getBooleanExtra("setTimer", false);
    boolean checkNow = intent.getBooleanExtra("checkNow", false);

    Intent i = new Intent(this, de.hero.vertretungsplan.CheckForAppUpdate.class);
    i.putExtra("checkNow", true);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    am.cancel(pi);/*from w ww.j a va  2  s.  c  o m*/
    Log.d("CheckForAppUpdate", "Alarm canceled");
    if (setTimer) {

        long lngInterval = AlarmManager.INTERVAL_DAY * 7;
        Log.d("CheckForAppUpdate", "Alarm set");
        am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY * 6, lngInterval, pi);
        //For debugging: after 10 seconds
        //am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 25000 , AlarmManager.INTERVAL_HOUR , pi);

    }

    if (checkNow) {
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

        if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) {
            try {
                new HtmlWorkAppUpdate(this).execute(new URI(getString(R.string.htmlAdresseAktuelleVersion)));
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return START_NOT_STICKY;
}

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

private void setUpdateInterval(int interval) {
    boolean enableUpdateCheck = true;
    switch (interval) {
    case 0://w  w w. j a v  a2s.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 w w w  . ja  v a 2  s .co  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:at.florian_lentsch.expirysync.NotifyChecker.java

private static long getFirstStartMillis(Context appContext) {
    final SharedPreferences sharedPref = appContext.getSharedPreferences("main", Context.MODE_PRIVATE);
    long firstStartMillis = sharedPref.getLong(SettingsActivity.KEY_ALERT_TIME, -1);
    if (firstStartMillis == -1) {
        return -1;
    }//  w w w .j av a2 s  .  c  o  m

    Calendar midnight = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    midnight.set(Calendar.HOUR_OF_DAY, 0);
    midnight.set(Calendar.MINUTE, 0);
    midnight.set(Calendar.SECOND, 0);
    midnight.set(Calendar.MILLISECOND, 0);

    // add "today at 0:00" to the ms value for the alarm (else the alarm
    // would be scheduled for 1970-01-01):
    firstStartMillis += midnight.getTimeInMillis();

    // if we're already past the alarm time today, we need to add another
    // day:
    if (firstStartMillis <= Calendar.getInstance().getTimeInMillis()) {
        firstStartMillis += AlarmManager.INTERVAL_DAY;
    }

    return firstStartMillis;
}

From source file:com.commontime.plugin.notification.notification.Options.java

/**
 * Parse repeat interval.//from   w  w w . j a  v  a  2 s  .  c  o m
 */
private void parseInterval() {
    String every = options.optString("every").toLowerCase();

    if (every.isEmpty()) {
        interval = 0;
    } else if (every.equals("second")) {
        interval = 1000;
    } else if (every.equals("minute")) {
        interval = AlarmManager.INTERVAL_FIFTEEN_MINUTES / 15;
    } else if (every.equals("hour")) {
        interval = AlarmManager.INTERVAL_HOUR;
    } else if (every.equals("day")) {
        interval = AlarmManager.INTERVAL_DAY;
    } else if (every.equals("week")) {
        interval = AlarmManager.INTERVAL_DAY * 7;
    } else if (every.equals("month")) {
        interval = AlarmManager.INTERVAL_DAY * 31;
    } else if (every.equals("year")) {
        interval = AlarmManager.INTERVAL_DAY * 365;
    } else {
        try {
            interval = Integer.parseInt(every) * 60000;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:eu.istvank.apps.lenslog.receivers.NotifyAlarmReceiver.java

/**
 * Sets a repeating alarm that runs once a day at approximately 8:30 a.m. When the
 * alarm fires, the app broadcasts an Intent to this WakefulBroadcastReceiver.
 * @param context//from  w  w  w . j  a v  a2 s.c  o m
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public void setAlarm(Context context) {
    alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, NotifyAlarmReceiver.class);
    alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

    // get notification time from preferences
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    long notificationTime = sp.getLong(SettingsFragment.KEY_PREF_NOTIFICATION_TIME, 50400000);

    Calendar calendar = Calendar.getInstance();
    //TODO: if the time has passed already, set it to tomorrow.
    calendar.setTimeInMillis(notificationTime);

    // The following line is for debug only
    //alarmMgr.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);

    // Set the alarm to fire according to the device's clock, and to repeat once a day.
    alarmMgr.setInexactRepeating(AlarmManager.RTC, notificationTime, AlarmManager.INTERVAL_DAY, alarmIntent);

    // Enable {@code SampleBootReceiver} to automatically restart the alarm when the
    // device is rebooted.
    ComponentName receiver = new ComponentName(context, NotifyAlarmReceiver.class);
    PackageManager pm = context.getPackageManager();

    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:com.cpd.receivers.LibraryRenewAlarmBroadcastReceiver.java

public void setAlarm(Context context) {
    Log.d(TAG, "setAlarm() called with: " + "context = [" + context + "]");
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 12);
    calendar.set(Calendar.MINUTE, 1);
    calendar.set(Calendar.SECOND, 0);

    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, LibraryRenewAlarmBroadcastReceiver.class);

    PendingIntent pi = PendingIntent.getBroadcast(context, 1, intent, 0);

    am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY / DAILY_RETRIES, pi);
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static void scheduleCMAccountPing(Context context, Intent intent) {
    if (CMAccount.DEBUG)
        Log.d(TAG,/*w w  w.j av  a 2s . c o  m*/
                "Scheduling CMAccount 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);
}