gpt4 book ai didi

java - skuDetailsList 返回 null

转载 作者:搜寻专家 更新时间:2023-11-01 09:20:08 25 4
gpt4 key购买 nike

我正在尝试使用最新的 Google Play 结算 库 (2.0.1) 实现应用内购买

• 在内部应用测试中发布 apk 后,我已将产品 ID 添加到 skuList 和 Google Play 控制台

• 但是当我启动 billingFlow 时,我得到以下信息

2019-07-01 13:17:02.436 1225-1225/com.mypackage.myapp D/InAppBilling: Other code5
2019-07-01 13:17:02.436 1225-1225/com.mypackage.myapp D/InAppBilling: Invalid SKU input params. SKU can't be null

这是我的代码:

List skuList = new ArrayList<>();

skuList.add("product_1");
skuList.add("product_2");
skuList.add("product_3");
skuList.add("product_"4);

SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
mBillingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
&& skuDetailsList != null) {

for (Object skuDetailsObject : skuDetailsList) {
skuDetails = (SkuDetails) skuDetailsObject;
String sku = skuDetails.getSku();
String price = skuDetails.getPrice();
if ("product_1".equals(sku)) {

textA.setText(price);
} else if ("product_2".equals(sku)) {
textB.setText(price);
} else if ("product_3".equals(sku)) {
textC.setText(price);
} else if ("product_4".equals(sku)) {
textD.setText(price);
}
} else {
Log.d(TAG, "Sku is null");
}
Log.d(TAG, "i got response");
Log.d(TAG, String.valueOf(billingResult.getResponseCode()));
Log.d(TAG, billingResult.getDebugMessage());
}
});

mBuyButton = findViewById(R.id.pay);
mBuyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails)
.build();
mBillingClient.launchBillingFlow(PayActivity.this, flowParams);
}
});

这是 logcat

2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: Sku is null
2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: i got response
2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: -1 //billing result response code
2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: Service connection is disconnected. //debug message

我也尝试过使用保留的测试产品 ID android.test.purchase 但同样的错误

我也在 Play Console 上上传了应用(内部测试),但它也无法从那里运行

感谢任何帮助...

编辑:经过大量实验,我发现 Billing Service 正在断开连接但原因并非如下 https://developer.android.com/reference/com/android/billingclient/api/BillingClient.BillingResponse#service_disconnected (-1)

mBillingClient = BillingClient.newBuilder(PayActivity.this).setListener(this).enablePendingPurchases().build();
mBillingClient.startConnection(new BillingClientStateListener() {


@Override
public void onBillingSetupFinished(BillingResult billingResult) {

Log.d(TAG, "Connection finished");
}

@Override
public void onBillingServiceDisconnected() {
//TODO implement your own retry policy
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
mBillingClient.startConnection(this);
}
});

在收到响应后 onBillingSetupFinished 被调用

最佳答案

通过将我的应用程序移至 alpha 测试来解决问题

关于java - skuDetailsList 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56832130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com