Android

This guide describes how to add and use Apphud SDK to your Android app.

Features

Currently we support the following features for Android:

  • Only Google Play Store is currently supported

  • Auto-renewing subscriptions validation and renewals tracking

  • One time purchases validation

  • Refunds / Revokes tracking

  • Grace Period and On Hold states are supported

  • Fraud detection (basically verifying that purchase is valid and doesn't belong to another user)

  • Promo-Codes are supported

  • Introductory Prices are supported

  • Integrations with 3rd party services

  • Cross Platform is supported

  • If purchase is made through SDK's billing method, then it will be acknowledged / consumed by SDK.

Requirements

Apphud SDK requires minimum Android 4.1 and supports only Google Play store.

‚ÄčGoogle Play Service Account Credentials file is required to be uploaded to Apphud.

Installation

Add the following lines to your build.gradle file:

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.apphud:ApphudSDK-Android:0.3'
}

Initialize SDK

To initialize Apphud SDK you will need API Key. It is a unique identifier of your Apphud application. You can get it in your Apphud application settings under General tab.

Basic initialization looks like this:

Kotlin
Java
Kotlin
Apphud.start(this, "API_KEY")
Java
Apphud.start(this, "API_KEY");

Initialize with Custom User ID

There is additional parameter which sets custom user id:

Kotlin
Java
Kotlin
Apphud.start(this, "API_KEY", "custom_user_id")
Java
Apphud.start(this, "API_KEY", "custom_user_id");

Handle In-App Purchases

You are not required to use Apphud purchase method. If you purchase products by yourself, then you should sync purchases with Apphud. So there are two options:

Purchase using Apphud Billing Client

To make a purchase call:

Kotlin
Java
Kotlin
Apphud.purchase(activity, skuDetails) { _ -> }
Java
Apphud.purchase(activity, skuDetails, purchases -> { return null;});

At the launch of the app Apphud automatically fetches SKU Details for products that are added in Apphud dashboard. You can set ApphudListener and implement the following method:

fun apphudFetchSkuDetailsProducts(details: List<SkuDetails>)

Store array of SkuDetails somewhere in your app.

If using Apphud Billing Client all purchases will be acknowledged or consumed automatically.

Observer Mode

If you use your own billing then you should sync purchases each time user makes any purchase or restoration. Just call after purchase or restore:

Kotlin
Java
Kotlin
Apphud.syncPurchases()
Java
Apphud.syncPurchases();

Keep in mind, that you are responsible for acknowledging or consuming all purchases in observer mode!

Check Subscription Status

Kotlin
Java
Kotlin
Apphud.hasActiveSubscription()
Java
Apphud.hasActiveSubscription();

Returns true if user has active subscription. Use this method to determine whether to unlock premium functionality to the user.

This method works regardless of which billing you are using for purchases.

Migrate existing purchases

If you need to migrate existing purchases in case you already have a live app or if you need to restore purchases when user hits Restore button, just call syncPurchases() method.

Kotlin
Java
Kotlin
Apphud.syncPurchases()
Java
Apphud.syncPurchases();

Do not migrate purchases on every app launch. One successful time is enough. Store flag in your app if purchases were successfully migrated.

Match User IDs for integrations

Some integrations require you to match user ids between Apphud and corresponding integration. Please see documentation for your integration for details.

Cross Platform Support

If you have both iOS and Android apps you should decide whether you need cross platform support or not. This is basically means adding both platforms in one Apphud app rather than creating two different apps for each platform. Cross platform support has prons and cons.

When you should choose cross platform support?

If you added both platforms in one app, you will get:

  • Ability to have single subscription per user. If you have your own login system, you can use Apphud for cross-platform subscription support. If user purchases subscription on iOS, he will get that premium subscription on Android as well (if Apphud SDK started with the same user id).

  • One dashboard for both apps. You will be able to see summarised revenue in dashboard and charts.

When you should NOT choose cross platform support?

  • You don't have login system in your apps. So users from two platforms can't be merged.

  • You don't want Android app revenue to be shared with iOS app revenue. This might be useful, if you have different Apphud Members on each platform.

  • You don't want to have universal dashboard or charts.

Later this fall, we will add more filters in dashboard and charts so you can split data across platforms.