0

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?

Egemen
  • 2,178
  • 5
  • 22
  • 32
  • I still think this is a duplicate and tried closing it twice. There's no logcat, no nothing - which would have been the alternate close reason, as this question is rather abstract. Check the package name & signature. When nothing is being returned, you'd still get `BillingClient.BillingResponseCode.ITEM_UNAVAILABLE` instead of `BillingResult`. Your logging is insufficient, because only the output of the client matters. – Martin Zeitler Oct 14 '21 at 11:56
  • I don't understand how you still claim this to be a duplicate. Suggested solutions in the relevant posts didn't help fix the problem. I didn't include the whole logcat in order not to clutter the question. And I'm not sure what you mean by "... instead of `BillingResult`". Have a look at `SkuDetailsResponseListener` javadoc, it should always return a result. The response code in the result could be `ITEM_UNAVAILABLE`; however, it's not the case here as I do not receive the result at all. – Egemen Oct 14 '21 at 18:58

1 Answers1

0

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.

Egemen
  • 2,178
  • 5
  • 22
  • 32