Android additional platforms
By Technical Support
#23 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-ph ... plugin.git

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

Code: Select all<access origin="*.bulkpush.com">
</access>


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

Code: Select allfunction 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

Code: Select allfunction init() {
    document.addEventListener("deviceready", initBulkpush, true);
     //rest of the code
     }


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

Code: Select all//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-ph ... ication.js