Notification In Android- Part 1

Android notification is one of an integral part of the Android System. It has become one of the prominent tools for the Applications to reach out to its intended audience to lure them towards exciting offers and many more interesting facts.

Displaying notification on Android is fairly easy, although, with Android Oreo OS, you need to take care of a couple of extra things. In this blog post, we would have a look at different Styles of Notification but first, let’s classify them into two types:

  • Action Notification
  • Over-the-Top Notification Aka Heads Up Notification

Notification can further be classified into the following categories based on the notification Style:

  • Large Text Notification
  • Inbox Notification
  • Message Notification
  • Big Image Notification

Let’s walk though about each notification one by one:

Action Notification

As the name suggests notification which performs some actions are known to be Action Notification. An action notification has an icon, label and Pending Intent which is fired when any Action is performed. With the introduction of Android N, the icons were removed from the notification and user is displayed notification with Labels.

Over the Top Notification Aka Heads Up Notification

Such kind of notification is common in Android Lollipop and above OS. You might have noticed, when a device is active i.e it is unlocked and you receive a call, a floating window is displayed from the top of the screen. This floating window is what we call Heads Up notification or Over the top notification, Similar to Action notification, action can be performed on these as well like Accept/Decline for a call. For notification to be displayed like a Heads-Up notification you need to have the following conditions satisfied in your App:

  • The user must be interacting with the application in Full-Screen Mode.
  • The notification must have High Priority.
  • Ringtone or vibration must be set for devices running on Android 7.1 or lower
  • The Notification Channel has high importance on devices running Android 8.0 and higher
//for Devices running Android 7.1 or lower
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
notificationBuilder.setVibrate(new long[0]);

//for Devices running Android 8.0 and above
notificationChannel = new NotificationChannel(notificationChannelID,
                    CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);

Large Text Notification

These type of notification are generally used when you want to display large text to the user. We can do that by setting the text inside the method bigText()

notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(BaseApplication.getInstance().getResources().getString(R.string.large_notification_text)));

Big Picture Notification

Such type of notification is used, when you want to display the notification that contains an image. You can achieve the desired functionality by implementing the following line of code:

Bitmap pic = BitmapFactory.decodeResource(BaseApplication.getInstance().getResources(), R.drawable.background_image);
 notificationBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(pic).setSummaryText(BaseApplication.getInstance().getString(R.string.image_preview_text)).setBigContentTitle(BaseApplication.getInstance().getString(R.string.image_content_title)));

Method setSummaryText(String) is used to display the subtext for the image and method setBigContentTitle() is used to set the title for the image.

Inbox Style Notification

We generally see such type of notification coming from Gmail/Yahoo, informing the user about the new messages received in their inbox. With InboxStyle a single notification can contain multiple lines i.e it is a consolidated view, hence you do not need to bombard the user with many notifications. We leverage the following method to achieve functionality.

notificationBuilder.setStyle(new NotificationCompat.InboxStyle()
                .addLine("Hi")
                .addLine("How are you?")
                .setBigContentTitle("New Messages from " +sender)
                .setSummaryText("+2 more"));

Let’s look into each method one by one:

  • addLine(), the method will add a line to the content of the notification.
  • setBigContentTitle(), method will override the text set by ContentTitle() method of NotificationBuilder.
  • setSummaryText(), the method will set the text as the summary and display order is dependent on the OS.

Message Style Notification

This style is used to display the notification for content between two or more people. This style can be created using the following line of code:

        Person user = new Person.Builder().setName("Lisha").build();
        Person currentUser = new Person.Builder().setName("Sarabjit").build();
        NotificationCompat.MessagingStyle.Message message1 = new NotificationCompat.MessagingStyle.
                Message("Hi", 0, user);
        NotificationCompat.MessagingStyle.Message message3 = new NotificationCompat.MessagingStyle.
                Message("Where are you ?", 2, user);
        NotificationCompat.MessagingStyle.Message message2 = new NotificationCompat.MessagingStyle.
                Message("Hello !", 1, currentUser);

        return new NotificationCompat.MessagingStyle(user).
                addMessage(message1).
                addMessage(message2).
                addMessage(message3).
                setGroupConversation(true).
                setConversationTitle("Friends");

In the second phase of Android Notification- Part 2, we will cover Reply Notification and Media Notification. The project demonstrating the above notifications is available here

Till then Stay Tuned and Happy Coding and Happy New year 2019 !!

534 thoughts on “Notification In Android- Part 1”

  1. Its like you read my mind! You appear to know so much about this, like
    you wrote the book in it or something. I think that you could do with a few pics to drive the message
    home a little bit, but instead of that, this is great blog.
    A fantastic read. I’ll definitely be back.

  2. Howdy! I realize this is somewhat off-topic but
    I needed to ask. Does building a well-established blog such as yours take a large amount of work?
    I am completely new to blogging however I do write in my
    diary everyday. I’d like to start a blog so I can share my experience and
    thoughts online. Please let me know if you have any kind
    of ideas or tips for brand new aspiring blog owners.
    Appreciate it!

  3. I’m truly enjoying the design and layout of your blog. It’s a very easy on the eyes which
    makes it much more pleasant for me to come here and visit more often.
    Did you hire out a developer to create your theme? Exceptional
    work!

  4. Если Вы занимаетесь продвижением сайтов (блогов)
    или просто устали платить «SEO специалистам»,то Вам это будет интересно.
    В любом случае Вы извлечёте из данной информации-нужную Вам.
    https://offeramazon.ru/2020/09/25/xrumer/

  5. Have you ever thought about including a little bit more than just your articles?
    I mean, what you say is fundamental and everything.
    Nevertheless imagine if you added some great pictures or videos to give your posts more, “pop”!
    Your content is excellent but with images and videos,
    this site could definitely be one of the very best in its niche.
    Terrific blog!

  6. With havin so much content and articles do you ever run into any issues of plagorism or
    copyright violation? My blog has a lot of exclusive
    content I’ve either written myself or outsourced but it
    appears a lot of it is popping it up all over the internet without
    my permission. Do you know any methods to help protect against
    content from being stolen? I’d definitely appreciate it.

  7. Please let me know if you’re looking for a article author for your site.
    You have some really good articles and I think I would be
    a good asset. If you ever want to take some of the load off,
    I’d love to write some articles for your blog in exchange for
    a link back to mine. Please shoot me an e-mail if
    interested. Many thanks!

  8. Howdy I am so thrilled I found your site, I really found you by error, while I was searching on Askjeeve for something else, Nonetheless I am here now
    and would just like to say thank you for a tremendous post and a all round exciting blog (I also love the theme/design),
    I don’t have time to look over it all at the moment but I have bookmarked
    it and also added your RSS feeds, so when I have time I will be back to read more, Please do
    keep up the fantastic job.

  9. Amazing blog! Do you have any helpful hints for aspiring writers?
    I’m planning to start my own site soon but I’m a
    little lost on everything. Would you suggest starting with a free platform
    like WordPress or go for a paid option? There are so many
    options out there that I’m totally overwhelmed .. Any tips?

    Appreciate it!hienanhdo.com

  10. Unquestionably consider that which you said.
    Your favourite reason appeared to be at the web the easiest thing to understand
    of. I say to you, I definitely get annoyed at the same time as other folks think
    about worries that they just don’t recognise about. You managed to hit the nail
    upon the highest and also defined out the entire thing with no need side
    effect , other people can take a signal. Will
    likely be back to get more. Thanks

  11. Nice post. I was checking constantly this blog and I am impressed!
    Extremely useful info specifically the last part :
    ) I care for such info much. I was looking for this certain information for a very long time.

    Thank you and good luck.

  12. Thanks a lot for sharing this with all people you really realize what you
    are talking about! Bookmarked. Please additionally seek advice from my
    web site =). We may have a hyperlink change agreement
    between us

  13. It’s appropriate time to make some plans for the future
    and it is time to be happy. I’ve read this post and if I could I want to suggest you some interesting
    things or suggestions. Maybe you can write next articles referring to
    this article. I wish to read more things about it!

  14. Have you ever thought about publishing an ebook or guest authoring on other blogs?
    I have a blog based upon on the same topics you discuss and would love to
    have you share some stories/information. I know my visitors would enjoy your work.

    If you are even remotely interested, feel free to send me an email.

  15. Hi just wanted to give you a quick heads up and let you know a few
    of the pictures aren’t loading correctly. I’m not sure why but I
    think its a linking issue. I’ve tried it in two different web browsers and both show the same results.

  16. It’s the best time to make some plans for the future and
    it’s time to be happy. I have read this post and if I could I want to suggest you some interesting things or suggestions.

    Perhaps you could write next articles referring to this article.
    I want to read more things about it!

  17. I’m impressed, I have to admit. Rarely do I encounter a blog that’s both educative and engaging,
    and let me tell you, you have hit the nail on the head. The problem is something which
    not enough folks are speaking intelligently
    about. Now i’m very happy that I stumbled across this during my hunt
    for something relating to this.

  18. Just desire to say your article is as amazing. The clearness on your publish is
    just spectacular and i can assume you’re an expert
    on this subject. Well along with your permission allow me to seize your RSS feed to stay up to date
    with impending post. Thanks 1,000,000 and please carry on the gratifying work.

  19. Thank you for the good writeup. It in fact was a amusement
    account it. Look advanced to far added agreeable from you!
    By the way, how can we communicate?

  20. I think that what you posted was actually very reasonable.
    However, think about this, what if you were
    to create a awesome headline? I ain’t suggesting your information is not solid., however what if you added a
    title that makes people want more? I mean Notification In Android- Part 1 – Sarabjit's
    Blog is kinda plain. You could look at Yahoo’s front page and
    note how they create news headlines to get people interested.

    You might add a video or a related picture or two to get readers interested about what you’ve
    got to say. Just my opinion, it could bring your posts a little
    bit more interesting.

  21. Greetings from Carolina! I’m bored to death at work so I decided to browse your
    site on my iphone during lunch break. I enjoy the info you provide here and can’t wait to take a look when I get home.

    I’m surprised at how fast your blog loaded on my phone ..
    I’m not even using WIFI, just 3G .. Anyways, wonderful blog!

  22. Hi there very cool site!! Guy .. Excellent .. Amazing ..
    I will bookmark your blog and take the feeds additionally?
    I’m satisfied to search out numerous useful information here
    within the publish, we want work out more strategies
    on this regard, thanks for sharing. . . .
    . .

  23. Thanks for another informative web site. Where else may I am getting that kind of info written in such a perfect approach?
    I have a venture that I am simply now operating on, and I’ve been at the look out for such information.

  24. excellent put up, very informative. I ponder why the other specialists of this sector don’t understand
    this. You must proceed your writing. I’m sure, you have a great readers’ base already!

  25. Hey there, I think your website might be having browser
    compatibility issues. When I look at your blog in Firefox, it
    looks fine but when opening in Internet Explorer,
    it has some overlapping. I just wanted to give you a quick
    heads up! Other then that, excellent blog!

  26. I would like to thank you for the efforts you’ve
    put in writing this blog. I really hope to check out the same high-grade content from you in the future as well.
    In truth, your creative writing abilities has encouraged me to get my own site now ;
    )

Leave a Reply

Your email address will not be published. Required fields are marked *