Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERR_ACCESS_DENIED in webview in Android - only with sdk 30

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?

like image 513
danybarco Avatar asked Aug 24 '20 10:08

danybarco


Video Answer


3 Answers

I had the same issue and it seems related to the latest changes applied to the webview in Android 11: https://developer.android.com/reference/android/webkit/WebSettings#setAllowFileAccess(boolean)

Now you will have to call setAllowFileAccess(true) in the settings of the webview to make it work. The default value was true for sdk 29 and lower versions, but now you will have to allow the access yourself.

like image 186
Aitor Font Puig Avatar answered Sep 24 '22 23:09

Aitor Font Puig


For NativeScript add

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

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

like image 24
Nana kTk Avatar answered Sep 24 '22 23:09

Nana kTk


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.

like image 3
davecoffin Avatar answered Sep 25 '22 23:09

davecoffin