Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can a WebView display a local page through a hyperlink?
    text
    copied!<p>I am creating help pages for my application that I display in a WebView. I can easily see the home page, but I can't figure out how to follow local hyperlinks.</p> <p>Here is my code so far:</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { ... content = (WebView) findViewById(R.id.content); content.loadData(getTextFromResource(R.raw.help_main), "text/html", "utf-8"); content.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); } private String getTextFromResource(int aResourceId) { InputStream vRaw = getResources().openRawResource(aResourceId); ByteArrayOutputStream vStream = new ByteArrayOutputStream(); try { int i = vRaw.read(); while (i != -1) { vStream.write(i); i = vRaw.read(); } vRaw.close(); } catch (IOException e) { } return vStream.toString(); } </code></pre> <p>And in <code>/res/raw/help_main.html</code>:</p> <pre><code>&lt;h1&gt;Help menu&lt;/h1&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="help_overview.html"&gt;Overview&lt;/a&gt;&lt;/li&gt; ... &lt;/ul&gt; </code></pre> <p>The link never leads to the Overview page, I tried with these URLs but nothing worked:</p> <ul> <li>help_overview.html</li> <li>./help_overview.html</li> <li>file://res/raw/help_overview.html</li> <li>file://android_asset/help_overview.html</li> <li>file://android_res/raw/help_overview.html</li> </ul> <p>Links to the internet work, but not local links, what URL should I use?</p> <p>I've seen the question <a href="https://stackoverflow.com/questions/14548286/local-html-page-raw-folder-in-webview-with-links-to-another-html-page">Local html page \raw\ folder in webview with links to another html page</a>, but its answer doesn't say <em>what</em> URL I should provide.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload