BillingClient always returns SERVICE_DISCONNECTED
Asked Answered
I

4

20

So I have a billing client which I instantiate with

billingClient = BillingClient.newBuilder(this).setListener(this).build();

I then call

billingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(int responseCode) {
            //TODO: use this for stuff
            com.android.billingclient.api.Purchase.PurchasesResult result;
result = billingClient.queryPurchases(BillingClient.SkuType.SUBS);
    Timber.d(result.toString());

        }

        @Override
        public void onBillingServiceDisconnected() {
            //TODO: use this for stuff
            Timber.d("something went wrong ");
        }
    });

for whatever reason the breakpoint on the timber line always returns disconnected. can anyone provide insight or an example to how i would do this?

Invasion answered 18/4, 2018 at 20:24 Comment(3)
i faced the same problem.how did you solve this?Prase
I'm running into this right now and it's driving me nuts.Clarino
See if you BillingClient is actually ready, Please refer to my answer on the below thread #56332590Leavis
I
3

Turns out I was not using a version of my apk that was signed with the right version numbering and such. Once I fixed that I was able to connect to play services and figure out what i wanted.

Invasion answered 23/5, 2018 at 18:27 Comment(4)
How'd you fix that?Lucubration
It was just ensuring that the versioning on the apk and play services was the same. I have various logging and what not for that in app, so just making sure that matched what the play console saysInvasion
@Invasion you mean about the app versionNumber and versionCode? or maybe the billing dependency version added in the build.gradle? Otherwise, where do you check?Vacancy
I am also curious about this, I ran into the same issue and I have not been able to fix it. What do you mean by the apk and play services versioning being the same?Goines
G
9

I came across this problem. Be also sure to start the connection:

mBillingClient = BillingClient.newBuilder(mContext).setListener(purchasesUpdatedListener).build();

        mBillingClient.startConnection(new BillingClientStateListener() {
            @Override
            public void onBillingSetupFinished(@BillingClient.BillingResponse int billingResponseCode) {
                if (billingResponseCode == BillingClient.BillingResponse.OK) {

                    Log.d(TAG, "onBillingSetupFinished: BillingClient.BillingResponse.OK ");

                }


            }
            @Override
            public void onBillingServiceDisconnected() {
                // Try to restart the connection on the next request to
                // Google Play by calling the startConnection() method.
            }


        });
Graecoroman answered 3/11, 2018 at 13:7 Comment(3)
At first I thought your comment wasn't helpful, however I have been able to check for myself that if you receive a SERVICE_DISCONNECTED response, then you need to call (again) to the startConnection() method. Thumbs up!Swee
@Swee is enough to call the startConnection() in the onBillingServiceDisconnected() or do we have to call it also in the onBillingSetupFinished() when the billingResponseCode == SERVICE_DISCONNECTED?Harbinger
SERVICE_DISCONNECTED might be returned during service request even when service connection failed with error BILLING_UNAVAILABLE response code during initialisation. make sure to fix BILLING_UNAVAILABLE issue first. Add additional logging to check if service initialisation if fine or not, before making service request.Nyala
I
3

Turns out I was not using a version of my apk that was signed with the right version numbering and such. Once I fixed that I was able to connect to play services and figure out what i wanted.

Invasion answered 23/5, 2018 at 18:27 Comment(4)
How'd you fix that?Lucubration
It was just ensuring that the versioning on the apk and play services was the same. I have various logging and what not for that in app, so just making sure that matched what the play console saysInvasion
@Invasion you mean about the app versionNumber and versionCode? or maybe the billing dependency version added in the build.gradle? Otherwise, where do you check?Vacancy
I am also curious about this, I ran into the same issue and I have not been able to fix it. What do you mean by the apk and play services versioning being the same?Goines
C
1

I know it's too late to answer this, but i was missing this permission in manifest,

<uses-permission android:name="com.android.vending.BILLING" />

hope that helps someone

Certifiable answered 2/12, 2022 at 12:48 Comment(1)
That's not required since the version 1.0 developer.android.com/google/play/billing/…Atomics
P
0

If you use custom rom or rooted device it probably won't work.

Run a system image on which the Google Play client application is preinstalled. If Google Play is not preinstalled in the system image, your application won't be able to communicate with the Google Play licensing server.

https://developer.android.com/google/play/licensing/setting-up

Pressroom answered 5/12, 2021 at 14:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.