我有
BillingFlowParams purchaseParams = BillingFlowParams.newBuilder().setSku(skuId).setType(billingType).setOldSkus(oldSkus).build();
但现在
setSku
setType
setOldSkus
都被弃用了。
我想更新旧代码而不发布混乱活动和未来订阅的更新。我该如何正确更新上面的代码?
目前我使用String myProduct="my_newsweek_1";
来识别购买和BillingClient.SkuType.SUBS
来识别类型,我只是将null
传递给setOldSkus
文档报告
setSku (String sku)
和setType (String type)
已经被setSkuDetails(SkuDetails)
取代(这个SkuDetails
对象只接受String
作为构造函数中的参数并抛出JSONException
所以似乎它不适用于旧的String
常量)
和
setOldSkus(ArrayList<String> oldSkus)
已被setOldSku(String)
取代
launchBillingFlow()
需要BillingFlowParams。您可以使用自己的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);
}