set Alarm via Intent - Android android.app

Android examples for android.app:Alarm Set up

Description

set Alarm via Intent

Demo Code

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

public class Main {

  public static void setAlarm(Context context, Intent intentBroadcast, long timeInMillis) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

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

    am.set(AlarmManager.RTC_WAKEUP, timeInMillis, sender);

  }/* w w w.  j  a v a 2s . c  o  m*/

  public static void setAlarm(Context context, PendingIntent pendingIntent, long timeInMillis) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    am.set(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);

  }

}

Related Tutorials