Android Google Billing Client - onSkuDetailsResponse Always Empty List

3.4k Views Asked by At

I was wondering could you help. I followed the instructions at https://developer.android.com/google/play/billing/integrate, but I cannot seem to get the purchase flow working. The billing seems to setup ok, but when I try to query for my in-app products, the list is always returning empty. Can someone please help?

In my app level build.gradle file, I have included the Google Billing SDK:

implementation 'com.android.billingclient:billing:3.0.0'

Then I have created an activity to test out the code. It first initialises the BillingClient and starts the connection. The connection seems to finish the setup correctly. Once setup correctly, I then try to query the products that I have available in my Google Play Console under 'Store presence' > 'In-app products' > 'Manage products'

enter image description here

The following is then the code in the Activity that should kick off the process and return the SkuDetails list, but unfortunately it is returning back empty.

private BillingClient billingClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_billing);

    this.billingClient = BillingClient.newBuilder(this)
            .enablePendingPurchases()
            .setListener(this.purchaseUpdateListener)
            .build();
    this.billingClient.startConnection(billingClientStateListener);
}

private PurchasesUpdatedListener purchaseUpdateListener = new PurchasesUpdatedListener() {
    @Override
    public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> list) {
        Log.d("Billing", "onPurchasesUpdated - List Size: " + list.size());
    }
};

private BillingClientStateListener billingClientStateListener = new BillingClientStateListener() {
    @Override
    public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
        if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
            Log.d("Billing", "onBillingSetupFinished - OK");
            queryProducts();
        } else {
            Log.d("Billing", "onBillingSetupFinished - Something wrong response Code: " + billingResult.getResponseCode());
        }
    }

    @Override
    public void onBillingServiceDisconnected() {
        Log.d("Billing", "Service disconnected");
    }
};

private void queryProducts() {
    List<String> productIdsList = new ArrayList<>();
    productIdsList.add("test.billing.001");

    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(productIdsList).setType(BillingClient.SkuType.INAPP);
    this.billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
        @Override
        public void onSkuDetailsResponse(@NonNull BillingResult billingResult, @Nullable List< SkuDetails > list) {
            Log.d("Billing", "onSkuDetailsResponse - List Size: " + list.size());
        }
    });
}
3

There are 3 best solutions below

3
On BEST ANSWER

So for anyone who is having similar issues, it seems that (well in my case anyways) that my app needed to be successfully published before I could retrieve the in-app products from the app. Once my app was published, I was then able to query and use the in-app products.

0
On

It should be some of the prerequisites below are not satisfied. Read this article for more information.

  1. Upload the application to Closing Testing, no need to publish at this stage. (Internal Testing may be sufficient, but not verified).
  2. Create SKUs, note that the ID should match the ID of the application request.
  3. Add the tester's mailbox, which is the Google account login to the device to test the app SKU.
  4. Switch License Respond to LICENSED (Path: play console homepage -> Setup -> License testing).
  5. The Application ID for uploading Closing Testing needs to be the same as the Application ID for local debugging.
0
On

According to Maxim Alov comment for Billing 5.0.0, the problem is in invitations for testers. My steps to fix this problem:

  1. Open tester's invitation link and accept
  2. Open app via link from previous step

After two these steps (in my case second helped) all products started to come

I'm using billing-lib-5.0.0 and also had the same issue - queryProductDetails() was always empty on my release builds, let alone debug builds. I'd actually added all my test gmail emails to list of testers for Closed Testing, and also LICENSED all of them. No effect. Eventually, I recognized that the link to my test app is not generated on Play Console Closed Testing track page. I recreated the track, this time for Internal Testing, and the link has appeared. Then I logged in to each of my gmails and accepted to be a tester from that link. After doing that, products started to come, in IDE