android - InAppBilling v3 IabResult 响应代码 BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED

标签 android in-app-purchase in-app-billing in-app

根据开发者网站上的文档,我最近在我的应用程序中实现了 InAppBilling v3。我使用了 TRIVIAL DRIVE 示例中提供的 utils 包中的类。

我面临的问题是,如果用户已经在另一台设备上再次启动购买流程时购买了应用内产品,Play 商店对话框会显示 ITEM ALREADY OWNEDIabResult 与常量 IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED 不匹配。返回的响应代码实际上是 IabHelper 类中的错误代码之一(-1005 用户已取消)。

我真的很想知道如何获得实际的响应代码而不是错误代码。任何帮助,将不胜感激。

回调代码如下

// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener =
        new IabHelper.OnIabPurchaseFinishedListener() {
            public void onIabPurchaseFinished(IabResult result, Purchase purchase) {

                if (result.isFailure()) {
                    if (result.getResponse() ==
                            IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                        //already owned
                        boolean isPremium = true;
                        SharedPrefsUtils.setPremium(BaseActivity.this, isPremium);
                        EventBus.getDefault().post(new InAppBillingUiUpdateEvent(isPremium));
                        //setWaitScreen(false);
                        return;
                    }
                    //handle error
                    complain(result.getResponse() + " " + "Error purchasing: " + result);
                    //setWaitScreen(false);
                    return;
                }
                if (!verifyDeveloperPayload(purchase)) {
                    //corrupted
                    complain("Error purchasing. Authenticity verification failed.");
                    //setWaitScreen(false);
                    return;
                }

                //successful
                if (purchase.getSku().equals(NO_ADS_PRODUCT_ID)) {
                    // bought the premium upgrade!
                    alert("Thank you for upgrading to premium!");
                    boolean isPremium = true;
                    SharedPrefsUtils.setPremium(BaseActivity.this, isPremium);
                    EventBus.getDefault().post(new InAppBillingUiUpdateEvent(isPremium));
                    //setWaitScreen(false);
                }
            }
        }; 

最佳答案

我终于设法在 IabHelper 代码中找到了问题,所以只要在 handleActivityResult 中返回 Activity.RESULT_CANCELED 结果代码,它就会出现> 所有此类情况的 IabResult 方法都已通过 用户取消 (-1005) 修复,无论原因是什么。因此,为了获得正确的实际响应代码,请在 handleActivityResult

中替换以下代码
 else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled.");
        if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null);
    }

有了这个

 else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        result = new IabResult(responseCode, null);
        if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null);
    }

希望它能节省一些人的时间

关于android - InAppBilling v3 IabResult 响应代码 BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31533335/

相关文章:

android - 如何在 React Navigation 中创建屏幕下推

android - 我的顶点只显示一个三角形?

android - 为什么 Realm 会为所有的模型类生成代理类?

iOS IAP paymentQueue :updatedTransactions

使用同一测试帐户在多台设备上进行 Android 应用内结算 v3 测试

android - 应用内结算错误

android - Google Play Android 开发者 API

android - CalledFromWrongThreadException 使用基于 PhoneGap 的 Activity 修改 View

iOS IAP 订阅定时炸弹

google-play - PWA 的应用内购买 - Google Play 商店和 Apple 商店