5
votes

I have an issue with In App Billing. I am using the helper class from the TrivialDrive sample.
Here is how I implement it.

  1. User presses Remove Ads
  2. Start Helper
  3. Use Listener to detect when helper is setup.
  4. Query Inventory
  5. Use Listener to detect when complete
  6. Check whether purchase has already been made. If so remove ads and exit
  7. If not then launchPurchaseFlow to purchase.

This works fine on one device, however if a user buys on one device then attempts it on another device the second device works as follows:

The helper sets up as normal, then when it checks inventory, it finds no item purchased (I understand there is a delay before this updates). It then attempts to purchase, but says item already bought on the Google play window. This would be fine if I could detect this in code, but it returns to the listener that the user canceled the purchase.

Is there a way to detect that the user has already bought the item using the purchaseFinishedListener?

2

2 Answers

3
votes

The code in the handleActivityResult method returns User Canceled

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);
}

I added the line if (responseCode==BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) result = new IabResult(BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED, "Success");

0
votes

Try this

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new
IabHelper.QueryInventoryFinishedListener() {

public void onQueryInventoryFinished(IabResult result, Inventory inventory) {

    .....................

    if (inventory.hasPurchase(SKU_CONTENT)) {

        mHelper.consumeAsync(inventory.getPurchase(SKU_CONTENT), null);
    }
}

};