Android

  1. Download the phonegap plugin for Android from this link (Android 2.2 or above).
  2. 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.
  3. Modify the AndroidManifest.xml adding the following configuration lines (replace your_app_package with the Application root package):
      <uses-permission android:name="android.permission.GET_ACCOUNTS" />
      <uses-permission android:name="android.permission.WAKE_LOCK" />
      <uses-permission android:name="android.permission.VIBRATE" />
      
      <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
      <permission android:name="your_app_package.permission.C2D_MESSAGE" android:protectionLevel="signature" />
      <uses-permission android:name="your_app_package.permission.C2D_MESSAGE" />
  4. Modify the AndroidManifest.xml adding the following configuration lines into the application tag lines (replace your_app_package with the Application root package):
      <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
          <action android:name="com.google.android.c2dm.intent.RECEIVE" />
          <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
          <category android:name="your_app_package" />
        </intent-filter>
      </receiver>
      
      <service android:name=".GCMIntentService" />
  5. Modify the res/xml/plugins.xml adding the following lines, to inform Cordova about the plugin location:
      <plugin name="GCMPlugin" value="com.plugin.GCM.GCMPlugin" />
  6. 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.
  7. Add the PushipNotification.js script to the assets/www folder and include it to the index.html file
  8. 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));
          }
      });
  9. 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

 

 

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: