Vah*_*han 6 android subscription play-billing-library
在 Google Play Billing Library 5 中,有 ProductDetais,而不是已弃用的 SkuDetails。SkuDetails 有 freeTrialPeriod 字段,该字段返回订阅的免费试用。在 ProductDetails 中我找不到任何类似的字段,有没有办法从 ProductDetails 获得免费试用期?
是的,有办法。首先检查这是否是订阅(而不是一次性购买)。然后获取您需要的定价计划。免费试用期始终是定价计划的第一个定价阶段,并且priceAmountMicros = 0且FormattedPrice =“free”。如果定价计划中的第一个定价阶段符合条件,您可以使用其计费周期作为试用期。
int trialDays = -1;
if(BillingClient.ProductType.SUBS.equals(productDetails.getProductType()))
{
List<ProductDetails.SubscriptionOfferDetails> subscriptionPlans = productDetails.getSubscriptionOfferDetails();
ProductDetails.SubscriptionOfferDetails pricingPlan = subscriptionOffers.get(planIndex);
ProductDetails.PricingPhase firstPricingPhase = offer.getPricingPhases().getPricingPhaseList().get(0);
if(firstPricingPhase.getPriceAmountMicros() == 0)
{
trialDays = BillingFlavor.parseDuration(firstPricingPhase.getBillingPeriod());
}
}
return trialDays;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1894 次 |
| 最近记录: |