• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

TechLila

Bleeding Edge, Always

  • Home
  • About
  • Contact
  • Deals and Offers
Techlila Logo
Share
Tweet
Share
Pin
708 Shares
Watson Sentiment Analysis
Up Next

Using Watson Sentiment Analysis to Build Smart and Aware Android Apps

Add Push Notifications Capability

TechLila Mobile Android

How to Add Push Notifications Capability to an Android Project Using IBM Bluemix

Avatar of Prateek Prasad Prateek Prasad
Last updated on: March 30, 2019

Writing mobile software is one of the hottest skills that can fetch you a job. With the entire ecosystem being driven by two large platforms namely iOS and Android, it’s indeed the best time to be a developer.

Assuming that you have some amount of programming experience already under your belt, app development won’t be overwhelming for you. And it will indeed be a learning experience, I tell this from personal experience, learning to build on top of a platform opens your mind up to a whole new way of thinking. Because now you’re not only managing what’s happening in the foreground and background of your app, you are also managing its different invisible states and making sure it’s being a “good citizen” of the ecosystem that’s is your user’s device.

This article is a part of an ongoing series here at TechLila where we’ll focus on how you can be a better developer by spending time on building experiences instead of cracking your head thinking about problems that have already been solved elegantly (I’ll come to that in just a bit). Do note however that this series is not for beginners, we’ll have something in store for you soon enough. This series focuses on helping out developers who already have a fair share of expertise in Android.

This article is the first in a series of articles that we’ll be publishing to help Android developers add key “engaging” features to their apps by leveraging existing infrastructure instead of worrying about building it from scratch.

Push Notifications on Android

In this first one, we’ll focus on Push Notifications. Push Notifications fall into the engagement bracket of software integration.

Alright so assume you just completed building the next epic app which is totally killer and you are extremely optimistic about its future. In the first few days, the app is doing really well. The stability is top notch and the downloads just keep increasing and you can’t keep your eyes on the metrics. But soon enough you start noticing a very strange pattern in your app’s usage. While it’s managing to attract new users to its self but it’s losing the existing users. Retention is just dropping every day. You get all anxious worrying about what to do now, you thought people would really like it. But it’s just nothing working out.

If you’re in such a situation then this post might justifications help you out a bunch. The problem isn’t your app. It’s the user’s phone. Let me explain. Your idea is a killer and if you’re confident about its viability then all you should care about is fixing the retention problem. So yeah, I’m your user and I have a typical Android phone. With a decent 32 GB storage and thanks to Reliance Jio, a pretty stable internet connection. What do I do? I go and explore what’s out there for me to consume. In this process, I just choke up my device with 100s of apps and while it’s true that I really liked your app and found it to be interesting, honestly at this point I’ve forgotten about it. It still exists on my phone but I just don’t notice it that well among all the other apps that are there.

The problem here is your app isn’t engaging enough. It just reminds users that it’s there sitting on their device waiting for them to use it and among all the attention freak apps like Facebook and WhatsApp constantly bombarding your users with notifications it’s very likely that your app will get lost in the crowd unless it fixes the engagement problem.

How to Add Push Notifications to Your Android Project

Push Notification is a great lightweight mechanism to fix the problem and this article will show you just how to implement it in your own projects.

We are going to use IBM’s Bluemix for integrating the Push Notifications into our apps. There are a ton of other providers which will give you an SDK to integrate into the project and go about developing it. But there are a couple of key reasons why I choose Bluemix over others.

  • First Bluemix offers a ton of more features that I can add to an existing project with zero hassled (push notifications happen to be just one of those offerings). Their console makes it easy to manage all their integrations.
  • Second, if you are a beginner and try out any other SDK you most likely will get stuck somewhere (I did). With Bluemix that’s hardly the case since theory documentation and guides are so great.
  • Third and one of the most important reasons to choose Bluemix is that even though it is a paid service, it comes with a 30 days trial so you can play with all their offerings before deciding to commit to their platform and invest in it. It’s always a good practice to test some things out before investing in it.
  • Fourth and this is more like brownie points to IBM, there’s a sense of familiarity and trust developers have associated with IBM as a company. They’ve been doing some amazing work in the technology area for quite some time now and they know their stuff well, so you can jump ship without any worries

To proceed any further with this lesson any further we first need to make sure that we all are on the same page so before diving any further into this post make sure you have signed up for Bluemix (if you haven’t already) and logged in to the console.

This article is focused on Android, so I would assume some familiarity with writing apps for Android on your part. Alright, let’s get started.

Step 1: The Initial Setup

Open an existing project in Android Studio in which you want to integrate Push Notifications. You can also go ahead and create a fresh project just to test things out. If you are opening an existing project, make sure you switch to a new branch before making any additions to your project. Once you are done with this step, build the project and deploy it on your phone/emulator. This will just prove that everything is working as expected and we are good to go.

Step 2: Retrieve your Firebase Cloud Messaging API Key

Bluemix leverages Google Cloud Messaging to send downstream push notifications to your app. By taking over your Firebase Cloud Messaging (GCM) Project it just takes a huge hassle off your hands of setting and configuring things for you. Head over to console.firebase.google.com, and Login using a Google Account then follow the steps below

  • Create a new Project.
  • Give it a name.
  • Once it is setup go to Project Settings.
  • Click on Cloud Messaging.
  • Copy the Server API Key and the Sender ID as shown in the screenshot below.
  • After the above steps are completed, proceed further and add Firebase to your Android Project. This step involves entering your project’s package name and other details and then downloading the “google-services.json“ file.
Firebase Console

NOTE: It’s important that you complete this step correctly to have the upcoming steps working properly. Make sure your app is configured and the “google-services.json” file is placed in your project.

Step 1: Register App

Step One - Register App

Step 2: Download Config File

Step 2: Download Config File

Step 3: Add Firebase SDK

Step 3: Add Firebase SDK

Make sure you run your project at this stage just to see if everything is working properly. If everything is good to proceed to the next step.

Step 3: Configure a Bluemix Service

  • Head over to your Bluemix Console.
  • Open your Bluemix catalog and then click the IBM Push Notifications for Bluemix service instance you have created.
  • Click on Manage and then go to Configure.
  • Select Mobile.
  • Now enter the credentials you just copied in the previous step over here. Update the GCM/FCM Push Credentials tab with the Sender ID/Project number and API Key.
  • Hit Save.

Step 4: Sending a Push!

  • Alright, we’re almost done. Deploy your app on your phone/emulator and now head over to your console.
  • Select Send Notification.
  • Configure your message on this section.
Tag Notification
  • Once everything is done, hit Send and head over to your device.

Bluemix has some additional options for Android as per their documentation. You can extensively configure your notification. Here are the options (directly from their docs):

  • Collapse Key: Collapse keys are attached to notifications. If multiple notifications arrive sequentially with the same collapse key when the device is offline, they are collapsed. When a device comes online, it receives notifications from the FCM/GCM server, and displays only the latest notification bearing the same collapse key. If the collapse key is not set, both the new and old messages are stored for the future delivery.
  • Sound: Indicates a sound clip to be played on the receipt of a notification. Supports default or the name of a sound resource that is bundled in the app.
  • Icon: Specify the name of the icon to display for the notification. Ensure that you have packaged the icon in the res/drawable folder, with the client application.
  • Priority: Specifies the options for assigning delivery priority to messages.
    • A priority high or max will result in heads-up notification.

     

    • A priority low or default will not open network connections on a sleeping device.

     

    • A priority min will be a silent notification.
  • Visibility: You can choose to set the notification visibility option to either public or private.
    • The private option restricts public viewing and you can choose to enable it if your device is secure with a pin or pattern, and the notification setting is set to Hide sensitive notification content. When the visibility is set as private, a redact field must be mentioned. Only the content specified in the redact field will show up on a securely locked screen on the device.

     

    • The public option would render the notifications to be freely read.
  • Time to live: This value is set in seconds. If this parameter is not specified, the FCM/GCM server stores the message for four weeks and will try to deliver. The validity expires after four weeks. The possible value range is from 0 to 2,419,200 seconds.
  • Delay when idle: You can set this to either of the following values:
    • True instructs the FCM/GCM server not to deliver the notification if the device is idle.

     

    • False ensures notification delivery even if the device is idle.
  • Sync: By setting this option to true, notifications across all your registered devices are in sync. If the user with a username has multiple devices with the same application installed, reading the notification on one device ensures deletion of notifications in the other devices. You need to ensure that you are registered with Push Notifications service with userId for this option to work.
  • Additional payload: Specifies the custom payload values for your notifications.
  • Expandable notification: This provides customers an option to expand a notification with more information, while a basic notification would be visible with the notification collapsed. The following options are supported:
    • Big Picture Notifications: You can choose to include a picture when the notification is expanded. Ensure that you provide a Title text and URL for the picture.

     

    • Big Text Notifications: You can choose to include additional text with a title. Ensure that the Big Text message and Title text information is furnished.

     

    • Inbox Style Notifications: You can send the notification styled as an inbox notification. Provide a Title text and furnish the message in Lines.

Conclusion

That’s it! just like that you set up push notifications in your app in four easy steps without going through the hassle of procuring a server and bothering about unnecessary complexities. This is how easy developing with IBM Bluemix becomes. Push notification is just one of their offerings. They offer databases and Watson APIs among the many. And since the Bluemix console ties everything together you don’t need to keep shuffling between services. It’s all under one roof. I hope that this article has helped you to learn something new and if you are interested in learning more things like these, I would highly encourage you to try Bluemix.

Share
Tweet
Share
Pin
708 Shares

Disclosure: Content published on TechLila is reader-supported. We may receive a commission for purchases made through our affiliate links at no extra cost to you. Read our Disclaimer page to know more about our funding, editorial policies, and ways to support us.

Sharing is Caring

Share
Tweet
Share
Pin
708 Shares
Avatar of Prateek Prasad

Prateek Prasad

Prateek is a Mobile Developer and Designer based out of Bengaluru. When he's not working with the First Order on the next version of the Death Star, he's creating Illustrations and producing videos for TechLila.He's also trying to do something about his coffee addiction.

Category

  • Android

Tags

IBM Bluemix

Reader Interactions

What people are saying

  1. Avatar of MarinaMarina

    You have shared some important information here. Glad to read your blog.

    Reply
  2. Avatar of Suraj PadmasaliSuraj Padmasali

    Nice step by step guide, easy to understand! It helped me a lot!

    Reply
  3. Avatar of EmmaEmma

    Nice article. Love your tips that you have provided step by step.

    Reply

Add Your Comment Cancel reply

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

Primary Sidebar

Popular

How to Increase Broadband Speed on Windows

10 Best Android Launchers of 2021

Things to Do After Installing Windows 10 – Windows 10 Tips and Tricks

Top 10 Search Engines You Can Use to Search the Web Privately

55 Interesting Computer Facts That Will Blow Your Mind

What to Look for When Buying a Laptop – A Laptop Buying Guide

Fusion Drive Vs SSD – Things Nobody Tells you About Fusion vs SSD Storage

Useful Tools

• Grammarly – Free Grammar Checker
• SEMrush – The Best SEO Tool Trusted by Experts
• Setapp – One-stop subscription for Mac and iOS

Trending Topics

  • Android
  • Internet
  • iPhone
  • Linux
  • Macintosh
  • Security
  • Social Media
  • Technology
  • Windows

Worth Checking

10 Best Sound Equalizer for Windows 10 (2022 Edition!)

14 Best VLC Skins that are Highly Recommended and Free

Footer Logo Footer Text Logo

Footer

About

Hello and welcome to TechLila, the famous technology blog where you can find resourceful articles for mastering the basics and beyond.

At TechLila, our main goal is to provide unique information, such as quality tips and tricks, tutorials, how-to guides on Windows, Macintosh, Linux, Android, iPhone, Security and a few miscellaneous sub-topics such as reviews.

Links

  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms

Follow

Custom Theme Using Genesis Framework

Cloud hosting by Cloudways

Language

en English
bg Българскиzh-CN 简体中文nl Nederlandsen Englishtl Filipinofr Françaisde Deutschid Bahasa Indonesiait Italianoja 日本語pl Polskipt Portuguêsro Românăru Русскийsr Српски језикes Españolsv Svenskatr Türkçeuk Українськаvi Tiếng Việt

© Copyright  2012–2023 TechLila. All Rights Reserved.