In App Purchase in Android (Part 1)

Tram Ho

This can be in the form of selling app-specific items or subscriptions that allow users to access premium features for a limited time,

To be able to implement this feature, I would like to introduce to you Google Play Billing – a service that allows you to pay for products in your app.

Main ingredients of google play billing:

  • Google Play Console: where you can set up the types of products that will be sold on your app as well as subscription plans.
  • Google Play Billing Library: is the library that will need to be integrated into your android application
  • Google Play Developer API: set of APIs that you use to communicate with google play. can query and manage the items to be sold. In addition, using the api can also verify that the user has actually bought the product or is cheating or checking whether it is still working or not.

Now, let’s get into setting up the environment for In App Purchase.

  1. First we need to set up the Google Play Billing Library for your app.

Add dependency in /build.gradle

implementation ‘com.android.billingclient: billing: 3.0.0’

To be able to create items that can be purchased on the google console, we need to upload an apk containing the Google Billing library to the console. So after adding Google Billing library, build an apk version and upload it to the play console.

  1. Once you’ve uploaded the apk to the play console, you’ll be able to create products and packages to be sold in the GooglePlay Console. When creating a new product, you are asked to enter the product id for that item. This product id will not be duplicated and cannot be changed after creation.
  2. After you have finished setting up the products and packages to be sold, you can query whether the products or packages were successful or not as follows:

Once successful, you will get information about the products to be sold. Details of this information can be found at SkuDetails

To understand INAPP and SUBS as well as the difference between them, take a look at Google Billing Overview

Above I have shown you how to set up the environment, create products and query for products for sale. The next article I will guide you to pay when users buy the product.

Thank you for reading the article!

Share the news now

Source : Viblo