I have a notification at a specific time, see my code:
//Create alarm manager AlarmManager alarmMgr0 = (AlarmManager)getSystemService(Context.ALARM_SERVICE); //Create pending intent & register it to your alarm notifier class Intent intent0 = new Intent(this, AlarmReceiver_maandag_1e.class); intent0.putExtra("uur", "1e"); PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0, intent0, 0); //set timer you want alarm to work (here I have set it to 8.30) Calendar timeOff9 = Calendar.getInstance(); timeOff9.set(Calendar.HOUR_OF_DAY, 8); timeOff9.set(Calendar.MINUTE, 30); timeOff9.set(Calendar.SECOND, 0); //set that timer as a RTC Wakeup to alarm manager object alarmMgr0.set(AlarmManager.RTC_WAKEUP, timeOff9.getTimeInMillis(), pendingIntent0);
This works just fine, except for one.
The notification is set at 8:30 with the alarm manager. If I launch the application after 8:30, 9:00, for example, the notification still shows.
Is it possible that the alarm goes off at 8:30, but not later?
Edit
For those who have the same problem, here is the solution:
Put this in your translator:
long current_time = System.currentTimeMillis(); Calendar timeOff9 = Calendar.getInstance(); timeOff9.set(Calendar.HOUR_OF_DAY, 8); timeOff9.set(Calendar.MINUTE, 35); timeOff9.set(Calendar.SECOND, 0); long limit_time = timeOff9.getTimeInMillis(); if (current_time > limit_time) {
android notifications alarmmanager
Gromdroid
source share