Java Code Examples for android.app.AlarmManager#INTERVAL_HALF_HOUR

The following examples show how to use android.app.AlarmManager#INTERVAL_HALF_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 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: 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 4
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);
	}
}