In Android, how do I send different types of push notification from the same app

In Android, when you get the same type of push notification, the most recent one replaces the previous one in your notification screen, mostly likely to prevent clutter. However, I saw that in some apps, I get separate notifications from the same app that do not replace the previous notification. How do I program my app to do that?

Answers


In order for having multiple notifications on the status bar, all you have to do is set a unique notification ID for every notification you want. If you send two notifications with the same ID, the notification manager replaces the oldest one with the newest. Have a look in Notification Manager's notify method.

Here's an example of how to send a notification:

Notification notification = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(title)
            .setContentText(message)
            .setAutoCancel(true)
            .setSound(alarmSound)
            .setPriority(Notification.PRIORITY_MAX)
            .build();

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(notificationId, notification);

Make sure notificationId is unique, otherwise it'll replace the oldest notification with the same ID.


Need Your Help

javascript find child object in nested arrays

javascript arrays

I have a javascript structure like below (nested arrays of objects)

Check out my age range is matching or not with the 'date of birth' stored in database

php mysql wordpress custom-post-type wpdb

I'm using custom post type to creating users in my wordpress website. I'm integrating an advance search for list down the users. In that case I need to search user by age ranges like 21 - 30 31 - 4...