»  ANDROID »  Android Additional Platforms »  PhoneGap/Cordova SDK

PhoneGap/Cordova SDK

Phonegap/cordova sdk has never been so easy! Our extensive guides for all platforms currently available on the market show how to integrate push notifications within several minutes and with several lines of code. You can choose between native programming tools and a diverse set of cross-platform solutions. We are working hard on extending the list of supported SDKs, plugins and modules, so we advise coming back once in a while to see what's new. If you believe that some great tools should be added here, please let us know, and we will do our best to get them up and running!

 

1. Install the Plugin source code for Phonegap push notifications into your app by running the following command in the command line: phonegap plugin add https://github.com/BulkPush/BulkPush-phonegap-3.0-plugin.git

2. Whitelist *.bulkpush.com domain in the config.xml file:

 



 

3. Register for push notifications: Add the following function to your javascript file, enter the correct Project Number (Locate your Project Number) and  BulkPush App ID

 

function initBulkpush()
       {
    var pushNotification = window.plugins.pushNotification;
 
    //set push notifications handler
 document.addEventListener('push-notification', function(event) {
                          var title = event.notification.title;
                       var userData = event.notification.userdata;
 
                  if(typeof(userData) != "undefined") {
                  console.warn('user data: '
       + JSON.stringify(userData));
                                   }
 
                                alert(title);
 
                                pushNotification.stopGeoPushes();
                                 });
 
//initialize bulkpush with projectid: "GOOGLE_PROJECT_ID",
//appid : "bulkpush_APP_ID". This will
 
trigger all pending push notifications on start.
    pushNotification.onDeviceReady({ projectid:
"515998511673", appid :  "R0GG9ICFLM" });
    }
 
    function registerBulkpush(){
   var pushNotification = window.plugins.pushNotification;
   pushNotification.registerDevice(function(token) {
               alert("Registered Successfully "+token );
                     onBulkpushInitialized(token);
                                    },
                function(status) {
                        console.warn(JSON.stringify(
['failed to register ', status]));
                                    });
  }

 

Add method init() to the onload function in HTML:

In the init function add:

 

function init() {
    document.addEventListener("deviceready", initBulkpush, true);
     //rest of the code
     }

 

4. Receiving push notifications. See the following snippet of code in initBulkpush function

 

//set push notifications handler
   document.addEventListener('push-notification', function(event) {
                               var title = event.notification.title;
                               var userData = event.notification.userdata;
 
  if(typeof(userData) != "undefined") {
              console.warn('user data: '
               + JSON.stringify(userData));
                                  }
 
                                 alert(title);
 
                               pushNotification.stopGeoPushes();
                                });

 

Due to compatibility with Android 4 please make sure you are using at least 11 version of the Android API.
The SDK will run on older devices.

Push Notifications Plugin API:

See the full plugin API here : https://github.com/BulkPush/bulkpush-phonegap-3.0-plugin/blob/master/www/PushNotification.js

 

 

© 2015 BulkPush.com By Broadnet Technologies Ltd.