问题
Now this is odd...
Using
AccountManager.newChooseAccountIntent(null, null, new String[] {"com.google"}, null, null, null, null);
does give me a list of accounts. But using
AccountManager.get(context).getAccountsByType("com.google")
returns 0 accounts. The problem only happens in marshmallow.
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
still exists in the manifest.
Any ideas...?
UPDATE: Turns out, must ask permission for GET_ACCOUNTS, even though docs say otherwise... (see comments)
回答1:
According to this g+ post https://plus.google.com/+BrendonSled/posts/jdrHS3GC7c6 permission GET_ACCOUNTS is now listed as dangerous and user has to allow it
回答2:
For anyone getting here, the real answer is here
in short, you need to use AccountManager.newChooseAccountIntent()
(ref)
来源:https://stackoverflow.com/questions/32162164/getaccountsbytype-does-not-return-anything-in-marshmallow