Monday, 14 May 2012

Receiver

package com.BirthdayWisherFinal;

import java.util.Calendar;

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

public class AlarmSetupReceiver extends BroadcastReceiver{

    public static AlarmManager alarmManager;
    public static PendingIntent intentExecuted;
    public static Integer interval;
    public static Calendar now;
    public static  Intent i;
    public static boolean FoundAlarm;
   
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
           
       
        now = Calendar.getInstance();
        // here u can set the time when you want to send the message
        // for testing purpose i have set to 1:30 pm
        // for testing purpose set the hour,min respectively n msg will be send on dat time
        now.set(Calendar.HOUR_OF_DAY, 13);
        now.set(Calendar.MINUTE, 30);
        now.set(Calendar.SECOND, 0);
   
        alarmManager = (AlarmManager)(context.getSystemService(Context.ALARM_SERVICE));
        i = new Intent(context,EventReceiver.class);
           
        intentExecuted = PendingIntent.getBroadcast(context,1, i,
                PendingIntent.FLAG_CANCEL_CURRENT);
       
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,now.getTimeInMillis()
                , 24*60*60*1000,intentExecuted);
        Log.v("Birthday Wisher", "alarm setup done for birthday wisher");
    }
}

No comments:

Post a Comment