ERR_ACCESS_DENIED in webview in Android - only with sdk 30

Viewed 9048

I'm upgrading my app, actually it has sdk 28, and I need to upgrade to 29 in order to be allowed to create new versions in November.

sdk 30 it's available, so I try with this. The app works well, the only thing that I found, was that when I try to load in a webview a local html file, the webview show me an error:

  • net:err_access_denied with code -1

If I change the sdk version from 30 to 29, it "magically" works.

I has to mention that this file html is downloaded from a server, but when I try to open in a webview, it exists, and all it's apparently correct. I can see with other app like es file explorer.

¿There are some limitations with this new sdk and local html files in webview?

6 Answers

For NativeScript add

androidSettings.setAllowFileAccess(true);
androidSettings.setAllowContentAccess(true);

to _setAndroidWebViewSettings in the index.android.js file of nativescript-webview-interface folder

To piggyback on Nana's awesome answer, you dont need to modify the plugin code, as doing that will blow your change away every time you npm i. Do this instead:

webviewLoaded(args) {
  const view = args.object;
  if (view.android) {
    view.android.getSettings().setAllowFileAccess(true);
    view.android.getSettings().setAllowContentAccess(true);
  }
}

^ That is the true beauty of Nativescript.

I had the same issue, here is how I fixed using Kotlin

webview.settings.allowFileAccess = true
webview.settings.allowContentAccess = true

We had the same issue for our hybrid app in cordova.

Adding the following code to the file SystemWebViewEngine.java worked for us:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        settings.setAllowFileAccess(true);
        settings.setAllowContentAccess(true);
}

Thanks to your answers we were able to find ours!

Related