Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top