Skip to content
Advertisement

How to verify user purchase for a non-consumable product on app launch

I just completed setting up inapp billing using google play billing with aidl. On successful purchase the premium feature is activated through a boolean. But after the app is closed and relaunched, premium feature disappears. i.e the boolean reverts to false. I would like to know how to ensure the boolean stays as true after app launch as long as premium has been purchased.

On MainActivity

JavaScript

}

On InAppBilling Activity

JavaScript

}

JavaScript

Advertisement

Answer

In your purchase finish listener, modify below code to store value into shared preferance.

JavaScript

And on app relaunch get this value from shared preference again.

JavaScript

Update(19 Feb, 2022):

  • As @Shazniq said, It’s always good to store those details on the server for safety, along with user profile data. So on every launch of the app, you can verify the details. You have to apply your own logic to verify it whenever you need it.
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement