How do I check purchase history after delete and reinstall application
Asked Answered
S

3

7

I am developing an application which will allow user to purchase using In App Purchase and I want to remove ads after purchase. I can purchase succesfully with code below

BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                        .setSku("android.test.purchased")
                        .setType(BillingClient.SkuType.INAPP)
                        .build();
mBillingClient.launchBillingFlow(getActivity(), flowParams);

But I cannot see the result from queryPurchaseHistoryAsync when I open app again and call this method below.

mBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
            @Override
            public void onPurchaseHistoryResponse(int responseCode, List<Purchase> purchasesList) {

                purchasesList.size();
            }
        });

purchasesList.size() == 0

Is "queryPurchaseHistoryAsync" method cannot show test purchase or Am I doing something wrong?

Edit: Is queryPurchaseHistoryAsync method check purchase after delete and install app again.

Saucedo answered 12/2, 2019 at 19:27 Comment(0)
S
3

Yes queryPurchaseHistoryAsync method check purchase after deleting and installing the app again against particular user

mBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
        @Override
        public void onPurchaseHistoryResponse(@NonNull BillingResult billingResult, @Nullable List<PurchaseHistoryRecord> list) {
            
        }
    });
Skeie answered 22/6, 2022 at 8:7 Comment(0)
H
0

Try this it will give all purchase items.

mBillingClient.querySkuDetailsAsync(params.build(),
                            new SkuDetailsResponseListener() {
                                @Override
                                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                                    listener.onSkuDetailsResponse(responseCode, skuDetailsList);
                                }
                            });
Heracles answered 14/3, 2019 at 6:24 Comment(0)
A
-1

mBillingClient.queryPurchases() is all you need. Call it at every app start and, for example, every time your main activity resumes. This way your (reinstalled) app will eventually detect all user's purchases.

Avionics answered 3/1, 2020 at 22:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.