Java Code Examples for android.app.AlarmManager#INTERVAL_HOUR
The following examples show how to use
android.app.AlarmManager#INTERVAL_HOUR .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From your-local-weather with GNU General Public License v3.0 | 7 votes |
public static long intervalMillisForAlarm(String intervalMinutes) { switch (intervalMinutes) { case "0": case "15": return AlarmManager.INTERVAL_FIFTEEN_MINUTES; case "30": return AlarmManager.INTERVAL_HALF_HOUR; case "60": return AlarmManager.INTERVAL_HOUR; case "720": return AlarmManager.INTERVAL_HALF_DAY; case "1440": return AlarmManager.INTERVAL_DAY; case "OFF": case "regular_only": return Long.MAX_VALUE; default: return Integer.parseInt(intervalMinutes) * 60 * 1000; } }
Example 2
Source File: Utils.java From good-weather with GNU General Public License v3.0 | 6 votes |
public static long intervalMillisForAlarm(String intervalMinutes) { int interval = Integer.parseInt(intervalMinutes); switch (interval) { case 15: return AlarmManager.INTERVAL_FIFTEEN_MINUTES; case 30: return AlarmManager.INTERVAL_HALF_HOUR; case 60: return AlarmManager.INTERVAL_HOUR; case 720: return AlarmManager.INTERVAL_HALF_DAY; case 1440: return AlarmManager.INTERVAL_DAY; default: return interval * 60 * 1000; } }
Example 3
Source File: SettingsPresenter.java From Muslim-Athkar-Islamic-Reminders with MIT License | 5 votes |
private long calculateInterval(int id) { /* <string-array name="frequency"> <item>Every 1 hour</item> <item>Every 3 hours</item> <item>Every 6 hours</item> <item>Every 12 hours</item> <item>Once a day</item> */ switch (id){ case 0: //Every 1 hours return AlarmManager.INTERVAL_HOUR; case 1: //Every 3 hours return (AlarmManager.INTERVAL_HOUR*3); case 2: //Every 6 hours return (AlarmManager.INTERVAL_HOUR*6); case 3: //Every 12 hours return AlarmManager.INTERVAL_HALF_DAY; case 4: //Once a day return AlarmManager.INTERVAL_DAY; } return AlarmManager.INTERVAL_HOUR; }
Example 4
Source File: DateUtil.java From FriendBook with GNU General Public License v3.0 | 5 votes |
/** * 时间友好显示 * 刚刚-%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)); }
Example 5
Source File: Options.java From showCaseCordova with Apache License 2.0 | 5 votes |
/** * 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(); } } }
Example 6
Source File: BlockchainService.java From bither-android with Apache License 2.0 | 5 votes |
private void scheduleStartBlockchainService(@Nonnull final Context context) { BitherSetting.SyncInterval syncInterval = AppSharedPreference.getInstance().getSyncInterval(); if (syncInterval == BitherSetting.SyncInterval.OnlyOpenApp || AddressManager.getInstance().getAllAddresses().size() == 0) { return; } long interval = AlarmManager.INTERVAL_HOUR; if (syncInterval == BitherSetting.SyncInterval.Normal) { final long lastUsedAgo = AppSharedPreference.getInstance().getLastUsedAgo(); if (lastUsedAgo < BitherSetting.LAST_USAGE_THRESHOLD_JUST_MS) { interval = AlarmManager.INTERVAL_FIFTEEN_MINUTES; log.info("start INTERVAL_FIFTEEN_MINUTES"); } else if (lastUsedAgo < BitherSetting.LAST_USAGE_THRESHOLD_RECENTLY_MS) { interval = AlarmManager.INTERVAL_HALF_DAY; log.info("start INTERVAL_HALF_DAY"); } else { interval = AlarmManager.INTERVAL_DAY; log.info("start INTERVAL_DAY"); } } final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context .ALARM_SERVICE); final PendingIntent alarmIntent = PendingIntent.getService(context, 0, new Intent(context, BlockchainService.class), 0); alarmManager.cancel(alarmIntent); final long now = System.currentTimeMillis(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // as of KitKat, set() is inexact { alarmManager.set(AlarmManager.RTC_WAKEUP, now + interval, alarmIntent); } else // workaround for no inexact set() before KitKat { alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + interval, AlarmManager.INTERVAL_HOUR, alarmIntent); } }
Example 7
Source File: UpdateInfoModelAdapter.java From coolreader with MIT License | 5 votes |
public UpdateInfoModelAdapter(Context context, int resourceId, List<UpdateInfoModel> objects) { super(context, resourceId, objects); this.layoutResourceId = resourceId; this.context = context; this.data = objects; this.originalData = data.toArray(originalData); now = new Date(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String updatesIntervalStr = preferences.getString(Constants.PREF_UPDATE_INTERVAL, "0"); int updatesInterval = Integer.parseInt(updatesIntervalStr); switch (updatesInterval) { case 1: repeatTime = AlarmManager.INTERVAL_FIFTEEN_MINUTES; break; case 2: repeatTime = AlarmManager.INTERVAL_HALF_HOUR; break; case 3: repeatTime = AlarmManager.INTERVAL_HOUR; break; case 4: repeatTime = AlarmManager.INTERVAL_HALF_DAY; break; case 5: repeatTime = AlarmManager.INTERVAL_DAY; break; default: break; } }
Example 8
Source File: AlarmManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
void setImpl(int type, long triggerAtTime, long windowLength, long interval, PendingIntent operation, IAlarmListener directReceiver, String listenerTag, int flags, WorkSource workSource, AlarmManager.AlarmClockInfo alarmClock, int callingUid, String callingPackage) { // must be *either* PendingIntent or AlarmReceiver, but not both if ((operation == null && directReceiver == null) || (operation != null && directReceiver != null)) { Slog.w(TAG, "Alarms must either supply a PendingIntent or an AlarmReceiver"); // NB: previous releases failed silently here, so we are continuing to do the same // rather than throw an IllegalArgumentException. return; } // Sanity check the window length. This will catch people mistakenly // trying to pass an end-of-window timestamp rather than a duration. if (windowLength > AlarmManager.INTERVAL_HALF_DAY) { Slog.w(TAG, "Window length " + windowLength + "ms suspiciously long; limiting to 1 hour"); windowLength = AlarmManager.INTERVAL_HOUR; } // Sanity check the recurrence interval. This will catch people who supply // seconds when the API expects milliseconds, or apps trying shenanigans // around intentional period overflow, etc. final long minInterval = mConstants.MIN_INTERVAL; if (interval > 0 && interval < minInterval) { Slog.w(TAG, "Suspiciously short interval " + interval + " millis; expanding to " + (minInterval/1000) + " seconds"); interval = minInterval; } else if (interval > mConstants.MAX_INTERVAL) { Slog.w(TAG, "Suspiciously long interval " + interval + " millis; clamping"); interval = mConstants.MAX_INTERVAL; } if (type < RTC_WAKEUP || type > ELAPSED_REALTIME) { throw new IllegalArgumentException("Invalid alarm type " + type); } if (triggerAtTime < 0) { final long what = Binder.getCallingPid(); Slog.w(TAG, "Invalid alarm trigger time! " + triggerAtTime + " from uid=" + callingUid + " pid=" + what); triggerAtTime = 0; } final long nowElapsed = SystemClock.elapsedRealtime(); final long nominalTrigger = convertToElapsed(triggerAtTime, type); // Try to prevent spamming by making sure we aren't firing alarms in the immediate future final long minTrigger = nowElapsed + mConstants.MIN_FUTURITY; final long triggerElapsed = (nominalTrigger > minTrigger) ? nominalTrigger : minTrigger; final long maxElapsed; if (windowLength == AlarmManager.WINDOW_EXACT) { maxElapsed = triggerElapsed; } else if (windowLength < 0) { maxElapsed = maxTriggerTime(nowElapsed, triggerElapsed, interval); // Fix this window in place, so that as time approaches we don't collapse it. windowLength = maxElapsed - triggerElapsed; } else { maxElapsed = triggerElapsed + windowLength; } synchronized (mLock) { if (DEBUG_BATCH) { Slog.v(TAG, "set(" + operation + ") : type=" + type + " triggerAtTime=" + triggerAtTime + " win=" + windowLength + " tElapsed=" + triggerElapsed + " maxElapsed=" + maxElapsed + " interval=" + interval + " flags=0x" + Integer.toHexString(flags)); } setImplLocked(type, triggerAtTime, triggerElapsed, windowLength, maxElapsed, interval, operation, directReceiver, listenerTag, flags, true, workSource, alarmClock, callingUid, callingPackage); } }
Example 9
Source File: StringUtils.java From FriendBook with GNU General Public License v3.0 | 4 votes |
/** * 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)); }
Example 10
Source File: SolsticeWidget0.java From SuntimesWidget with GNU General Public License v3.0 | 4 votes |
@Override protected long getUpdateInterval() { return AlarmManager.INTERVAL_HOUR * 3; }
Example 11
Source File: MyScheduleReceiver.java From coolreader with MIT License | 4 votes |
public static void reschedule(Context context, int updatesInterval) { long repeatTime = 0; switch (updatesInterval) { case 1: repeatTime = AlarmManager.INTERVAL_FIFTEEN_MINUTES; break; case 2: repeatTime = AlarmManager.INTERVAL_HALF_HOUR; break; case 3: repeatTime = AlarmManager.INTERVAL_HOUR; break; case 4: repeatTime = AlarmManager.INTERVAL_HALF_DAY; break; case 5: repeatTime = AlarmManager.INTERVAL_DAY; break; default: break; } AlarmManager service = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, MyStartServiceReceiver.class); PendingIntent pending = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); if (repeatTime > 0) { Log.d(UpdateService.TAG, "Setting up schedule"); // Start repeatTime seconds after boot completed Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 60); // InexactRepeating allows Android to optimize the energy consumption Log.i(UpdateService.TAG, "Repeating in: " + repeatTime); // service.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), repeatTime, pending); service.set(AlarmManager.RTC, cal.getTimeInMillis() + repeatTime, pending); } else { Log.i(UpdateService.TAG, "Canceling Schedule"); service.cancel(pending); } }