如何在调用 Google Billing 功能之前检查用户是否已在设备上登录 Google Play 帐户

问题描述

我正在尝试通过调用 https://developer.android.com/reference/com/android/billingclient/api/BillingClient#queryskudetailsasync

从 Google Play 商店获取应用内购买的价格

但是,如果用户没有登录 Google 帐户(或需要在 Google Play 应用程序中再次登录),请求将失败,但计费响应代码将为 BillingResponseCode.SERVICE_disCONNECTED(我无法区分Google Play 服务实际上在设备上失败了,或者他们只是没有登录。我想为用户提供更清晰的说明以帮助他们解决问题)

在我们的遗留代码

        if (ContextCompat.checkSelfPermission(getContext(),permission.GET_ACCOUNTS)
                != PackageManager.PERMISSION_GRANTED) {
            // We have no way of kNowing whether the user is logged into a google account so
            // default to yes
            return true;
        }

        Account[] list = mAccountManager.getAccounts();

        for (Account account : list) {
            if (account.type.equalsIgnoreCase(GOOGLE_ACCOUNT_TYPE)) {
                return true;
            }
        }

        return false;

然而,它现在在权限部分经常失败,即使我删除了权限检查,其余的逻辑仍然有效......(而 checkSelfPermission 正在返回 PERMISSION_DENIED......)

我找到了另一个替代建议,即使用 GoogleSignIn,但这是一个 auth Api,所以我想知道是否有任何副作用

return GoogleSignIn.getLastSignedInAccount(context) != null

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)