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

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

Open
regnete opened this issue Aug 24, 2020 · 8 comments
Open

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

regnete opened this issue Aug 24, 2020 · 8 comments

Comments

@regnete
Copy link

regnete commented Aug 24, 2020

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.

@jfoclpf
Copy link
Collaborator

jfoclpf commented Nov 21, 2021

@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?

@jfoclpf
Copy link
Collaborator

jfoclpf commented Nov 21, 2021

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

@jfoclpf
Copy link
Collaborator

jfoclpf commented Nov 21, 2021

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)

@jfoclpf
Copy link
Collaborator

jfoclpf commented Nov 22, 2021

@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

@r000bin97
Copy link

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

@jfoclpf
Copy link
Collaborator

jfoclpf commented Nov 29, 2021

@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

@r000bin97
Copy link

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

@jfoclpf
Copy link
Collaborator

jfoclpf commented Nov 29, 2021

@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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants