Smart Advice. Agile. Personalized. Transparent.

OPA Mobile SDK - Get Started, add a Scheme URL to your App

Philip Whitwell


This article will walk you through how to get set up a development environment to allow you to build a custom mobile app based on the OPA Mobile SDK.  Then we will look at the required changes to add a scheme URL to the app to allow it to be invoked from other mobile apps or a mobile browser.  This article was developed on a Windows installation of JDeveloper creating an Android app, it should still be helpful for developers looking at MacOs and iOS apps but please email any amendments. 

Getting Started

The first step is to download the OPA Mobile SDK from eDelivery, download Oracle Policy Automation for Mobile Devices, expand the Zip.

Examine the included MAFxxx.zip to find the current version number

Based on the version number, in the example, 2.4.1, find the correct JDeveloper version in the matrix.

So in this case we need JDeveloper 12.2.1, the fourth dot point is not usually significant to the MAF compatibility.

JDeveloper installs are available here.

Next, update/add the correct version of MAF to JDeveloper.

  • Goto Help ->Check for Updates
  • Then choose local file option and select from the expanded zip downloaded from eDelivery

Setting up an Android Virtual Device

The easiest way to get started with testing is to install Android SDK, you can get the correct versions of the SDK API required for your build and the required Android Virtual Devices

To see which API is required goto  Application -> Application Properties -> Deployment -> Android1 then click pencil to edit

Then Install Android SDK https://www.androidauthority.com/how-to-install-android-sdk-software-development-kit-21137/

Launch Android AVD Manager -> Create Virtual Device and then start

Test the Hub Sample

  • In JDeveloper goto Application -> Open and then navigate to the Hub-sample.jws in the downloaded zip from eDelivery
  • Next goto Application -> Deploy -> Android1 ->Deploy application to emulator

Make sure the app launches and you can run an Assessment with the Sample Data.

Adding the Scheme URL to the Hub Sample

The first step to adding a scheme URL is to modify the Maf-application.xml.

Open from Application Resources->Descriptors->ADF Meta-INF, see below.

Add a suitable name for URL scheme and make a note of the class for Lifecycle Event Listener

Add the following code to the Start method in the LifeCycleListenerImpl class


    public void start() {
// Add a listener to handle scheme URL in the case that the application has been invoked from another application
        EventSource openURLEventSource = EventSourceFactory.getEventSource(EventSourceFactory.OPEN_URL_EVENT_SOURCE_NAME);
        openURLEventSource.addListener(new EventListener() {
            public void onMessage(Event event) {
                String url = event.getPayload();
             Trace.log(Utility.ApplicationLogger, Level.INFO, LifeCycleListenerImpl.class, "SchemeURL",
                int index = url.indexOf("?");
                String paramsString = url.substring(index + 1, url.length());
                try {
                    paramsString = java.net.URLDecoder.decode(paramsString, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                String[] params = StringUtils.split(paramsString, "&");
                Map parameters = new HashMap();
                for(int i = 0; i < params.length; i++) {
                    String[] pair = StringUtils.split(params[i], "=");
                    if(pair.length == 2) {
                        parameters.put(pair[0], pair[1]);
                String schemeUrlPolicyModel = (String) parameters.get("policy_model");
                String schemeUrlSavedSessionName = (String) parameters.get("Data");
                try {                    
                    ValueExpression ve1 = AdfmfJavaUtilities.getValueExpression("#{applicationScope.schemeUrlPolicyModel}", String.class);
                    ve1.setValue(AdfmfJavaUtilities.getELContext(), schemeUrlPolicyModel);
                    ValueExpression ve2 = AdfmfJavaUtilities.getValueExpression("#{applicationScope.schemeUrlSavedSessionName}", String.class);
                    ve2.setValue(AdfmfJavaUtilities.getELContext(), schemeUrlSavedSessionName);
                } catch (Exception ex) {

The application is expecting to be launched by the following URL

opa://StartSession/?policy_model=PolicyModel?&Data={engineer:342344;product_code:32;product_desc:Faulty scanner;task_number:932472;sr_number:AA3342;sw_version:17.8;task_subj:Task%20subject;modality:US}

This web page can be downloaded to your Android Emulator or Device and used to test the scheme URL

You can test the launch of OPA Mobile now but nothing will be done with the data or policy model.  OPA Mobile will be load (if not already) and then brought into focus.

First ensure you save your work in JDeveloper and Deploy the Android1 profile to the Android Emulator.

Seeding Data Into the Policy Model

The first step is to make sure that there is a policy model available for download from an OPA Hub instance or bundled locally with the application. The policy model must have the exact name specified in the URL, and must have attributes with the required public names to match the data passed in the URL.

It is also a good idea to make sure the data is clearly visible in the Interview

The easiest way to see the data seeded into Policy Model is to add the following code into the Assessments Page 

    public void handleLaunchNewAssessment(ActionEvent event) {
        try {
            String schemeURLPolicyModel = (String) BeanUtils.getVal("#{applicationScope.schemeUrlPolicyModel}");
            String seedData = (String) BeanUtils.getVal("#{applicationScope.schemeUrlSavedSessionName}");
            if (schemeURLPolicyModel==selectedPolicyModelName)
                String attributeData="";
                String[] params = org.apache.commons.lang.StringUtils.split(seedData, ";");
                Map parameters = new HashMap();
                for(int i = 0; i < params.length; i++) {
                    String[] pair = org.apache.commons.lang.StringUtils.split(params[i], ":");
                    if(pair.length == 2) {
                        attributeData=attributeData +  "<attribute id=\"" + pair[0] + "\" inferred=\"false\" type=\"text\">\n";
                        attributeData=attributeData +  "        <text-val>" + pair[1] + "</text-val>\n" ;
                        attributeData=attributeData +  "</attribute>\n";
                        //parameters.put(pair[0], pair[1]);
                seedData="<session-data xmlns=\"http://oracle.com/determinations/engine/sessiondata/10.2\">\n" + 
                "  <entity id=\"global\">\n" + 
                "    <instance id=\"global\">\n";
                 seedData=seedData + attributeData + "    </instance>\n" + 
                    "  </entity>\n" + 
                Log.info(this, "Policy seedData: " + seedData);
                Assessment newAssessment = this.persistenceService.createAssessment(UUID.randomUUID().toString(), newAssessmentName, selectedPolicyModelName, null, System.currentTimeMillis(), Assessment.Status.IN_PROGRESS, seedData, null, null, null);
                byte[] policyModelData = this.persistenceService.getPolicyModelById(selectedPolicyModelName).getData();
                this.activeInterviewSession = InterviewRuntime.startInterview(selectedPolicyModelName, policyModelData, newAssessment.getSeedData());
               this.selectedAssessment = newAssessment;
        } catch (Exception ex) {
            Log.severe(this, ex);
            String msgTemplate = bundle.getString("MsgErrorLaunchingNewAssessment");
            String msg = MessageFormat.format(msgTemplate, ex.getMessage());
            throw new AdfException(msg, AdfException.ERROR);

This will add the seed data for all new assessments for the Policy Model and Data specified in the URL.  Note it does not launch the Assessment automatically but waits for the user to select Add Assessment.

It is possible to have the assessment opened automatically but this requires changes to the Task Flow.

Now retest on the Android Emulator.

First ensure you save your work in JDeveloper and Deploy the Android1 profile to the Android Emulator.

Finding more help

This article is meant to get developers started on using the OPA Mobile SDK, more details are available in the online help.

If you want to get started with OPA Mobile and Service Cloud try this article OPA Mobile and Service Cloud Synch OOTB.

If you would like help from an Oracle Partner, Start Point Industries have a Mobile Accelerator available for OPA Mobile available here.


Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.