0

I have used Billing client to handle inapp purchase. Once a non-consumable product is purchased, after acknowledging I can save a value in shared preferences.

Constraints If the user clear the app data or uninstall the app, It will be lost. How to handle this scenario.

Note I am not convinced to save it in cloud. pls suggest how to fetch it from Google play each time the app starts using billing Client.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
venkatesh
  • 319
  • 2
  • 10

2 Answers2

0

You should call billingClient.queryPurchases() to get what items the user owns when the app is first started after installation.

Then you can save it in SharedPreferences but I recommend to call billingClient.queryPurchases() periodically to update the list. This is still more important if the item is a subscription to know if it is still active or has expired.

And do not forget to verify the signature of the data received to avoid fraud.

from56
  • 3,976
  • 2
  • 13
  • 23
0

Ok,

You should call billingClient.queryPurchases() to get what items the user owns when the app is first started after installation.

But billingClient.queryPurchases() according to documentation:

Only active subscriptions and non-consumed one-time purchases are returned.

So how you get the purchased, already consumed items (not subscriptions but IAP)?

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30920640) – manuna Jan 31 '22 at 17:58