During the on-boarding process with the mobile platform (SMP on premise or HCPms), client apps send information about the device, then the mobile platform stores and associates this information with an application connection ID. This information is what we call application settings and clients can access it and modify it at any time.

Application settings include information about the device type, phone number, password policies, push notification information, etc.  All properties are optional. If you know the application connection ID, you can use any REST client to access this information. For example:

Field

Value

URL

https://hcpms-<your user>trial.hanatrial.ondemand.com/odata/applications/latest<application id>/Connections(‘<app conn id>’)

HTTP Operation

GET

Switch to Basic Auth Tab

Username

Your username

Password

Your password

Click the “Refresh Headers” button

/wp-content/uploads/2015/09/appsettings_793502.jpg

In OData SDK SP08, the LogonCore instance provides a new class called com.sap.maf.tools.logon.core.reg.AppSettings that allows developers to download and upload application settings from and to the mobile platform. The new AppSettings class guarantees that, if the ApplicationSettings instance is available, it is in a consistent and valid state; the values this class stores are validated against a metadata document

Important!

  • An instance of the new AppSettings class is available via a LogonCore instance, only if the device is registered with the LogonCore component.
  • The new com.sap.maf.tools.logon.core.reg.AppSettings replaces the previous com.sap.smp.rest.AppSettings, which is deprecated and should not be used.

Application settings are important to enable push notifications in a client app. For example Android client apps can use new AppSettings class for two purposes:

  1. To get the Sender ID from Push configuration in the mobile platform. Once the client app downloads the Sender ID, it can use it to register the device with GCM
  2. To send the GCM registration ID to the mobile platform. The mobile platform must have the GCM registration ID to send the notifications it receives from the backend.

For more information about the use of AppSettings to enable push notifications, check How To… Create an Android App with Push notif… | SCN

You can also use the new AppSettings method to update the device phone number and the device model, which could be used by administrators for performance analysis or troubleshooting. So you could create a simple screen where users can edit and upload this type of information.

The following code snippet are meant to help you use the new AppSettings class to download and upload application settings from and to the mobile platform.

Downloading Application Settings


1. Create a listener that implements IAppSettingsDownloadListener

In order to download the application settings from the mobile platform, developers need to create a download listener that implements IAppSettingsDownloadListener interface

Download Listener
public class CustomAppSettingsDownloadListener implements IAppSettingsDownloadListener {

  private static CustomAppSettingsDownloadListener instance;

  private final CountDownLatch latch = new CountDownLatch(1);
  AppSettings
settings;
  Exception
error;

  private CustomAppSettingsDownloadListener() {
  }

  /**
  * @return Download listener
  */
 
public static CustomAppSettingsDownloadListener getInstance() {
   
if (instance == null) {
     
instance = new CustomAppSettingsDownloadListener();
    }
   
return instance;
  }

  @Override
 
public void appSettingsDownloadFinished() {
   
try {
       LogonCore logonCore = LogonCore.getInstance();
      
this.settings = logonCore.getAppSettings();
      
this.latch.countDown();
    }
catch (LogonCoreException e) {
      
this.error = e;
    }
  }

@Override
public void appSettingsDownloadFailed() {
   
this.error = new CustomAppSettingsException(“appSettingsDownloadFailed”);
   
latch.countDown();
}

public synchronized boolean finished() {
   
return (settings != null || error != null);
}

public synchronized Exception getError() {
   
return error;
}

public synchronized AppSettings getAppSettings() {
   
return settings;
}

/**
* Waits for the completion of the asynchronous process. In case this listener is not invoked within 30 seconds then it fails with an exception.
*/
public void waitForCompletion() {
   
try {
      
if (!latch.await(60, TimeUnit.SECONDS))
           
throw new IllegalStateException(“AppSettings download listener was not called within 30 seconds.”);
      
else if (!finished())
           
throw new IllegalStateException(“AppSettings download  listener is not in finished state after having completed successfully”);
       }
catch (InterruptedException e) {
           
throw new IllegalStateException(“AppSettings download listener waiting for results was interrupted.”, e);
      }
  }
}


2. Call download method

Header 1
public static boolean downloadAppSettings() throws CustomAppSettingsException {

CustomAppSettingsDownloadListener settingsListener = CustomAppSettingsDownloadListener.getInstance();
   if (settingsListener.getAppSettings()==null) {
     
try {

       //Get LogonCore instance
      
LogonCore logonCore = LogonCore.getInstance();
      
//Get AppSettings class from LogonCore instance
      
AppSettings settings = logonCore.getAppSettings();
      
//Listener implements
      
settings.setListener(settingsListener);
      
//Download application settings
      
settings.downloadAppSettings();
      
//Wait for download to complete
      
settingsListener.waitForCompletion();
      
if (settingsListener.getError() != null) {
             Log.e(
TAG, “registerInBackground”, settingsListener.getError());
       }
     }
catch (LogonCoreException e) {
      Log.e(
TAG, “registerInBackground”, e);
     
throw new CustomAppSettingsException(e);
     }

     //Check if application settings were downloaded
    
AppSettings settings = settingsListener.getAppSettings();
    
if (settings != null) {
       Log.d(
TAG, “downloadAppSettings::AppSettings downloaded”);
      
return true;
     }
else {
      
return false;
     }
  }
else {
    
return true;
  }
}

Upload Application Settings

1. Create a listener that implements IAppSettingsUploadListener

The process to upload the application settings is very similar to the download process. First you define and upload listener that implements IAppSettingsUploadListener

Upload Listener

package com.sap.sample.appsettingstest.services;

import com.sap.maf.tools.logon.core.reg.IAppSettingsUploadListener;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class CustomAppSettingsUploadListener implements IAppSettingsUploadListener {

      private static CustomAppSettingsUploadListener instance;
     
private final CountDownLatch latch = new CountDownLatch(1);
      Exception
error;

      private CustomAppSettingsUploadListener() {
      }

     /**
      * @return Upload listener
      */
     
public static CustomAppSettingsUploadListener getInstance() {
        
if (instance == null) {
          
instance = new CustomAppSettingsUploadListener();
         }
        
return instance;
      }

      @Override
     
public void updateAppSettingsFinished() {
       
latch.countDown();
      }

      @Override
     
public void updateAppSettingsFailed() {
         
this.error = new CustomAppSettingsException(“updateAppSettingsFailed”);
         
latch.countDown();
     }

     public synchronized Exception getError() {
       
return error;
     }

    /**
     * Waits for the completion of the asynchronous process.

     * In case this listener is not invoked within 30 seconds then it fails with an exception.
     */
     
public void waitForCompletion() {
       
try {
         
if (!latch.await(30, TimeUnit.SECONDS))
           
throw new IllegalStateException(“AppSettings upload listener was not called within 30 seconds.”);
        }
catch (InterruptedException e) {
          
throw new IllegalStateException(“AppSettings upload listener waiting for results was interrupted.”, e);
      }
   }
}

2. Call upload method

Header 1
public static void uploadAppSettings(HashMap<String, AppSettingsProperty> appSettingsValue) throws CustomAppSettingsException {
CustomAppSettingsUploadListener uploadListener = CustomAppSettingsUploadListener.getInstance();

  try {
  
//Get LogonCore instance
  
LogonCore logonCore = LogonCore.getInstance();
  
//Get AppSettings class from LogonCore instance
  
AppSettings settings = logonCore.getAppSettings();
  
//Listener implements
  
settings.setListener(uploadListener);
  
//Download application settings
  
settings.updateAppSettings(appSettingsValue);
  
//Wait for download to complete
  
uploadListener.waitForCompletion();
  
if (uploadListener.getError()!=null){
      Log.e(
TAG, “uploadAppSettings”, uploadListener.getError());
   }

  } catch (LogonCoreException e){
   
throw new CustomAppSettingsException(e);
  }
}

Questions and comments are welcome,

Claudia

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply