setup Alarm using Calendar - Android Android OS

Android examples for Android OS:Alarm Set Up

Description

setup Alarm using Calendar

Demo Code


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

public class Main{
    static public void setupAlarm(Context context) {
        Intent receiverIntent = new Intent(context, AlarmReceiver.class);
        PendingIntent sender = PendingIntent.getBroadcast(context, 0,
                receiverIntent, 0);/* www  .ja  va  2 s .  co m*/

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

        Calendar cal = Calendar.getInstance();

        cal.add(Calendar.DATE, 1);
        cal.set(Calendar.HOUR_OF_DAY, 7);
        cal.set(Calendar.MINUTE, 30);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);

        long triggerTime = cal.getTimeInMillis();

        am.set(AlarmManager.RTC_WAKEUP, triggerTime, sender);
    }
}

Related Tutorials