Search code examples
androidalarmmanager

AlarmManger not working with date


Hi I am trying to make reminders above api 11. I did all things with and working on time also means if i set time , its working but if i want to set reminder for tomorrow or any day it is not able to do.. so i put this calender code to set alarm which is working. With time working

    Calendar calendar = Calendar.getInstance();

    // working time only
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, min);
    calendar.set(Calendar.SECOND, 00);
    AlarmBcastReceiver alarmBcastReceiver = new AlarmBcastReceiver();
    alarmBcastReceiver.SetAlarm(this, calendar);

Now if tried to put date in this calender. this is not working i.e.

    Calendar calendar = Calendar.getInstance();

    calendar.set(Calendar.DAY_OF_MONTH, day);
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.YEAR, year);

    // working time only
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, min);
    calendar.set(Calendar.SECOND, 00);
    AlarmBcastReceiver alarmBcastReceiver = new AlarmBcastReceiver();
    alarmBcastReceiver.SetAlarm(this, calendar, notiId);

I also tried to set this //calendar.set(year, month, day, hour, min); but it also not working.


Solution

  • You are passing wrong moth. You are passing 10 and want to test for October. You will need to pass it considering 0-11 for January - December.

    Which means,

    change your month to 9.

    calendar.set(Calendar.MONTH, 9);
    

    That will make the alarm date of October. So make changes and test.

    A reference

    Hope this helps.