1

I want to disable ads in an app whenever a user purchases a consumable virtual currency item. Is there any was to check if a consumable purchase has been bought before - from the documentation it looks like the status of the purchase is set to unowned once consumed.

eamo
  • 23
  • 2

2 Answers2

1

use queryPurchaseHistoryAsync(...)

Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.

And check if any of the Purchase.sku's in the response match the SKU...of the item you care about.

Eric
  • 16,397
  • 8
  • 68
  • 76
0

According to the documentation, you are correct - getPurchases() will only return the un-consumed purchases.

A way around this would be storing a boolean in your SharedPreferences for each item purchased. When you read the value, set the default to false.

SharedPreferences myPrefs = getSharedPreferences(MY_SHARED_PREFS, Context.MODE_PRIVATE);
boolean isPurchased = myPrefs.getBoolean(PURCHASED_ITEM_001, false);
ImmortalDev
  • 476
  • 3
  • 5
  • Thanks, this seems to be the only way. Was hoping to avoid this as the SharedPreference will be lost with an uninstall. – eamo Jun 13 '14 at 16:56
  • 2
    I know it's been quite some time, but I was looking for an alternative because setting a preference does not account for refunds. Unfortunately, we now have a society of people that purchase items and perform chargebacks to keep the item without paying. – Abandoned Cart Jan 19 '19 at 15:09
  • 1
    This is not correct, since user can reinstall the app and you will lost this SharedPreferences and his/her previous purchase will come up as active. Check out; https://stackoverflow.com/a/55211744/1847645 – Berkay Turancı Mar 19 '19 at 18:15