Reputation: 577
what is the problem in that code ? I am trying to fire the alarm at 11 am and i am setting it at 10 am so it is supposed to fire after an hour which is never happened
public void schedulePayment(Context ctxt,int numOfDays) {
mgr = (AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);
Intent myIntent = new Intent(ctxt, NotificationPayment.class);
PendingIntent pendingIntent = PendingIntent.getService(ctxt, 0, myIntent, 0);
Calendar time = Calendar.getInstance();
time.setTimeInMillis(System.currentTimeMillis());
time.clear();
time.set(Calendar.HOUR_OF_DAY, 11);
time.set(Calendar.MINUTE, 1);
time.set(Calendar.SECOND, 1);
long limit_time = time.getTimeInMillis() ;
// if(time.before(Calendar.getInstance())){
// Log.d("add time ","extra");
// limit_time+=AlarmManager.INTERVAL_DAY;
// }
Log.d("in schedule ","done..."+limit_time);
mgr.setRepeating(AlarmManager.RTC_WAKEUP, limit_time,AlarmManager.INTERVAL_HALF_HOUR, pendingIntent);
}
Upvotes: 1
Views: 167
Reputation: 1029
Alarm manager never fired becouse your limit_time(second argument in setRepeating) less than currentTimeMillis.Try to use System.currentTimeMillis + interval instead limit_time
Upvotes: 1
Reputation: 4905
Don't call time.clear();
This is deleting all the calendar fields, like the date.
Upvotes: 2