Skip to content

Repository files navigation

Android Play Billing Sample (PBL)

A production-ready Android template for Google Play Billing v9 using Kotlin and DataBinding. Supports one-time purchases and subscriptions with a clean, reusable architecture.


🚀 Features

  • One-time Purchase (INAPP) & Subscriptions (SUBS).
  • Reusable BillingManager with auto-service reconnection.
  • Auto-Sync & Restore on app start.
  • Material 3 UI with dynamic localized pricing.
  • Local Persistence for offline premium status.
  • Error Handling for network issues and cancellations.

🛠 Tech Stack

  • Language: Kotlin
  • UI: XML, Material 3, DataBinding
  • Billing: Google Play Billing Library v9.1.0
  • Min SDK: 24

📂 Project Structure

app/
├── billing/
│   ├── BillingManager.kt      # Core Google Play Billing operations
│   ├── BillingConstants.kt    # Product IDs and constants
│   └── BillingListener.kt     # Interface for UI communication
├── data/
│   └── PremiumManager.kt      # Local storage for premium status
└── ui/
    └── PremiumActivity.kt     # Main screen and user interaction

⚙️ Setup Guide

  1. Clone the repository:
    git clone https://github.com/sangidduha/android-play-billing.git
  2. Configure Google Play Console:
    • Create an application in the Play Console.
    • Set up the following Product IDs:
      • INAPP: premium_lifetime
      • SUBS: premium_weekly, premium_monthly, premium_yearly
  3. Upload to Internal Test Track:
    • To test billing, the app must be uploaded to a test track (Internal/Alpha/Beta) and have the same version code as your local build.
  4. License Testing:
    • Add your email to the "License Testing" section in the Play Console to perform test purchases without being charged.

🔄 How to Reuse

This project is designed to be a "plug-and-play" template.

For One-time Purchase (INAPP) only:

  1. Copy BillingManager.kt, BillingConstants.kt, and BillingListener.kt.
  2. Update your Product ID in BillingConstants.kt.
  3. Call makePurchase(activity, id, ProductType.INAPP).

For Subscriptions (SUBS) only:

  1. Follow the same steps as above.
  2. Call makePurchase(activity, id, ProductType.SUBS, basePlanId).

Auto-Sync Strategy:

Professional Android apps should perform a "silent" check for purchases on the Splash Screen or Home Activity. This sets the global premium state before the user encounters ads or locked features. In this sample, this is demonstrated in onBillingLibraryReady.


📜 License

This project is licensed under the MIT License - see the LICENSE file for details.


Created by Syed Sangid Duha

About

Professional Android Billing v9 template (Kotlin/XML). Supports IAP, Subscriptions, and Restore.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages