com.worklight.androidgap.api
Class WL
- java.lang.Object
-
- com.worklight.androidgap.api.WL
-
public class WL extends java.lang.Object
Provides initialization services for hybrid applications.
-
-
Method Summary
Methods Modifier and Type Method and Description void
addActionReceiver(WLActionReceiver wlActionReceiver)
Registers a new native action receiver with the IBM MobileFirst Platform.static WL
createInstance(Context context)
Creates a shared instance of Worklight if one does not exist.static WL
getInstance()
Gets an instance of the WL class This method can not be called beforeWL.createInstance(Context)
.java.lang.String
getMainHtmlFilePath()
Calculates and returns the main HTML file path.java.net.URL
getServerUrl()
Returns the current IBM MobileFirst Platform Server URLvoid
hideSplashScreen()
Hides the default IBM MobileFirst Platform splash screen if it is shown, and does nothing if the default IBM MobileFirst Platform splash screen is already hiddenvoid
initializeWebFramework(Context context, WLInitWebFrameworkListener listener)
Initializes the IBM MobileFirst Platformvoid
removeActionReceiver(WLActionReceiver wlActionReceiver)
Unregisters a receiver from receiving actions.void
sendActionToJS(java.lang.String action)
Sends action to JavaScript action receivers.void
sendActionToJS(java.lang.String action, JSONObject data)
Sends action to JavaScript action receivers.void
setServerUrl(java.net.URL url)
Sets the IBM MobileFirst Platform Server URL to the specified URLvoid
showSplashScreen(Activity activity)
Shows the default IBM MobileFirst Platform splash screen on the activity that was passed as a parameter
-
-
-
Method Detail
-
createInstance
public static WL createInstance(Context context)
Creates a shared instance of Worklight if one does not exist.This method should be called before any other IBM MobileFirst Platform hybrid calls. If this method was called twice it will ignore the context parameter and will return the existing instance.
- Parameters:
context
- Application Context- Returns:
- An instance of Worklight
-
setServerUrl
public void setServerUrl(java.net.URL url)
Sets the IBM MobileFirst Platform Server URL to the specified URLChanges the IBM MobileFirst Platform Server URL to the new URL and cleans the HTTP client context. After calling this method, the application is not logged in to any server.
Notes:
- The responsibility for checking the validity of the URL is on the developer.
- This call does not clean the HTTP client context saved in JavaScript.
For hybrid applications, it is recommended to set the server URL by using the following JavaScript function:
WL.App.setServerUrl
.
WL.getInstance().setServerUrl(new URL("http://9.148.23.88:10080/context"));
- Parameters:
url
- URL of the new server, including protocol, IP, port, and context.
-
getServerUrl
public java.net.URL getServerUrl()
Returns the current IBM MobileFirst Platform Server URL
-
getInstance
public static WL getInstance()
Gets an instance of the WL class This method can not be called beforeWL.createInstance(Context)
.- Returns:
- An instance of the WL class
-
initializeWebFramework
public void initializeWebFramework(Context context, WLInitWebFrameworkListener listener)
Initializes the IBM MobileFirst Platform- Parameters:
context
- Application contextlistener
- Listener to be notified on completion of the initialization
-
getMainHtmlFilePath
public java.lang.String getMainHtmlFilePath()
Calculates and returns the main HTML file path. This path is then used to load the Cordova WebView using loadUrl() method of CordovaActivity. This method should be called only after successful web framework initialization, that is, in WLInitWebFrameworkListener.onInitWebFrameworkComplete. This is to ensure that the IBM MobileFirst Platform initialization is complete and the web resources are ready to be used.- Returns:
- Path of the main HTML file
-
showSplashScreen
public void showSplashScreen(Activity activity)
Shows the default IBM MobileFirst Platform splash screen on the activity that was passed as a parameter- Parameters:
activity
- Activity to be used for the splash screen.
-
hideSplashScreen
public void hideSplashScreen()
Hides the default IBM MobileFirst Platform splash screen if it is shown, and does nothing if the default IBM MobileFirst Platform splash screen is already hidden
-
sendActionToJS
public void sendActionToJS(java.lang.String action)
Sends action to JavaScript action receivers. Note: if there are no JavaScript action receivers registered, the action is queued until a JavaScript action receiver is registered.- Parameters:
action
- Custom string representing an action
-
sendActionToJS
public void sendActionToJS(java.lang.String action, JSONObject data)
Sends action to JavaScript action receivers. Note: if there are no JavaScript action receivers registered, the action is queued until a JavaScript action receiver is registered.- Parameters:
action
- Custom string representing an actiondata
- (optional) Custom JSONObject instance containing key-value pairs ExampleWL.getInstance().sendActionToJS("doSomething"); JSONObject data = new JSONObject(); data.put("customData", 12345); WL.getInstance().sendActionToJS("doSomething", data);
-
addActionReceiver
public void addActionReceiver(WLActionReceiver wlActionReceiver)
Registers a new native action receiver with the IBM MobileFirst Platform.- Parameters:
wlActionReceiver
- Object that implements the WLActionReceiver interface- Since:
- IBM Worklight V6.2.0
Example
MyReceiver myReceiver = new MyReceiver(); WL.getInstance().addActionReceiver(myReceiver);
-
removeActionReceiver
public void removeActionReceiver(WLActionReceiver wlActionReceiver)
Unregisters a receiver from receiving actions. After calling this API receiver will no longer receive actions.- Parameters:
wlActionReceiver
- Object that implements the WLActionReceiver protocol ExampleWL.getInstance().removeActionReceiver(myReceiver);
-
-