Home > Blockchain >  Android Cordova, why can't I access a source image file using this code anymore?
Android Cordova, why can't I access a source image file using this code anymore?

Time:01-10

The following JavaScript code from my Cordova Android app (running in a webview) on Android 13

var redIcon = L.icon({                                
                iconUrl: 'file:///android_asset/www/lib/images/marker-red-small.png',                           
                iconSize:     [40, 40]
            });

fails and triggers this message in the console:

Not allowed to load local resource: file:///android_asset/www/lib/images/marker-red-small.png

The same code used to work with previous versions of Android (versions 8 and 9 at least)

CodePudding user response:

"The scheme, https, is not configurable by nature.

Please note that this is a breaking change that will cause data associated with the file:// scheme, such as cookies, local storage, local cache, and web-based databases, to be lost. You will need to handle the migration of data. If you are unable to migrate the data at this time, you can revert this setting by setting the AndroidInsecureFileModeEnabled preference flag.

<preference name="AndroidInsecureFileModeEnabled" value="true" />

Setting this flag will keep the content on the file:// scheme, which Google reports to be insecure."

see update docs for Cordova-android 10: https://cordova.apache.org/announcements/2021/07/20/cordova-android-10.0.0.html

I think it's the above preference, not 100% sure. But if not, the update docs should help you further.

CodePudding user response:

According to the documentation (release announcement) handed by Mister_CK, I removed this part

file:///android_asset/www/

and it worked.

By default it will use

https://localhost/
  • Related