Pet*_*ter 33 android in-app-billing kotlin android-billing play-billing-library
我已将我的 Kotlin 应用程序从 4.0 升级到 android-billing 5.0,因此,SkuDetails 现已弃用,因此我将使用迁移说明迁移到使用 ProductDetails 。
之前我使用SkuDetails.price向用户显示应用内购买的购买价格,但我在ProductDetails中找不到类似的方法。
在 Google Play Billing Library 5.0 中,是否有一种未弃用的方法来检索应用内购买或订阅的价格?
Tyl*_*r V 38
根据文档,您可以调用getOneTimePurchaseOfferDetails()
ProductDetails 返回一个ProductDetails.OneTimePurchaseOfferDetails
对象,该对象具有getFormattedPrice()
返回应用内购买价格的方法。
对于订阅,您可以调用getSubscriptionOfferDetails()
它返回对象列表ProductDetails.SubscriptionOfferDetails
,这些对象具有getPricingPhases()
返回不同定价阶段的方法。定价阶段对象有一个getFormattedPrice()
获取价格的方法。
更新
为了更好地解释这种新方法的功能,您现在可以为给定的订阅产品创建多个“基本计划”。例如,您可以创建“无限制”产品,然后创建 50 美元/年的“无限制年度”计划和 5 美元/月的“无限制每月”计划。
类似的配置返回的结果ProductDetails
将如下所示 - 您有一个productId
具有多个付款率/计划的单一配置。offerId
如果您添加的促销活动(例如第一年的折扣)在现有基本计划 ID 下显示为非空。
{
productId: "unlimited",
subscriptionOfferDetails:
[
{
basePlanId: "unlimited-monthly",
offerId: null,
pricingPhases:
[
{formattedPrice: "$5", billingPeriod: P1M, recurrence: 1}
]
},
{
basePlanId: "unlimited-annual",
offerId: null,
pricingPhases:
[
{formattedPrice: "$50", billingPeriod: P1Y, recurrence: 1}
]
},
{
basePlanId: "unlimited-annual",
offerId: "unlimited-annual-promotion",
pricingPhases:
[
{formattedPrice: "$30", billingPeriod: P1Y, recurrence: 2}
{formattedPrice: "$50", billingPeriod: P1Y, recurrence: 1}
]
}
],
oneTimePurchaseOfferDetails: null
}
Run Code Online (Sandbox Code Playgroud)
谷歌还提供了有关新格式的详细信息。
小智 15
在 Kotlin 中,您可以在产品上调用它
subscriptionOfferDetails?.get(0)?.pricingPhases?.pricingPhaseList?.get(0)?.formattedPrice
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9866 次 |
最近记录: |