Android IabHelper.queryInventoryAsync方法返回不正确的产品信息

时间:2013-07-30 17:56:39

标签: java android in-app-purchase google-play in-app-billing

我正在Android应用中实施应用内购买。我在Google Play开发者控制台中设置了应用并设置了多个产品。

我根据Android文档将IabHelper及相关的结算文件添加到我的代码库中。我能够成功setup

        String base64EncodedPublicKey = Configurations.getInstance().getGooglePlayLicenseKey();
        googlePlayHelper = new IabHelper(AtavistApplication.getContext(), base64EncodedPublicKey);
        googlePlayHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (!result.isSuccess()) {
                    Utilities.log("Unable to setup billing: " + result);
                    isBillingSetup = false;
                } else {
                    Utilities.log("Billing setup successfully");
                    isBillingSetup = true;
                }
            }
        });

但是当我向Google Play查询产品信息时如下:

   IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result, Inventory inventory)
        {
            if (result.isFailure()) {
                Utilities.log("getProducts failed");
                callback.failure(null);
            } else {
                Utilities.log("getProducts succeeded");
                callback.success(inventory);
            }
        }
    };

    googlePlayHelper.queryInventoryAsync(true, identifiers, mQueryFinishedListener);

其中identifiers是字符串产品标识符的列表:

    ArrayList<String> productIDs = new ArrayList<String>();
    productIDs.add("com.first.product");
    productIDs.add("com.second.product");
    productIDs.add("com.third.product");

我得到一个成功的回复,其中只包含一个产品,而该产品不是我在Google Play帐户中设置的产品。它的productID是我们之前提供的产品的productID,但它刚刚从Google Play活动产品列表中删除。

问题:

  1. 为什么queryInventoryAsync没有返回正确的列表?
  2. 为什么它会返回目前尚未在Google Play中设置的产品?
  3. 我是否遗漏了导致这种混淆的一些基本配置步骤?

1 个答案:

答案 0 :(得分:0)

事实证明,我上传到Google Play开发者控制台(在设置产品之前)的apk与我正在构建和测试的codebase / apk之间存在一些不一致。

具体来说,捆绑包标识符(包名称)不同,它们使用不同的密钥库进行签名。

不知道为什么这会返回一个看似有效的产品而不是一个明确的错误,但是将两个apks排成一行就解决了这个问题。