Beginner’s Guide to Sending Push Notifications on Android Devices

Push Notification are those messages which pops up on your screen containing information regarding a certain mobile app. Those messages pops up even if your apps are not opened. They are used for a lots of things, such as, for sending cricket’s score, for sending weather report, for sending a sale alert etc. Each mobile platforms has their own services for this. In this article, we are going to discuss the services regarding Android Devices.

Push Notifications helps you to reach out to your customers. It is like an one-on-one conversation between you and your customer. By using Push Notification, you can remind your subscribers to visit and re-visit your website.

Basic Uses of Push notification

There are a tons of benefits for Push Notification. Let me tell you some of the basic among them.

  • You can promote an item or offer to increase your sales
  • It improves Customers’ Experience.
  • It helps to drive the users to other social media platforms
  • You can send the transaction receipt rightaway
  • Conversion of users.

Google Cloud Messaging

Google Cloud Messaging commonly referred to as GCM, is a mobile notification service developed by Google that enables third-party application developers to send notification data or information from developer-run servers to applications that target the Google Android Operating System, as well as applications or extensions developed for the Google Chrome internet browser. It is available to developers free of charge. The GCM Service was first announced in June 2012 as a successor to Google’s now-defunct Android Cloud to Device Messaging (C2DM) service, citing improvements to authentication and delivery, new API endpoints and messaging parameters, and the removal of limitations on API send-rates and message sizes. It has been superseded by Google’s Firebase Cloud Messaging(FCM). GCM Architecture.svg

How Does It Work?

There are mainly three Server Entities in this Ecosystem. They are:

  1. Your Server
  2. GSM
  3. Android Device

How it works is that your server receives an event from your application saying your inventory is low in the warehouse, this person made an order or have an appointment, then your server will call GSM with your API key and the list of device IDs that have been registered as well as the message you want to send. For each message you want to send, you have to create another call, but you can send to multiple devices with a single message, with a single call then all the different Android devices will receive that message that match the device ID that you are calling GSM with. This is totally free service provided by Google as a part of its Play Store.

Enabling GCM services

You can do this in three steps.

  1. Enabling GCM service in your Google Project.
  2. Then you would add a GCM  Receiver in your application and
  3. then you would add a GCM Push to your server.
  • To enable GCM services, go to consoledevelopers.google.com/project, Create a new project. The project name cannot be changed in anytime in the future. This is an identifier for the back-end code.

Now, we will enable the Google Cloud Messaging APIs. Go to APIs and Auth. Scroll down to Android’s GSM. Now turn the service On. Next go to Credentials. It’s time to create a public API. API is the server key.If at anytime you feel that your API key has been compromised you can go to the same page and create another one by clicking “Regenerate Key”.

  • Adding GCM Receiver

Create a blank application and save it. Plug-in your android device then Compile your device. Add the manifest file(blank app) to the Project. Next, you need to add the GCM Receiver to the project. What this does is that it enables push notifications to your application. The receiver should be added as a Library. Then we add a Google Play Services jar as a deployment references. You can get that from Android SDK.

  • Next step is to add some information to your manifest. Do not forget to turn on the “push Notification” service.
  • Obtaining the Registration Token: An Android application needs to register with GCM connection servers before it can receive messages. When an app registers, it receives a registration token and sends it to the app server. The client app should store a boolean value indicating whether the registration token has been sent to the server. Google provides the Instance ID API to handle the creation and updating of registration tokens. Once you’ve received your registration token, make sure to send it to your server.
  • Displaying of the Push Notifications: As soon as the notifications are received, GSM immediately displays them in the notification trays. Provided, you must have NotificationsListenerService.
  • Adding of the Icons: The next necessary step is to associate all the notifications with their respective icons. If you don’t have one, you can get it from Google’s Material Design Icons Library.

These steps will help you set up your Android device, after which you will be able to push notifications to your subscribers.