Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Dan_vL
Product and Topic Expert
Product and Topic Expert
0 Kudos




Push


If you are using SP13 or newer please see https://blogs.sap.com/2016/10/30/getting-started-kapsel-part-4-pushsp13/.
Push messages provide a way to inform or remind a user that an action should be taken by delivering a short message that appears as a notification on the device.



When clicked on, the app that is associated with the message is opened.

The Kapsel push plugin provides an abstraction layer over the Google Cloud Messaging for Android (GCM) and Apple Push Notification Service (APNS).  A notification can be sent to a device via a REST call to a specific registration id, a user id that may have registered on multiple devices, or to all users of an application as shown in the following examples.
http://localhost:8080/restnotification/registration/application_registration_id
http://localhost:8080/restnotification/application/com.mycompany.push/user/daniel_v
http://localhost:8080/restnotification/application/com.mycompany.push

The REST call should also include a payload for the message such as the following.
{"alert":"New Vacation Approval Request", "data":"For (i826565) request (7)" }

Note that both GCM and APNS require open ports that may be blocked on some corporate networks or routers.  GCM on older devices uses ports between 5228 and 5230 on older Android devices as per Google Cloud Messaging not working on 4.1.2 devices on a corporate network.  APNS uses the ports described here.

For additional details see C:\SAP\MobileSDK3\KapselSDK\docs\api\sap.Push.html or Using the Push Plugin.

The following steps will demonstrate this plugin using Google Cloud Messaging.  Note, it requires either an Android 4.2.2 or higher device with Google Play Store installed (Setting Up Google Play Services) or an Android emulator that targets the Google API's.


Note, the Push plugin requires the following Android SDK library to be downloaded.  This will resolve the dependency in the build.gradle file for play-services-gcm.


The process for iOS and Windows is covered by others.  Here are a few posts to check out.
Apple Push Notification Services in iOS 6
[Kapsel] How to use the Push plugin on iOS
[Kapsel] How to use the Push plugin on Windows

  • Follow the instructions at Try Cloud Messaging for Android and click on the button GET A CONFIGURATION FILE in step 2, when asked, click on ENABLE GOOGLE CLOUD MESSAGING and then record the sender ID and Server API Key.

  • Follow the steps shown in Configuring a Kapsel App in the Management Cockpitto create an Application with the application id of
    com.mycompany.push

    This app does not use an OData endpoint so the endpoint can be set to a dummy URL such as
    http://mycompany.com

    and add the Basic SSO mechanism and the default security provider.

  • Fill in the Push settings for the application.

  • Edit the Notification security provider and add a System Login (Admin Only) authentication provider.  Set the user name and password to a value like smpPushUser and smpPushPwd and the role Notification User.  Note this user name and password will need to be entered later when we send a notification to the device using the Advanced REST client.
    Restart the SMP 3.0 server.

  • Create the project.
    cordova create C:\Kapsel_Projects\PushDemo com.mycompany.push PushDemo
    cd PushDemo
    cordova platform add android


  • Add push plugin.
    cordova plugin add kapsel-plugin-push --searchpath %KAPSEL_HOME%/plugins


  • Replace www\index.html with index.html.
    Update index.html and enter the serverHost(line 10) and sender ID (line 77).  Note the sender ID is an optional setting as of SP10.

  • Prepare, build and deploy the project.
    cordova run android


  • Click on the Register For Push button
    Note that when reopening the app, the Register For Push button must be pressed again or in a non-sample app, it should be called in the logonSuccessCallback method which would be called each time the application starts.

  • Send a REST request to the SMP server to send a notification to a Kapsel app.  For further details see Notification Data Sent Using Push API.

    An example using Postman.


    When prompted for a User Name and Password enter smpPushUser and smpPushPwd.  The following are some further examples.
    http://127.0.0.1:8080/restnotification/application/com.mycompany.push/
    {"alert":"New Vacation Approval Request", "data":"For (i826565) request (7)" }

     
    http://localhost:8080/restnotification/registration/59a72605-2a64-4778-953d-c215a7d565eb 
    {"alert":"New Vacation Approval Request", "data":"For (i826565) request (7)" }

     
    http://localhost:8080/restnotification/application/com.mycompany.push/user/nosec_identity 
    {"alert":"New Vacation Approval Request", "data":"For (i826565) request (7)" }

    If the status is 403, this indicates a permission problem.  Double check that that the correct user id and password for the Notification security profile were correctly entered.  Also double check that the correct role name of Notification User was assigned to the Roles of the authentication provider for the Notification security profile.

    If the status is 404, this may indicate that the app did not successfully register for notifications.  Try pressing the Register for Push button again and verify that the Successfully registered alert displays.

    If the status is 200, this may indicate that the app has not registered and received a registration id from Google or perhaps that there is some issue reaching the Google GCM service.  Double check that the sender ID was added to the index.html.

  • The notification will be processed by the app if it is running in the foreground.

  • Now press the back button to exit the app and send the notification again from the Advanced Rest Client.  The notification should appear on the device or simulator and clicking on it will open the app.  Notice that a custom icon was used by replacing the file
    C:\Kapsel_Projects\PushDemo\platforms\android\res\drawable-hdpi\icon.png



    If the app is not in the foreground when a notification arrives, the details of the notification can be accessed by calling sap.Push.checkForNotification(processMissedNotification).

    Note the notification shown will be for the notification that was selected from the notification bar.

  • A logcat filter using the log tag value of PUSH will filter out the messages sent from the Kapsel push plugin.  Note, this filter will not show the messages displayed using console.log().

  • Push notifications can be disabled on Android and iOS.
    On iOS open Settings > Notifications > PushDemo
    On Android open Settings > Apps > PushDemo > Uncheck Show Notifications

  • On Android, there are separate volume controls.  If you do not here a notification sound, check the volume level for Notifications. Settings > Sound > Volumes > Notifications.

  • On Android, the sound played when a notification arrives can be selected.  Settings > Sound > Default notification.On an Android emulator, the sound file first needs to be copied onto the device.  Open the DDMS perspective in eclipse, select the File Explorer and copy C:\adt-bundle-windows-x86_64-20130917\sdk\platforms\android-19\data\res\raw\fallbackring.ogg to storage\sdcard\Notifications.  Restart the emulator.  Fallbackring should now be accessible in the settings.

  • On some Android devices there is an error while registering for notification.
    java.lang.UnsupportedOperationException: Device does not have package com.google.android.gsf

    This may occur if the Google Play Services are missing.  In order to receive push notifications on those devices when using SP10 of the SDK or higher, follow the below instructions.
    Open the Android SDK Manager click on the Obsolete checkbox and download Extras >Google Cloud Messaging for Android Library (Obsolete) Copy the below jar into the libs folder of the PushDemo project.
    C:\Android\adt-bundle-windows-x86_64-20130522\sdk\extras\google\gcm\gcm-client\dist\gcm.jar



Note, there is an open source push plugin that is described at Cordova Push Notifications Plugin.

The following post describes some items to keep in mind once your push enable app is ready for release.  Keeping Google Cloud Messaging For Android Working Reliably.
Note, there is a feature of the SMP and HCPms server called Push Hub.  A description of this is available at SAP HANA Cloud Platform mobile services - Feature Release

Back to Getting Started With Kapsel

13 Comments