I have an Android app that's already published on Google Play. I am now trying to update the Billing Library from v2 to v4. Connection to Google Play works fine; however, getting SKU details with BillingClient#querySkuDetailsAsync
does not return anything.
I saw a similar question in this post, but as far as I see the suggested solution applies to apps that aren't published yet.
Another similar post suggests using BillingClient.SkuType.SUBS
instead of BillingClient.SkuType.INAPP
. Although that's wrong in my case, I've still tried it, but I am still not getting any results.
Here is the relevant code:
private BillingClientStateListener clientStateListener() {
return new BillingClientStateListener() {
@Override
public void onBillingServiceDisconnected() {
activity.logWarn("Billing service disconnected, trying again...");
// TODO try to reconnect
}
@Override
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
if (isBillingResultSuccessful(billingResult, CONNECTING)) {
activity.logInfo("Successfully connected to billing service");
fetchSkuDetails();
}
}
};
}
private void fetchSkuDetails() {
activity.logInfo("Fetching SKU details...");
billingClient.querySkuDetailsAsync(
createSkuDetailsParams(),
(billingResult, skuDetailsList) -> {
activity.hideProgressBar();
activity.logInfo("Received SKU response. Billing result: %s, sku list size: %d",
billingResult, skuDetailsList.size());
if (isBillingResultSuccessful(billingResult, RETRIEVING_PRODUCTS)) {
addProducts(skuDetailsList);
skuResponseListener.onSkuDetailsResponse(skuDetailsList);
}
});
}
private SkuDetailsParams createSkuDetailsParams() {
List<String> skuList = new ArrayList<>(NUM_COIN_PRODUCTS);
for (int i = 1; i <= NUM_COIN_PRODUCTS; i++) {
skuList.add(PRODUCT_ID_PREFIX + i);
}
return SkuDetailsParams.newBuilder()
.setSkusList(skuList)
.setType(SkuType.INAPP)
.build();
}
The last log entry I see is "Fetching SKU details...", but the callback event is never called after that. The product ids I add to SKU list already exist and in app purchases work with my production app.
What could be the problem?
I found the reason, I made a simple stupid mistake. The culprit was this line in SkuDetailsResponseListener#onSkuDetailsResponse
:
activity.hideProgressBar();
This method attempts to set the visibility of the progress bar by using the UI window (Activity#getWindow
), which did hang within the async callback; therefore, the log statement that comes after that line was never executed. This led me to naively assume that the callback was never executed at all.
There is one more thing though: I was receiving BillingResponseCode
6, which is "Fatal error during the API action.". I changed the AVD to Pixel 4 (API 30), and I retrieve the SKU details now.