Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

I recently wrote a blog about how to utilize the SMP Cloud edition for applications developed with third-party tools such as Neptune and the Phonegap build service from Adobe.

In addition to enable secure access to your backend SAP systems this new offering from SAP can also be used as a service provider for push notifications.

The no-brainer for usage is of course enabling notifications for SAP workflows, as it is very easy to set up, and also because the customer ROI with reduced time and increased availability concerning decision workflows is obvious.

In addition you can use push notifications for various other scenarios as long as the messaging is not business critical (Neither Apple or Google guarantees delivery). An example can be informing your workforce that their time entry needs to be completed the next day. Something that could easily be set up as a background job on your ABAP system.

I will guide you through the steps needed for push enabling hybrid applications built with the Adobe Phonegap build service both on the client, on the SMP Cloud edition and on the backend (In this blog I will use the Neptune ABAP add-on and some of the functionality is from the 2.1 upcoming release).

To enable the Android GCM and iOS APNS service you need a google application key and a push ssl certificate for Apple.

I will not go into details about how to obtain these as there are tons of other blogs about this on the web.

Next you need to enable the Push settings in the SMP Cloud administration. Go to your application and navigate to the Push settings. Import your Certificate (For Apple use production for either Enterprise and App store applications or Sandbox if you just need ad-hoc testing) and copy your Application Key from Google:

Using the Neptune function “export to Phonegap” you need to check the GenericPush under the plugins to ensure that the push plugin is included in your push package:

Include the registration of the app to Google GCM and Apple APNS in the DeviceReady function (I added some debug alerts which should be removed once the app is working):

function onDeviceReady()

{

    document.addEventListener('resume', onResume, false);

    document.addEventListener('pause', onPause, false);

    document.addEventListener('online', onOnline, false);

    document.addEventListener('offline', onOffline, false);

    deviceID = device.uuid;

    deviceType = device.platform;

    var devType = device.name;

   if(deviceType == 'iOS')

   {

      if(devType.indexOf("iPad") !== -1)

      {

deviceType = "iPad";

      }

      else

      {

         deviceType = "iPhone";

      }

   }

pushNotification = window.plugins.pushNotification;

// REGISTER PUSH

if (device.platform == "android" || device.platform == "Android") {

    pushNotification.register(successHandler, errorHandler,{"senderID": GoogleProject,"ecb":"onNotificationGCM"});

} else {

alert("Register iOS");

    pushNotification.register(tokenHandler, errorHandler,{"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"});

    alert("Register done...");

}

}

You also need to implement the methods for success and error handlers. Information can be found here (Or you can just copy our template when Neptune 2.1 is released) https://github.com/phonegap-build/PushPlugin/blob/master/README.md

Now we need to connect the APNS Device Token or the Android GCM Registration ID to the Application Connection of the SMP Cloud. I created a postPush function (It is important that this should be called for every logon as the Device Token can be changed at any time). Again remove debug alerts for productive use:

function postPush()

{

var xml;

var ua = navigator.userAgent.toLowerCase();

var isAndroid = ua.indexOf("android") > -1;

if(isAndroid) {

xml = '<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">'+

'<content type="application/xml"><m:properties><d:AndroidGcmRegistrationId>'

+ DeviceNotifID + '</d:AndroidGcmRegistrationId ></m:properties></content></entry>';

}

else

{

xml = '<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">'+

'<content type="application/xml"><m:properties><d:ApnsDeviceToken>'

+ DeviceNotifID + '</d:ApnsDeviceToken></m:properties></content></entry>';

}

  var tok = $("#sap-user").val() + ':' + $("#sap-password").val();

  hash = Base64.encode(tok);

  auth = "Basic " + hash;

  alert("Start ajax push post");

    $.ajax({

            type:"POST",

            data: xml,

            beforeSend: function (request)

            {

                 request.setRequestHeader("Authorization", auth);

                 request.setRequestHeader("X-SUP-APPCID", deviceID);

                 request.setRequestHeader("X-HTTP-METHOD", "MERGE");

                request.setRequestHeader("Content-Type", "application/atom+xml");

       },

            url: "https://smp-<yourSMPCloud>.hana<trial>.ondemand.com/public/odata/applications/latest/neptune/Connections('" + deviceID + "')",

            statusCode: {

            200: function() {

             alert("smp reg done 200");

             doLoginsmp();

            },

            201: function() {

            alert("smp reg done 201");

             doLoginsmp();

            },

            404: function(data) {

              alert("404" + data);

              },

            success: function( data ) {

                alert("sucess" + data);

            },

             error: function( data ) {

               alert("data");

              }

            }

});

alert("Stop ajax push post");

}

On the SMP Cloud you should now see your Application Connection and this will now be updated with a Push ID:

Lastly we need to inform the Neptune Server on the ABAP backend of the Application Connection ID and the Service Provider for push. This is done by simply adding this information as url parameters as you log in at the end of your URL: +"?phone-id=" + deviceID + "&phone-os=" + deviceType + "&phone-provider=SMPCLOUD")

That should give you an entry in the /NEPTUNE/DEVICES table:

In the ABAP backend you can now test the /NEPTUNE/SEND application to see if everything works:

Also check the logs on the SMP Cloud (Very helpful feature)

Congratulations you now should be able to receive Push notifications on both your iOS and Android devices!

Thanks to jens.koerner and his team for all their help!

References:

Using Neptune as a third-party development tool for the SMP Cloud Edition


SAP Mobile Platform on HANA Cloud released!

Key Offerings from SAP Mobile Platform Cloud

http://neptune-software.com/tips-and-tricks/login-screen-for-phonegap/

Download «  Neptune Software

2 Comments
Labels in this area