Reputation: 27
I'm using below code to download and sava a file in my phone storage.
var fileTransfer = new FileTransfer();
fileTransfer.download(
"http://developer.android.com/assets/images/home/ics-android.png",
"/storage/emulated/0/Download/ics-android.png",
function(entry) {
alert("download complete: " + entry.fullPath);
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
});
This code is working fine on any android device which are running on Android Lollipop or below. But from Android Marshmellow this doesn't work and return following error.
download error source " the url used"
download error target: " the target used "
upload error code 1
Can someone help me to solve this issue?
Upvotes: 0
Views: 55
Reputation: 2525
You can use this https://ionicframework.com/docs/native/android-permissions/ model for it.
You need android.permission.WRITE_EXTERNAL_STORAGE
and android.permission.READ_EXTERNAL_STORAGE
for it.
You can use below example for it. I got this example code from above-mentioned page. Go through it and add what you want.
this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE).then(
result => console.log('Has permission?',result.hasPermission),
err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE)
);
this.androidPermissions.requestPermissions([this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE, this.androidPermissions.PERMISSION.READ_EXTERNAL_STORAGE]);
Upvotes: 1