Question

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);

    }       
Was it helpful?

Solution

Don't call time.clear(); This is deleting all the calendar fields, like the date.

OTHER TIPS

Alarm manager never fired becouse your limit_time(second argument in setRepeating) less than currentTimeMillis.Try to use System.currentTimeMillis + interval instead limit_time

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top