Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic Android Internal Shared Memory

I'm using Ionic v1 with $cordovaFile and cordova email plugin to create a file and then attach it to a new email. I have a working solution for iOS on any device, but I've come across a weird issue with Android.

Android File System Layout

When attempting to attach a file created in any internal storage location on Android (dataDirectory, etc), I receive "permission denied for attachment". However, when I save the file to external storage, the attachment is successfully added.

I have published my application using external storage for Android, but unfortunately some of today's most popular devices don't have external storage.

Does anyone know a solution? I've considered workarounds, such as uploading the file to a file-hosting service, and including a download link in the email. I would use $cordovaFileTransfer, but I don't know if there would be permissions errors in internal storage. I'd like to use a true email attachment if possible. Thanks!

like image 623
Matt Goodrich Avatar asked Sep 06 '17 18:09

Matt Goodrich


People also ask

Does local storage work in ionic?

That's one of the biggest arguments in favour of Ionic Storage; Ionic Storage will automatically select the best possible underlying storage engine available on the current platform. Normally this means IndexedDB or otherwise localstorage.

How is data stored in ionic?

With Ionic Storage we can either call set() or get() and both will return a Promise. Unlike our Observable from before this is only handled with a then() block, but the operation is still async! If we want to get a list of all IDs we can easily return the Storage value for our predefined STORAGE_KEY .

Is ionic secure storage free?

Try it free now.


1 Answers

I think your issue is related to permission. I have implemented this for file attachment to give a permission for file attachment try it hope this help you. Try this plugin cordova.plugins.permissions

 function checkPermission() {
            var permissions = cordova.plugins.permissions;
            permissions.hasPermission(permissions.READ_EXTERNAL_STORAGE, checkPermissionCallback, null);
        }

function checkPermissionCallback(status) {
            $localStorage.StoragePermission = status.hasPermission;
            if (!status.hasPermission) {
                var permissions = cordova.plugins.permissions;
                permissions.requestPermission(permissions.READ_EXTERNAL_STORAGE, null, null);                
            }
        }
like image 94
Pritish Avatar answered Oct 06 '22 10:10

Pritish