Reputation: 443
Hi i am using compile 'com.github.delight-im:Android-AdvancedWebView:v3.0.0' for display html5, my target file is stored in my phone storage path is "file:///storage/sdcard0/DcLms/Conjunction/index.html". when I am working with normal android WebView no issues. But trying with above mentioned library i got Webpage not available issue.
String targetPath = "file:///storage/sdcard0/DcLms/Conjunction/index.html";
AdvancedWebView webView = (AdvancedWebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new HelloWebViewClient());
webView.loadUrl(targetPath);
WebView basicView = (WebView) findViewById(R.id.basicView);
webView.setWebViewClient(new HelloWebViewClient());
basicView.getSettings().setJavaScriptEnabled(true);
basicView.setWebChromeClient(new WebChromeClient());
basicView.getSettings().setDomStorageEnabled(true);
basicView.loadUrl(targetPath);
basicView.setWebViewClient(new HelloWebViewClient());
Upvotes: 1
Views: 578
Reputation: 2539
First of all AdvancedWebView
configures all settings automatically on it's instantiating. Take a look on the sources here.
And the problem is that by default AdvancedWebView
dissallow access using file://
scheme:
...
final WebSettings webSettings = getSettings();
webSettings.setAllowFileAccess(false);
setAllowAccessFromFileUrls(webSettings, false);
webSettings.setBuiltInZoomControls(false);
...
So after creation of AdvancedWebView
you need to add following lines:
AdvancedWebView webView = (AdvancedWebView) findViewById(R.id.webView);
webView.getSettings().setAllowFileAccess(true);
if (Build.VERSION.SDK_INT >= 16) {
webView.getSettings().setAllowFileAccessFromFileURLs(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}
NOTE: AdvancedWebView
just subclassing WebView
so it will not make any difference - the only difference that it configurating settings for you and handle some of the events.
Upvotes: 1