korchix
korchix

Reputation: 1700

How to check if the user has bought a subscription

in my android app i implemented the in App-Billing, where the user can buy a subscription in the app. when the user launch the app, i want to check if he has any subscription at all, to decide which content should i show him. i'm using the latest in-app-billing library implementation 'com.android.billingclient:billing:1.1' thank you in advance for the help

Upvotes: 4

Views: 3971

Answers (2)

korchix
korchix

Reputation: 1700

my goal was to find out, if the user has a subscription at all. i have resolved it like this.

    mBillingManager = new BillingManager(this);

    Purchase.PurchasesResult  purchasesResult = mBillingManager.getPurchaseMadeByUser();
    if(purchasesResult.getResponseCode() == BillingClient.BillingResponse.OK && (purchasesResult.getPurchasesList() != null)){
        hasSubscription = true;
    }

and everywhere in the app, i check if hasSubscription == true then don't load the ads.

to set up the In-App Billing in my App, i followed this Tutorial from Google : https://codelabs.developers.google.com/codelabs/play-billing-codelab/#0

Upvotes: 2

Kishan Vaishnav
Kishan Vaishnav

Reputation: 2631

You have two options

  1. Create a WebAPI as Google suggest having a separate server which tracks users purchases and communicates with the Google APIs. Refer LINK.
  2. Use Google's InApp billing library to get users subscription.

Refer this answer. It will give you some idea of In-app purchase workflow.

I also suggest you go through some articles about InApp purchase.

  • Tutorial: How to Implement In-app Billing in Android LINK
  • Article on implementing InApp purchase LINK.
  • How to verify purchase for android app in server side (google play in app billing v3) LINK.
  • Another SO answer LINK
  • Another SO answer LINK
  • Code Project Sample LINK.

Upvotes: 2

Related Questions