1

I have updated Android Billing library to version 2.0 (released this month).

In addition to minor changes (that is useless to report here) I have edited this line to support the new library version:

cl = BillingClient.newBuilder(mActivity).setListener(this).build();

in this way:

cl = BillingClient.newBuilder(mActivity).enablePendingPurchases().setListener(this).build();

since as stated by release notes enablePendingPurchases() is required (and without this App crashes).

In order to get the all Skus to fulfill the removal of methods for Sku hardcoding (honestly I don't how removing them is supposed to improve something), I have tried to query using this code querySkuDetails():

SkuDetailsParams.Builder spb = SkuDetailsParams.newBuilder();
cl.querySkuDetailsAsync(spb.build(), new SkuDetailsResponseListener() {
    @Override
    public void onSkuDetailsResponse(BillingResult br, List<SkuDetails> ls) {

    }
});

But the BillingResult response code is always 5 DEVELOPER_ERRORif I place the method call in onBillingClientSetupFinished.

The previous version has no issue, and I'm wondering if I'm missing something to support the new version properly.

Billing service is able to connect to its backend, but this operation for some reason fails. So seems that error is in the way I use querySkuDetails() because onSkuDetailsResponse returns always code 5 DEVELOPER ERROR despite the status code I get inonBillingSetupFinished is OK.

AndreaF
  • 11,975
  • 27
  • 102
  • 168

3 Answers3

1

-1 SERVICE DISCONNECTED means onBillingClientSetupFinished() had not happened and .querySkuDetailsAsync() should run after onBillingClientSetupFinished(); if it returns 5 DEVELOPER_ERROR, the package name or public key might not match and/or the billing service can somehow not be connected.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • The key and all the rest match since as I have said all the others operations work. And onlu `querySkuDetailsAsync` has problem, (and this method is required only with the new version that doesn't allow to use Skus string hardcoded. – AndreaF May 19 '19 at 19:04
0

Maybe it's because there already was an IInAppBillingService.aidl in your project. Try to removed it and clean the project.

MaxF
  • 2,123
  • 1
  • 14
  • 17
0

According to the docs when using querySkuDetailsAsync(...): https://developer.android.com/google/play/billing/billing_library_overview#Query

The SkuDetailsParam that you pass in should also have the list of SKUs and a SkuType (either SkuType.INAPP or SkuType.SUBS). You are missing these two fields in the sample code you provided.

Sample code from the docs:

val skuList = ArrayList<String>()
skuList.add("premium_upgrade")
skuList.add("gas")
val params = SkuDetailsParams.newBuilder()
params.setSkusList(skuList).setType(SkuType.INAPP)
billingClient.querySkuDetailsAsync(params.build(), { billingResult, skuDetailsList ->
    // Process the result.
})

Also, at this time, Google's GitHub sample project hasn't been updated for Billing v2, but it is still helpful if you want to get both the SkuType.INAPP and SkuType.SUBS: https://github.com/googlesamples/android-play-billing/blob/master/TrivialDrive_v2/shared-module/src/main/java/com/example/billingmodule/billing/BillingManager.java

Anonsage
  • 8,030
  • 5
  • 48
  • 51