Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android BillingClient Error: "Exception while launching billing flow: ; for sku: android.test.purchased; try to reconnect"

Tags:

android

I have been trying to build an android application with in app payments, and am having trouble setting it up. I am calling the following:

      Activity activity = new Activity();
      billingClient = BillingClient.newBuilder(this).setListener(this).build();
      billingClient.startConnection(new BillingClientStateListener() {
          @Override
          public void onBillingSetupFinished(@BillingResponse int billingResponseCode) {
              if (billingResponseCode == BillingResponse.OK) {
                  List<String> skuList = new ArrayList<> ();
                  skuList.add("android.test.purchased");
                  SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
                  params.setSkusList(skuList).setType(SkuType.INAPP);
                  billingClient.querySkuDetailsAsync(params.build(),
                          (responseCode, skuDetailsList) -> {
                              if (responseCode == BillingResponse.OK
                                      && skuDetailsList != null) {
                                  for (SkuDetails skuDetails : skuDetailsList) {
                                      System.out.println("The price is "+skuDetails.getPrice());
                                      BillingFlowParams flowParams = BillingFlowParams.newBuilder().setSkuDetails(skuDetails).build();
                                      int code = billingClient.launchBillingFlow(activity,flowParams);
                                      System.out.println("Code is: "+code);
                                  }
                              }
                          });
              }
          }
          @Override
          public void onBillingServiceDisconnected() {
              System.out.print("Billing disconnected?");
          }
      });

When I run this, I get that the code is -1, and I get the error: Exception while launching billing flow: ; for sku: android.test.purchased; try to reconnect I found that the error code -1 is "Play Store service is not connected now - potentially transient state" (https://developer.android.com/reference/com/android/billingclient/api/BillingClient.BillingResponse). I have tried both the testing productIDs (android.test.purchased), as well as a real one that I created, with the same results. I have also restarted the (physical) device. I can access the Play Store app like normal, so I can't figure out what I am doing wrong here.

like image 627
jmo Avatar asked Apr 20 '19 02:04

jmo


1 Answers

I got the same error:

W/BillingClient(25145): Exception while launching billing flow: ; for sku: someSKU; try to reconnect

and my code is almost entirely based on the official Google's example, "TrivialDrive_v2", using billing library version 1.2.2. My main activity extends NativeActivity. This did not help. After one day of looking for a possible cause I ran out of ideas 😥

Looking at the logcat I noticed just by accident the message

I/ActivityManager(962): START u0 {cmp=com.mypackage.myapp/com.android.billingclient.api.ProxyBillingActivity (has extras)} from uid 10116 on display 0

There was nothing wrong with this message, it was just an information, but it was the last message before the error occurred. So I googled "ProxyBillingActivity", and found this. Just out of curiosity I added the following definition

<activity
    android:name="com.android.billingclient.api.ProxyBillingActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />

to my Manifest file and voilà! Billing works. Then I searched through the entire "TrivialDrive_v2" example sources and all xml and manifest files to see if they also have such a definition, but they don't. Oh well.

like image 164
dolphin Avatar answered Nov 13 '22 12:11

dolphin