0

I have a webview set up that works.

It loads a page from the root of the assets folder called index.html

I want it a html link in that index.html to be able to open a local link that can be found in assets\catalyst\index.html

I have added the link in the root index file, but when i click the link in the app, it crashes.

I have tried

<a href="file:///android_asset/catalyst/index.html">

<a href="./catalyst/index.html">

but neither stop it crashing.

i assume it is some sort of permissions.

i set a lot of "getSettings" on the original webview, that I hoped would cover all the permissions but to no avail.

This is the link in the root index.html

<a href="file:///android_asset/catalyst/index.html"><img src="./homepage/catalystimage.jpg" alt="catalystimage"></a>

This is in the Java file allowing the loadurl of the first webview.

        webView=findViewById(R.id.webviewid);
        webView.setWebChromeClient(new WebChromeClient());
        webView.loadUrl("file:///android_asset/index.html");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setPluginState(WebSettings.PluginState.ON);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setAllowContentAccess(true);
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setAllowFileAccessFromFileURLs(true);
        webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
        WebView.setOverScrollMode(View.OVER_SCROLL_NEVER);````

i want it to load the local index.html file from the subfolder.

it crashes the app.
Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
3dlabs
  • 11
  • 6
  • Enable first debugging for webview. Open your first HTML file. Open your desktop browser -> developer tools -> remote device and select your android device. Now you can click on your href link and look at the console tab to see what error is being thrown. – BR75 Jan 14 '20 at 21:19

1 Answers1

1

The html file should be placed in the assets folder (note the spelling), which will belong in the root directory of your project.

So move

src/main/assests/index.html to

assets/index.html In an Android Studio project use this folder:

/app/src/main/assets/index.html

Add this line, webView.setWebViewClient(new WebViewClient());

Check it: Load local html file in webview android

sai gopal
  • 66
  • 1
  • 9
  • Hi Sai, thank you for taking the time to respond. The index.html is in /app/src/main/assets/ that loads fine. it is just when i click on a html link in that index file to open the link in the position below /app/src/main/assets/catalyst/index.html that it makes the app crash. – 3dlabs Sep 27 '19 at 16:18
  • 1
    Try this, webView.setWebViewClient(new WebViewClient()); – sai gopal Sep 27 '19 at 16:54
  • I already have the webview.setWebChromeclient to enable the openGL elements. Would your suggestion cause a conflict? – 3dlabs Sep 27 '19 at 18:18