I am trying to adapt a web application into android webview by webview.loadUrl("file:///android_asset/Content_to_Change/dev/index.html").
I have pasted whole application code into assets folder as 'assets/Content_To_Change/dev'. When I run the android app, index page is loaded fine, but after that execution halts here and there in predictive manner with reference errors like below:
Uncaught TypeError: Cannot read property 'identifier' of undefined at file:///android_asset/Content_To_Change/dev/activity/views/screen4/screen.js:361
Uncaught TypeError: Cannot read property 'yPoint' of null at file:///android_asset/Content_To_Change/dev/activity/views/screen4/screen.js:394
Also these errors sometimes happens at one place and sometimes at other. I am wondering why there reference errors popping up while the app is working without any errors in safari(iOS) and desktop browsers!
After doing some more hit and trials, it seems there is some sort of load order mismatch in rendering of js/css ? I also tried with android:hardwareAccelerated="true" in manifest but to no avail...:(
Here is my Code:
String url = "file:///android_asset/Content_To_Change/dev/index.html";
mWebView = (WebView) findViewById(R.id.webViewMain);
// webView.setInitialScale(WEBVIEW_SCALE);
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(true);
settings.setDomStorageEnabled(true); //
settings.setLoadWithOverviewMode(true);
settings.setDatabaseEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setPluginState(WebSettings.PluginState.ON);
settings.setAllowFileAccess(true);
settings.enableSmoothTransition();
settings.setDisplayZoomControls(false);
// settings.set
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLoadsImagesAutomatically(true);
settings.setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1");
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.setScrollbarFadingEnabled(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
{
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowContentAccess(true);
settings.setAllowUniversalAccessFromFileURLs(true);
}
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient()); // forces it to
mWebView.loadUrl(url);
Menifest has this:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Please advise what should I do in order to run my web app seamlessly in webview.
0 comments:
Post a Comment