In the Billing V3 application

I have a problem with In App Billing. I use the helper class from the TrivialDrive example.
This is how I implement it.

  • Press User Delete Ads
  • Initial assistant
  • Use a listener to determine when an assistant is configured.
  • Inventory of requests
  • Use listener to detect when completed
  • Check if a purchase has been made. If so remove the ad and exit
  • If not, runPurchaseFlow to purchase.

This works fine on one device, however, if a user purchases on one device and then tries on another device, the second device works as follows:

The assistant is configured as usual, then when he checks the inventory, he does not find the purchased item (I understand that there is a delay before this update). Then he tries to purchase, but says that the item has already been purchased in the Google game window. It would be nice if I could detect this in the code, but it returns to the listener that the user has canceled the purchase.

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

+4
source share
2 answers

The code in the handleActivityResult method returns the user with cancellation

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

+2
source

try it

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

};

0
source

Source: https://habr.com/ru/post/1498765/


All Articles