Example usage for android.app AlarmManager setInexactRepeating

List of usage examples for android.app AlarmManager setInexactRepeating

Introduction

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

Prototype

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

Source Link

Document

Schedule a repeating alarm that has inexact trigger time requirements; for example, an alarm that repeats every hour, but not necessarily at the top of every hour.

Usage

From source file:Main.java

private static void schedulePendingIntent(Context context, PendingIntent pendingIntent, long frequency) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, frequency, frequency, pendingIntent);
}

From source file:Main.java

public static void scheduleRepeat(Context context, Intent intent, Long triggerAtMillis, Long intervalMillis) {
    PendingIntent p = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, intervalMillis, p);

    Log.d("petsitter-alarm", "Alarme agendado com sucesso com repeat.");
}

From source file:Main.java

private static void setIntervalDayAlarm(Context context, PendingIntent intent, long time) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, time, AlarmManager.INTERVAL_DAY, intent);
}

From source file:Main.java

public static void startServiceAlarm(Context context, Class<?> service, long interval) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(context, service);
    PendingIntent p = PendingIntent.getService(context, 10000, i, PendingIntent.FLAG_CANCEL_CURRENT);
    am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, interval, p);
}

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

static void scheduleInexactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) {
    Intent i = new Intent(ctxt, PollReceiver.class).putExtra(EXTRA_IS_DOWNLOAD, isDownload);
    PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0);

    alarms.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period,
            period, pi);/*ww w .j av a  2s  . co m*/
}

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

static void scheduleInexactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) {
    Intent i = buildBaseIntent(ctxt).putExtra(EXTRA_IS_DOWNLOAD, isDownload);
    PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0);

    alarms.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period,
            period, pi);/*  ww w  .  j av a  2  s.  co  m*/
}

From source file:com.chess.genesis.net.GenesisNotifier.java

public static void ScheduleWakeup(final Context context) {
    final Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE, Pref.getInt(context, R.array.pf_notifierPolling));
    final long start = cal.getTimeInMillis();
    final long interval = start - System.currentTimeMillis();

    final Intent intent = new Intent(context, GenesisAlarm.class);
    final PendingIntent pintent = PendingIntent.getBroadcast(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.setInexactRepeating(AlarmManager.RTC, start, interval, pintent);
}

From source file:com.github.rutvijkumar.twittfuse.Util.java

public static final void scheduleAlarm(Activity activity) {
    // Construct an intent that will execute the AlarmReceiver
    Intent intent = new Intent(activity.getApplicationContext(), OfflineTweetAlarmReceiver.class);

    // Create a PendingIntent to be triggered when the alarm goes off
    final PendingIntent pIntent = PendingIntent.getBroadcast(activity, OfflineTweetAlarmReceiver.REQUEST_CODE,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Setup periodic alarm every 10 seconds
    long firstMillis = System.currentTimeMillis(); // first run of alarm is
    // immediate//from w w  w. j a v a2  s.co  m
    int intervalMillis = 10000; // 10 seconds
    AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
    alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstMillis, intervalMillis, pIntent);
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static void scheduleCMAccountPing(Context context, Intent intent) {
    if (CMAccount.DEBUG)
        Log.d(TAG,// w  w  w.  j  a  va2 s  .  c om
                "Scheduling CMAccount ping, starting = "
                        + new Timestamp(SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY)
                        + " interval (" + AlarmManager.INTERVAL_DAY + ")");
    PendingIntent reRegisterPendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
            SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY, AlarmManager.INTERVAL_DAY,
            reRegisterPendingIntent);
}

From source file:com.phonemetra.account.util.AccountUtils.java

public static void scheduleAccountPing(Context context, Intent intent) {
    if (Account.DEBUG)
        Log.d(TAG,//from   w ww .j  a  v  a  2  s  .  co  m
                "Scheduling Account ping, starting = "
                        + new Timestamp(SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY)
                        + " interval (" + AlarmManager.INTERVAL_DAY + ")");
    PendingIntent reRegisterPendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
            SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY, AlarmManager.INTERVAL_DAY,
            reRegisterPendingIntent);
}