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:
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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With