Hi there,

In my last blog I promised to write a new one about how to use “mobile services”. I first thought about writing about our Offline OData innovation, but Midhun was much faster than me. So I take the topic of push notifications.

Notifications are adding real time capabilities to mobile applications. They help to speed up things. Typically it is triggered by a business event occurring in a back-end, so one of the most important parts for enabling real-time in mobile scenarios is to carefully think about the implementation of triggering events from the backend. Which business events are important, who are the recipients, what information should be sent (basically none, it should be a poke/pull implantation). If you have a clear understanding of those questions and hopefully some answers you can think about implementing push notifications.

Since all those questions are business related and I can’t answer them here, I’ll focus to the technical implementation, which is always the same.

So for this we mock the business event just by using a rest client. That’s the easy part and I will later explain how to do that. The middle layer is obviously SAP HANA Cloud Platform mobile services and for this blog I choose Android to demonstrate the receiver part and I’ll use the Hybrid SDK (Cordova plugins provided by SMP SDK). Basically I followed this great guide (Getting Started with Kapsel – Part 4 — Push) by Daniel Van Leeuwen, which covers most of the client related steps. I strongly encourage you to do the same if you did not yet. So stop reading here and create a hybrid, Android, mobile app, which is push enabled. Come back to this blog if you are ready.

Hi and welcome back.

I think you have recognised that Daniel used the SMP Admin UI to set the server sided configuration of Push. Instead of doing it for SMP, I will now show you how to do the same in the Admin Cockpit of “mobile services”.

Open the Admin Cockpit, and select the “Applications” tile.

/wp-content/uploads/2015/02/pic1_646614.png

As you can see I have already created an Application Configuration that points to a public OData service. The AppID (com.sap.hcpms.push.demo) can be named as you like. Here on this screen you can see a PushURL. This URL is the “old” API that supports SAP Gateway subscription based notifications. This kind of notifications is suitable for scenarios where your backend keeps track of the registered devices. Today we will concentrate on the enhanced and more flexible Push API. So right now, just ignore this URL.

At this point you need to either create a new Application Configuration or “Configure” an existing one.

Navigate to the “Push” tab (first click “Configure).

As you can see, you con configure various native push services here. HANA Cloud Platform mobile services supports native Android (GCM), iOS notifications (APNS), Blackberry, Windows Phone and Windows Desktop (Metrrrr…, sorry Windows Store Apps).

Since we want to use Android today, we need to provide an API Key and a Sender ID. In order to get those you need to follow the instructions here:

http://developer.android.com/google/gcm/gs.html

Your Sender ID is your Project Number – a simple numerical value like 123456789123.

The API key is a bit longer, it is also described how to get this under the link above.

We know put the values, generated by Google into the Admin Cockpit and store the values. That’s it. It’s done, really. This is how it should look like:

/wp-content/uploads/2015/02/pic2_646615.png

Save your changes.

One more thing:

Not everybody is allowed to send notification to the server. Even the Administrator can’t do this. You need a user with a special role in order to issue notifications. Typically a technical user that is known to the backend is granted the so called “Notification User” role.

In order to do this you need to navigate to the HCP account page.

Select “Services”.

Notification_1.png

Now select the little “Configure Roles” icon on the far right hand side.

Now select the “Notification User” in the upper part of the screen.

Click on “Assign…” and put your user ID into the dialog.

Then confirm the dialog.

The screen should look like the following:

Notification_2.png

You need to repeat these steps for any user you want to grant access to the notification API.

We can now start our client application and register against HANA Cloud Platform mobile services.

Once we are registered we need to register with Google to get a “registration_id”, this is handled by the push plugin in the client (it uses the native push libraries by Google to do so). This registration id needs to be sent to the mobile services in order to make HCPms aware of the particular device (we knew the device before, but not in the context of GCM). This is also done by the push plugin, so you don’t have to care about it.

In summary, “mobile services” knows how to act like a GCM server and it knows all about the clients. So you could say it behaves like a message broker.

Now we can mock the back-end event using POSTMAN (Google Chrome plugin) or any other REST client (I like the RESTClient from Wiztools as well – more control for cookies, curl for the hackers among you).

This is a valid back-end call:

POST /restnotification/application/com.sap.hcpms.push.demo/ HTTP/1.1
Host: hcpms-d055161trial.hanatrial.ondemand.com
Content-Type: application/json
Authorization: Basic bm90bXlwYXNzd29yZA==
Cache-Control: no-cache

{“alert”:”New Vacation Approval Request”, “data”:”It works!!” }

Notice that we use /restnotifications instead of /Notification. The new REST API provides a lot more options – try it out.


tl;dr

1. Follow:Getting Started with Kapsel – Part 4 — Push

2. Follow: Getting Started on Android | Android Developers

3. Create Application config in HCPms cockpit and provide Sender ID and API Key

4. Test you application using a rest client.

Have Fun,

Martin

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Aishvarya Jaiswal

    Hi Martin,

    Great stuff. I have finished upto assigning the Notification User but I am not clear with Google’s “registration_id” and how to actually send a push notification on the device using Postman plugin.

    Can you please explain how to get a “registration_id” from Google and also what are the things to do in “mock the back-end event using POSTMAN“. Please explain the Postman part in a bit detail. Also, what should be the URL to post to.


    Here is what I tried:


    Tried.PNG

    (0) 
  2. Koorma Pramodh Yellapu

    Hi Martin,

    Great post for on boarding HCMps!

    Can you please help me with understanding the difference between –
    HCPms/SMP 3.0 stack Netweaver Gateway OData vs Phonegap + Netweaver Gateway OData stack for developing enterprise mobile applications that interact with SAP?

    regards

    Pramodh

    (0) 
  3. Dhani Sebastian

    Hi Martin,

    Really helpful blog.

    Once I have done onboarding my user with HCPms, how can I confirm that whether my device registration_id has reached the mobile server? Is there any way to see my device registration_id in Hana Mobile server(like we have in SMP2.3 and previous servers)?

    Regards,

    Dhani

    (0) 
  4. zac moody

    Hi Martin

    Can you please detail out the steps for registering a device with HCPms. When I try to send a push notification via postman i get the following message

    Screen Shot 2015-06-23 at 4.09.18 pm.png

    I am referring to the following link to register a device

    SAP HANA Cloud Platform Mobile Services

    Is this step required? Also how do we specify a targetId in the push message?

    Thanks

    (0) 
      1. zac moody

        Thank Martin.

        Have a very basic question now. Is SMP required and mandatory to develop mobile apps that use HCPms?

        I have a native app developed for IOS and Android and have the backed OData services ready. I need to use HCPms for managing Push notifications and Mobile documents. Is this possible without SMP?

        (0) 
        1. Michael Appleby

          Unless you are asking for clarification/correction of some part of the Document, please create a new Discussion marked as a Question.  The Comments section of a Blog (or Document) is not the right vehicle for asking questions as the results are not easily searchable.  Once your issue is solved, a Discussion with the solution (and marked with Correct Answer) makes the results visible to others experiencing a similar problem.  If a blog or document is related, put in a link.  Read the Getting Started documents (link at the top right) including the Rules of Engagement. 

          NOTE: Getting the link is easy enough for both the author and Blog.  Simply MouseOver the item, Right Click, and select Copy Shortcut.  Paste it into your Discussion.  You can also click on the url after pasting.  Click on the A to expand the options and select T (on the right) to Auto-Title the url.

          Thanks, Mike (Moderator)

          SAP Technology RIG

          (0) 

Leave a Reply