Using Google Cloud Messaging (GCM) we can send push notification from web server to the android devices that are registered.
This is how the process works:
1.Android device sends sender id to GCM server for registration.
2.GCM Server returns registration id to android device after successful registration.
3.Android device sends registration id to web server.
4.GCM registration id is stored in the database at server.
5.We can get registration id from database whenever push notification is required.
6.GCM sends push notification after getting request.
Steps to follow for push notifications:
1. We have to Register with Google Cloud Messaging from Google developer Console and it provides Sender ID and API key for GCM.
Registering with Google Cloud Messaging:
Go to the link Google APIs Console page and create a new project.
Now the project id is generated after creating the project. You can see the project id in the url. The project id will be used as a SENDER ID in android application.
After this turn on the Google Cloud Messaging for Android.
Now, click on API Manager and create the API Key for your project. This API key will be used when sending requests to GCM server.
2. Then configure your app to use push notification plugin
Install the PushPlugin from github by following command:
$ phonegap local plugin add https://github.com/phonegap-build/PushPlugin
Add the following script line to your main html file to PushNotification.js.