在特定时间通知

我有一个特定的时间通知,看我的代码:

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

除了一件事情,这是完美的。

通知设置为8:30与警报pipe理器如果我启动应用程序在8:30之后,9:00例如,通知仍显示..

警报是否有可能在晚上8点30分起飞,但不迟到?

编辑

对于有同样问题的人,这里是解决scheme:

把它放在你的广播接收器里:

 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) { //nothing } else { //show notification } 

Solutions Collecting From Web of "在特定时间通知"