1tSurge
1tSurge

Reputation: 693

BillingClient always returns SERVICE_DISCONNECTED

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?

Upvotes: 20

Views: 14132

Answers (4)

Fusion Developers
Fusion Developers

Reputation: 728

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

Upvotes: 1

sucicf1
sucicf1

Reputation: 365

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

Upvotes: 1

Paolo
Paolo

Reputation: 3713

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.
            }


        });

Upvotes: 9

1tSurge
1tSurge

Reputation: 693

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.

Upvotes: 3

Related Questions