Search code examples
androidin-app-purchasegoogle-playbilling

How to modify sample in-app billing app to enable paid functions?


Let's say I provide 2-in-1 app: free and paid version. If user paid, then he gets additional functions available in the application.

To simplify the task and understanding, I took sample application. Then, I've added one more button to the main screen (this is our 'paid' function) - this button is disabled by default. If user paid for Potion (in the sample application), then this button should be enabled.

So, the following questions I have:

  1. Which functions should be modified in the sample app to enable button once user paid? To simplify the task more, we can assume that user can buy only Potion, nothing more. Looks like it is not enough to add myButton.setEnabled(true) to onPurchaseStateChange / if (purchaseState == PurchaseState.PURCHASED) only. Also, I need to have this button enabled after application start if user paid. Should I do it in restoreDatabase? Do I need to call this restoreDatabase in onStart() also?
  2. The same question is about button disabling - where should I do this?
  3. Once button is enabled, if user presses it, I need to verify that user really paid for the application (don't rely just on database value) - looks like I should call RESTORE_TRANSACTIONS. Then based on result either show warning and disable button, or allow further actions.

Solution

  • Usage of AndroidBillingLibrary simplifies the task.