【发布时间】:2013-09-18 14:52:58
【问题描述】:
我想知道应用程序在使用时会在哪些情况下返回一个空数组
AccountManager am = AccountManager.get(this);
Accoun[] accounts = am.getAccountsByType("com.google");
return accounts[0].name
并返回一个空值(或空指针异常)
我问是因为我的应用程序仅在 google play 商店中可用,所以他们需要一个 google 帐户才能访问它。 那么如果应用程序是从 Play 商店下载的(除非他们侧加载它),那么 accountmanager 怎么能不返回类型为 com.google 的帐户。
同样,问题是什么情况会导致 am.getAccountsByType("com.google") 返回空值或空指针异常。
【问题讨论】:
-
我认为这里的关键是“除非他们侧装它”。此外,也可以从 Play 商店安装应用程序,然后删除您的 Google 帐户,尽管我没有尝试过。
-
@CommonsWare 我认为如果他们删除了主要的 Google 帐户,他们也会删除它附带的应用程序?
-
@CommonsWare 我不知道这是否会导致差异,但是如果用户拥有像 person@gmail.es 这样的 gmail 帐户,用户的帐户类型是否可能会有所不同?
-
我从未尝试从
AccountManager检索 Google 帐户信息。我不希望基于 Gmail 域名的行为会发生变化,但谷歌的方式往往是神秘的...... :)
标签: android google-play accountmanager