Java Code Examples for android.app.AlarmManager#INTERVAL_FIFTEEN_MINUTES

The following examples show how to use android.app.AlarmManager#INTERVAL_FIFTEEN_MINUTES . 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 vote down vote up
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 vote down vote up
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: Options.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
/**
 * 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 4
Source File: BlockchainService.java    From bither-android with Apache License 2.0 5 votes vote down vote up
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 5
Source File: UpdateInfoModelAdapter.java    From coolreader with MIT License 5 votes vote down vote up
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 6
Source File: MyScheduleReceiver.java    From coolreader with MIT License 4 votes vote down vote up
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);
	}
}
 
Example 7
Source File: BackgroundAlarmListener.java    From wear-notify-for-reddit with Apache License 2.0 4 votes vote down vote up
@Override public long getMaxAge(Context context) {
    return (AlarmManager.INTERVAL_FIFTEEN_MINUTES * 2);
}