Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In App Billing V3

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?

like image 938
Dandroid Avatar asked Oct 21 '22 02:10

Dandroid


1 Answers

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

like image 80
Dandroid Avatar answered Oct 27 '22 17:10

Dandroid