title: HTML link to local file in WebView with target API 24
body: <p>How can one use HTML links to navigate to local files (HTML pages) in <code>WebView</code> if targeting API 24 or higher?</p>
  
  <p>This has been discussed before and solutions use the <code>file://</code> URI scheme.
  What worked so far was using</p>
  
  <pre><code>&lt;a href="file:///android_asset/my_page.html"&gt;Go to local page&lt;/a&gt;
  </code></pre>
  
  <p>in an HTML file that is displayed in a <code>WebView</code> and clicking the link would load the local page <code>app/src/main/assets/my_page.html</code>.</p>
  
  <p>However, starting from API 24, a <a href="https://developer.android.com/reference/android/os/FileUriExposedException.html" rel="nofollow noreferrer">FileUriExposedException</a> is raised when clicking such a link. From logcat:</p>
  
  <pre><code>mypackage.myapp W/System.err: android.os.FileUriExposedException: file:///android_asset/my_page.html exposed beyond app through Intent.getData()
  ...
  mypackage.myapp W/System.err:     at org.chromium.android_webview.ResourcesContextWrapperFactory$WebViewContextWrapper.startActivity(ResourcesContextWrapperFactory.java:121)
  mypackage.myapp W/System.err:     at org.chromium.android_webview.AwContentsClient.sendBrowsingIntent(AwContentsClient.java:203)
  </code></pre>
  
  <p>According to the documentation, this is thrown when "an application exposes a <code>file://</code> Uri to another app.". I wonder why this is the case, because according to the log everything seems to happen inside <code>mypackage.myapp</code>.</p>
  
  <p>The documentation suggests using the <code>content://</code> URI scheme instead, but this does not work in HTML files.</p>