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:Main.java

private static void setAlarm(AlarmManager alarmManager, Calendar calendar, PendingIntent pendingIntent) {
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            pendingIntent);//from  w ww  .jav  a2s. c o  m
}

From source file:Main.java

private static void setIntervalDayAlarm(Context context, PendingIntent intent, long time) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, time, AlarmManager.INTERVAL_DAY, intent);
}

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://from  w w  w .ja v a  2  s .c  o  m
        return AlarmManager.INTERVAL_DAY;
    }
}

From source file:org.isoron.uhabits.helpers.ReminderHelper.java

public static void createReminderAlarm(Context context, Habit habit, @Nullable Long reminderTime) {
    if (!habit.hasReminder())
        return;/*ww  w.  j a  v  a 2s. c  om*/

    if (reminderTime == null) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        //noinspection ConstantConditions
        calendar.set(Calendar.HOUR_OF_DAY, habit.reminderHour);
        //noinspection ConstantConditions
        calendar.set(Calendar.MINUTE, habit.reminderMin);
        calendar.set(Calendar.SECOND, 0);

        reminderTime = calendar.getTimeInMillis();

        if (System.currentTimeMillis() > reminderTime)
            reminderTime += AlarmManager.INTERVAL_DAY;
    }

    long timestamp = DateHelper.getStartOfDay(DateHelper.toLocalTime(reminderTime));

    Uri uri = habit.getUri();

    Intent alarmIntent = new Intent(context, HabitBroadcastReceiver.class);
    alarmIntent.setAction(HabitBroadcastReceiver.ACTION_SHOW_REMINDER);
    alarmIntent.setData(uri);
    alarmIntent.putExtra("timestamp", timestamp);
    alarmIntent.putExtra("reminderTime", reminderTime);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
            ((int) (habit.getId() % Integer.MAX_VALUE)) + 1, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    if (Build.VERSION.SDK_INT >= 23)
        manager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);
    else if (Build.VERSION.SDK_INT >= 19)
        manager.setExact(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);
    else
        manager.set(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);

    String name = habit.name.substring(0, Math.min(3, habit.name.length()));
    Log.d("ReminderHelper", String.format("Setting alarm (%s): %s",
            DateFormat.getDateTimeInstance().format(new Date(reminderTime)), name));
}

From source file:br.ajmarques.cordova.plugin.localnotification.Options.java

/**
 * Parst die bergebenen Eigenschaften./*from   w w w .  j a va 2 s. co  m*/
 */
public Options parse(JSONObject options) {
    String repeat = options.optString("repeat");

    this.options = options;

    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:at.florian_lentsch.expirysync.NotifyChecker.java

/**
 * Sets the alarm that checks for products soon to expire (or already have
 * expired)//w  ww.ja v a 2 s.com
 * 
 * @param context
 */
protected static void setAlarm(Context context) {
    Context appContext = context.getApplicationContext();
    Intent receiverIntent = new Intent(appContext, NotifyChecker.class);

    // Fetch info about when the alarm is to sound each day from the shared
    // preferences:
    long firstStartMillis = getFirstStartMillis(appContext);
    if (firstStartMillis < 0) {
        Log.i("Alarm", "Alert time not configured - not setting alarm");
        return;
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(firstStartMillis);
    // Log.i("Alarm", "Setting alarm: " + firstStartMillis + ", " + (new
    // SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",
    // Locale.US)).format(firstStartMillis));

    // Set the alarm:
    PendingIntent alarmIntent = PendingIntent.getBroadcast(appContext, 0, receiverIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmMgr = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE);
    alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, firstStartMillis, AlarmManager.INTERVAL_DAY, alarmIntent);
}

From source file:org.birthdayadapter.util.AccountHelper.java

/**
 * Add account for Birthday Adapter to Android system
 *//*  w ww  .ja va2s  . co  m*/
public Bundle addAccountAndSync() {
    Log.d(Constants.TAG, "Adding account...");

    // enable automatic sync once per day
    ContentResolver.setSyncAutomatically(Constants.ACCOUNT, Constants.CONTENT_AUTHORITY, true);
    ContentResolver.setIsSyncable(Constants.ACCOUNT, Constants.ACCOUNT_TYPE, 1);

    // add periodic sync interval once per day
    long freq = AlarmManager.INTERVAL_DAY;
    ContentResolver.addPeriodicSync(Constants.ACCOUNT, Constants.ACCOUNT_TYPE, new Bundle(), freq);

    AccountManager am = AccountManager.get(mContext);
    if (am.addAccountExplicitly(Constants.ACCOUNT, null, null)) {
        Bundle result = new Bundle();
        result.putString(AccountManager.KEY_ACCOUNT_NAME, Constants.ACCOUNT.name);
        result.putString(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT.type);

        // Force a sync! Even when background sync is disabled, this will force one sync!
        manualSync();

        return result;
    } else {
        return null;
    }
}

From source file:com.cryart.sabbathschool.util.SSNotification.java

public static void setRepeatingNotification(Context context) {
    AlarmManager _SSAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent _SSNotificationIntent = new Intent(context, SSBroadcastReceiver.class);
    PendingIntent _SSAlarmIntent = PendingIntent.getBroadcast(context, 0, _SSNotificationIntent, 0);

    Calendar _SSNotificationTime = Calendar.getInstance();

    SharedPreferences ssPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    String ss_settings_notification_time = ssPreferences.getString(
            SSConstants.SS_SETTINGS_NOTIFICATION_TIME_KEY,
            SSConstants.SS_SETTINGS_NOTIFICATION_TIME_DEFAULT_VALUE);

    _SSNotificationTime.set(Calendar.HOUR_OF_DAY, SSHelper.parseHourFromString(ss_settings_notification_time,
            SSConstants.SS_NOTIFICATION_TIME_SETTINGS_FORMAT));
    _SSNotificationTime.set(Calendar.MINUTE, SSHelper.parseMinuteFromString(ss_settings_notification_time,
            SSConstants.SS_NOTIFICATION_TIME_SETTINGS_FORMAT));
    _SSNotificationTime.set(Calendar.SECOND, 0);

    _SSAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, _SSNotificationTime.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, _SSAlarmIntent);
}

From source file:nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver.java

public AlarmReceiver() {
    Context context = GBApplication.getContext();
    Intent intent = new Intent("DAILY_ALARM");
    intent.setPackage(BuildConfig.APPLICATION_ID);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, new Intent("DAILY_ALARM"), 0);
    AlarmManager am = (AlarmManager) (context.getSystemService(Context.ALARM_SERVICE));

    am.setInexactRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + 10000,
            AlarmManager.INTERVAL_DAY, pendingIntent);
}

From source file:mchs.neverforget.services.NotificationIntentService.java

public static void startCustomRecurrentNotificationAlarm(Context context, int customId) {
    //Toast.makeText(context, "startCustomRecurrentNotificationAlarm"+customId, Toast.LENGTH_SHORT).show();
    Intent intent = new Intent(context, NotificationIntentService.class);
    if (customId == 1) {
        intent.setAction(ACTION_NOTIFY_CUSTOM1);
    } else if (customId == 2) {
        intent.setAction(ACTION_NOTIFY_CUSTOM2);
    } else if (customId == 3) {
        intent.setAction(ACTION_NOTIFY_CUSTOM3);
    }//from w w  w.  jav a 2  s  .  co  m

    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);

    String[] hourOfDay = PreferenceManager.getDefaultSharedPreferences(context)
            .getString("notification_time_picker" + customId, "12:00").split(":");
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hourOfDay[0]));
    calendar.set(Calendar.MINUTE, Integer.parseInt(hourOfDay[1]));

    if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 1);
    }
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, pendingIntent);

}