Support promo codes in your app
To support promotion codes, your app must call the
queryPurchases() method whenever the app starts or resumes. This method returns a bundle of all current, unconsumed purchases, including purchases the user made by redeeming a promo code. The simplest approach is to call queryPurchases() in your activity's onResume() method, since that callback fires when the activity is created, as well as when the activity is unpaused. Calling
queryPurchases() in onStart() and onResume() guarantees that your app finds out about all purchases and redemptions the user may have made while the app wasn't running. Furthermore, if a user makes a purchase while the app is running and your app misses it for any reason, your app still finds out about the purchase the next time the activity resumes and calls
queryPurchases().
Your Activity's
onPurchasesUpdated() method receives a response intent identifying when a purchase is completed. However, your app should still call
queryPurchases() in onStart() and onResume(), in the case the purchase and consumption workflow didn't complete. For example, if the user successfully redeems a promo code and then your app crashes before the item is consumed, your app still receives information about the purchase when the app calls
queryPurchases() on its next startup.
Your app should also support the scenario where a user redeems a promo code in the Play Store app while the app is running. Your app can find out about the redemption through the
onPurchasesUpdated() listener.