Issue
For all who are struggling with this for ages, too.
Since Android 6.0 Google has introduced a new security check. When you want to add an attachment out of your cache storage you will get a permission denied error.
You can solve it like this.
Just use imagepicker to get the images first and save it to results like it's indicated in Cordova's examples.
Then use the Cordova file plugin to move the images from cache to the externalRootDirectory (SD storage, you don't need an SD storage in your device to use this).
Here is a working example of how to do it within an Ionic application:
window.imagePicker.getPictures(
function(results) {
// Restrict amount of images
for (var i = 0; i < results.length; i++) {
// Get image only uri
$scope.justImg = results[i].replace(cordova.file.cacheDirectory, '');
// Move file from cache to sd (needed by android 6.0)
$cordovaFile.moveFile(cordova.file.cacheDirectory, $scope.justImg, cordova.file.externalRootDirectory).then(function (success) {
// Set new path for image
var newPath = cordova.file.externalRootDirectory + $scope.justImg;
// Save new path to email attachments
$scope.emailAttachments.push(newPath);
// Push no base 64 for view images
$scope.allImages.push(newPath);
}, function (error) {
console.log(error);
});
}
}, function (error) {
console.log('Error : ' + error);
}, {
maximumImagesCount: 3,
width: 800,
outputType: 0,
quality: 100
}
);
Hope I could help some guys struggling with this for days like I did.
If you got questions, let me know.
Solution
[SOLVED] This issue has been resolved by myself, you can now use it for your own troubleshooting.
Answered By - Max Wesener
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.