I'm trying to implement the new Google Play Billing to my app, and try to retrieve my already purchased in-app product, by using queryPurchaseHistoryAsync()
method, and the Purchase
list always empty with 0 elemnts.
The code is working fine on my device which I purchased the item, but with my other device which has the same Google account, it returns nothing.
Also as in the Documentation, queryPurchaseHistoryAsync()
should sync with Google to get the purchase history, but for some reason it does not seem to sync.
My code is:
BillingClient billingClient = BillingClient.newBuilder(getApplicationContext()).setListener(new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
if(responseCode == BillingClient.BillingResponse.OK) {
//Do something
}
}
}).build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(int responseCode) {
if(responseCode == BillingClient.BillingResponse.OK) {
//Response is OK and working fine
}
}
@Override
public void onBillingServiceDisconnected() {
//Do something
}
});
billingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
@Override
public void onPurchaseHistoryResponse(int responseCode, List<Purchase> purchasesList) {
if(responseCode == BillingClient.BillingResponse.OK) {
//Always returning 0 size() of purchasesList
Toast.makeText(getApplicationContext(), "There are " + purchasesList.size() + " items you've purchased.", Toast.LENGTH_LONG).show();
}
}
});
Where exactly have I gone wrong with this code?
Thank you so much.