由于不推荐使用 setOldSku(String oldSku)

Since setOldSku(String oldSku) is depreciated

由于setOldSku(String oldSku)被折旧了,如何获取purchasetoken并在setOldSk的新方法中传递?

 public void initiatePurchaseFlow(final SkuDetails skuDetails, final String oldSkuId) {
    Runnable purchaseFlowRequest = new Runnable() {
        @Override
        public void run() {
            Log.d(TAG, " SKU Details: " + skuDetails.getTitle());
            BillingFlowParams purchaseParams = BillingFlowParams.newBuilder()
                    .setSkuDetails(skuDetails).setOldSku(oldSkuId, myPurchaseToken).build();
            mBillingClient.launchBillingFlow(mActivity);
        }
    };

    executeServiceRequest(purchaseFlowRequest);
}

暂时降级到'com.android.billingclient:billing:2.0.1'即可。

用 deprecated 替换此方法并根据您的要求使用 ProrationMode

Learn more about ProrationMode

private fun updatePurchase(skuDetails: SkuDetails) {
   val updateParams = BillingFlowParams.SubscriptionUpdateParams.newBuilder()
       .setOldSkuPurchaseToken("oldPurchaseToken")
       .setReplaceSkusProrationMode(BillingFlowParams.ProrationMode.IMMEDIATE_AND_CHARGE_PRORATED_PRICE)
       .build()
 
   val billingFlowParams = BillingFlowParams.newBuilder()
       .setSkuDetails(skuDetails)
       .setSubscriptionUpdateParams(updateParams)
       .build()
 
   billingClient.launchBillingFlow(this, billingFlowParams)
}

以下方法用于较新的计费库