How can i get information about in-app-purchases in Google Play Billing for android

Mohd Naushad

I want to get information about how to get detail of already Purchases product with or without internet connection in android studio.

As i know, in google play billing library has 2 method for retrieving the information.

1. PurchasesResult purchasesResult = billingClient.queryPurchases(SkuType.INAPP);

2. billingClient.queryPurchaseHistoryAsync(SkuType.INAPP,
                                         new PurchaseHistoryResponseListener() {
    @Override
    public void onPurchaseHistoryResponse(BillingResult billingResult,
                                          List<Purchase> purchasesList) {
        if (billingResult.getResponseCode() == BillingResponse.OK
                && purchasesList != null) {
            for (Purchase purchase : purchasesList) {
                // Process the result.
            }
         }
    }
});

But i don't know how to retrieve the information.

Anupam
This is the way I have implemented In-App Purchase. It is working smoothly. Hope it helps.

mBillingClient = BillingClient.newBuilder(this).setListener(new PurchasesUpdatedListener() {
            @Override
            public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {

                //  Log.d("anupam", responseCode + "");
                if (responseCode == BillingClient.BillingResponse.OK && purchases != null) {
                    for (Purchase purchase : purchases) {
                    //List of purchases
                    }
                } else if (responseCode == BillingClient.BillingResponse.USER_CANCELED) {
                    Toast.makeText(SplashActivity.this, "Sorry, you have canceled purchase Subscription.", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(SplashActivity.this, "Sorry, some error occurred.", Toast.LENGTH_SHORT).show();
                }
            }
        }).build();

        mBillingClient.startConnection(new BillingClientStateListener() {
            @Override
            public void onBillingSetupFinished(@BillingClient.BillingResponse int billingResponseCode) {

                if (billingResponseCode == BillingClient.BillingResponse.OK) {
                    // The billing client is ready. You can query purchases here.

                    final Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.SUBS);
                    for (Purchase sourcePurchase : purchasesResult.getPurchasesList()) {
                        if (sourcePurchase != null) {

                            ConsumeResponseListener listener = new ConsumeResponseListener() {
                                @Override
                                public void onConsumeResponse(final int responseCode, final String purchaseToken) {
                                    // Log.d("anupam2", responseCode + "  <------->  "+ purchasesResult.getPurchasesList() + "  <------->  " + purchaseToken);
                                }
                            };
                            mBillingClient.consumeAsync(sourcePurchase.getPurchaseToken(), listener);
                        } else {

                        }
                    }

                    if (purchasesResult.getPurchasesList().size() > 0) {
                        //  Log.d("anupam3", purchasesResult.getPurchasesList().size() + "");

                    } else {
                        //  Log.d("anupam4", purchasesResult.getPurchasesList().size() + "");
                        BillingFlowParams.Builder builder = BillingFlowParams.newBuilder().setSku("234r23446").setType(BillingClient.SkuType.SUBS);
                        int responseCode = mBillingClient.launchBillingFlow(SplashActivity.this, builder.build());
                        if (responseCode == 7) {

                            //Item already purchased
                        }
                    }
                }
            }

            @Override
            public void onBillingServiceDisconnected() {
                // Try to restart the connection on the next request to
                // Google Play by calling the startConnection() method.
                Toast.makeText(SplashActivity.this, "Failed", Toast.LENGTH_LONG).show();
            }
        });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I implement Google Play Licensing for an Android app?

How can I get information about type of a Go variable

Where can I get a token for in app billing v3 api on appengine or android?

How to verify purchase for android app in server side (google play in app billing v3)

Android In-app Billing, multiple purchases of the same item

Time trial for one-time purchases with Google Play In-App Billing

How can I get the information about an individual IM in the Slack API?

How can I get more information about "Waiting for target device to come online" in Android Studio?

How to implement auto renew subscription in app billing google play

Android In-App Billing: Refunded in-app purchases not cancelled

When can I add In app purchases ? Google Android Play Store

How can I get information about the file that launched my app?

Google in app purchases google play store on firebase : )

How can I get app crash log from Google play console

Google Play store: Discount for in app purchases

How to realize a google play billing subscription in an open source app?

In App Purchases where I can get the token?

How can I get information about children of some StorageReference?

How can I parse price from Google Play In-app Billing

Use Google Play Gift Card To Test In-App billing and purchases - is this possisble?

Testing Android In App Billing real purchases

How do I get the Google Play Billing Library?

Testing Android In App Billing purchases

In-App purchases from Google Play

How can I get information about store users in BigCommerce?

How to get notified about one-time product purchases on Google Play

How do I defer a subscription in Android (Google Play Billing)?

Can I test Google Play In-App Review in Android Emulator?

How do I get in-app purchases to show up to the player on Google Play