gpt4 book ai didi

android - BillingFlowParams.Builder setSkuDetails 用于测试静态 Google Play 结算响应

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:03:55 24 4
gpt4 key购买 nike

我正在使用三个保留的产品 ID 测试应用内购买以测试静态 Google Play 结算 responses :

  • android.test.purchased
  • android.test.canceled
  • android.test.item_unavailable

但是,setSkusetType 似乎在BillingFlowParams.Builder 中被弃用class .相反,我们应该使用 setSkuDetails(SkuDetails)

我应该如何更改示例代码中的 BillingFlowParams 以将 SkuDetails 用于测试产品 ID?

BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSku(skuId)
.setType(SkuType.INAPP)
.build();
int responseCode = mBillingClient.launchBillingFlow(flowParams);

最佳答案

您应该从 BillingClient.querySkuDetailsAsync 获取 SkuDetails,示例代码可能如下所示:

private BillingClient mBillingClient;

// ....

mBillingClient = BillingClient.newBuilder(this).setListener(new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
if (responseCode == BillingClient.BillingResponse.OK
&& purchases != null) {

// do something you want

} else if (responseCode == BillingClient.BillingResponse.USER_CANCELED) {
} else {
}
}
}).build();


mBillingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@BillingClient.BillingResponse int billingResponseCode) {

if (billingResponseCode == BillingClient.BillingResponse.OK) {
// The billing client is ready. You can query purchases here.

List<String> skuList = new ArrayList<>();
skuList.add("android.test.purchased");

SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder()
.setSkusList(skuList).setType(BillingClient.SkuType.INAPP).build();
mBillingClient.querySkuDetailsAsync(skuDetailsParams,
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {

BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetailsList.get(0))
.build();
int billingResponseCode = billingClient.launchBillingFlow(SkuActivity.this, flowParams);
if (billingResponseCode == BillingClient.BillingResponse.OK) {
// do something you want
}
}
});
}
}


@Override
public void onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
});

你也可以看看https://developer.android.com/google/play/billing/billing_library_overview

关于android - BillingFlowParams.Builder setSkuDetails 用于测试静态 Google Play 结算响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53026541/

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