1

I have a little online help consisting of several HTML linked with each other.

That worked fine in the past but with Android 8 can only show the entry page and as soon as I click any link I get:

10-08 09:04:17.616 22871 22871 E AndroidRuntime: FATAL EXCEPTION: main
10-08 09:04:17.616 22871 22871 E AndroidRuntime: Process: net.sourceforge.uiq3.fx602p, PID: 22871
10-08 09:04:17.616 22871 22871 E AndroidRuntime: android.os.FileUriExposedException: file:///android_asset/Modes.html exposed beyond app through Intent.getData()
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.net.Uri.checkFileUriExposed(Uri.java:2356)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.content.Intent.prepareToLeaveProcess(Intent.java:10511)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.content.Intent.prepareToLeaveProcess(Intent.java:10465)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.app.Activity.startActivityForResult(Activity.java:4564)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.app.Activity.startActivityForResult(Activity.java:4522)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.app.Activity.startActivity(Activity.java:4883)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.app.Activity.startActivity(Activity.java:4851)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.content.ContextWrapper.startActivity(ContextWrapper.java:377)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at aiM.startActivity(SourceFile:22)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at agA.a(SourceFile:34)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(SourceFile:173)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.os.MessageQueue.nativePollOnce(Native Method)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.os.MessageQueue.next(MessageQueue.java:325)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:142)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6944)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
10-08 09:04:17.616 22871 22871 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Of course all pages are displayed inside the app and nothing is "leaked" to the outside. And even if: It's just the online help and wouldn't care less if it was.

Enough of the rant: How to fix this?

UPDATE 1:

The page consisted only of a simple layout and an almost empty activity:

<LinearLayout
  android:layout_height='match_parent'
  android:layout_width='match_parent'
  xmlns:android='http://schemas.android.com/apk/res/android'
>
  <WebView
    android:id='@+id/Help'
    android:layout_height='match_parent'
    android:layout_width='match_parent'
  ></WebView>
</LinearLayout>

@igor_rb suggested to overload shouldOverrideUrlLoading the WebViewClient — but I don't actually use a WebViewClient at the moment.

Martin
  • 11,577
  • 16
  • 80
  • 110
  • Related https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed and https://stackoverflow.com/questions/50072638/fileuriexposedexception-in-android – AskNilesh Oct 08 '18 at 07:14

1 Answers1

1

You can try override shouldOverrideUrlLoading method, more info.

Give the host application a chance to take control when a URL is about to be loaded in the current WebView. If a WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the URL. If a WebViewClient is provided, returning true causes the current WebView to abort loading the URL, while returning false causes the WebView to continue loading the URL as usual.

For example, you can try simply return false from him:

  WebViewClient client = new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return false;
    }
};
igor_rb
  • 1,821
  • 1
  • 19
  • 34
  • I think there is something missing here. What I do with `client` ? Just creating the instance won't make a difference, will it? – Martin Oct 08 '18 at 07:54
  • ´android.webkit.WebView´ has a `setWebViewClient` method. I guess it goes in there. – Martin Oct 08 '18 at 08:01