katzer / cordova-plugin-email-composer

Edit and send email messages
Apache License 2.0
344 stars 333 forks source link

Android Attachment Question #315

Closed kd8ssq closed 5 years ago

kd8ssq commented 5 years ago

Is there a reason why I can successfully attach a file when the file is located in cordova.file.externalDataDirectory but not when it's located in cordova.file.dataDirectory? It's the exact same file, I just change where the file is saved/read from and when it's saved in the externalDataDirectory, the email plugin successfully pulls the text file into the email as an attachment.

kd8ssq commented 5 years ago

Here's the error that the log shows

11-16 20:25:55.923 29328-29390/com.myApp.app1037 E/EmailComposer: Failed to get uri for file 11-16 20:25:55.924 29328-29390/com.myApp.app1037 W/System.err: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.myApp.app1037/files/log.txt

I even attempted to hardcode the path and receive the same error file:///data/user/0/com.myApp.app1037/files/log.txt

kd8ssq commented 5 years ago

Looks like I have to use this format for android "app://databases/db.db3". When I tried that format for iOS it doesn't work, so I have to go back to using the dataDirectory for iOS.

katzer commented 5 years ago

@kd8ssq This is because of insufficient permissions.

If you use the latest master branch (0.9.0.beta), then you have to

  1. Add the READ_EXTERNAL_STORAGE permission to your app's manifest
  2. Request the permission:

    var email = cordova.plugins.email;
    email.requestPermission(email.permission.READ_EXTERNAL_STORAGE);
  3. In case the user has granted access, you can attach files outside of the app's own file system.

Please note that the permission is only needed for external files (file:///). All other schemes don't need that permission.

kd8ssq commented 5 years ago

Ok, thanks.