What is Push Notifications?
Push notification allows an app to notify you of new messages or events without the need to actually open the application, similar to how a text message will make a sound and pop up on your screen. This is a great way for apps to interact with us in the background, whether it be a game notifying us of some event occurring in our game world .
In addition to pushing messages to the screen, push notification allows apps to display a number or ‘badge’ on the app’s icon. For example, the Mail icon will show the number four when we have four unread messages.
Benefits of Push Notifications:
-
Engage customers
-
Keep customers informed and connected
-
Guide customers to their business.
-
Lower cost and better tracking than SMS.
-
No cost to the customer for rich media, unlike MMS.
-
Can target to events and times when most users use your app.
-
Can notify users when a message is waiting, creating an in-app inb
-
Can incorporate users’ location to deliver relevant content.
-
Marketer-friendly interface for campaign setup, send, and reporting. Little IT support is needed.
Android Push Notifications:
Each mobile platform have their own server for push Notifications to send the messages and events to their platform based application.for example
1.Apple using APN -Apple Push Notification Service.
2.Windows Using WNS-Windows Push Notification Service.
3.Blackberry Using BPS-Blackberry Push Sevice
4.Android Using GCM-Google Cloud Messaging
Why we Dint go for GCM ?
Because of, to use the GCM service in android Application the device must registered with Google Account .without having Google account in Android device the Android Push Notifications Service providing by Google will not Work.Which is not possible that every merchant will have own Google Account which should be a bottleneck when the product in the market.and in some case it should be a forcing action to the merchant to access the Notification Service.so we just dropped this Service.
But no worry by following GCM mechanism there are bunch of services providing by some Third party service providers like Mixpanel,Parse,Airbob,UrbanAirship,Push.IO and Mqtt are available in the market to offering Push Notification service for android applications.but in these providers also there are some dependencies are there.
eg:
Mixpanel-Need Google Account
Airbob-Need Google Account.
Other than Google account ,usually there should be a pricing plans based on Notifications Usage per month or based on no of users.
GCM Mechanism:
1.First Android device Sends SENDER ID,APPLICATION ID to GCM server for registration.
2.Upon successful registration GCM server issue REGISTRATION ID to Android device.
3.After receiving Registration ID,device will send registration id to our server.
4.Our Server will store Registration id to database for later usage.
a.Whenever push notification needed our server sends a message to GCM along with Registration ID (which is already in the DB).
b.GCM delivered messages to respected devices using Registration ID.
Requirements:
So by considering the above dependencies we just concluded with Parse API for push notifications ,which is the only API satisfies our requirement.especially no need of Google account to be registered in the corresponding device to receive push notifications.
The following lists are required for implementing push notification using Parse in android devices.
1.Parse SDK for Android. Download me.
2.Need Parse account to registered our Application.
(No need to upload application file.we just give the name of our application for understanding).
Implementing Parse in Android Application.
The below steps are to be followed to implement Push Service in the Application.
STEP 1:
After downloaded the Parse Api .we need to import the jar file to ‘libs’ folder of our YeldiAra Project.
STEP 2:
Call Parse.initialize from your onCreate methods to set your application id and client key
Also in this method, specify a default Activity to handle push notifications, then save your installation object:
STEP 3:
Our app must request the “INTERNET” and “ACCESS_NETWORK_STATE” permissions, if it isn’t doing so already. Add these lines:
STEP 4:
Add the following XML to AndroidManifest.xml immediately before the closing </application> tag:
which is used to initialize the Push service in the application.to receive notifications.
Also add the push permissions, typically before the <application> tag:
if we completed the above steps in the Application we are almost done and we can say the say the device is ready for receiving Pushed messages/notifications from Parse server.
Sending Push Notifications from Parse Server:
So we are done our job in the client side.next is to send the messages to the devices/Terminals which are running YeldiAra.
Parse not only providing needed services for mobile platform.they also considered the User interface and built the Dashboard to sending Push notifications to the devices.
STEP1:
Login into Parse Admin using the Login username and Password.
STEP2:
After a successful logged in the Parse admin will take you into their Dashboard.
See the below shot.
in the left top corner u have to choose your Application name to send push notifications.
STEP 3:
As i said in the Parse implementation STEP 2.we need APPLICATION ID and CLIENT KEY.so to get the those two keys we just select Settings Tab.Under Settings Tab select Applications Key tab (which will be display in the left side) to get the Keys.See the below shot.
Note:Enable Client Push enable under Push Notifications Tab.
STEP 4:
Now select Push Notifications Tab.under the Push Notifications Tab you can see the following filters and selectors.
-
Send To – Everyone/Segment
-
Device Types – iOS/Android Devices/Windows
-
Compose Msg – Message to send to the Devices (Max 180 Chars only)
Message / JSON format
STEP 5:
Now send the messages you want to send to the customers.as your wish by composing messages.See the below shot.
STEP 6:
Once the message sent successfully to the devices you can see the status of the messages and number of subscribers in the Dashboard.
see the below shot.
STEP 7:
The message will be shown in the Notification bar with application icon with corresponding sent message from Parse Server.
Push Notifications Inside Application:
As per Android platform the push notifications will be display in the Notification bar.Actually which is not our requirement so the notifications should be display and have to show inside our Application.
To achive this we have to add the custom receiver in the Application.and also in the server side we have to send message in JSON format with some tag in the sending message.Lets see in separate topic.
Custom Push implementation in Android:
In Android every messaging services like SMS,MMS,PORT SMS and Push Notifications are working based on Broadcast receiver.which will be running in background as a service without any user interaction.whenever message is targeting the device the Receiver class will catch the respective message and we have to parse the message to show to the User.
So in our condition the Server (Parse) will send the message in JSON format we have to use Json Parser to parse the message and we will be storing it in local Database to show the messages in Notification Module.
Our Receiver class formally looks like as below.
in AndroidManifest.xml file also we have use this receiver class to receive the notifications.
every receiver class will be working based on action .here YA is the Action name ,so this is the Action name we have to use while sending Push notification from Parse server.with include the tag name as “action”:”YA” .
Now the Application has ready for displaying Custom Notification message sent by Parse Server.after receiving message message we have to store it in local DB to display later in the Application.
Send Custom Push message from Server:
Sending message from Parse is simple,follow the below template to send messages to devices.
We have send the custom message to specific customers using Channels tag in the JSON format.which is a array so you can target multiple Channels.