Reputation: 149
I am implementing in app services using in app billing library v6.0.1. Strangely the Billing Client is not connecting to Play Services.
I have tested the following code in both release and debug versions but to no avail.
The connection to play services code is as under:
billingClient = BillingClient.newBuilder(MainActivity.this)
.setListener(purchasesUpdatedListener)
.enablePendingPurchases()
.build();
boolean check = billingClient.isReady();
//start the connection after initializing the billing client
if(check)
establishConnection();
else
Toast.makeText(MainActivity.this,"Billing client is not ready",Toast.LENGTH_SHORT).show();
The establish connection method is as under:
private void establishConnection() {
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished( BillingResult billingResult) {
Toast.makeText(MainActivity.this,billingResult.getResponseCode(),Toast.LENGTH_SHORT).show();
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
// The BillingClient is ready. You can query purchases here.
//showProducts();
Toast.makeText(MainActivity.this,"Billing client is successfully connected",Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(MainActivity.this,"Billing client failed to connect",Toast.LENGTH_SHORT).show();
}
@Override
public void onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
//establishConnection();
Toast.makeText(MainActivity.this,"Billing connection is disconnected",Toast.LENGTH_SHORT).show();
}
});
}
The line is always returning false due to unknown reason.
boolean check = billingClient.isReady();
Please help me to find a solution to this problem.
Upvotes: 0
Views: 759
Reputation: 111
You should call establishConnection method when billingClient.isReady() = false. It means the connection does not establish yet.
Upvotes: 1