当前位置: 首页>>代码示例>>Java>>正文


Java AlarmManager.INTERVAL_DAY属性代码示例

本文整理汇总了Java中android.app.AlarmManager.INTERVAL_DAY属性的典型用法代码示例。如果您正苦于以下问题:Java AlarmManager.INTERVAL_DAY属性的具体用法?Java AlarmManager.INTERVAL_DAY怎么用?Java AlarmManager.INTERVAL_DAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.app.AlarmManager的用法示例。


在下文中一共展示了AlarmManager.INTERVAL_DAY属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: intervalMillisForRecurringAlarm

private static long intervalMillisForRecurringAlarm(String intervalPref) {
    int interval = Integer.parseInt(intervalPref);
    switch (interval) {
        case 0:
            return 0; // special case for cancel
        case 15:
            return AlarmManager.INTERVAL_FIFTEEN_MINUTES;
        case 30:
            return AlarmManager.INTERVAL_HALF_HOUR;
        case 1:
            return AlarmManager.INTERVAL_HOUR;
        case 12:
            return AlarmManager.INTERVAL_HALF_DAY;
        case 24:
            return AlarmManager.INTERVAL_DAY;
        default: // cases 2 and 6 (or any number of hours)
            return interval * 3600000;
    }
}
 
开发者ID:hichemcesar24,项目名称:Weather-Android,代码行数:19,代码来源:AlarmReceiver.java

示例2: formatSomeAgo

/**
 * 时间友好显示
 * 刚刚-%s分钟前-%s小时前-昨天-前天-%s天前
 */
public static String formatSomeAgo(long timeInMillis) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(timeInMillis);
    Calendar mCurrentDate = Calendar.getInstance();
    long crim = mCurrentDate.getTimeInMillis(); // current
    long trim = calendar.getTimeInMillis(); // target
    long diff = crim - trim;

    int year = mCurrentDate.get(Calendar.YEAR);
    int month = mCurrentDate.get(Calendar.MONTH);
    int day = mCurrentDate.get(Calendar.DATE);

    if (diff < 60 * 1000) {
        return "刚刚";
    }
    if (diff >= 60 * 1000 && diff < AlarmManager.INTERVAL_HOUR) {
        return String.format("%s分钟前", diff / 60 / 1000);
    }
    mCurrentDate.set(year, month, day, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return String.format("%s小时前", diff / AlarmManager.INTERVAL_HOUR);
    }
    mCurrentDate.set(year, month, day - 1, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return "昨天";
    }
    mCurrentDate.set(year, month, day - 2, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return "前天";
    }
    if (diff < AlarmManager.INTERVAL_DAY * 30) {
        return String.format("%s天前", diff / AlarmManager.INTERVAL_DAY);
    }
    if (diff < AlarmManager.INTERVAL_DAY * 30 * 12) {
        return String.format("%s月前", diff / (AlarmManager.INTERVAL_DAY * 30));
    }
    return String.format("%s年前", mCurrentDate.get(Calendar.YEAR) - calendar.get(Calendar.YEAR));
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:42,代码来源:DateUtil.java

示例3: scheduleRepeatingRTCNotification

/**
 * This is the real time /wall clock time
 *
 * @param context
 */
public static void scheduleRepeatingRTCNotification(Context context) {
    //get calendar instance to be able to select what time notification should be scheduled
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    //Setting time of the day (8am here) when notification will be sent every day (default)
    //TODO: Set it to only go off on Saturday nights
    calendar.set(Calendar.DAY_OF_WEEK, 7);
    calendar.set(Calendar.HOUR_OF_DAY, 20);
    calendar.set(Calendar.MINUTE, 30);
    calendar.set(Calendar.MILLISECOND, 0);

    //Setting intent to class where Alarm broadcast message will be handled
    Intent intent = new Intent(context, NotificationPublisher.class);
    intent.setAction(WatchItConstants.NOTIFICATION_MESSAGE);
    //Setting alarm pending intent
    alarmIntentRTC = PendingIntent.getBroadcast(context, WatchItConstants.ALARM_TYPE_RTC, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    //getting instance of AlarmManager service
    alarmManagerRTC = (AlarmManager) context.getSystemService(ALARM_SERVICE);

    //Setting alarm to wake up device every day for clock time.
    //AlarmManager.RTC_WAKEUP is responsible to wake up device for sure, which may not be good practice all the time.
    // Use this when you know what you're doing.
    //Use RTC when you don't need to wake up device, but want to deliver the notification whenever device is woke-up
    //We'll be using RTC.WAKEUP for demo purpose only
    long interval = 7 * AlarmManager.INTERVAL_DAY;
    setRepeatingExactAlarm(calendar.getTimeInMillis(), interval, alarmIntentRTC);
}
 
开发者ID:hsm59,项目名称:WatchIt,代码行数:33,代码来源:NotificationHelper.java

示例4: parseInterval

/**
 * Parse repeat interval.
 */
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("quarter")) {
        interval = AlarmManager.INTERVAL_HOUR * 2190;
    } else
    if (every.equals("year")) {
        interval = AlarmManager.INTERVAL_DAY * 365;
    } else {
        try {
            interval = Integer.parseInt(every) * 60000;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:40,代码来源:Options.java

示例5: scheduleStartBlockchainService

public static void scheduleStartBlockchainService(final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context),
            context.getResources());
    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);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:27,代码来源:WalletApplication.java

示例6: persistUpdateIntervalIndex

public static void persistUpdateIntervalIndex(int intervalIndex, Context context) {
    long intervalValue;
    switch(intervalIndex) {
        case 0:
            intervalValue = 0;
            break;
        case 1:
            intervalValue = AlarmManager.INTERVAL_HOUR;
            break;
        case 2:
            intervalValue = AlarmManager.INTERVAL_HALF_DAY;
            break;
        case 3:
            intervalValue = AlarmManager.INTERVAL_DAY;
            break;
        default:
            intervalValue = OTAListener.DEFAULT_INTERVAL_VALUE;
            break;
    }

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    sharedPreferences.edit().putLong(UPDATE_INTERVAL, intervalValue).apply();
    if (intervalValue > 0) {
        WakefulIntentService.cancelAlarms(context);
        WakefulIntentService.scheduleAlarms(new OTAListener(), context, true);
        OTAUtils.toast(R.string.autoupdate_enabled, context);
    } else {
        WakefulIntentService.cancelAlarms(context);
        OTAUtils.toast(R.string.autoupdate_disabled, context);
    }
}
 
开发者ID:DroidThug,项目名称:VulcanOTA,代码行数:31,代码来源:AppConfig.java

示例7: formatSomeAgo

/**
 * format time friendly
 *
 * @param sdate YYYY-MM-DD HH:mm:ss
 * @return n分钟前, n小时前, 昨天, 前天, n天前, n个月前
 */
public static String formatSomeAgo(String sdate) {
    if (sdate == null) return "";
    Calendar calendar = parseCalendar(sdate);
    if (calendar == null) return sdate;

    Calendar mCurrentDate = Calendar.getInstance();
    long crim = mCurrentDate.getTimeInMillis(); // current
    long trim = calendar.getTimeInMillis(); // target
    long diff = crim - trim;

    int year = mCurrentDate.get(Calendar.YEAR);
    int month = mCurrentDate.get(Calendar.MONTH);
    int day = mCurrentDate.get(Calendar.DATE);

    if (diff < 60 * 1000) {
        return "刚刚";
    }
    if (diff >= 60 * 1000 && diff < AlarmManager.INTERVAL_HOUR) {
        return String.format("%s分钟前", diff / 60 / 1000);
    }
    mCurrentDate.set(year, month, day, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return String.format("%s小时前", diff / AlarmManager.INTERVAL_HOUR);
    }
    mCurrentDate.set(year, month, day - 1, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return "昨天";
    }
    mCurrentDate.set(year, month, day - 2, 0, 0, 0);
    if (trim >= mCurrentDate.getTimeInMillis()) {
        return "前天";
    }
    if (diff < AlarmManager.INTERVAL_DAY * 30) {
        return String.format("%s天前", diff / AlarmManager.INTERVAL_DAY);
    }
    if (diff < AlarmManager.INTERVAL_DAY * 30 * 12) {
        return String.format("%s月前", diff / (AlarmManager.INTERVAL_DAY * 30));
    }
    return String.format("%s年前", mCurrentDate.get(Calendar.YEAR) - calendar.get(Calendar.YEAR));
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:46,代码来源:StringUtils.java

示例8: differDay

public int differDay(Date start, Date now) {
    long differ = now.getTime() - start.getTime();
    if (differ <= 0)
        return 0;
    return (int) (differ / AlarmManager.INTERVAL_DAY);
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:6,代码来源:TimeUtils.java

示例9: calculateNextTime

public static long calculateNextTime(int hour, int minute, String weeks) {

        long now = System.currentTimeMillis();
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(now);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minute);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        long nextTime = calendar.getTimeInMillis();

        if (weeks == null) {

            if (nextTime > now) {
                return nextTime;
            } else {
                calendar.add(Calendar.DAY_OF_MONTH, 1);
                nextTime = calendar.getTimeInMillis();
                return nextTime;
            }
        } else {
            nextTime = 0;
            long tempTime;
            final String[] weeksValue = weeks.split(",");
            for (String aWeeksValue : weeksValue) {
                int week = Integer.parseInt(aWeeksValue);
                calendar.set(Calendar.DAY_OF_WEEK, week);
                tempTime = calendar.getTimeInMillis();

                if (tempTime <= now) {
                    tempTime += AlarmManager.INTERVAL_DAY * 7;
                }
                if (nextTime == 0) {
                    nextTime = tempTime;
                } else {
                    nextTime = Math.min(tempTime, nextTime);
                }

            }
            return nextTime;
        }
    }
 
开发者ID:segasunset,项目名称:WeatherAlarmClock,代码行数:43,代码来源:AlarmManagerHelper.java

示例10: setNextAlarm

public static void setNextAlarm(Context context) {
    // Prepare alarm
    Intent diaryAlertIntent = new Intent(context, AlarmHandler.class);
    diaryAlertIntent.setAction(AlarmHandler.DIARY_ALERT);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, diaryAlertIntent, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Get alarm time
    SharedPreferences sharedPreferences = context.getSharedPreferences(
            MainActivity.PREFERENCES, Context.MODE_PRIVATE);
    long diaryReminderTime = sharedPreferences.getLong(
            SettingsFragment.KEY_PREF_DIARY_ALERT_TIME, ~0);

    if (diaryReminderTime != ~0 ) {
        Calendar diaryAlertTime = Calendar.getInstance();
        diaryAlertTime.setTimeInMillis(diaryReminderTime);
        // Get a calendar for today and set the time to the alarm time
        Calendar alarmCalendar = Calendar.getInstance();
        alarmCalendar.setTimeInMillis(System.currentTimeMillis());
        alarmCalendar.set(Calendar.HOUR_OF_DAY, diaryAlertTime.get(Calendar.HOUR_OF_DAY));
        alarmCalendar.set(Calendar.MINUTE, diaryAlertTime.get(Calendar.MINUTE));

        // Compare with current time to see if the next alarm is today or tomorrow
        Calendar nowCalendar = Calendar.getInstance();
        nowCalendar.setTimeInMillis(System.currentTimeMillis());

        long alarmTime = alarmCalendar.getTimeInMillis();
        // If alarm time is earlier in the day...
        if( alarmCalendar.getTimeInMillis() <= nowCalendar.getTimeInMillis() ){
            // ...then check if we already had today's
            long lastDiaryReminderTime = sharedPreferences.getLong(AlarmHandler.LAST_DIARY_NOTIFICATION_PREF, ~0);
            if (lastDiaryReminderTime != ~0 && lastDiaryReminderTime != 0) {
                Calendar lastAlertTime = Calendar.getInstance();
                lastAlertTime.setTimeInMillis(lastDiaryReminderTime);
                // If last alert was in same year and day of year...
                if (lastAlertTime.get(Calendar.YEAR) == nowCalendar.get(Calendar.YEAR) &&
                        lastAlertTime.get(Calendar.DAY_OF_YEAR) == nowCalendar.get(Calendar.DAY_OF_YEAR)) {
                    // ...set for tomorrow by adding one day
                    alarmTime = alarmTime + AlarmManager.INTERVAL_DAY;
                }
                // Otherwise, leave as is because we haven't done one today and it will trigger immediately
            }
            else {
                // don't know when the last one was so set for tomorrow by adding one day
                alarmTime = alarmTime + AlarmManager.INTERVAL_DAY;
            }
        }
        // Otherwise leave as is and it will trigger later today

        // Create the alarm
        if (android.os.Build.VERSION.SDK_INT < 19) {
            alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, alarmIntent);
        } else {
            alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTime, alarmIntent);
        }
    }
}
 
开发者ID:jgevans,项目名称:TherapyGuide,代码行数:57,代码来源:AlarmSetter.java


注:本文中的android.app.AlarmManager.INTERVAL_DAY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。