getAccountsByType 在棉花糖中没有 return 任何东西

getAccountsByType does not return anything in marshmallow

这很奇怪...

正在使用

AccountManager.newChooseAccountIntent(null, null, new String[] {"com.google"}, null, null, null, null);

确实给了我一个帐户列表。但是使用

AccountManager.get(context).getAccountsByType("com.google")

returns 0 个帐户。该问题仅发生在棉花糖中。

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

仍然存在于清单中。

有什么想法...?

更新: 事实证明,必须请求 GET_ACCOUNTS 的许可,即使文档另有说明......(见评论)

根据这个 g+ post https://plus.google.com/+BrendonSled/posts/jdrHS3GC7c6 权限 GET_ACCOUNTS 现在被列为危险并且用户必须允许它

对于来到这里的任何人,真正的答案是 here

简而言之,你需要使用AccountManager.newChooseAccountIntent() (ref)