为什么我不能再使用这段代码访问Android Cordova中的源图像文件?

huangapple go评论86阅读模式
英文:

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

问题

以下是翻译好的部分:

来自我的 Cordova Android 应用(在 Android 13 的 WebView 中运行)的以下 JavaScript 代码:

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

在控制台中触发了以下消息:

不允许加载本地资源:file:///android_asset/www/lib/images/marker-red-small.png

相同的代码在之前的 Android 版本(至少在版本 8 和 9)中可以正常工作。

英文:

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)

答案1

得分: 1

"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.

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.

英文:

"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.

huangapple
  • 本文由 发表于 2023年1月9日 18:50:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056193.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定