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 |
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!
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:
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; * In case this listener is not invoked within 30 seconds then it fails with an exception. |
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
34 | |
25 | |
12 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |