#java #android
#java #Android
Вопрос:
У меня есть код для создания уведомления:
NotificationManager notifyMngr=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification=new Notification(mId, "New alert!", System.currentTimeMillis());
Intent alert = new Intent(this, AlertInfoActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, alert, 0);
notification.setLatestEventInfo(this, data.get("name"), data.get("post_date"), contentIntent);
notifyMngr.notify((int) System.currentTimeMillis(), notification);
Мне нужно создать несколько уведомлений, и каждое уведомление должно запускать новый объект AlertInfoActivity по щелчку мыши. Но этот код всегда выполняет 1 объект действия. Как я могу выполнить свою задачу?
Комментарии:
1. вы хотите запускать несколько действий, когда пользователь нажимает на одно уведомление?
2. нет. Я выполняю несколько уведомлений.
Ответ №1:
Вам нужно создать уведомление для каждого действия, которое вы хотите запустить. Вот так:
NotificationManager notifyMngr=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
//First Notification
Notification notification=new Notification(mId, "New alert!", System.currentTimeMillis());
Intent alert = new Intent(this, AlertInfoActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, alert, 0);
notification.setLatestEventInfo(this, data.get("name"), data.get("post_date"), contentIntent);
notifyMngr.notify((int) System.currentTimeMillis(), notification);
//Second Notification
Notification notification2 = new Notification(mId, "Second Alert!", System.currentTimeMillis());
Intent alert2 = new Intent(this, DifferntAcitivty.class);
PendingIntent contentIntent2 = PendingIntent.getActivity(this, 0, notification2, 0);
notification2.setLatestEventInfo(this, data.get("name"), data.get("post_date"), contentIntent2);
notifyMngr.notify((int) System.currentTimeMillis(), notification2);
//Third Notification
Notification notification3=new Notification(mId, "Third Alert!", System.currentTimeMillis());
Intent alert3 = new Intent(this, ThirdActivity.class);
PendingIntent contentIntent3 = PendingIntent.getActivity(this, 0, alert3, 0);
notification3.setLatestEventInfo(this, data.get("name"), data.get("post_date"), contentIntent3);
notifyMngr.notify((int) System.currentTimeMillis(), notification3);
//And so on and so forth.