-1

I would like to program an app, that sends two types of notifications. The user should see both of them.

Until now the notifications update each other, even if I change the flags of the pendingIntents.

That is my code:

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 Answers1

1

Create 2 different notification builder objects,

Example

First Notification object

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

Second Notification object

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

Use the notification manager to show the notification

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

Please note that the reference code was taken from this answer.

Community
  • 1
  • 1
oldcode
  • 1,669
  • 3
  • 22
  • 41