0

After following this tutorial and going through this, I was able to implement the in-app billing.

One question that I have is when the user starts the app, do I have to check every time that the he/she has purchased the item? What is a good way/correct way to do it (so that it does not delay the first Activity, and has all the purchased items accessible in the first activity as well?

There is a getPurchases() here, which has been used in the IabHelper class inside the int queryPurchases(Inventory inv) function. Is that it?

rgamber
  • 5,749
  • 10
  • 55
  • 99
  • Check my answer from here [Library is doing for you](https://stackoverflow.com/questions/8735931/how-to-implement-in-app-billing-in-an-android-application/60977881#60977881) – Ucdemir Apr 01 '20 at 18:36

1 Answers1

3

The getPurchases() is used to retrieve a list of purchases that the user has made with a Google account. This primarily helps in restoring the user's purchase(if any) after, say the user has reset his phone to factory settings. This list is retrieved from the Google Play's app cache / from the network.

With In-app Billing version 3, the call to getPurchases() returns with the list of purchases(those that are not consumed) fairly quickly. But occassionally it may take some time for the Google play app to fetch the purchase list (if you clear the GP app's cache and app data, it has to fetch the purchases from your account which will involve a network operation, so there will be some delay).Otherwise, the response will be instantaneous.

So, It would be good to save the 'purchase state' of your in-app-item locally in the Shared Preference or in a file on your device. This way you can quickly check if the in-app item has been purchased. And it would be good to check your item's purchase state, every time your app starts.

Community
  • 1
  • 1
siddharthsn
  • 1,709
  • 1
  • 21
  • 32
  • It would be good to save it locally from a performance point of view, but otherwise it seems very insecure to store it in a text file. I will update my question to say this more appropriately. – rgamber Jan 20 '14 at 00:55
  • Thats true, Even with the Shared Preferences with MODE_PRIVATE, the user can access the file if the device is rooted. In this case you might want to think about encrypting your file. Alternatively, you can just rely on Google Play to fetch the purchase information and verify it. – siddharthsn Jan 20 '14 at 01:15
  • Google Play app always stores the updated details of your purchase in its cache. Unless you clear the GP app's cache the getPurchases() is reliably quick. – siddharthsn Jan 20 '14 at 01:17
  • Yes, I was just testing it. Checking with Google Play every time works fine, but I was wondering how other developers approach this. Is it reliable/fast enough for me to completely rely on just that (checking with GP everytime)? – rgamber Jan 20 '14 at 01:42
  • 1
    Yes, It will be fine. Only when you clear the Google Play App's cache and then try to call GetPurchases(), there will be a delay. – siddharthsn Jan 20 '14 at 06:37