Android Alarm Create setRepeatingAlarm(Context context, Intent intentBroadcast, long time, long interval)

Here you can find the source of setRepeatingAlarm(Context context, Intent intentBroadcast, long time, long interval)

Description

set Repeating Alarm

Declaration

public static void setRepeatingAlarm(Context context,
            Intent intentBroadcast, long time, long interval) 

Method Source Code

//package com.java2s;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import java.util.Calendar;

public class Main {
    public static final String SET_ALARM = "com.kit.set_alarm";

    public static void setRepeatingAlarm(Context context,
            Intent intentBroadcast, int hour, int minute, int second,
            int millisecond, long interval) {
        AlarmManager alarm = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, hour);

        calendar.set(Calendar.MINUTE, minute);

        calendar.set(Calendar.SECOND, second);

        calendar.set(Calendar.MILLISECOND, millisecond);

        intentBroadcast.setAction(SET_ALARM);

        PendingIntent sender = PendingIntent.getBroadcast(context, 0,
                intentBroadcast, PendingIntent.FLAG_UPDATE_CURRENT);

        alarm.setRepeating(AlarmManager.RTC_WAKEUP,
                calendar.getTimeInMillis(), interval, sender);//set the properties of alarm

    }//from w  ww.j  a v a2  s . c  o m

    public static void setRepeatingAlarm(Context context,
            Intent intentBroadcast, long time, long interval) {
        AlarmManager am = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
                0, intentBroadcast, PendingIntent.FLAG_UPDATE_CURRENT);

        am.setRepeating(AlarmManager.RTC_WAKEUP, time, interval,
                pendingIntent);
    }

    public static void setRepeatingAlarm(Context context,
            PendingIntent pendingIntent, long time, long interval) {
        AlarmManager am = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);

        am.setRepeating(AlarmManager.RTC_WAKEUP, time, interval,
                pendingIntent);
    }
}

Related

  1. setExact(AlarmManager alarmManger, int type, long triggerAtMillis, PendingIntent operation)
  2. setExact(AlarmManager alarmManger, int type, long triggerAtMillis, PendingIntent operation)
  3. setAlarm(Context context, Calendar calendar, PendingIntent pIntent)
  4. setBoolean(ContentValues alarm, String key, boolean value)
  5. setRepeatingAlarm(Context context, Intent intentBroadcast, int hour, int minute, int second, int millisecond, long interval)
  6. setRepeatingAlarm(Context context, PendingIntent pendingIntent, long time, long interval)
  7. setAlarm(Context context, Intent intentBroadcast, long timeInMillis)
  8. setAlarm(Context context, PendingIntent pendingIntent, long timeInMillis)
  9. registAlarm(Context context, Class target, int code, long time, HashMap data)