katzer / cordova-plugin-email-composer

Edit and send email messages
Apache License 2.0
345 stars 336 forks source link

Crash on Samsung Galaxy A12 / Android 11 #376

Closed m1cster closed 2 years ago

m1cster commented 2 years ago

Description: Opening the email composer crashes the app on android 11 (Samsung Galaxy A12 on Android 11 is a repro case). I also tried to open the email composer with only the subject given, but had the same result.

Exception is:

126 06-07 06:57:48.508 26002 26513 E AndroidRuntime: FATAL EXCEPTION: pool-4-thread-1
127 06-07 06:57:48.508 26002 26513 E AndroidRuntime: Process: XX.XXXXXX.XXXXXXX, PID: 26002
128 06-07 06:57:48.508 26002 26513 E AndroidRuntime: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
129 06-07 06:57:48.508 26002 26513 E AndroidRuntime:  at java.util.ArrayList.remove(ArrayList.java:503)
130 06-07 06:57:48.508 26002 26513 E AndroidRuntime:  at de.appplant.cordova.emailcomposer.Impl.getDraft(Impl.java:90)
131 06-07 06:57:48.508 26002 26513 E AndroidRuntime:  at de.appplant.cordova.emailcomposer.EmailComposer$4.run(EmailComposer.java:173)
132 06-07 06:57:48.508 26002 26513 E AndroidRuntime:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
133 06-07 06:57:48.508 26002 26513 E AndroidRuntime:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
134 06-07 06:57:48.508 26002 26513 E AndroidRuntime:  at java.lang.Thread.run(Thread.java:923)

Environment:

"cordova-plugin-androidx-adapter": "^1.1.1",
"cordova-plugin-appminimize": "^1.0.1",
"cordova-plugin-badge": "^0.8.8",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-firebase-analytics": "^4.3.1",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-local-notification": "file:plugins_custom/cordova-plugin-local-notifications",
"cordova-plugin-screeninfo": "file:plugins_custom/cordova-plugin-screeninfo",
"cordova-plugin-simple-storage": "file:plugins_custom/cordova-plugin-simple-storage",
"cordova-plugin-wkwebview-engine": "^1.2.1",
"cordova-support-android-plugin": "^1.0.2",
"cordova-support-google-services": "^1.4.1",

"cordova-android": "^10.1.2",
"cordova-ios": "^5.1.1",
"cordova-plugin-androidx": "^3.0.0",
"cordova-plugin-email-composer": "^0.10.0",
"cordova-plugin-whitelist": "^1.3.4",
"cordova-sqlite-ext": "^6.0.0"

Implementation:

var fileHandler = (window as any).cordova.file;
var path = fileHandler.cacheDirectory;
var date = new Date();
var dateString = date.getFullYear() + '-' + (date.getMonth() + 1).toString().padStart(2, '0') + '-' + date.getDate().toString().padStart(2, '0');
var fileName = "Export_" + dateString + ".html";

window.resolveLocalFileSystemURL(fileHandler.cacheDirectory, cacheDir => {
    cacheDir.filesystem.root.getFile(fileName, {create: true, exclusive: false}, file => {
        file.createWriter(writer => {
            writer.onwriteend = () => {
                var reader = new FileReader();

                file.file(fileContent => {
                    reader.onloadend = () => {
                        console.log("Successful file read: " + reader.result);
                        var email = {to: '', attachments: [path + '/'+ fileName], subject: 'Export', body: ''};
                        (window as any).cordova.plugins.email.open(email);
                    };

                    reader.readAsText(fileContent);
                }, error => console.log('error: ' + error));
            }

            writer.onerror = error => console.log("Failed file write: " + error.toString());
            writer.write(htmlString);
        });
    }, error => {
        console.log('error: ' + error.toString());
    });
});
m1cster commented 2 years ago

I just realized that on the master branch, there was already a bug report open (#361) that got fixed with #368. I checked again which version of the plugin I used and it seems to be the most recent one. However, comparing the code against the master branch in getDraft, there was a difference which was considered the fix in #361/#368.

So I'm wondering, when the fix will be officially released in npm?

jfoclpf commented 2 years ago

You are installing this plugin from npm, try to install it directly from this (original) repo

cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git

Tell me if this works

m1cster commented 2 years ago

Yes, it fixed it! Thank you!!

jfoclpf commented 2 years ago

you are welcomed, we send to NPM after more fixes and after we are sure this version is stable. Right now, you made us further believe it is :)