getAccountsByType does not return anything in marshmallow

对着背影说爱祢 提交于 2019-12-05 17:41:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!