katzer/cordova-plugin-email-composer

cordova.plugins.email.hasAccount always returns false on Android 10

regnete opened this issue · 8 comments

cordova.plugins.email.hasAccount alsways returns false on Android 10 even if on or more accounts are configured on the device.
I tracked it down to a permission issue (see https://stackoverflow.com/a/54941079/4094951) and will shortly provide a pull request containing a fix.

Details:
For Android 10 to have to declare the additional permisson READ_CONTACTS in AndroidManifest.xml and you also have to request that permission on runtime. Otherwise AccountManager.get(ctx).getAccounts() will always return an empty array.

@regnete sorry the late reply, does this problem still applies?

cordova.plugins.email.hasAccount does not work on Android 10+?

Do you confirm #351 is a solid and stable fix?

indeed I tested now on Android 11 with one Gmail account with

cordova.plugins.email.hasAccount((res)=> console.log(res))

and got false

Tested with another device with Android 9 and got true

I will test your PR in Android 9 and 11 with

cordova plugin add github:katzer/cordova-plugin-email-composer#pull/351/head

I suppose this does work (saw here)

@regnete
I could build your PR with the current branch but not only it doesn't work, but it also crashes in Android 11 while opening email app. I closed that PR #351 thus.

To solve this issue, please do kindly submit a new PR from the current head of master and test it with Android 11.
Thanks and have a great day

I am following the problem with interest. I am facing the same problem that hasAccount () is not working. In my case on Android 11 + SDK 30

@r000bin97 you can try to test @regnete 's PR #351

cordova plugin rm cordova-plugin-email-composer
cordova plugin add github:katzer/cordova-plugin-email-composer#pull/351/head
cordova clean && cordova build android

It crashed on my side when I tested it

You can also try to improve that PR in case of crash and submit a new one :)
You are very welcomed

Thanks for the hint, but unfortunately I then have exactly the same problem. I've already tried all of the fixes that I found on github. None has worked so far

@r000bin97 did you test it with the following in config.xml under <platform name="android">?

    <config-file target="app/src/main/AndroidManifest.xml" parent="/manifest">
        <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
        <uses-permission android:name="android.permission.READ_CONTACTS"/>
    </config-file>