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.

6155031
  • 4,171
  • 6
  • 27
  • 56

3 Answers3

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) {
            
        }
    });
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);
                                }
                            });
VIISHRUT MAVANII
  • 11,410
  • 7
  • 34
  • 49
-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.

algrid
  • 5,600
  • 3
  • 34
  • 37