问题
Is there a way to host a Worklight app inside an Android Fragment?
I have attempted to use the WLWebView inside a Fragments onCreateView
WLWebView webView = new WLWebView(getActivity());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///path_to_app.html_file", 60000);
return webView;
But it results in a timeout error even though I can see the HTML. It could be the connection to Worklight failing as we are using WL.Client.connect()
. The error doesn't specify which URL timed out.
I do believe that the WLDroidGap class (which is used as the primary activity) adds a whole lot of extras to the WLWebView to make things work but I don't have access to the source to see what exactly.
The requirement we have is that we want to have a Native app hosting a Worklight app.
Is this possible?
回答1:
Create CordovaWebViewClient() and CordovaChromeClient() instances and use them with your webView. Check out two init() methods of https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaActivity.java
webView.setWebViewClient(webViewClient);
webView.setWebChromeClient(webChromeClient);
webViewClient.setWebView(webView);
webChromeClient.setWebView(webView);
回答2:
What is the rationale behind having a native app hosting a Worklight Hybrid app?
The current alternatives are:
- Native app that uses the Worklight Native API for Android
- Hybrid app that uses WL.NativePage.show to display native screens
More about this in the Getting Started training modules, chapters 6 and 7.
来源:https://stackoverflow.com/questions/17646059/worklight-app-inside-an-android-fragment