我正在使用应用程序计费库 v6.0.1 来实现应用程序服务。奇怪的是,计费客户端未连接到 Play 服务。
我已经在发布版和调试版中测试了以下代码,但没有成功。
连接播放服务代码如下:
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();
建立连接方法如下:
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();
}
});
}
由于未知原因,该行总是返回 false。
boolean check = billingClient.isReady();
请帮我找到解决这个问题的方法。
当 billingClient.isReady() = false 时,您应该调用建立连接方法。这意味着连接尚未建立。