EinfachHans / capacitor-email-composer

E-Mail Composer Plugin for Capacitor
MIT License
22 stars 8 forks source link

App Crash due to android.os.TransactionTooLargeException #19

Closed tknight00 closed 12 months ago

tknight00 commented 1 year ago

Android 12 Ionic 6 Capacitor 4

I'm taking a screenshot using Capacitor Screenshot, and attempting to email it via Capacitor Email Composer.

I'm using the following code

let openOptions: OpenOptions = {
    attachments: [{
            name: 'screenshot.png',
            path: this.dataurl.split(",")[1],
            type: 'base64',
        }],
    body: 'Screenshot attached',
    bcc: [],
    cc: [],
    isHtml: false,
    subject: 'Screenshot',
    to: [],
};
EmailComposer.open(openOptions);

Gmail opens and I see the attached screenshot, and everything appears to of populated correctly for roughly 1 second before the app crashes. I can still send the email as all the data is correctly inserted. I don't see any console log errors. Removing the attached image prevents the crash.

----- Below is the DEBUG log generated by Android Studio -----

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: *removed*, PID: 5935
    java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 710264 bytes
        at android.app.ActivityClient.activityStopped(ActivityClient.java:86)
        at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:143)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8663)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
     Caused by: android.os.TransactionTooLargeException: data parcel size 710264 bytes
        at android.os.BinderProxy.transactNative(Native Method)
        at android.os.BinderProxy.transact(BinderProxy.java:635)
        at android.app.IActivityClientController$Stub$Proxy.activityStopped(IActivityClientController.java:1358)
        at android.app.ActivityClient.activityStopped(ActivityClient.java:83)
        at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:143) 
        at android.os.Handler.handleCallback(Handler.java:938) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loopOnce(Looper.java:226) 
        at android.os.Looper.loop(Looper.java:313) 
        at android.app.ActivityThread.main(ActivityThread.java:8663) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135) 
I/Process: Sending signal. PID: 5935 SIG: 9
Disconnected from the target VM, address: 'localhost:53579', transport: 'socket'

The screenshot image is only 693kb. Shouldn't this be a try/catch that generates a console.log? Also, how do I discover the file size limit? If it exceeds the limit, why is it still correctly populated in gmail?

Prishii commented 1 year ago

Android 13 Capacitor 5 Ionic 5

Facing the same issue while trying to send the jpeg images. The gmail opens and is populated with data correctly but the application crashes. There is no exception/error thrown either.

But, when used an image of size 10KB it works! So this might be related to the size? Anyways, there is no size limit given in the documentation also. (works for pdf)

EinfachHans commented 1 year ago

I would appreciate PR's for this. I currently only have the time to manage this plugin for my own usage and i don't use attachments. If anyone has enough native experience to debug and fix this, it would be highly appreciated 🙏🏼

develmood commented 1 year ago

We found out that this limitation exists within the Android OS. This exception is thrown in different scenarios, for example when you want to share data from a size of about 500kb between two apps .So no problem that can be solved with this plugin.

Read more: https://developer.android.com/reference/android/os/TransactionTooLargeException

To work around the problem, the data must be saved on the device beforehand. You can use https://capacitorjs.com/docs/apis/filesystem for this. The stored file can then be transferred to the email client via the path with EmailComposer.

EinfachHans commented 12 months ago

@develmood thanks for your investigation! I will add a note in the readme docs. Thanks 😊