Java Code Examples for android.app.AlarmManager#INTERVAL_DAY
The following examples show how to use
android.app.AlarmManager#INTERVAL_DAY .
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: AccountResolver.java From RememBirthday with GNU General Public License v3.0 | 6 votes |
/** * Add account for Birthday Adapter to Android system */ public Bundle addAccountAndSync() { Log.d(getClass().getSimpleName(), "Adding calendar account : " + account.name); // enable automatic sync once per day ContentResolver.setSyncAutomatically(account, authority, true); ContentResolver.setIsSyncable(account, type, 1); // add periodic sync interval once per day long freq = AlarmManager.INTERVAL_DAY; ContentResolver.addPeriodicSync(account, type, new Bundle(), freq); AccountManager accountManager = AccountManager.get(context); if (accountManager.addAccountExplicitly(account, null, null)) { Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); // Force a sync! Even when background sync is disabled, this will force one sync! manualSync(); return result; } else { return null; } }
Example 3
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 4
Source File: ServiceUI.java From FairEmail with GNU General Public License v3.0 | 6 votes |
static void scheduleBanner(Context context, boolean set) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (set) { long now = new Date().getTime(); long interval = AlarmManager.INTERVAL_DAY * HIDE_BANNER * 7; long due = interval - (now % interval); long trigger = now + due; Log.i("Set banner alarm at " + new Date(trigger) + " due=" + due); am.set(AlarmManager.RTC, trigger, getBannerIntent(context)); prefs.edit().putLong("banner_hidden", trigger).apply(); } else { Log.i("Cancel banner alarm"); am.cancel(getBannerIntent(context)); prefs.edit().remove("banner_hidden").apply(); } }
Example 5
Source File: ServiceSchedulerTest.java From android-sdk with Apache License 2.0 | 6 votes |
@Test public void testScheduleWithDurationExtra() { final Intent intent = new Intent(context, EventIntentService.class); when(pendingIntentFactory.hasPendingIntent(intent)).thenReturn(false); PendingIntent pendingIntent = getPendingIntent(); when(pendingIntentFactory.getPendingIntent(intent)).thenReturn(pendingIntent); when(optlyStorage.getLong(EventIntentService.EXTRA_INTERVAL, AlarmManager.INTERVAL_HOUR)).thenReturn(AlarmManager.INTERVAL_HOUR); long duration = AlarmManager.INTERVAL_DAY; intent.putExtra(EventIntentService.EXTRA_INTERVAL, duration); serviceScheduler.schedule(intent, duration); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ArgumentCaptor<JobInfo> jobInfoArgumentCaptor = ArgumentCaptor.forClass(JobInfo.class); verify(jobScheduler).schedule(jobInfoArgumentCaptor.capture()); assertEquals(jobInfoArgumentCaptor.getValue().getIntervalMillis(), duration ); } else { verify(alarmManager).setInexactRepeating(AlarmManager.ELAPSED_REALTIME, duration, duration, pendingIntent); } verify(logger).info("Scheduled {}", intent.getComponent().toShortString()); pendingIntent.cancel(); }
Example 6
Source File: TaskbarController.java From Taskbar with Apache License 2.0 | 6 votes |
@VisibleForTesting long getSearchInterval(SharedPreferences pref) { long searchInterval = -1; switch(pref.getString(PREF_RECENTS_AMOUNT, PREF_RECENTS_AMOUNT_PAST_DAY)) { case PREF_RECENTS_AMOUNT_PAST_DAY: searchInterval = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY; break; case PREF_RECENTS_AMOUNT_APP_START: long appStartTime = pref.getLong(PREF_TIME_OF_SERVICE_START, System.currentTimeMillis()); long deviceStartTime = System.currentTimeMillis() - SystemClock.elapsedRealtime(); searchInterval = Math.max(deviceStartTime, appStartTime); break; case PREF_RECENTS_AMOUNT_SHOW_ALL: searchInterval = 0; break; } return searchInterval; }
Example 7
Source File: TaskbarControllerTest.java From Taskbar with Apache License 2.0 | 5 votes |
@Test public void testGetSearchInterval() { long permitTimeDeltaMillis = 100; prefs.edit().remove(PREF_RECENTS_AMOUNT).apply(); long searchInterval = uiController.getSearchInterval(prefs); long lastDayTime = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY; assertEquals(lastDayTime, searchInterval, permitTimeDeltaMillis); prefs.edit().putString(PREF_RECENTS_AMOUNT, PREF_RECENTS_AMOUNT_APP_START).apply(); long deviceStartTime = System.currentTimeMillis() - SystemClock.elapsedRealtime(); // The service start time is larger than device start time long appStartTime = deviceStartTime * 2; prefs.edit().putLong(PREF_TIME_OF_SERVICE_START, appStartTime).apply(); searchInterval = uiController.getSearchInterval(prefs); assertEquals(appStartTime, searchInterval); // The service start time is smaller than device start time prefs.edit().putLong(PREF_TIME_OF_SERVICE_START, deviceStartTime - 100).apply(); searchInterval = uiController.getSearchInterval(prefs); deviceStartTime = System.currentTimeMillis() - SystemClock.elapsedRealtime(); assertEquals(deviceStartTime, searchInterval, permitTimeDeltaMillis); prefs.edit().remove(PREF_TIME_OF_SERVICE_START).apply(); prefs.edit().putString(PREF_RECENTS_AMOUNT, PREF_RECENTS_AMOUNT_SHOW_ALL).apply(); searchInterval = uiController.getSearchInterval(prefs); assertEquals(0, searchInterval); prefs.edit().putString(PREF_RECENTS_AMOUNT, PREF_RECENTS_AMOUNT_RUNNING_APPS_ONLY).apply(); searchInterval = uiController.getSearchInterval(prefs); assertEquals(-1, searchInterval); prefs.edit().putString(PREF_RECENTS_AMOUNT, UNSUPPORTED).apply(); searchInterval = uiController.getSearchInterval(prefs); assertEquals(-1, searchInterval); prefs.edit().remove(PREF_RECENTS_AMOUNT).apply(); }
Example 8
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 9
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 10
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 11
Source File: BeeboAlermManager.java From iBeebo with GNU General Public License v3.0 | 5 votes |
public static void startAlarm(boolean debug, Context context, boolean silent) { String value = SettingUtils.getFrequency(); long time = AlarmManager.INTERVAL_DAY; if (value.equals("1")) { time = (1000 * 30); } if (value.equals("2")) { time = (1000 * 60 * 2); } if (value.equals("3")) { time = (1000 * 60 * 5); } if (DEBUG) { time = 1000 * 5;// 5秒 } AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, FetchNewMsgService.class); PendingIntent sender = PendingIntent.getService(context, REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT); alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, time, sender); if (!silent) { Toast.makeText(context, context.getString(R.string.start_fetch_msg), Toast.LENGTH_SHORT).show(); } }
Example 12
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 13
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 14
Source File: BeeboAlermManager.java From iBeebo with GNU General Public License v3.0 | 5 votes |
public static void startAlarm(boolean debug, Context context, boolean silent) { String value = SettingUtils.getFrequency(); long time = AlarmManager.INTERVAL_DAY; if (value.equals("1")) { time = (1000 * 30); } if (value.equals("2")) { time = (1000 * 60 * 2); } if (value.equals("3")) { time = (1000 * 60 * 5); } if (DEBUG) { time = 1000 * 5;// 5秒 } AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, FetchNewMsgService.class); PendingIntent sender = PendingIntent.getService(context, REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT); alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, time, sender); if (!silent) { Toast.makeText(context, context.getString(R.string.start_fetch_msg), Toast.LENGTH_SHORT).show(); } }
Example 15
Source File: TimeUtils.java From AssistantBySDK with Apache License 2.0 | 4 votes |
public int differDay(Date start, Date now) { long differ = now.getTime() - start.getTime(); if (differ <= 0) return 0; return (int) (differ / AlarmManager.INTERVAL_DAY); }
Example 16
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 17
Source File: SuntimesWidget0.java From SuntimesWidget with GNU General Public License v3.0 | 4 votes |
/** * @return an AlarmManager interval; e.g. AlarmManager.INTERVAL_DAY */ protected long getUpdateInterval() { return AlarmManager.INTERVAL_DAY; }
Example 18
Source File: PollReceiver.java From ApkTrack with GNU General Public License v3.0 | 4 votes |
@Override // No alarms for 7 days: don't try to reschedule. public long getMaxAge(Context context) { return(AlarmManager.INTERVAL_DAY * 7); }
Example 19
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); } }