2
votes

I have a really strange problem with Google In-app billing API.

I want to get the details of my available subscriptions to show their localised price on the UI. I'm using the IabHelper to query the details of the SKUs I specify, but the result contains no products, but after I purchase the subscription it's working, even if I cancel the subscription then and reinstall the app.

Here is my code:

    List<String> additionalSkus = new ArrayList<>();

    for (Subscription subscription : subscriptions) {
        additionalSkus.add(subscription.getSku());
    }

    iabHelper.queryInventoryAsync(true, additionalSkus, new IabHelper.QueryInventoryFinishedListener() {
        @Override
        public void onQueryInventoryFinished(IabResult result, Inventory inv) {
            if (iabHelper == null || result.isFailure()) {
                Log.i("subs", result.getMessage());
            }

            for (Subscription subscription : subscriptions) {
                SkuDetails skuDetails = inv.getSkuDetails(subscription.getSku());

                if (skuDetails != null) {
                    subscription.setLocalizedPrice(skuDetails.getPrice());
                    Log.i("subs", subscription.getLocalizedPrice());
                }

            }
        }
    });

I have everything set up right about the In-app billing process. My products are active, I have a published beta APK, I can even get the details of my managed products, and purchase managed products and subscriptions, but this isn't working.

1

1 Answers

4
votes

If you're using the latest version of IabHelper class, you should note that the function arguments relevant to additional skus to query are split to moreItemSkus (PRODUCT skus) and moreSubsSkus (SUBSCRIPTIONS skus).

public void queryInventoryAsync(final boolean querySkuDetails, final List<String> moreItemSkus,
        final List<String> moreSubsSkus, final QueryInventoryFinishedListener listener)

In your case, your call should be

iabHelper.queryInventoryAsync(true, null, additionalSkus, new IabHelper.QueryInventoryFinishedListener() ...