Reputation: 1086
https://developer.android.com/training/data-storage#scoped-storage
Device name: User-Agent: Mozilla/5.0 (Linux; Android 11; Pixel 3a Build/RPB1.200504.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.106 Mobile Safari/537.36
1)android targetSdkVersion 30 requestLegacyExternalStorage = false.
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.example.ui"
minSdkVersion 21
targetSdkVersion 30
}
}
}
XMLHttpRequest request done from javascript level in cordova based android app.
var xhr = new XMLHttpRequest();
xhr.open("GET", lFileUrl, true);
xhr.responseType = "blob";
UI.Util.info("PtxUtils.getInlineAttachmnetJson() >> inside xhr.open");
xhr.onload = function(e) {
try {
UI.Util.info("PtxUtils.getInlineAttachmnetJson() >> inside xhr.onload");
}
3)XMLHttpRequest throwing error
ERR_ACCESS_DENIED, when getFilesDir() API used.
PtxUtils.js:2950 GET
file:///data/user/0/com.example.ui/files/KK&T%20SEW_temp/IMG-20200630-223714.jpg net::ERR_ACCESS_DENIED
23:09:57.058 PtxUtils.js:2950 XHR failed loading: GET "file:///data/user/0/com.example.ui/files/KK&T%20SEW_temp/IMG-20200630-223714.jpg".
4)XMLHttpRequest throwing error
ERR_ACCESS_DENIED, when getExternalFilesDir()() API used.
PtxUtils.js:2950 GET file:///storage/emulated/0/Android/data/com.example.ui/files/KK&T%20SEW_temp/IMG-20200701-135735.jpg net::ERR_ACCESS_DENIED
PtxUtils.js:2950 XHR failed loading: GET "file:///storage/emulated/0/Android/data/com.example.ui/files/KK&T%20SEW_temp/IMG-20200701-135735.jpg".
5)android targetSdkVersion 29 requestLegacyExternalStorage = false
with getFilesDir() path getExternalFilesDir() XMLHttpRequest is pass with no error, file data is retrieved.
Upvotes: 2
Views: 1252
Reputation: 25727
It seems to me you will probably need the following permissions:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
And also for good measure I would also try:
<uses-permission android:name="android.permission.INTERNET"/>
and put this in Manifest :
<application
android:usesCleartextTraffic="true">
</application>
Additionally, after you make the changes clear data, uninstall the app, re-install, and try again.
Finally, if you are using webview anywhere, also do this:
webView.getSettings().setAllowContentAccess(true);
webView.getSettings().setAllowFileAccess(true);
Upvotes: 1