schedule Alarm In Hours - Android android.app

Android examples for android.app:AlarmManager

Description

schedule Alarm In Hours

Demo Code

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;

public class Main {

  private static final String LOG_TAG = "AlarmUtils";

  public static int scheduleInHours(Context context, PendingIntent pi, int hours) {

    int period = hours * 60 * 60 * 1000; // in millis

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

    long alarmTime = System.currentTimeMillis() + period;

    mgr.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);

    return period;
  }//w  w w  .j  a  va2  s  .co m

}

Related Tutorials