INTERVAL_DAY源码实例Demo

android.app.AlarmManager#INTERVAL_DAY源码实例Demo

下面列出了android.app.AlarmManager#INTERVAL_DAY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FairEmail   文件: ServiceUI.java
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();
    }
}
 
源代码2 项目: your-local-weather   文件: Utils.java
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;
    }
}
 
源代码3 项目: Taskbar   文件: TaskbarController.java
@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;
}
 
源代码4 项目: android-sdk   文件: ServiceSchedulerTest.java
@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();
}
 
源代码5 项目: RememBirthday   文件: AccountResolver.java
/**
 * 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;
    }
}
 
源代码6 项目: good-weather   文件: Utils.java
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;
    }
}
 
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;
}
 
源代码8 项目: FriendBook   文件: DateUtil.java
/**
 * 时间友好显示
 * 刚刚-%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));
}
 
源代码9 项目: Taskbar   文件: TaskbarControllerTest.java
@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();
}
 
源代码10 项目: showCaseCordova   文件: Options.java
/**
 * 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();
        }
    }
}
 
源代码11 项目: iBeebo   文件: BeeboAlermManager.java
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();
        }
    }
 
源代码12 项目: bither-android   文件: BlockchainService.java
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);
    }
}
 
源代码13 项目: coolreader   文件: UpdateInfoModelAdapter.java
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;
	}
}
 
源代码14 项目: iBeebo   文件: BeeboAlermManager.java
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();
        }
    }
 
源代码15 项目: FriendBook   文件: StringUtils.java
/**
 * 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));
}
 
源代码16 项目: AssistantBySDK   文件: TimeUtils.java
public int differDay(Date start, Date now) {
    long differ = now.getTime() - start.getTime();
    if (differ <= 0)
        return 0;
    return (int) (differ / AlarmManager.INTERVAL_DAY);
}
 
源代码17 项目: SuntimesWidget   文件: SuntimesWidget0.java
/**
 * @return an AlarmManager interval; e.g. AlarmManager.INTERVAL_DAY
 */
protected long getUpdateInterval()
{
    return AlarmManager.INTERVAL_DAY;
}
 
源代码18 项目: ApkTrack   文件: PollReceiver.java
@Override
// No alarms for 7 days: don't try to reschedule.
public long getMaxAge(Context context) {
    return(AlarmManager.INTERVAL_DAY * 7);
}
 
源代码19 项目: coolreader   文件: MyScheduleReceiver.java
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);
	}
}