skuDetailsList returning null
Asked Answered
M

4

6

I am trying to implement in-app purchases using the latest Google Play Billing Library (2.0.1)

• I've Added product Ids to the skuList and in the Google Play Console after publishing apk in Internal App Testing

• But when I launch billingFlow I get the following

2019-07-01 13:17:02.436 1225-1225/com.mypackage.myapp D/InAppBilling: Other code5
2019-07-01 13:17:02.436 1225-1225/com.mypackage.myapp D/InAppBilling: Invalid SKU input params. SKU can't be null

Here's my code:

List skuList = new ArrayList<>();

        skuList.add("product_1");
        skuList.add("product_2");
        skuList.add("product_3");
        skuList.add("product_"4);

 SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
        params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
        mBillingClient.querySkuDetailsAsync(params.build(),
                new SkuDetailsResponseListener() {
                    @Override
                    public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
                        if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
                                && skuDetailsList != null) {

                            for (Object skuDetailsObject : skuDetailsList) {
                                skuDetails = (SkuDetails) skuDetailsObject;
                                String sku = skuDetails.getSku();
                                String price = skuDetails.getPrice();
                                if ("product_1".equals(sku)) {

                                    textA.setText(price);
                                } else if ("product_2".equals(sku)) {
                                    textB.setText(price);
                                } else if ("product_3".equals(sku)) {
                                    textC.setText(price);
                                } else if ("product_4".equals(sku)) {
                                    textD.setText(price);
                                }
                             } else {
                            Log.d(TAG, "Sku is null");
                             }
                        Log.d(TAG, "i got response");
                        Log.d(TAG, String.valueOf(billingResult.getResponseCode()));
                        Log.d(TAG, billingResult.getDebugMessage());
                    }
                });

    mBuyButton = findViewById(R.id.pay);
    mBuyButton.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {

     BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                            .setSkuDetails(skuDetails)
                            .build();
     mBillingClient.launchBillingFlow(PayActivity.this, flowParams);
        }
    });

and here's the logcat

2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: Sku is null
2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: i got response
2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: -1 //billing result response code 
2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: Service connection is disconnected. //debug message

I have also tried with reserved test product ids android.test.purchase but same error

I have also uploaded app on Play Console (internal testing) but it didn't work from there too

Any help is appreciated...

EDIT: After lots of experiments I found that Billing Service is being disconnected but the reason is not as below https://developer.android.com/reference/com/android/billingclient/api/BillingClient.BillingResponse#service_disconnected (-1)

mBillingClient = BillingClient.newBuilder(PayActivity.this).setListener(this).enablePendingPurchases().build();
        mBillingClient.startConnection(new BillingClientStateListener() {


            @Override
            public void onBillingSetupFinished(BillingResult billingResult) {

                Log.d(TAG, "Connection finished");
            }

            @Override
            public void onBillingServiceDisconnected() {
                //TODO implement your own retry policy
                // Try to restart the connection on the next request to
                // Google Play by calling the startConnection() method.
                mBillingClient.startConnection(this);
            }
        });

and after getting response onBillingSetupFinished is being called

Maulmain answered 1/7, 2019 at 8:13 Comment(2)
did you add test users credentialsQuantity
you mean testers in Play Console?Maulmain
M
5

Issue solved it by moving my app to alpha testing

Maulmain answered 3/7, 2019 at 9:31 Comment(3)
How long did it start working after you moved to alpha.Moule
I published the app in internal testing and installed from thereMaulmain
Wait, you need to install the App for you to get the SkuDetails. Can't it work when you run the App straight from Android Studio.Moule
S
2

Retry connecting

@Override
public void onBillingSetupFinished(BillingResult billingResult) {

  if(!billingResult.getResponseCode==BillingClient.BillingResponseCode.OK) {
       mBillingClient.startConnection(this);
  }

  Log.d(TAG, "Connection finished");

}
Steelwork answered 1/7, 2019 at 11:3 Comment(0)
R
1

In my case i forgot to add newly added subscription on play console in following code, then i added it and issue was gone.

public void querySKUDetails(SkuDetailsResponseListener listener) {
    if (!isBillingClientReady) {
        return;
    }
    List<String> skuList = new ArrayList<> ();

    // you need to add your new subscription sku here
    skuList.add(BillingConstants.SKU_POPULAR_MONTHLY);
    skuList.add(BillingConstants.SKU_PREMIUM_YEARLY);

    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skuList).setType(SkuType.SUBS);
    mBillingClient.querySkuDetailsAsync(params.build(),
            listener);
}
Refinement answered 25/2, 2020 at 8:5 Comment(0)
C
0

Initialize your skuList like this and then add products -

List<String> skuList = new ArrayList<> ();
   skuList.add("product_1");
    skuList.add("product_2");
    skuList.add("product_3");
    skuList.add("product_4");
Cotonou answered 1/7, 2019 at 8:49 Comment(5)
yeah but that's not the issueMaulmain
kindly it check nowMaulmain
Sure, checking.Cotonou
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="com.android.vending.BILLING" />Maulmain
Did you add the product ids in Play Console?Cotonou

© 2022 - 2024 — McMap. All rights reserved.