Push notifications
There may be times where we create an app that needs to receive messages or events from a remote server. Instead of polling the server for updates, we want the server to let our app know directly.
Getting ready
Push notifications allow a remote server to send a message directly to a specific device. To implement push notifications, we will need a project number and an API key from the Google Developers Console (https://cloud.google.com/console):
First, we have to set up a project on the Google Developers Console if we do not have one already. When logged in, click on Create Project and enter a project name and ID:
Once we have created or selected an existing project, we need to make a note of the Project Number. This is used to be able to receive messages:
Select the APIs option under the APIs & auth section in the left-hand menu and make sure that the Google Cloud Messaging for Android option is on: