katzer / cordova-plugin-email-composer

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

Application crush after try to open client #361

Closed maxzirilli closed 3 years ago

maxzirilli commented 3 years ago

It's almost a pair of days that application crash when we try to open client.

Function HasClient also returns false; GMail is correctly installed;

We have Xiami phones and Android 11 installed

asgeo1 commented 3 years ago

It's crashing for me too on Android.

     java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.remove(ArrayList.java:503)
        at de.appplant.cordova.emailcomposer.Impl.getDraft(Impl.java:90)
        at de.appplant.cordova.emailcomposer.EmailComposer$4.run(EmailComposer.java:173)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

Seems to be an issue with this line of code: https://github.com/katzer/cordova-plugin-email-composer/blob/master/src/android/Impl.java#L90 removing an index that doesn't exist.

Melf11 commented 3 years ago

same issue here, even if there is no file attached to email and with basic email data. Using 'mailto'

    Process: com.wkv.shippingcontrol, PID: 16457
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.remove(ArrayList.java:503)
        at de.appplant.cordova.emailcomposer.Impl.getDraft(Impl.java:90)
        at de.appplant.cordova.emailcomposer.EmailComposer$4.run(EmailComposer.java:173)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
linktap01 commented 3 years ago

Same issue here. Is there any fix yet?

RolfDohrmann commented 3 years ago

Same here.

Device: Samsung A50 OS: Android 11 Context: Ionic/Angular/capacitor app

this.emailComposer.open(email);

Opening the mail client works on 2 devices:

Samsung S9+, Android 10 Samsung Tab A, Android 8.1

It crashes on

Samsung A50, Android 11

Android log:

E/AndroidRuntime: FATAL EXCEPTION: pool-3-thread-2 Process: de.minidat.windat, PID: 22863 java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.remove(ArrayList.java:503) at de.appplant.cordova.emailcomposer.Impl.getDraft(Impl.java:90) at de.appplant.cordova.emailcomposer.EmailComposer$4.run(EmailComposer.java:173) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)

Any idea how to fix this? Is this specific to Android 11?

linktap01 commented 3 years ago

Yes, the issue is specific to Android 11. I m still waiting for the fix :-(

ashwin-dongare commented 3 years ago

Hey, @katzer Can you please look into this I am also having the same issue with the Android 11 app is crashing. Thanks in advance!

Euxiniar commented 3 years ago

I'm a bit worried. This plugin seems abandoned

Melf11 commented 3 years ago

looks like, but i can't really find an alternative... :-(

Melf11 commented 3 years ago

seems like it's happen when no default app is selected for sending mails on the mobile. I took the getDrafts() Method from this file: Impl.java at 9f19ee5a8f27b18fce861f3412601dc84bf2f2e5 than the app opens the select menu for default mail app and it will work.

Melf11 commented 3 years ago

A dirty fix is to just return getFilledEmailIntent(params) in getDraft(), but it works.

Impl.java

Intent getDraft (JSONObject params) {
   return getFilledEmailIntent(params);
}
RolfDohrmann commented 3 years ago

A dirty fix is to just return getFilledEmailIntent(params) in getDraft(), but it works.

Impl.java

Intent getDraft (JSONObject params) {
   return getFilledEmailIntent(params);
}

Thanks a lot Melf11! Your fix works great!

linktap01 commented 3 years ago

A dirty fix is to just return getFilledEmailIntent(params) in getDraft(), but it works.

Impl.java

Intent getDraft (JSONObject params) {
   return getFilledEmailIntent(params);
}

It works! Thanks so much!

MattSynaptic commented 3 years ago

return getFilledEmailIntent(params);

That works for me but it shows all of the apps on the device, not just the email ones. Does anyone know a way to limit the options?

ashwin-dongare commented 3 years ago

A dirty fix is to just return getFilledEmailIntent(params) in getDraft(), but it works.

Impl.java

Intent getDraft (JSONObject params) {
   return getFilledEmailIntent(params);
}

Thanks Works pretty well

vLorente commented 3 years ago

Thanks a lot @Melf11 ! Your fix save my life!

PetePrattis commented 3 years ago

@Melf11 's fix and some other fixes that I tried, resulted in Android 11 successfully opening a draft email after prompting all possible apps, but any attachments failed to attach. This small change in the getDraft() made it possible to show the correct apps in prompt and to successfully attach files. The change: return Intent.createChooser(draft, header) instead of return Intent.createChooser(targets.remove(0), header)
Not sure what possible side effects there may be, but I tested it on Android 11 & 10 target sdk 30.

Intent getDraft (JSONObject params) {
        Intent draft  = getFilledEmailIntent(params);
        String app    = params.optString("app", MAILTO_SCHEME);
        String header = params.optString("chooserHeader", "Open with");

        if (!app.equals(MAILTO_SCHEME) && isAppInstalled(app)) {
            return draft.setPackage(app);
        }

        List<Intent> targets = new ArrayList<>();

        for (String clientId : getEmailClientIds()) {
            Intent target = (Intent) draft.clone();
            targets.add(target.setPackage(clientId));
        }

        return Intent.createChooser(draft, header)
                .putExtra(EXTRA_INITIAL_INTENTS, targets.toArray(new Parcelable[0]));
    }
PetePrattis commented 3 years ago

After testing it for a few days, it seems to be a stable fix, tested it on Android 11, 10 and older devices and all have the same expected behavior. Tested with multiple attachments and other use cases. Opened a pull request. #365

Melf11 commented 3 years ago

After testing it for a few days, it seems to be a stable fix, tested it on Android 11, 10 and older devices and all have the same expected behavior. Tested with multiple attachments and other use cases. Opened a pull request. #365

good work! thank you!

marshall86 commented 3 years ago

waiting for the fix pls

PetePrattis commented 3 years ago

waiting for the fix pls

Check this pull request #365 and my posts above. I would appreciate some feedback from other testers, whether this fix is actually working for everybody or not.

niclaforge commented 3 years ago

@PetePrattis your fix worked for us. Thanks

ebhsgit commented 3 years ago

The issue is Android 11 blocking queryIntentActivities() I've made PR #368 to fix the issue. I only have limit range of devices for testing.

Try it, and comment if it doesn't work for any devices

PetePrattis commented 3 years ago

@ebhsgit your pr #368 fixes the issue with Android 11, I tested it with Android 11, 10 and some older devices target sdk 30. Tested it for a variety of use cases, including multiple attachments. Everything worked as intended, we will implement this fix for our product if testing keeps going well, good job!

188599 commented 3 years ago

The issue is Android 11 blocking queryIntentActivities() I've made PR #368 to fix the issue. I only have limit range of devices for testing.

Try it, and comment if it doesn't work for any devices

I tried on our app and I couldn't get it to work, not sure I missed something.

Removed the old plugin and installed it again using cordova's cordova plugin add https://github.com/ebhsgit/cordova-plugin-email-composer#pr-Fix_361-Android_11_support

Checked the plugin.xml and it seems to be the correct one with the fix. Installed on an Android 11 device and it did not work.

Already removed the entire platform and added it back again, nothing changes. If I missed anything, please let me know. Thanks in advance.

Edit: I tried to look for the new portion of code added in the plugin.xml within platforms/android/app but I couldn't find it.

Does anyone know where exactly would that piece of code go into after cordova generates it's files? I imagine it would be either in platforms\android\app\src\main\AndroidManifest.xml or platforms\android\app\src\main\res\xml\config.xml but it wasn't in either of those places.

ebhsgit commented 3 years ago

@188599

Can you check the manifest.xml to see if it has the queries tag

<queries>
        <intent>
                <action android:name="android.intent.action.SENDTO" />
                <data android:scheme="mailto" />
            </intent>
</queries>

If not, then you are not using the fix

188599 commented 3 years ago

@ebhsgit I don't see any a manifest.xml file anywere within the build, only the AndroidManifest.xml and that one does not have the queries tag at all.

Do you use cordova as well? If you do, would you mind walking me through the steps you took to make this work? I'm certain I have the right plugin, because like I said the plugins\cordova-plugin-email-composer\plugin.xml does have the changes made by you, so it's something wrong in the build process that's not generating the proper tags in the xml file.

Edit: Finally figured out what the problem was.

Had to change target="app/src/main/AndroidManifest.xml" to simply target="AndroidManifest.xml", otherwise it kept creating an empty queries tag in the AndroidManifest.xml for me.

The plugin also stopped crashing, so it's working as expected, thank you 👍

jfoclpf commented 3 years ago

Anyone has more feedback with the PR #368?

Does it work stably on Android 11, with Chinese smartphones (Xiaomi, for example)?

Do the attachments work OK? Does it pop up only email Apps?

@PetePrattis @ebhsgit @maxzirilli @niclaforge Which PR are you using in your projects in production?