Using cordova build Android app, and add cordova hot code push plugin to make app update automatically, and using Fetch API to load JSON files which located in current project directory, the problem is when update the app, any JSON files cannot be reload,and throw the error
Fetch API cannot load file:///android_asset/www/xx/xxx.json. URL scheme "file" is not supported.
How to solve this Fecth error in Android app? Or is there any plugin that need add to my cordova project?
https://github.com/github/fetch/pull/92#issuecomment-140665932
You may use XMLHttpRequest for loading local assets.
I used the code below to sidestep a similar issue with fetch(). I didn't want to use the code from the link in Jan's answer because I didn't want to manually stream the data (the response object resulting from that code didn't have a responseText property).
function fetchLocalResource(url) {
const req = new XMLHttpRequest();
req.onload = function() {
const text = req.responseText;
// Do something with text...
};
req.open('GET', url);
req.send();
}
来源:https://stackoverflow.com/questions/44278371/fetch-api-cannot-load-file-android-asset-www-xx-xxx-json-url-scheme-file-i