Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening email with file attachment causes app crash on Android 8 #270

Closed
dpa99c opened this issue Sep 11, 2017 · 4 comments
Closed

Opening email with file attachment causes app crash on Android 8 #270

dpa99c opened this issue Sep 11, 2017 · 4 comments
Assignees

Comments

@dpa99c
Copy link

dpa99c commented Sep 11, 2017

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 20:29:34.703 14952-15146/io.cordova.hellocordova E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-2
 Process: io.cordova.hellocordova, PID: 14952
 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:155)
     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.

@katzer
Copy link
Owner

katzer commented Sep 13, 2017

@dpa99c Could you please let me know if it's working by installing the plugin from master?

@dpa99c
Copy link
Author

dpa99c commented Sep 13, 2017

@katzer Yes, this fixes it. Tested the master branch with Android 8.0 and it now works fine.
Thanks for the quick turnaround time.

@thisIsChetan
Copy link

I was facing the same issue. But now it is working fine. Thank you @katzer

@katzer
Copy link
Owner

katzer commented Sep 14, 2017

I've published v0.8.9

@katzer katzer closed this as completed Sep 14, 2017
moses pushed a commit to flarehealth/cordova-plugin-email-composer that referenced this issue Dec 4, 2017
* katzer-master: (61 commits)
  Release v0.8.11
  Apply URL encoding when constructing mailto: link (katzer#273)
  Release v0.8.10
  Fix warnings with iOS 11
  Bump version to next dev cycle
  Update changelog
  Added alias for outlook
  Open gmail on ios and macos [fixes katzer#272]
  Release v0.8.9
  Bump version to next dev cycle
  Fix opening email with file attachment causes app crash on Android 8
(katzer#270)
  Release v0.8.8
  Update changelog
  Fix crash on iOS if attachment could not be found [fixes katzer#267]
  Fix plugin id in package.json
  Update documentation regarding Android and HTML
  Release v0.8.7
  Add support for an app:// (Windows)
  Add support for an app:// (macOS)
  Rename fileManager to fm
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants