Developing Offline Mobile Apps using SAP’s Mobile Solution on HANA Cloud Platform

SAP’s mobile solution is now available on the HANA Cloud Platform. It is called HANA Cloud Platform mobile services (HCPms), it enables mobile application development, configuration and management. HCPms is a real MaaS offering so SAP takes care of upgrades, backups, patching, scalability etc,. To the developer community the happy news is that HCPms is available as a trial through hanatrial.ondemand.com.

There are few difference between SMP on-premise  (SMP 3) and HCPms, but the SDK is common for both. Hence the app developed for SMP 3 runs on HCPms too without any code change. If you are developing any enterprise mobile application, you can make it work offline (CRUD) using HCPms. Here I am explaining how to develop an offline mobile app that runs on HCPms. For this you need to activate HCPms trial, Apache ANT, Node.js, Cordova version 3.6.3-0.2.13 and SMP SDK SP05.

Add Application in HCPms

  1. Login to HCPms (https://hcpmsadmin-<your HANA account user name>.dispatcher.hanatrial.ondemand.com/sap/mobile/admin/ui/home/index.html).
  2. Click on Applications, then click on Add icon on bottom left ScreenHunter_18 Jan. 11 16.10 and provide below details:
    Application ID : com.kapsel.logon
    Name: com.kapsel.logon
    Type: Hybrid
    Security Configuration : Basic
    Optionally provide Description and Vendor.
    ScreenHunter_16 Dec. 19 11.24
  3. Click Save
  4. Next, click on Backend and provide below details:
    Backend URL : http://services.odata.org/V2/OData/OData.svc/
    Authentication Type: No Authentication
    ScreenHunter_18 Jan. 03 20.42
  5. Save the configuration

Create Offline Hybrid Mobile App

One type of mobile app that can be developed using HCPms is an HTML5 hybrid app based on Apache Cordova. Kapsel is a set of Cordova plugins that comes with SMP SDK. Logon and Odata Offline Kapsel plugins in a Cordova project enables registration of mobile app with HCPms and offline feature. Execute below cordova commands to create an offline app.

  1. Create Cordova project using the command:
    cordova -d create C:\Kapsel_Projects\OfflineDemo com.mycompany.offline OfflineDemo “{\”plugin_search_path\”:\”C:/SAP/MobileSDK3/KapselSDK/plugins/\”}”
    cd C:\Kapsel_Projects\OfflineDemo
  2. Command to add Android platform support to the project:
    cordova -d platform add android
  3. Add Logon, Offline and Network info plugin using the command:
    cordova -d plugin add com.sap.mp.cordova.plugins.odata
    cordova -d plugin add com.sap.mp.cordova.plugins.logon
    cordova plugin add org.apache.cordova.network-information
  4. Download datajs file and place it in www folder
  5. Replace index.html with index.html
  6. Execute below command to copy the files to the Android platform folder
    cordova -d prepare
  7. Run the project using the command (you have to either connect your phone with PC or setup an Android simulator to execute this command)
    cordova run android

     

How it works ?

An offline store (local DB in device called ultraliteDB) will be created when the device is online, that stores the specified Odata collection, later when the device is offline a custom HTTPClient will be applied (sap.OData.applyHttpClient();) over the actual HTTP call hence the data will be pulled from local DB instead of making an actual HTTP request.

Defining an Odata collection to use it offline:

“definingRequests” : {
“ProductsDR” : “/Products
}

Odata collections in the service:

ScreenHunter_18 Jan. 14 10.12

When the device comes online, local changes made to the offline store can be send to backend via a call to sap.flush(); and the offline store can be updated by calling store.refresh();

References: http://scn.sap.com/docs/DOC-58063

2 thoughts on “Developing Offline Mobile Apps using SAP’s Mobile Solution on HANA Cloud Platform”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.