我需要多次创建多个通知。通知应该出现的时间被提取到 event_id 等。通知时间在另一个类中设置。下面的代码发生的情况是,对于设置在 10:00 的通知,在 10:00 之后设置的所有通知也会同时出现。请帮忙。只有正确的通知需要出现。不是未来的。
for(int j=0;j<event_id.size();j++)
{
if(Integer.parseInt(event_id.get(j).toString())>newEventID&&Long.parseLong(event_time.get(j).toString())>System.currentTimeMillis())
{
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);//alarm manager
NotificationManager notificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification note=new Notification(R.drawable.friendi_main_logo, event_desc.get(j).toString(), System.currentTimeMillis());
Intent mainScreenIntent=new Intent(getApplicationContext(),MainScreenActivity.class);
mainScreenIntent.putExtra("UserID", user_id);
int uniqueCode=0;
uniqueCode= Integer.parseInt(event_id.get(j).toString());//unique code for each pending intent
//separate pending intent for each alarm.. one alarm manager can invoke only one PI
PendingIntent ListOfNotification=PendingIntent.getActivity(getApplicationContext(), uniqueCode,mainScreenIntent,0);
note.flags=Notification.FLAG_AUTO_CANCEL;
alarmManager.set(AlarmManager.RTC_WAKEUP, Long.valueOf(event_time.get(j).toString()), ListOfNotification);//invokes pending intent @ the event_time
note.setLatestEventInfo(getApplicationContext(), "Event: "+event_title.get(j).toString(), event_group.get(j).toString()+": "+event_desc.get(j).toString(),ListOfNotification );
// Uri path=Uri.parse("android.resource://" + getPackageName() + "/alarm_sms.mp3");
// note.sound=path;
note.defaults=Notification.DEFAULT_ALL;
notificationManager.notify(EVENT_NOTIFY_ID, note);
EVENT_NOTIFY_ID++;
flag=true;
}
}