[WebView] doesn't load local html files
Describe the bug
Wenn using the Accompanist WebView Wrapper with a local file url (e.g. file:///data/user/0/com.example.application/files/something/root/imprint.html) it doesn't load and prints out a chrome net::ERR_ACCESS_DENIED.
It works when I use an AndroidView() with a android.webkit.WebView inside
To Reproduce
Steps to reproduce the behavior:
- Create a local html file which can be accessed by your app
- Use the Accompanist WebView and try to load the file
WebView(state = rememberWebViewState("file:///...something.html") - Run the App and open the View
- See error
Expected behavior
The WebView Wrapper should load the url like the android.webkit.WebView does
Screenshots?
Environment:
- Android OS version: Android 9
- Device: Nokia 8
- Accompanist version: 0.25.0
It works fine for me. I use version 0.26.2-beta.
My URL looks slightly different (the file that I access is located in src/main/assets):
file:///android_asset/somefile.html
Then something like this:
val state = rememberWebViewState(url)
WebView(
modifier = Modifier.contentDescription("Document Web View"), state = state
)
Unable to reproduce, I suspect a permissions problem where you are trying to access a file you don't have the rights to. As the comment above shows, that is the correct form to access a file from your assets.
It is not a file from assets, it is a file we download and unzip. If it was a permission problem, why does it work using android.webkit.WebView?
I will try it with 0.26 beta when I'm back from vacation.
I got it running. We were applying the setting webView.settings.allowFileAccess and I didn't do this in Accompanist WebView Wrapper... so when I use
WebView(
onCreated = { it.settings.allowFileAccess = true },
state = rememberWebViewState(imprintUrl)
)
it works