Developer

SAP Mobile Place Workflow

Add and use Mobile Place in your Android project.

Context

You must use the Android Native Client SDK libraries. The libraries are available as part of the SAP Mobile Platform Client SDK Installer. Mobile Place ships in the form of separate artifacts such as library JAR files.

Before you can use MobilePlace, you must add associated artifacts. You must also add dependent JARs, AARs, and configure your build settings. For the rest of the procedure, we assume that you are starting a new project for Android. If you are working with an existing project, the steps may vary.

Procedure

  1. Create a new project (or open an existing one) in Android Studio.
    Ensure that AndroidManifest.xml contains INTERNET permission:
    <uses-permission android:name="android.permission.INTERNET"/>
  2. Copy the following files into the libs folder of your project:
    • MobilePlace.aar
    • HttpConversation.aar
    • ClientLog.aar
    • SupportabilityFacade.aar
  3. Implement the necessary code.
    1. Create a new Activity class (or use an existing one) and add:
      //the application id you used 
      private static final String APP_ID = "flight";
      
      //the version number you used in your configuration on Discovery Services
      private static final String VERSION = "1.0";
      
      //configuration controller that can get configuration based on the email address and the APP_ID/VERSION
      
      private ConfigurationController configController;
      
      private static final String TAG = "TAG";
      
    1. Implement this code in the onCreate() method:
      @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              //get an instance of the Configuration Controller
              configController = new ConfigurationController(this);
              //get configuration for the APP_ID/VERSION
              //this will present a popup asking the user to input his/her email address
              configController.getConfigurationParameters(this, APP_ID, VERSION, new CompletionListener() {
      			
      			@Override
      			public void onSuccess(IConfigurationParameters parameters) {
      				if (parameters instanceof IValidConfigurationParameters) {
      					//In case the library succeeds to download and parse configuration
      					IValidConfigurationParameters validParams = (IValidConfigurationParameters) parameters;
      					//print configuration to console
      					Log.i(TAG, "host: "+validParams.getHost());
      					Log.i(TAG, "port: "+validParams.getPort());
      					Log.i(TAG, "protocol: "+validParams.getProtocol());
      					Log.i(TAG, "AuthConfig.size: "+validParams.getAuthConfigs().size());
      					//Implement a visitor to check if a specific auth configuration is downloaded
      					for(AuthConfig ac : validParams.getAuthConfigs()){
      						ac.accept(new IConfigurationVisitor<Boolean>() {
      
      							@Override
      							public Boolean visit(OAuth2Config arg0) {
      								// TODO Auto-generated method stub
      								return null;
      							}
      
      							@Override
      							public Boolean visit(Saml2Config arg0) {
      								// TODO Auto-generated method stub
      								return null;
      							}
      
      							@Override
      							public Boolean visit(GenericConfig arg0) {
      								// TODO Auto-generated method stub
      								return null;
      							}
      						});
      					}
      					
      				} else {
      					//In case the library received an error payload
      					InvalidConfigurationParameters invalidParams = (InvalidConfigurationParameters) parameters;
      					Log.i(TAG, "Invalid configuration received: "+invalidParams.getErrorDocuments());
      				}
      			}
      			
      			@Override
      			public void onError(Throwable t) {
      				//handle error
      				//for now print to console
      				t.printStackTrace();
      			}
      		});
          }