Example usage for android.app AlarmManager setRepeating

List of usage examples for android.app AlarmManager setRepeating

Introduction

In this page you can find the example usage for android.app AlarmManager setRepeating.

Prototype

public void setRepeating(@AlarmType int type, long triggerAtMillis, long intervalMillis,
        PendingIntent operation) 

Source Link

Document

Schedule a repeating alarm.

Usage

From source file:Main.java

private static void setAlarm(AlarmManager alarmManager, Calendar calendar, PendingIntent pendingIntent) {
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            pendingIntent);/*w w  w.j a va 2 s  . c  o  m*/
}

From source file:com.andrewshu.android.reddit.mail.EnvelopeService.java

public static void resetAlarm(Context context, long interval) {
    // Create an IntentSender that will launch our service, to be scheduled
    // with the alarm manager.
    PendingIntent alarmSender = PendingIntent.getService(context, 0, new Intent(context, EnvelopeService.class),
            0);//ww w .j a  va  2  s  .  c o m
    AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE);
    am.cancel(alarmSender);
    if (interval != 0)
        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), interval,
                alarmSender);
}

From source file:com.abid_mujtaba.bitcoin.tracker.services.FetchPriceService.java

public static void start(Context context) // Method used to start service via AlarmManager
{
    Intent intent = new Intent(context, FetchPriceService.class); // Intent to launch service
    PendingIntent alarmIntent = PendingIntent.getService(context, 0, intent, 0); // PendingIntent required by AlarmManager. This gives the AlarmManager permission to launch this Intent as if it were being launched by this application

    AlarmManager amgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    amgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), INTERVAL, alarmIntent);
}

From source file:com.commonsware.android.wakecast.PollReceiver.java

static void scheduleAlarms(Context ctxt) {
    AlarmManager mgr = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(ctxt, PollReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0);

    mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + INITIAL_DELAY,
            PERIOD, pi);//  ww w .  j a v a  2 s .  c o m

}

From source file:nl.atcomputing.spacetravelagency.order.DepartureInfoService.java

static public void setupDepartureInfoServiceAlarm(Context context) {
    Intent intent = new Intent(context, DepartureInfoService.class);
    PendingIntent pi = PendingIntent.getService(context, 1, intent, 0);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Calendar cal = Calendar.getInstance();
    am.setRepeating(AlarmManager.RTC, cal.getTimeInMillis(), 600000, pi);
}

From source file:at.florian_lentsch.expirysync.NotifyChecker.java

/**
 * Sets the alarm that checks for products soon to expire (or already have
 * expired)/*from   w ww.j  a  va2  s.c o  m*/
 * 
 * @param context
 */
protected static void setAlarm(Context context) {
    Context appContext = context.getApplicationContext();
    Intent receiverIntent = new Intent(appContext, NotifyChecker.class);

    // Fetch info about when the alarm is to sound each day from the shared
    // preferences:
    long firstStartMillis = getFirstStartMillis(appContext);
    if (firstStartMillis < 0) {
        Log.i("Alarm", "Alert time not configured - not setting alarm");
        return;
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(firstStartMillis);
    // Log.i("Alarm", "Setting alarm: " + firstStartMillis + ", " + (new
    // SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",
    // Locale.US)).format(firstStartMillis));

    // Set the alarm:
    PendingIntent alarmIntent = PendingIntent.getBroadcast(appContext, 0, receiverIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmMgr = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE);
    alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, firstStartMillis, AlarmManager.INTERVAL_DAY, alarmIntent);
}

From source file:org.leopub.mat.service.MessageService.java

public static void setUpdate(int latency, int period) {
    Context context = MyApplication.getAppContext();
    Logger.i(TAG, "setUpdate latency:" + latency + ", period:" + period);
    Intent i = new Intent(context, MessageService.class);
    PendingIntent pi = PendingIntent.getService(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    if (period > 0) {
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + latency * 60 * 1000,
                period * 60 * 1000, pi);
    } else {//from  w ww  .ja  v  a2  s .  c  o  m
        alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + latency * 60 * 1000, pi);
    }
    Logger.i(TAG, "setUpdate Done");
}

From source file:Main.java

public static PendingIntent scheduleLocalNotification(Context context, int slot, String title, String message,
        Long alertTime, int repeat) {
    Log.i(TAG, "Scheduling local notification");
    Intent alertIntent = new Intent(getNotificationName(slot));

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, slot, alertIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (alarmManager != null) {
        if (repeat == 0) {
            alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent);
        } else {/*w ww.  ja  v  a 2  s . c o  m*/
            Calendar alarmStartTime = Calendar.getInstance();
            alarmStartTime.add(Calendar.MINUTE, 1);
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alertTime, repeat, pendingIntent);
        }
    }
    return pendingIntent;
}

From source file:ch.fixme.status.Widget.java

protected static void setAlarm(Context ctxt, Intent i, int widgetId, int delay) {
    // Get interval
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
    long update_interval = Long
            .parseLong(prefs.getString(Prefs.KEY_CHECK_INTERVAL, Prefs.DEFAULT_CHECK_INTERVAL)) * 60L * 1000L;
    // Set alarm/*from   w w  w  . j av  a 2 s  .  c o  m*/
    AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pi = PendingIntent.getService(ctxt, widgetId, i, 0);
    am.cancel(pi);
    am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + delay, update_interval, pi);
    // Log.i(Main.TAG, "start notification every " + update_interval / 1000
    // + "s");
}

From source file:de.escoand.readdaily.ReminderHandler.java

public static void startReminder(final Context context, final int hour, final int minute) {
    Intent intent = new Intent(context, ReminderHandler.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);
    GregorianCalendar cal = new GregorianCalendar();

    // get next reminder
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, 0);/*from  w  w  w. j ava 2 s. c om*/
    cal.set(Calendar.MILLISECOND, 0);
    if (cal.before(Calendar.getInstance()))
        cal.add(Calendar.DATE, 1);

    am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 24 * 60 * 60 * 1000, pendingIntent);

    LogHandler.log(Log.WARN, "activated " + hour + ":" + minute);
}