androidin-app-purchasein-app-billingcurrency-formattinggoogle-play-billing

Differentiate different types of dollar currencies for Google Play in-app billing


Google Play's in-app billing library has a good function to get a product's local price and currency as a string:

ProductDetails.OneTimePurchaseOfferDetails oneTimePurchaseOfferDetails = productDetails.getOneTimePurchaseOfferDetails();
                if (oneTimePurchaseOfferDetails != null) {
                    formattedPrice = oneTimePurchaseOfferDetails.getFormattedPrice();
                }

This will return, for example, $4.99 in USA and €4.99 in France.

However, it returns $4.99 in Canada, Australia, and New Zealand too.

What's the best way to generate different strings for the different types of "dollars"? i.e. to add "CAD" or "AUD" to the price?


Solution

  • You can use the getPriceCurrencyCode() method from ProductDetails.OneTimePurchaseOfferDetails to get the three-letter currency code (e.g., "USD", "CAD", "AUD")

    Here's the link for more info:
    https://developer.android.com/reference/com/android/billingclient/api/ProductDetails.OneTimePurchaseOfferDetails