Android cannot restore in-app purchases (v3) items

I implemented successfully when purchasing the app and it worked well, but whenever I tried to restore previously purchased items, the queryInventory () method always returns empty inventory. Any solutions?

How I tested:

  • I used a random android device, downloaded my app from the play store, bought the item, uninstalled the app, downloaded the app again, bought the same item (with the same account), charged me again.

  • Connected to eclipse with a test device and a test account, purchased some items and then checked logbat adb queryInventory (), the inventory list returned size = 0, but returned successfully ("BILLING_RESPONSE_RESULT_OK (0)").

Inventory Request Code:

mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (!result.isSuccess()) {
                    logDebug("mHelper setup failed.");
                    complain("Problem setting up in-app billing: " + result);
                    return;
                }

                logDebug("mHelper setup successful. Querying inventory....");
                mHelper.queryInventoryAsync(mGotInventoryListener);
            }
        });

      

Get the query result code:

     // Listener that called when we finish querying the items we own
    IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
            if (result.isFailure()) {
                logDebug("Query inventory failed.");
                complain("Failed to query inventory: " + result);
                return;
            }

            logDebug("Query inventory was successful.");

            // Check for items delivery
            for( int i = 0; i < purchaseOptions; i++ ) {
                if (inventory.hasPurchase(SKU_ITEMS[i])) {
                    logDebug("We have " + SKU_ITEMS[i] + " restored.");
                    mHelper.consumeAsync(inventory.getPurchase(SKU_ITEMS[i]), mConsumeFinishedListener);
                    return;
                }
            }
        }
    };

      

+3


source to share





All Articles