Android Play Billing Library: get product introductory price?

2.7k views Asked by At

I'm investigating using the new Play Billing Library, and one thing I'm concerned about is the products introductory prices.

I'm wondering if there is a way to retrieve the introductory prices with the new library. As far as I know it could be done with the Google Play In-app Billing APIs as described in this Stackoverflow question, but I can't find a similar approach using the new Billing library.

Has anyone come through this before?

2

There are 2 answers

1
goRGon On BEST ANSWER

You should just query SKU details and use getIntroductoryPrice() method for the items from the result list.

P.S. It was added recently into 1.0 release. So if you got the library within first days of the release, you should clear your gradle cache and /build folders to re-download an updated release.

9
EdgeDev On

Yes, there is. Kindly see this >> https://codelabs.developers.google.com/codelabs/play-billing-codelab/#1

val skuList = arrayListOf("sku_id_of_in_app_product","sku_id_of_in_app_product")
val itemType = SkuType.INAPP // or SkuType.SUBS that corresponds with the skuList
val skuDetailsParams = SkuDetailsParams.newBuilder().setSkusList(skuList).setType(itemType).build()

mBillingClient.querySkuDetailsAsync(skuDetailsParams, object : SkuDetailsResponseListener{
    override fun onSkuDetailsResponse(responseCode: Int, skuDetailsList: MutableList<SkuDetails>?) {
       responseListener.onSkuDetailsResponse(responseCode, skuDetailsList);
   }
})

Your Listener: You need to use a listener so that you will be able to get a response when the Asynchronous Query is done!

val responseListener = SkuDetailsResponseListener { responseCode, skuDetailsList ->
    if (responseCode == BillingClient.BillingResponse.OK && skuDetailsList != null) {
        val inList = ArrayList<SkuRowData>()
        for (details in skuDetailsList) {
            Log.i(TAG, "Found sku: $details")
            inList.add(SkuRowData(details.sku, details.title, details.price, details.introductoryPrice, details.description, details.type))
         }
     }
 }

SkuRowData is just a model class

class SkuRowData(sku: String?, title: String?, price: String?, introductory_price: String?, description: String?, type: String?)

Be aware that you can only get introductory Price for subscription in app product!