我已经从一个老级别的计费api迁移到最近的一个,现在我尝试添加
BillingClient.Builder enablePendingPurchases = BillingClient.newBuilder(this).setListener(this);
但我不能让它工作,这里有个错误
Caused by: java.lang.IllegalArgumentException: Support for pending purchases must be enabled. Enable this by calling 'enablePendingPurchases()' on BillingClientBuilder.
at com.android.billingclient.api.BillingClient$Builder.build(BillingClient.java:309)
at com.aplicacion.vivaluganoapp.ar.ponerDineroActivity.setupBillingClient(ponerDineroActivity.java:144)
at com.aplicacion.vivaluganoapp.ar.ponerDineroActivity.onCreate(ponerDineroActivity.java:125)
完整代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_poner_dinero);
recyclerProduct.setHasFixedSize(true);
recyclerProduct.setLayoutManager(new LinearLayoutManager(this));
BillingClient.Builder enablePendingPurchases = BillingClient.newBuilder(this).setListener(this);
enablePendingPurchases.build();
setupBillingClient();
}
private void setupBillingClient() {
billingClient = BillingClient.newBuilder (this).setListener(this).build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult responseCode) {
int maca = BillingClient.BillingResponseCode.OK;
String maca2 = String.valueOf(maca);
String maca3 = String.valueOf(responseCode);
if (maca3 == maca2)
{
Toast.makeText(ponerDineroActivity.this, "WORKS", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(ponerDineroActivity.this, "ERROR", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onBillingServiceDisconnected() {
Toast.makeText(ponerDineroActivity.this, "Disconnected from Billing", Toast.LENGTH_SHORT).show();
}
});
}
如果我只放:
BillingClient.Builder enablePendingPurchases = BillingClient.newBuilder(this);
错误是:
Caused by: java.lang.IllegalArgumentException: Please provide a valid listener for purchases updates.
有什么帮助吗?我厌倦了尝试
最佳答案
从你问题中的第一个stacktrace
通过调用“enablependingpurchases()”启用此功能
我们可以找到方法enablePendingPurchases()
的文档。
需要调用此方法来确认您的申请
已更新以支持挂起的购买。悬而未决的
购买不会自动启用,因为您的应用程序将
要求更新以确保付款前未授予权利
已经安全了。有关如何处理挂起的详细信息
交易见
https://developer.android.com/google/play/billing/billing_library_overview
如果未调用此方法,则BillingClient实例创建将失败。
你的代码行应该是:
enablePendingPurchases = BillingClient.newBuilder(this)
.enablePendingPurchases()
.setListener(this);
代替:
enablePendingPurchases = BillingClient.newBuilder(this).setListener(this);