Google play billing purchase result shows empty list after a successful purchase in the google play billing library.
While purchase the product it returning the list as expected. After navigating to the two screens and if I check the go-to purchase screen again the Purchase list is empty for the same app.
Why the purchase list is empty after navigating to the screen?
if (billingClient.isReady()) {
Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
List<Purchase> purchases = purchasesResult.getPurchasesList();
if (purchases.size() > 0) {
for (Purchase pur : purchases) {
String thisSku = pur.getSkus().get(0);
if (thisSku.equals(AD_REMOVAL_SKU)) {
return true;
}
}
}
billingClient = BillingClient.newBuilder(context).enablePendingPurchases().setListener(purchasesUpdatedListener).build();
private PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> list) {
// To be implemented in a later section.
LogUtils.LOGI(TAG, "billingResult on billingResult" + billingResult.getResponseCode());
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && list != null) {
Toast.makeText(context.getApplicationContext(), list.toString(), Toast.LENGTH_LONG).show();
Toast.makeText(context.getApplicationContext(), billingResult.toString(), Toast.LENGTH_LONG).show();
Purchase info = list.get(0);
for (Purchase purchase : list) {
Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
if (info.getSkus().get(0).equals(AdsRemovalHelper.SKU)) {
ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
LogUtils.LOGI(TAG, "Consume params ===" + consumeParams);
billingClient.consumeAsync(consumeParams, new ConsumeResponseListener() {
@Override
public void onConsumeResponse(BillingResult billingResult, String s) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK ) {
LogUtils.LOGI(TAG, "Consume String ===" + consumeParams);
Toast.makeText(context.getApplicationContext(), purchase.getSkus().toString(), Toast.LENGTH_LONG).show();
}
}
});
}
} else if (purchase.getPurchaseState() == Purchase.PurchaseState.PENDING) {
LogUtils.LOGI(TAG, "ConsumeString ===" );
} else if (purchase.getPurchaseState() == Purchase.PurchaseState.UNSPECIFIED_STATE) {
LogUtils.LOGI(TAG, "Consume S11111tring ===" );
}
} }