Free up to 1MM monthly messages. No credit card required.
When building mobile applications in Android (and mobile applications in general), it is tough to think of a use case where we don’t need to communicate with mobile devices to sync data and notify users. If you’re reading this article, this probably sounds familiar!
We are going to talk to you about two technologies that will make your life easier when developing real-time applications for Android.
In this tutorial, we’ll get started with GCM for Android and how to get started with PubNub real-time push notifications for Android. In our next tutorial, we’ll get coding and show you how to send and receive those notifications on Android devices.
Let’s consider the following scenario. You are developing a real-time sports application which feeds its users with critical news during a game. A key feature to the app would be to send reliable push notifications to the users as soon as their favorite team scores.
You could develop the notification system yourself. You’d have to take many cases into account, deal with queuing, saving the notification and resend in case of offline devices. It’s long, time consuming and more or less the same system as many other applications.
Google is here to save the day. Google Cloud Messaging takes care of all of these issues for you. It provides you with its service for free too. Sending push notifications suddenly becomes so much easier!
Note that this service is only available for small messages to the client applications: 4096 Bytes is the limit, so only lightweight information can be sent.
Google’s system considers 3 parties:
When an user installs an application, it must register itself to enable GCM. Once this is done, as soon as you decide to send your users a notification, a succession of actions will be triggered:
Pretty cool, but there’s a fair amount of engineering work that goes into setting up a GCM service. But overall the service is quality.
Obviously, once you are using PubNub Data Streams, you are already communicating in real time with all of your devices – but if you want to send push notifications for a native Android experience, GCM is a great ally.
PubNub has an easy integration with GCM. The PubNub channel replaces the third party servers which send these notifications to Google’s GCM servers. You may have any registered endpoint send a push notification to your connected devices.
Coming back to the sports news app example, you can have your sports critic send the score in real time from his phone and trigger a push notification to the rest of the audience’s devices. PubNub makes it simple – additional servers that you have to operate can be ruled out of the equation!
This allows the application to send push notifications to devices registered on specific channels in no time. It combines the native Android Notification API from Google with the real-time data stream network of PubNub. Your notifications will be natively understood by any Android device. If you already have GCM on your application and are considering using PubNub, you’ll hardly have to change anything about your app, most likely removing code!
Let’s start with getting you up and running.
You will need to follow these steps:
First step, head to the Google Developer Console. Open an account if you do not have one and follow these instructions. The two pieces of information you’ll want to keep are:
Now let’s head out to PubNub to get started. Sign up for a free PubNub account and get your publish/subscribe keys from the Admin Dashboard.
Next, you’ll also need to enable Push Notifications. Scroll down the page and add the option to your account.
You will be asked to provide the Server API Key provided by Google.
This is the key element which allows your PubNub channels to send notification requests to GCM servers.
That’s it! We are ready to roll!
You can start your Android project now!
You’re almost ready to start coding, let’s just make sure you have all the correct dependencies to start!
To add pubnub to your project, clone the git repository:
git clone https://github.com/pubnub/java.git
You’ll need to copy to your project 2 of the libraries found in the repo:
Next, you’ll need to add the Google Play SDK to your application. Follow these instructions.
A roundtable discussion led by PubNub’s COO, Casey Clegg, exploring the topics of what it means to be human in a virtual world.
Dr. Joe Kvedar, Chair of the Board for the American Telemedicine Association, joins our COO, Casey Clegg, to discuss why...
Today, we are glad to announce that we are currently in the process of implementing ISO-27001 security standards.