【问题标题】:Error You Already Own This Item错误您已经拥有此项目
【发布时间】:2016-08-18 21:30:06
【问题描述】:

我有一个新的 android 应用程序,我在其中添加应用程序内计费,我沮丧地撕毁了我的头发。

我上传了一个签名的 APK 并发布到 alpha。我创建了一组应用内产品并将它们全部激活。我创建了一个新的 gmail 帐户,并将它们定义为应用程序 apk 页面上的应用程序测试人员。 我已将我的 android 手机恢复出厂设置,并使用新的 gmail 帐户对其进行了初始化。我已将 /apps/testing 链接输入到 chrome 并注册为测试人员。然后我下载并安装了我的应用程序。在我的应用程序中,我询问了可用的应用程序内产品,并显示了我在上面创建的集合。我选择了一个购买并经历了以下购买过程。 1.屏幕显示要购买的产品和价格,并要求按继续,我这样做 2.屏幕显示付款方式,我选择兑换码 3.屏幕显示兑换您的代码,我输入我之前在开发者控制台中设置的促销代码之一(上面没有提到 - 对不起),然后按兑换 4.屏幕再次显示产品,这次价格被划掉并提供添加我选择的项目的选项(很奇怪被要求再次添加购买嘿嘿) 5.屏幕显示添加的项目 6. 几秒钟后屏幕显示错误您已经拥有此项目。

这怎么可能,这个用户在十分钟之前都不存在,并且只使用过这个应用程序一次。

我在堆栈溢出和其他类似的地方看到了很多问题,并尝试了所有方法,清除 google play 商店缓存,清除 google play 商店数据等。上面描述的这个序列是我在完全干净的情况下使用完全干净的用户的最新尝试电话。

我可以上传我使用的应用程序代码,但没有抓住重点,当这个 gmail 帐户以前从未从任何人那里购买过任何东西时,这个 gmail 帐户怎么可能已经拥有一个项目。这肯定是一个错误。

非常欢迎所有关于如何进行的线索。现在添加了代码,请注意这是一个混合 Android 应用,用户购买决策代码在 javascript/html 中,应用内操作在下面的包装器代码中

private void processCommand(JSONObject commandJSON) throws JSONException
    {
    String command = commandJSON.getString("method");
    if ("GetInAppProducts".equals(command))
        {
        Log.d(TAG, "Querying Inventory");
        InAppPurchaseSkuString = null ; // clear the purchased sku. Note this is tested in mConsumeFinishedListener
        mHelper.queryInventoryAsync(true, itemSkus, new IabHelper.QueryInventoryFinishedListener()
            {
            @Override
            public void onQueryInventoryFinished(IabResult iabResult, Inventory inventory)
                {
                InventoryRecord = inventory ;
                if (iabResult.isFailure())
                    {
                    Log.d(TAG, "Query inventory failed");
                    SendEndItemsToApp ();
                    }
                else
                    {
                    Log.d(TAG, "Query inventory was successful.");
                    InventoryCheckCount = 0 ; // seems that we cannot just fire off a whole lot of these checks at the same time, so do them in sequence
                    if (itemSkus.size()>0) { CheckForOwnedItems (); } else { SendEndItemsToApp (); }
                    }
                }
            });

        }
    else if ("BuyInAppProduct".equals(command))
        {
        JSONArray params = commandJSON.getJSONArray("parameters");
        InAppPurchaseSkuString = params.getString(0);
        Log.d(TAG, "User decision to purchase " + InAppPurchaseSkuString);
        mHelper.launchPurchaseFlow( MainActivity.this, InAppPurchaseSkuString, InAppPurchaseActivityCode, mPurchaseFinishedListener, "mypurchasetoken"); // consider putting the user email address in the last field - need to get from app
        };
    }//end of ProcessCommand


public void CheckForOwnedItems ()
    {
    Log.d(TAG, "Pre Purchase Inventory Processing Started");
    String sku = itemSkus.get(InventoryCheckCount);
    if (InventoryRecord.getSkuDetails(sku) != null)
        {
        if (InventoryRecord.hasPurchase(sku))
            {
            consumeItem ();
            }
        else
            {
            SendItemToApp ();
            InventoryCheckCount++;
            if (InventoryCheckCount < itemSkus.size()) { CheckForOwnedItems (); } else { SendEndItemsToApp (); }
            };
        };
    }//end of CheckForOwnedItems

public void SendItemToApp ()
    {
    String sku = itemSkus.get(InventoryCheckCount);
    String priceString = InventoryRecord.getSkuDetails(sku).getPrice().replaceAll("[^\\d.]+", ""); // RegExp removes all characters except digits and periods
    String infoString = "InAppProductDetails('" + sku + "','" + "dummy" + "','" + priceString + "');"; // dummy is a placeholder for product description which is not (yet?) used in the app
    Log.d(TAG, infoString);
    mWebView.evaluateJavascript (infoString, new ValueCallback<String>()
            {
            @Override
            public void onReceiveValue(String s)
                {
                //Log.d(TAG,"Returned from InAppProductDetails:");
                }
            }
        );
    }

public void SendEndItemsToApp ()
    {
    String endString = "InAppProductsEnd();"; // name is a placeholder for now
    Log.d(TAG, endString);
    mWebView.evaluateJavascript(endString, new ValueCallback<String>()
            {
            @Override
            public void onReceiveValue(String s)
                {
                //Log.d(TAG,"Returned from InAppProductsEnd:");
                }
            }
        );
    }

public void consumeItem()
    {
    Log.d(TAG,"Pre Purchase Inventory Query Started");
    String sku = itemSkus.get(InventoryCheckCount);
    mHelper.consumeAsync(InventoryRecord.getPurchase(sku), mConsumeFinishedListener);
    }

IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener()
    {
    public void onConsumeFinished (Purchase purchase, IabResult result)
        {
        if (result.isSuccess())
            {
            Log.d(TAG, "Pre Purchase Consume Item Completed");
            SendItemToApp ();
            InventoryCheckCount++;
            if (InventoryCheckCount < itemSkus.size()) { CheckForOwnedItems (); } else { SendEndItemsToApp (); }

            }
        else
            {
            Log.d(TAG,"Pre Purchase Consume Item Failed");
            }
        }
    };

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener()
    {
    public void onIabPurchaseFinished (IabResult result, Purchase purchase)
        {
        if (result.isFailure())
            {
            Log.d(TAG,"Purchase Scenario Failed");
            }
        else if (purchase.getSku().equals(InAppPurchaseSkuString))
            {
            Log.d(TAG,"Purchase Scenario Completed");
            String evalString = "InAppProductPurchased('" + InAppPurchaseSkuString + "');";
            Log.d(TAG, evalString);
            mWebView.evaluateJavascript (evalString, new ValueCallback<String>()
                        {
                        @Override
                        public void onReceiveValue(String s)
                            {
                            Log.d(TAG, "Returned from InAppProductPurchased:");
                            }
                        }
                );
            }
        }
    };

【问题讨论】:

  • 代码会很好。使用 Android 5+,您无需重置手机,只需添加用户即可。
  • 你找到解决办法了吗?
  • 是的,请看下面我的回答

标签: android in-app-billing


【解决方案1】:

我发现在使用 paypal(即真钱)进行购买时不会出现此错误,因此我认为此“错误您已拥有此商品”消息在某种程度上与使用促销代码有关考试。并且(到目前为止)我的贝宝帐户没有被收费(因为我是该应用程序的注册测试员)。

【讨论】:

    猜你喜欢
    • 2021-09-16
    • 1970-01-01
    • 2021-02-17
    • 2013-05-27
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 2013-10-12
    • 1970-01-01
    相关资源
    最近更新 更多