I am trying to download file from server to ionic app using cordova-file transfer plugin, it is working fine for android target SDK 22, but when I change the target SDK to 23 and try it throws EACESS open failed {Permission denied} error.
Here is my androidmanifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:maxSdkVersion="23" android:minSdkVersion="16" android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Download Function is:
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function (fileEntry) {
var filepath = cordova.file.externalRootDirectory + attachment.attachment_name;
console.log("filepath", filepath)
var fileTransfer = new FileTransfer();
// console.log('FilePath ' + filepath);
fileTransfer.download(data.URL, filepath,
function (fileEntry) {
// console.log("download complete: " + fileEntry.toURL());
},
function (error) {
console.log("ErrorDownload: " + JSON.stringify(error));
},
true,
{});
});
ERROR:
target":"file:///storage/emulated/0/ionic.png","http_status":200,"body":null,"exception":"/storage/emulated/0/ionic.png: open failed: EACCES (Permission denied)"
If I change targetSDK to 22 then file file will be downloaded to storage/sdcard/ path.