'Getting the ProductDetails price in android-billing-5.0

I have upgraded my Kotlin app to android-billing 5.0 from 4.0, and as such, SkuDetails is now deprecated so I am migrating to using ProductDetails using the migration instructions.

Previously I displayed the purchase price for in-app purchases to the user using SkuDetails.price, but I cannot find a similar method in ProductDetails.

In Google Play Billing Library 5.0, is there a non-deprecated way to retrieve the price for an in-app purchase or subscription?



Solution 1:[1]

Based on the documentation you can call getOneTimePurchaseOfferDetails() on ProductDetails to return a ProductDetails.OneTimePurchaseOfferDetails object, which has a getFormattedPrice() method to return the price for in-app purchases.

For subscriptions you can call getSubscriptionOfferDetails() which returns a list of ProductDetails.SubscriptionOfferDetails objects, which have a getPricingPhases() method to return different pricing phases. The pricing phase objects have a getFormattedPrice() method to get the price from.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler V