By Henry Atwell
Nougat has already made its debut globally; however, there are still a number of features need to be explored by developers worldwide. One such aspect to discuss is «Bundled Notifications. » Before discussing how developers can make best use of Bundled Notifications in Nougat 7.0, let us briefly discuss how notifications differ in Nougat from previous versions.
Notifications have been extended comprehensively in this recent release from Android. The default messaging app generates a good number of messages over time. Bundling historical notifications make it easier for users to access any number of notifications during a period. It is similar to stacking notifications one over another; however, in this case, you have all similar notifications stacked together, through one common app notification.
Imagine having too many notifications piled up within an app, and you have them grouped together, showing just one notification instead of too many of them appearing one above another. Clicking that one notification opens up all the notifications related to that app, with recent ones appearing right at the top. This is what you see in Nougat, unlike older Android versions that show individual notifications, appearing one below another. Just follow a systematic process for implementing these bundled notifications, and you can have app specific notifications bundled under a common header, with Nougat OS or future higher versions on your Android Smartphone.
The advantages of using bundled notifications are evident from the name itself. It is cumbersome to see a bunch of notifications appearing over one another, making things overwhelming. In case of bundled notifications, similar notifications within an app fit into a common bundle; therefore, they are displayed only when clicked by users.
Looking at Marshmallow devices, the notifications don’t overwhelm users. However, there is less detailing, which restricts users from seeing individual notifications. With unread messages displayed, you don’t have enough details telling more about the individual notifications.
So, let’s come down to our main discussion. The first thing you need to do is create a NotificationBuilder class, as shown in the following code segment:
The notification messages need to be displayed even before users have unlocked the device. Before users reboot their device, this is to take place, through device storage making use of SharedPreferences. So, let us actually look at how to go about doing this.
The sendBundledNotification() method, as seen above, allows you to build a new notification. This separates the whole thing into two parts—a summary notification, and the actual message notification. As seen from previous examples, each individual message that appeared on Nougat+ devices, is an example of message notification, whereas summary notifications are those single messages. There is binding between these two sections of notifications, using an identical group key known as setGroup() applied on the notification builder.
There is an important point to note here. A message notification gets posted using a notification ID that is uniquely generated, and a fixed ID is used to generate the summary message. This is helpful especially when you want different notifications for same message to come through a common notification for a summary. Ensure to flag the summary message; this can be done by calling setGroupSummary(true) right on the notification builder. Based on the official documentation, a summary notification is strongly recommended, telling it is more of a requirement than a recommendation.
It is a good practice to use NotificationCompat throughout while doing this. Because setGroupSummary(), as well as setGroup(), are the only available APIs in the API 20 series, you are bound to use them, especially when targeting the APIs below 20. So, now the only thing that remains is to make use of MessengerService to create notifications.
Notifications play an important role in the lives of mobile app users. They are useful because you get to know everything that’s happening, even if your app is closed. Notifications do tell you about everything new taking place with the app. Whether it’s products or services, events, offers, discounts, updates, upgrades, app notifications, or bug/error detection, you have information regarding everything through messages popping up on your Smartphone, even if it’s locked. Ensure that you take time to see them; it can make a big difference in the way you are using them.
So, that is all. Now you know how to create bundled notification, especially if you are an Android developer who cares about providing a wonderful app experience to the users. There are certainly other ways to present notifications; we’ll explore them in our later articles. However, bundled notifications are among the hot favorites because they keep things clean enough, with everything arranged systematically.
Henry Atwell is an Android app developer associated with Fusion Informatics , a custom Android application development company. He is an avid writer and often contributes to various blogs and Web sites.
# #
This article was contributed. ©Developer.com. All Rights Reserved
© Source: http://www.developer.com/ws/android/creating-bundled-notifications-with-android.html
All rights are reserved and belongs to a source media.