- Download the phonegap plugin for Android from this link (Android 2.2 or above).
- Add the following packages to your project: com.google.android.gcm and com.plugin.GCM. Add the GCMIntentService.java file to the root package of your Application.
- Modify the AndroidManifest.xml adding the following configuration lines (replace your_app_package with the Application root package):
- Modify the AndroidManifest.xml adding the following configuration lines into the application tag lines (replace your_app_package with the Application root package):
- Modify the res/xml/plugins.xml adding the following lines, to inform Cordova about the plugin location:
- If you didn’t configure the Google Api project yet, follow these instructions to get the GMC sender ID. Replace all the occurrence of “your_sender_id” with the given ID.
- Add the PushipNotification.js script to the assets/www folder and include it to the index.html file
- Add the following code to the OnDeviceReady method:
Puship.PushipAppId = puship_id; // an example of puship_id might be: "h1mCVGaP9dtGnwG"
var GCMCode = your_sender_id; // this is the senderID provided by google. example: "28654934133"
Puship.GCM.Register(GCMCode,
{
successCallback: function (pushipresult){
navigator.notification.alert("device registered" + pushipresult.DeviceId);
},
failCallback: function (pushipresult){
navigator.notification.alert("error during registration: "+ JSON.stringify(pushipresult));
}
});
- Create a new application in the Puship Manager to get the Puship App ID and replace the “puship_id” with the ID provided in the script above.
Done! You are able now to connect to the Puship Manager and send push notification to your devices!
Download a complete example using the link below to better understand the whole process
Full Android example
Adding tags, geolocations management and all the other api are described in the guide common to all the platform that can be consulted at the following link:
Common library documentation