0

I have the following code to set a date for AlaramManager ,

    AlarmManager alarm = (AlarmManager)getSystemService(Service.ALARM_SERVICE);

    int mYear = 2012;
    int mMonth = 5;
    int mDay = 26;
    int mHour = 12;
    int mMinute = 34;

    Date dateNotif = new Date (mYear - 1900, mMonth, mDay, mHour, mMinute); 


    Long myDate = dateNotif.getTime();
    Long current = System.currentTimeMillis();

    Intent i = new Intent(getApplicationContext(),ShowNotificationService.class);
    PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 12345,i, 0);

    alarm.set(AlarmManager.RTC_WAKEUP, dateNotif.getTime(), pendingIntent);

When the time of the emulator is 12:34 nothing appears for the notifications

Adham
  • 63,550
  • 98
  • 229
  • 344

1 Answers1

0

I have set Today date and time

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);//2012
calendar.set(Calendar.MONTH, 4);// It start from 0-11 so use 4 instead of 5
calendar.set(Calendar.DAY_OF_MONTH, 26);                 
calendar.set(Calendar.HOUR_OF_DAY,9);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);

Intent i = new Intent(getApplicationContext(),ShowNotificationService.class);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 12345,i, 0);

alarm.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), pendingIntent);
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
Parag Chauhan
  • 35,760
  • 13
  • 86
  • 95