set AlarmManager by Calendar - Android Android OS

Android examples for Android OS:Alarm Set Up

Description

set AlarmManager by Calendar

Demo Code


import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import java.util.Calendar;

public class Main{
    private static void setAlarmManager(Context context, Calendar targetCal) {

        Log.d("alarm", "Alarm is set " + targetCal.getTime() + "\n"
                + "***\n");

        Intent intent = new Intent(context, AlarmSnoozeApp.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                intent, PendingIntent.FLAG_ONE_SHOT);

        AlarmManager alarmManager = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                targetCal.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
                pendingIntent);/*  w  ww  .j a  va  2 s.  c o  m*/

    }
}

Related Tutorials