Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimal WebView Settings for HTML5 Support?

I'm interested in determining what the optimal settings are for a WebView that is intended to show HTML5 content.

Currently I'm using :

mWebView.setFocusable(true);
mWebView.setFocusableInTouchMode(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.getSettings().setRenderPriority(RenderPriority.HIGH);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setDatabaseEnabled(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

With these settings, the WebView score 189 (w/ 1 bonus) on html5test.com. I am wondering if there are any settings that I should/could change to get further compatibility with HTML5. Of course, this list is an amalgamation of settings compiled over some months, so I'm also open to being told I'm doing something wrong. I do not have control over the html content to be displayed but am trying to support as broad a swath of HTML5 as possible.

like image 923
Nick Campion Avatar asked Apr 10 '12 22:04

Nick Campion


People also ask

How do I display HTML content in WebView?

Android App Development for BeginnersStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken web view to show html content.

How do I enable JavaScript on WebView?

JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView . You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.

Is Android WebView deprecated?

This interface was deprecated in API level 12. This interface is now obsolete.


2 Answers

I would add:

    mWebView.setWebViewClient(new WebViewClient()); // tells page not to open links in android browser and instead open them in this webview
like image 133
thedrs Avatar answered Sep 19 '22 17:09

thedrs


Here is an (older) project concerned with optimal HTML5 settings:
http://code.google.com/p/html5webview/source/browse/trunk/HTML5WebView/src/org/itri/html5webview/HTML5WebView.java

FYI, normally I also set the database storage path for HTML5:

mWebView.getSettings().setDatabaseEnabled(true);
mWebView.getSettings().setDatabasePath("/data/data/" + Actvity.getPackageName() + "/databases/");
like image 32
Theo Avatar answered Sep 19 '22 17:09

Theo