cordova-email-plugin
cordova-email-plugin copied to clipboard
Opening email with file attachment causes app crash on Android 8
File access has been changed on Android 8, so using the current plugin implementation to attach a file to an email causing a crash on Android 8:
09-11 19:57:14.794 20528-20623/io.cordova.hellocordova E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-2
Process: io.cordova.hellocordova, PID: 20528
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/io.cordova.hellocordova/cache/email_composer/logo.png exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
at android.net.Uri.checkFileUriExposed(Uri.java:2348)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:941)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9735)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9741)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9720)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1609)
at android.app.Activity.startActivityForResult(Activity.java:4472)
at org.apache.cordova.CordovaActivity.startActivityForResult(CordovaActivity.java:342)
at android.app.Activity.startActivityForResult(Activity.java:4430)
at org.apache.cordova.CordovaInterfaceImpl.startActivityForResult(CordovaInterfaceImpl.java:66)
at de.martinreinhardt.cordova.plugins.email.EmailComposer$2.run(EmailComposer.java:154)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
To reproduce, just create a Cordova test project and run the example code on deviceready
in Android 8 emulator/device:
cordova.plugins.email.open({
attachments: [
'file://img/logo.png', //=> assets/www/img/logo.png (Android)
'file://css/index.css' //=> www/css/index.css (iOS)
]
});
The same code runs fine on Android 7.1.1 and below.
Seems there is a potential solution in this SO post.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
When will this be fixed?
I‘m not planning to release a new version as I‘m going to discontinue the development of this plugin
@dpa99c @seanda Don't worry brother. Use the following plugin instead of this https://github.com/katzer/cordova-plugin-email-composer
https://github.com/katzer/cordova-plugin-email-composer requires the GET_ACCOUNTS permission which is too permissive. dpa99c since you seem to be a plugin genius, have you managed to fork it and fix it ?
Edit: Problem solved with https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin#email