gpt4 book ai didi

android - 客户经理为 com.google 返回空值

转载 作者:行者123 更新时间:2023-11-29 00:26:38 26 4
gpt4 key购买 nike

我想知道在哪些情况下应用可以在使用时返回一个空数组

AccountManager am = AccountManager.get(this);
Accoun[] accounts = am.getAccountsByType("com.google");
return accounts[0].name

并返回一个空值(或空指针异常)

我问是因为我的应用程序仅在 Google Play 商店中可用,所以他们需要一个 Google 帐户才能访问它。那么,如果应用程序是从 Play 商店下载的(除非他们加载它),客户经理怎么能不返回 com.google 类型的帐户。

同样,问题是什么情况会导致 am.getAccountsByType("com.google") 返回空值或空指针异常。

最佳答案

尝试使用以下代码检查 Google 帐户是否存在。我在我的应用程序中使用它来检查该帐户是否存在。这行得通。

public static boolean isGoogleAccountPresent() {

AccountManager manager = AccountManager.get(context);
for(Account account : manager.getAccounts()) {
if("com.google".equals(account.type)) {
return true;
}
}
return false;
}

关于android - 客户经理为 com.google 返回空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18875580/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com