gpt4 book ai didi

android - 如何正确更新 Android BillingFlowParams 方法已弃用

转载 作者:行者123 更新时间:2023-12-02 12:07:22 26 4
gpt4 key购买 nike

我有

BillingFlowParams purchaseParams = BillingFlowParams.newBuilder().setSku(skuId).setType(billingType).setOldSkus(oldSkus).build();

但现在

setSku

setType

setOldSkus

全部已弃用。

我想更新旧代码,但又不想发布会扰乱当前订阅和 future 订阅的更新。我应该如何正确更新上述代码?

目前我使用一个String myProduct="my_newsweek_1";识别购买和BillingClient.SkuType.SUBS来识别类型,我只是通过 nullsetOldSkus

文档报告

setSku (String sku)setType (String type)已替换为 setSkuDetails(SkuDetails)(这个 SkuDetails 对象仅接收 String 作为构造函数中的参数,并抛出 JSONException 所以似乎它不适用于旧的 String 常量)

setOldSkus(ArrayList<String> oldSkus)已替换为 setOldSku(String)

最佳答案

您需要 BillingFlowParams 来launchBillingFlow()。您可以使用自己的 json 字符串创建 SkuDetails,但这不是预期的方式。您应该首先调用 querySkuDetailsAsync() 并获取必要的 skuDetailsList,然后将它们用于 launchBillingFlow()


public void querySkuDetailsAsync(@SkuType final String itemType, final List<String> skuList, final SkuDetailsResponseListener listener) {
Runnable queryRequest = new Runnable() {
@Override
public void run() {
// Query the purchase async
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(itemType);
mBillingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
//use skuDetails in skuDetailsList
}
});
}
};
executeServiceRequest(queryRequest);
}

public void initiatePurchaseFlow(final SkuDetails skuDetails) {
Runnable purchaseFlowRequest = new Runnable() {
@Override
public void run() {
Log.d(TAG, "Launching in-app purchase flow.");
BillingFlowParams purchaseParams = BillingFlowParams.newBuilder().setSkuDetails(skuDetails).build();
mBillingClient.launchBillingFlow(mActivity, purchaseParams);
}
};
executeServiceRequest(purchaseFlowRequest);
}

关于android - 如何正确更新 Android BillingFlowParams 方法已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54752757/

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