Illustration my Molly Hensley

Working with Google Play Billing — Part 1

Caren Chang
Android Developers
Published in
3 min readSep 28, 2020

--

For many Android apps, the main source of revenue comes from selling digital content through the app. This can be in the form of selling app-specific items such as coins for a game, or subscription plans that allow users to access premium features for a limited time. The way to implement selling these items in your Android app is with Google Play Billing, a collection of tools and services to help app developers sell digital content.

This blog post is the first in a new series on Google Play Billing 3. We’ll start by exploring the basics and then follow up with examples of more complex use cases and best practices.

Let’s start by getting familiar with some of the key components of Google Play Billing.

  1. Google Play Console — Besides being the place where you publish your Android apps, the Google Play Console is also where you set up the different types of content you want to sell in your app. Through the Play Console, you can configure the items you want to sell, including their price points, and other advanced configurations for each product such as free trial periods for subscriptions.
  2. Google Play Billing Library — This is the library that you integrate into your Android app. Use this library to connect with Google Play to perform tasks such as handling the purchase flow when users buy items.
  3. Google Play Developer API — This is a set of REST APIs that you can use to communicate with Google Play. Using these APIs, you can query and manage the items that your app sells. Among other things, these APIs are useful for verifying that purchases from users are not fraudulent or for checking whether a subscription is still active. We’ll be looking at these APIs more closely in the next post of this series.

In this first post, we’ll focus on setting up your environment to start selling items in your Android app.

  1. The first and most important step is to set up your Android app to use the Google Play Billing library.

Implement Google Play Billing in your app by adding the following dependency in your app/build.gradle file:

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

Once you’ve added the library dependency, build a release APK of your app and upload it to the Google Play Console.

2. Once you’ve uploaded the APK, you can use the Google Play Console to start adding in-app products to sell in your app. Under ‘Store Presence’, you’ll see a section for in-app products. This is where you can set up two types of items:

  • Managed Products (or one-time purchases)
  • Subscriptions

When you create new managed products and subscriptions, you are required to enter a Product ID, or SKU, for the item. This same Product ID is going to be used again later in your application code as we’ll see in the next step. Before creating a managed product, make sure to plan your Product IDs carefully. Product IDs need to be unique for your app, and they can’t be changed or reused after they’ve been created.

To make testing faster and easier, you can add your Google account to the License Testing section of your Google Play Developer Account. This will allow you to test with debug builds and debug signatures as long as the package name matches the APK in the Play Store.

3. Once you have your products set up in the Play Console, you can check to see that the setup was successful by querying for the details of the product in your app.

If everything goes well, you should be able to see details about the product that you just added in the Play Console!

In the next post of the series, we’ll look at how to take users through the purchase flow of a one time product.

If you want to check out resources for Play Billing, you can visit the official documentation here. We also have a collection of samples that demonstrate best practices for implementing the Billing library here. Code samples for this blog post can be found on Github.

--

--