B Local HTML and Application Container APIs

This chapter describes the MAF JavaScript API extensions, the MAF Container Utilities API, and how to use the AdfmfJavaUtilities API for HTML application features, including custom HTML springboard applications.

This chapter includes the following sections:

B.1 Using MAF APIs to Create a Custom HTML Springboard Application Feature

Using JavaScript to call the JavaScript API extensions enables you to add the navigation functions to a custom springboard page authored in HTML. As stated in What You May Need to Know About Custom Springboard Application Features with HTML Content you can enable callbacks and leverage Apache Cordova by including methods in the JavaScript <script> tag. The example below illustrates using this tag to call Cordova.

...
<script type="text/javascript">if (!window.adf) window.adf = {}; 
                                   adf.wwwPath = 
 "/~maf.device~/www/";</script> 
 <script type="text/javascript" src="/~maf.device~/www/js/base.js"></script>
...

It is recommended that you use the virtual path /~maf.device~/ when including base.js so that the browser will identify the request as being for a MAF resource and not for the remote server. This approach works in both remote as well as local HTML pages and is the best way to include base.js in an HTML feature (regardless of where it is being served from). For more information, see Enabling Remote Applications Access Container Services.

Tip:

To access (and determine the location of) the www/js directory, you must first deploy a MAF application and traverse to the deploy directory. The www/js directory resides within the platform-specific artifacts generated by the deployment. For iOS deployments, the directory is located within the temporary_xcode_project directory. For Android deployments, this directory is located in the assets directory of the Android application package (.apk) file. See also What You May Need to Know About Custom Springboard Application Features with HTML Content.

Note:

Because the path does not exist during design time, OEPE notes the JavaScript includes in the source editor as an error by highlighting it with a red, wavy underline. This path is resolved at runtime.

The MAF extension to the Cordova API enables the mobile device's API to access the configuration metadata in the maf-feature.xml and maf-application.xml files, which in turn results in communication between the mobile device and MAF's infrastructure. These extensions also direct the display behavior of the application features.

For information on the default MAF springboard page, springboard.amx, and about the ApplicationFeatures data control that you can use to build a customized springboard, see What You May Need to Know About Custom Springboard Application Features with MAF AMX Content.

B.1.1 About Executing Code in Custom HTML Pages

The example below illustrates a script defining the showpagecomplete event on the handlePageShown callback function. By listening to this event using standard DOM (Document Object Model) event listening, custom HTML pages (such as login pages) can invoke their own code after MAF has loaded and displayed the page for the first time.

<script>
        function handlePageShown()
        {
          console.log("Page is shown!");
        }
        document.addEventListener("showpagecomplete", handlePageShown, false);
</script>

Note:

The showpagecomplete event guarantees the appropriate MAF state; other browser and third-party events, such as load and Cordova's deviceready, may not. Do not use them.

B.2 The MAF Container Utilities API

The methods of the MAF Container Utilities API provide MAF applications with such functionality as navigating to the navigation bar, displaying a springboard, or displaying application features. You can use these methods at the Java and JavaScript layers of MAF.

In Java, the Container Utilities API is implemented as static methods on the AdfmfContainerUtilities class, which is located in the oracle.adfmf.framework.api package. The example below illustrates calling the gotoSpringboard method. For more information on oracle.adfmf.framework.api.AdfmfContainerUtilities, see .

import oracle.adfmf.framework.api.AdfmfContainerUtilities;
...
AdfmfContainerUtilities.gotoSpringboard();
...

B.2.1 Using the JavaScript Callbacks

The signatures of Java and JavaScript both match. In Java, they are synchronous and return results directly. Because JavaScript is asynchronous, there are two callback functions added for every function: a success callback that returns the results and a failed callback that returns any exception that is thrown. Within a Java method, the success value is returned from the function, or method, and the exception is thrown directly from the method. The pseudocode in the example below illustrates how a call with no arguments, public static functionName() throws, is executed within Java using try and catch blocks.

...
 try {
       result = AdfmfContainerUtilities.functionName();
    }
       catch() {
        ...
       }

...

Because JavaScript calls are asynchronous, the return is required through the callback mechanism when the execution of the function is complete. The pseudocode in the example below illustrates the signature of the JavaScript call.

adf.mf.api.functionName(
           function(successFunction, failureFunction ) { alert("functionName complete"); },
           function(successFunction, failureFunction ) { alert("functionName failed with " + 
                                                         adf.mf.util.stringify(failureFunction); }
);

JavaScript calls cannot return a result because they are asynchronous. They instead require a callback mechanism when the execution of the function has completed. The signature for both the success and failed callbacks is function(request, response), where the request argument is a JSON representation for the actual request and the response is the JSON representation of what was returned by the method (in the case of success callback functions) or, for failed callback functions, a JSON representation of the thrown exception.

Note:

The callback functions must be invoked before subsequent JavaScript calls can be made to avoid problems related to stack depth or race conditions.

The pseudocode in illustrates how a call with one or more arguments, such as public static <return value> <function name>(<arg0>, <arg1>, ...) throws <exceptions>, is executed within Java using a try-catch block.

try {
       result = AdfmfContainerUtilities.<function_name>(<arg0>, <arg1>, ...);
    }
       catch(<exception>) {
        ...
       }

JavaScript calls cannot return a result because they are asynchronous. They instead require a callback mechanism when the execution of the function has completed. The signature for both the success and failed callbacks is function(request, response), where the request argument is a JSON representation for the actual request and the response is the JSON representation of what was returned by the method (in the case of success callback functions) or, for failed callback functions, a JSON representation of the thrown exception.

Note:

The callback functions must be invoked before subsequent JavaScript calls can be made to avoid problems related to stack depth or race conditions.

B.2.2 Using the Container Utilities API

The Container Utilities API provides the following methods:

The Container Utilities API also include methods for placing badges and badge numbers on applications. For more information, see Application Icon Badging.

B.2.3 getApplicationInformation

This method returns an ApplicationInformation object that contains information about the application. This method returns such metadata as the application ID, application name, version, and the vendor of an application.

Within Java, this method is called as follows:

public static oracle.adfmf.framework.ApplicationInformation 
              getApplicationInformation()
              throws oracle.adfmf.framework.exception.AdfException

The following example illustrates calling this method.

import oracle.adfmf.framework.api.AdfmfContainerUtilties;
 
   ...
     try {
        ApplicationInformation ai = AdfmfContainerUtilities.getApplicationInformation();
        String applicationId = ai.getId();
        String applicationName = ai.getName();
        String vendor = ai.getVendor();
        String version = ai.getVersion();
        ...
     }catch(AdfException e) {
        // handle the exception
     }

In JavaScript, the success and failed callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:

public void getApplicationInformation(success, failed)

The success callback must be in the form of function(request, response), where the request argument contains the original request and the response argument contains the associated AdfmfContainerUtilities method's return value, which is the ApplicationInformation object containing application-level metadata. This includes the application name, vendor, version, and application ID.

The failed callback must be in the form of function(request, response), where the request contains the original request and the response contains the error.

The next example illustrates using these callback functions to retrieve the application information.

adf.mf.api.getApplicationInformation(
           function(req, res) { alert("getApplicationInformation complete"); },
           function(req, res) { alert("getApplicationInformation failed with " +
                                      adf.mf.util.stringify(res); }
                                    );

B.2.4 gotoDefaultFeature

This method requests that MAF display the default application feature. The default application feature is the one that is displayed when the mobile application is started.

Note:

This method may not be able to display an application feature if it has authentication- or authorization-related problems.

In JavaScript, the success and failed callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:

public void gotoDefaultFeature(success, failed)

The success callback function must be in the form of function(request, response), where the request argument contains the original request and the response argument contains the associated AdfmfContainerUtilities method's return value (void).

The failed callback function must be in the form of function(request, response), where the request argument contains the original request and the response argument contains the error.

This example illustrates using these callbacks to call the default application feature.

adf.mf.api.gotoDefaultFeature(
          function(req, res) { alert("gotoDefaultFeature complete"); },
          function(req, res) { alert("gotoDefaultFeature failed with " +
                                      adf.mf.util.stringify(res); }
                             );

B.2.5 gotoFeature

This method requests that MAF display the application feature identified by its ID.

Note:

This method may not be able to display an application feature if it has authentication- or authorization-related problems.

Within Java, this method is called as follows:

public static void gotoFeature(java.lang.String featureId)
                   throws oracle.adfmf.framework.exception.AdfException

This method's parameter, as shown in the example below, is the ID of the application feature.

import oracle.adfmf.framework.api.AdfmfContainerUtilties;
 
   ...
     try {
        AdfmfContainerUtilities.gotoFeature("feature.id");
     }catch(AdfException e) {
        // handle the exception
     }

In JavaScript, the success and failed callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:

public void gotoFeature(featureId, success, failed)

The featureId parameter is the application feature ID. This parameter activates the success callback function and must be in the form of function(request, response), where the request contains the original request and the response contains the associated AdfmfContainerUtilities method's return value (void).

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

The next example illustrates using these callback functions to call an application feature.

adf.mf.api.gotoFeature("feature0",
          function(req, res) { alert("gotoFeature complete"); },
function(req, res) { alert("gotoFeature failed with " +
                           adf.mf.util.stringify(res); }
   );

B.2.6 getFeatures

This method returns an array of FeatureInformation objects that represent the available application features. The returned metadata includes the feature ID, the application feature name, and the file locations for the image files used for the application icons. This call enables a custom springboard implementation to access the list of application features that are available after constraints have been applied. (These application features would also display within the default springboard.)

Within Java, this method is called as follows:

public static oracle.adfmf.framework.FeatureInformation[] getFeatures()
              throws oracle.adfmf.framework.exception.AdfException

The next example illustrates using this method.

import oracle.adfmf.framework.api.AdfmfContainerUtilties;
 
   ...
     try {
        FeatureInformation[] fia = null;
        fia = AdfmfContainerUtilities.getFeatures();
 
        for(int f = 0; f < fia.length; ++f) {
           FeatureInformation fi = fia[i];
           String featureId = fi.getId();
           String featureName = fi.getName();
           String featureIconPath = = fi.getIcon();
           String featureImagePath = fi.getImage();
           ...
        }
     }catch(AdfException e) {
        // handle the exception
     }

In JavaScript, the success and failed callback functions enable the returned values and the exceptions to be passed back to the JavaScript calling code as follows:

public void getFeatures(success, failed)

The success callback function must be in the form of function(request, response), where the request argument contains the original request and the response argument contains the associated AdfmfContainerUtilities method's return value (the array of FeatureInformation objects).

The failed callback function must be in the form of function(request, response), where the request argument contains the original request and the response argument contains the error (AdfException).

adf.mf.api.getFeatures(
          function(req, res) { alert("getFeatures complete"); },
          function(req, res) { alert("getFeatures failed with " +
                               adf.mf.util.stringify(res); }
                         );

B.2.7 getFeatureByName

This method returns information about the application feature using the passed-in name of the application feature.

Within Java, this method is called as follows:

public static oracle.adfmf.framework.FeatureInformation getFeatureByName(java.lang.String
                                                                         featureName)
                                     throws oracle.adfmf.framework.exception.AdfException

This method's parameter, as shown in the example below, is the name of the application feature.

 ...
     try {
        FeatureInformation fi = AdfmfContainerUtilities.getFeatureByName("feature.name");
        String featureId = fi.getId();
        String featureName = fi.getName();
        String featureIconPath = = fi.getIcon();
        String featureImagePath = fi.getImage();
     }catch(AdfException e) {
        // handle the exception
     }

In JavaScript, the success and failed callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:

public void getFeatureByName(featureName, success, failed)

The featureName parameter is the name of the application feature. The success callback function and must be in the form of function(request, response), where the request contains the original request and the response contains the associated AdfmfContainerUtilities method's return value (void).

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

The next example illustrates using these callback functions.

adf.mf.api.getFeatureByName("feature.name",
          function(req, res) { alert("getFeatureByName complete"); },
          function(req, res) { alert("getFeatureByName failed with " +
                                     adf.mf.util.stringify(res); }
);

B.2.8 getFeatureById

This method retrieves an application feature using its application ID.

Within Java, this method is called as follows:

import oracle.adfmf.framework.api.AdfmfContainerUtilties;

This method's parameter, as shown in this example, is the ID of the application feature.

   try {
        FeatureInformation fi =AdfmfContainerUtilities.getFeatureById("feature.id");
   }catch(AdfException e) {
        // handle the exception
   }

In JavaScript, the success and failed callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:

public void getFeatureById(featureId, success, failed)

The featureId parameter is the ID of the application feature. The success callback function and must be in the form of function(request, response), where the request contains the original request and the response contains the associated AdfmfContainerUtilities method's return value (void).

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

The example below illustrates using these callback functions to retrieve an application feature.

adf.mf.api.getFeatureById("feature.id",
          function(req, res) { alert("getFeatureById complete"); },
          function(req, res) { alert("getFeatureById failed with " +
                                     adf.mf.util.stringify(res); }
   );

B.2.9 resetFeature

This method resets the state of the application feature. It resets the Java-side model for the application feature and then restarts the user interface presentation as if the mobile application had just been loaded and displayed the application feature for the first time.

Within Java, this method is called as follows:

public static void resetFeature(java.lang.String featureId)
                   throws oracle.adfmf.framework.exception.AdfException

The method's parameter, as shown in the example below, is the ID of the application feature that is to be reset.

import oracle.adfmf.framework.api.AdfmfContainerUtilties;
 
   ...
     try {
        AdfmfContainerUtilities.resetFeature("feature.id");
     }catch(AdfException e) {
        // handle the exception

In JavaScript, the success and failed callback functions enable the returned value and exception to be passed back to the JavaScript calling code as follows:

public void resetFeature(featureId, success, failed)

The success callback function and must be in the form of function(request, response), where the request contains the original request and the response contains the associated method's return value (The ID of the application feature).

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

The example below illustrates using these callback functions to call an application feature.

adf.mf.api.resetFeature("feature0",
          function(req, res) { alert("resetFeature complete"); },
          function(req, res) { alert("resetFeature failed with " +
                                     adf.mf.util.stringify(res); }
                       );

B.2.10 resetApplication

This method resets the running application and it should be used only when resetting individual application features is not sufficient. For more information, see .

Within Java, this method is called as follows:

public static void resetApplication(java.lang.String message)

The method's parameter, as shown in the following example, is either a message describing the reason for which the application is being restarted, or null if no message is required.

import oracle.adfmf.framework.api.AdfmfContainerUtilties;
 
   ...
   try {
      AdfmfContainerUtilities.resetApplication("New content is available");
   }
   catch(Exception e) {
      // handle the exception
}

In JavaScript, the success and failed callback functions enable the returned value and exception to be passed back to the JavaScript calling code as follows:

public void resetApplication(message, success, failed)

The success callback function and must be in the form of function(request, response), where the request contains the original request and the response contains the associated method's return value (The ID of the application feature).

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

The following example illustrates using these callback functions to call an application.

adf.mf.api.resetApplication("message1",
          function(req, res) { alert("resetApplication complete"); },
          function(req, res) { alert("resetApplication failed with " +
                                     adf.mf.util.stringify(res); }
);

B.2.11 gotoSpringboard

This method requests that MAF activate the springboard.

Note:

This method may not be able to display the springboard if it has not been designated as a feature reference in the maf-application.xml file, or if it has authentication or authorization-related problems. See also Configuring Application Navigation.

Within Java, this method is called as follows:

public static void gotoSpringboard()

The example below illustrates using this method

import oracle.adfmf.framework.api.AdfmfContainerUtilties;
 
...
  try {
     AdfmfContainerUtilities.gotoSpringboard();
  }catch(AdfException e) {
        // handle the exception
  }

In JavaScript, the success and failed callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:

public void gotoSpringboard(success, failed)

The success callback function must be in the form of function(request, response), where the request contains the original request and the response contains the associated method's return value (void).

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

This example illustrates using these callback functions.

adf.mf.api.gotoSpringboard(
    function(req, res) { alert("gotoSpringboard complete"); },
    function(req, res) { alert("gotoSpringboard failed with " +
                               adf.mf.util.stringify(res); }
);

B.2.12 showSpringboard

This method requests that MAF display the springboard.

Within Java, this method is called as follows:

public static void showSpringboard()

The following example illustrates using this method.

import oracle.adfmf.framework.api.AdfmfContainerUtilties;
 
   ...
   try {
      AdfmfContainerUtilities.showSpringboard();
   }
   catch(Exception e) {
      // handle the exception
   }

In JavaScript, the success and failed callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:

public void showSpringboard(success, failed)

The success callback function must be in the form of function(request, response), where the request contains the original request and the response contains the associated method's return value (void).

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

The following example illustrates using these callback functions.

adf.mf.api.showSpringboard(
           function(req, res) { alert("showSpringboard complete"); },
           function(req, res) { alert("showSpringboard failed with " +
                                       adf.mf.util.stringify(res); }
);

B.2.13 hideSpringboard

This method requests that MAF hide the springboard.

Within Java, this method is called as follows:

public static void hideSpringboard()

The following example illustrates using this method.

import oracle.adfmf.framework.api.AdfmfContainerUtilties;
 
   ...
   try {
      AdfmfContainerUtilities.hideSpringboard();
   }
   catch(Exception e) {
      // handle the exception
   }

In JavaScript, the success and failed callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:

public void hideSpringboard(success, failed)

The success callback function must be in the form of function(request, response), where the request contains the original request and the response contains the associated method's return value (void).

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

The following example illustrates using these callback functions.

adf.mf.api.hideSpringboard(
       function(req, res) { alert("hideSpringboard complete"); },
       function(req, res) { alert("hideSpringboard failed with " +
                                   adf.mf.util.stringify(res); }
);

B.2.14 showNavigationBar

This method requests that MAF display the navigation bar.

Within Java, this method is called as follows:

public static void showNavigationBar()

This example illustrates using this method.

import oracle.adfmf.framework.api.AdfmfContainerUtilties;
 
...
  try {
     AdfmfContainerUtilities.showNavigationBar();
  }catch(Exception e) {
     // handle the exception
  }

In JavaScript, the success and failed callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:

public void showNavigationBar(success, failed)

The success callback function must be in the form of function(request, response), where the request contains the original request and the response contains the associated method's return value (void).

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

The example below illustrates using these callback functions.

adf.mf.api.showNavigationBar(
           function(req, res) { alert("showNavigationBar complete"); },
           function(req, res) { alert("showNavigationBar failed with " +                                       adf.mf.util.stringify(res); }
);

B.2.15 hideNavigationBar

This method requests that MAF hide the navigation bar.

Within Java, this method is called as follows:

public static void hideNavigationBar()

This example illustrates using this method.

import oracle.adfmf.framework.api.AdfmfContainerUtilties;
 
   ...
  try {
     AdfmfContainerUtilities.hideNavigationBar();
   }catch(Exception e) {
     // handle the exception
  }  

In JavaScript, the success and failed callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:

public void hideNavigationBar(success, failed)

The success callback function must be in the form of function(request, response), where the request contains the original request and the response contains the associated method's return value (void).

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

This example illustrates using these callback functions.

adf.mf.api.hideNavigationBar(
       function(req, res) { alert("hideNavigationBar complete"); },
       function(req, res) { alert("hideNavigationBar failed with " +                                   adf.mf.util.stringify(res); }
);

B.2.16 showPreferences

This method requests that MAF display the preferences page.

Within Java, this method is called as follows:

public static void showPreferences()

The following example illustrates using this method.

import oracle.adfmf.framework.api.AdfmfContainerUtilties;
 
   ...
   try {
      AdfmfContainerUtilities.showPreferences();
   }
   catch(Exception e) {
      // handle the exception
   }

n JavaScript, the success and failed callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:

public void showPreferences(success, failed)

The success callback function must be in the form of function(request, response), where the request contains the original request and the response contains the associated method's return value (void).

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

The following example illustrates using these callback functions.

adf.mf.api.showPreferences(
           function(req, res) { alert("showPreferences complete"); },
           function(req, res) { alert("showPreferences failed with " +
                                       adf.mf.util.stringify(res); }
);

B.2.17 invokeMethod

This method is not available in Java. The example below illustrates using the JavaScript callback methods to invoke a Java method from any class in a classpath.

adf.mf.api.invokeMethod(classname,
                        methodname,
                        param1,
                        param2,
                         ...
                        paramN,
                        successCallback,
                        failedCallback);

Table B-1 lists the parameters taken by this method.


Table B-1 Parameters Passed to invokeJavaMethod

Parameter Description

classname

The class name (including the package information) that MAF uses to create an instance when calling the Java method.

methodname

The name of the method that should be invoked on the instance of the class specified by the classname parameter.


The success callback function must be in the form of function(request, response), where the request contains the original request and the response contains the associated method's return value.

The failed callback function must be in the form of function(request, response), where the request contains the original request and the response contains the error.

Examples of using this method with multiple parameters are as follows:

  • adf.mf.api.invokeMethod("TestBean", "setStringProp", "foo", success, failed);
    
  • adf.mf.api.invokeMethod("TestBean", "getStringProp", success, failed);
    

An example of using an integer parameter is as follows:

adf.mf.api.invokeMethod("TestBean", "testSimpleIntMethod", "101", success, failed);

The following illustrates using complex parameters:

adf.mf.api.invokeMethod("TestBean", "testComplexMethod", 
           {"foo":"newfoo","baz":"newbaz",".type":"TestBeanComplexSubType"}, success, failed);

The following illustrates using no parameters:

adf.mf.api.invokeMethod("TestBean", "getComplexColl", success, failed);

The following illustrates using String parameters:

adf.mf.api.invokeMethod("TestBean", "testMethodStringStringString", "Hello ",                         "World", success, failed);

B.2.18 invokeContainerMethod

The invokeContainerMethod invokes a native method on the specified class with the given arguments. Table B-2 lists the parameters passed by this method.


Table B-2 Parameters Passed to invokeContainerMethod

Parameter Description

className

The class name (including the package information) that MAF uses to create an instance.

methodName

The name of the method that should be invoked.

args

An array of arguments that are passed to the method. Within this array, these arguments should be arranged in the order expected by the method.


This method returns an Object.

public static java.lang.Object invokeContainerMethod(java.lang.String className,
                                                     java.lang.String methodName)
                                                     java.lang.Object[] args)

B.2.19 invokeContainerJavaScriptFunction

The invokeContainerJavaScriptFunction invokes a JavaScript method. Table B-3 lists the parameters passed by this method.


Table B-3 Parameters Passed to invokeContainerJavaScriptFunction

Parameter Description

featureId

The ID of the application feature used by MAF to determine the context for the JavaScript invocation. The ID determines the web view in which this method is called.

method

The name of the method that should be invoked.

args

An array of arguments that are passed to the method. Within this array, these arguments should be arranged in the order expected by the method.


This method returns a JSON object.

Note:

The invokeContainerJavaScriptFunction API expects the JavaScript function to finish within 15 seconds for applications running on an Android-powered device or emulator, or it will return a timeout error.

public static java.lang.Object invokeContainerJavaScriptFunction(java.lang.String featureId,
                                                            java.lang.Object[] args)
                                throws oracle.adfmf.framework.exception.AdfException

The pseudocode in the next example illustrates a JavaScript file called appFunctions.js that is included in the application feature, called feature1. The JavaScript method, application.testFunction, which is described within this file, is called by the invokeContainerJavaScriptFunction method, shown in the second example below. Because the application includes a command button that is configured with an action listener that calls this function, a user sees the following alerts after clicking this button:

  • APP ALERT 0

  • APP ALERT 1

  • APP ALERT 2

(function() 
    {
       if (!window.application) window.application = {};
 
       application.testFunction = function()
       {
          var args = arguments;
 
          alert("APP ALERT " + args.length + " ");
          return "application.testFunction - passed";
       };
    })();

The pseudocode in the next example illustrates how the invokeApplicationJavaScriptFunction method calls the JavaScript method (application.testFunction) that is described in the previous example.

invokeApplicationJavaScriptFuntions 
    public void invokeApplicationJavaScriptFuntions(ActionEvent actionEvent) {
        AdfmfContainerUtilities.invokeContainerJavaScriptFunction("feature1",
                                                                  "application.testFunction",
                                                                   new Object[] {} );
        AdfmfContainerUtilities.invokeContainerJavaScriptFunction("feature1",
                                                                  "application.testFunction",
                                                                   new Object[] {"P1"} );
        AdfmfContainerUtilities.invokeContainerJavaScriptFunction("feature1",
                                                                  "application.testFunction",
                                                                   new Object[] {"P1", "P2"} );
    }

For more information, see and the APIDemo sample application. This sample application is available from File > New > MAF Examples.

B.2.20 sendEmail

B.2.21 sendSMS

B.2.22 Application Icon Badging

The AdfmfContainerUtilities class includes methods to place or retrieve a badge number on a mobile application icon. Table B-4 describes these methods.


Table B-4 Icon Badging Methods

Method Description Parameters

getApplicationIconBadgeNumber

Gets the current badge value on the mobile application icon. Returns zero (0) if the application icon is not badged.

None

setApplicationIconBadgeNumber

Sets the badge number on a mobile application icon.

The value of the badge (int badge).


Note:

Application icon badging is not supported on Android.

B.3 Accessing Files Using the getDirectoryPathRoot Method

The AdfmfJavaUtilties API includes the getDirectoryPathRoot method. This method, which can only be called from the Java layer, enables access to files on the iOS, Android, and Windows systems. As shown in the following example, this method enables access to the location of the temporary files, application files (on iOS systems), and the cache directory on the device using the TemporaryDirectory, ApplicationDirectory, and DeviceOnlyDirectory constants, respectively. Files stored in the DeviceOnlyDirectory location are not synchronized when the device is connected.

Note:

Verify that any directories or files accessed by an application exist before the application attempts to access them.

For more information on oracle.adfmf.framework.api.AdfmfJavaUtilities, see .

import oracle.adfmf.framework.api.AdfmfJavaUtilities;
 
...
 
public void getDirectoryPathRoot()
   {
 // returns the directory for storing temporary files   
 
     String tempDir =
AdfmfJavaUtilities.getDirectoryPathRoot(AdfmfJavaUtilities.TemporaryDirectory);
 
 // returns the directory for storing application files
 
     String appDir =
AdfmfJavaUtilities.getDirectoryPathRoot(AdfmfJavaUtilities.ApplicationDirectory);
 
 // returns the directory for storing cache files
  
     String deviceDir =
AdfmfJavaUtilities.getDirectoryPathRoot(AdfmfJavaUtilities.DeviceOnlyDirectory);
  
 // returns the directory for storing downloaded files
 
AdfmfJavaUtilities.getDirectoryPathRoot(AdfmfJavaUtilities.DownloadDirectory);
   } 

B.3.1 Accessing Platform-Independent Download Locations

File storage requirements differ by platform. The Android platform does not prescribe a central location from which applications can access files; instead, an application can write a file to any location to which it has write permission. iOS platforms, on the other hand, generally store files within an application directory. In Windows, applications do not access external files or directories: files are stored within the application package. Because of these differences, passing ApplicationDirectory to the getDirectoryPathRoot method can return the file location needed to display attachments for applications running on iOS-powered or Windows-powered devices, but not on Android-powered devices. Rather than writing platform-specific code to retrieve these locations for applications intended to run on both iOS- and Android-powered devices, you can enable the getDirectoryPathRoot method to return the paths to both the external storage location and the default attachments directory by passing it DownloadDirectory. This constant (an enum type) reflects the locations used by the displayFile method of the DeviceManager API, which displays attachments by using platform-specific functionality to locate these locations.

On Android, DownloadDirectory refers to the path returned by the Environment.getExternalStorageDirectory method (which retrieves the external Android storage directory, such as an SD card). For mobile applications running on iOS-powered devices, it returns the same location as ApplicationDirectory. For more information on the getExternalStorageDirectory, see the package reference documentation, available from the Android Developers website (http://developer.android.com/reference/packages.html). See also Files System Programming Guide, available from the iOS Developer Library (http://developer.apple.com/library/ios/navigation/).