-1

Я хотел бы запрограммировать приложение, которое отправляет два типа уведомлений. Пользователь должен увидеть их оба.Два параллельных уведомления из одного приложения (android)

До сих пор уведомления обновляют друг друга, даже если я изменяю флаги ожидающих запросов.

Это мой код:

Calendar calendar = Calendar.getInstance(); 

Intent intent = new Intent(this, Push.class); 
Intent intent2 = new Intent(this, Push2.class); 

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
PendingIntent pendingIntent2 = PendingIntent.getBroadcast(this, 1, intent2, PendingIntent.FLAG_UPDATE_CURRENT); 

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
AlarmManager alarmManager2 = (AlarmManager) getSystemService(ALARM_SERVICE); 

alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis()+10, pendingIntent); 
alarmManager2.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis()+10, pendingIntent2); 
+1

Создайте 2 разных объекта создания уведомлений. –

+0

Возможный дубликат http://stackoverflow.com/questions/18102052/how-to-display-multiple-notifications-in-android, пожалуйста, проверьте –

+0

В чем вопрос? –

ответ

1

Создание 2 различных объектов уведомления строитель,

Пример

объект Первый Уведомление

Notification.Builder builder = new Notification.Builder(context); 

builder.setContentIntent(contentIntent) 
      .setSmallIcon(R.drawable.some_img) 
      .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.some_big_img))    
      .setAutoCancel(true) 
      .setContentTitle(res.getString(R.string.your_notif_title)) 
      .setContentText(res.getString(R.string.your_notif_text)); 
Notification n1 = builder.build(); 

Второй Notificat ионный объект

Notification.Builder builder2 = new Notification.Builder(context); 

builder.setContentIntent(contentIntent) 
      .setSmallIcon(R.drawable.some_img) 
      .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.some_big_img))    
      .setAutoCancel(true) 
      .setContentTitle(res.getString(R.string.your_notif_title)) 
      .setContentText(res.getString(R.string.your_notif_text)); 
Notification n2 = builder2.build(); 

NotificationManager nm = (NotificationManager) context 
     .getSystemService(Context.NOTIFICATION_SERVICE); 

Используйте менеджер уведомлений, чтобы показать уведомление о

nm.notify(YOUR_NOTIF_ID, n1); 
nm.notify(YOUR_NOTIF_ID_2, n2); 

Пожалуйста, обратите внимание, что код ссылки был взят из this answer.

+0

Благодарю вас за помощь. – Incam

+0

@ Incam Примите ответ, если это поможет. –

Смежные вопросы