Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In App Billing getPrice() Android

I have successfully implemented in app billing into my app which all works fine. I am now trying to retrieve the price of items (set in developer console) so that I can reflect these prices within my app without hard-coding values.

This code quite obviously only gathers prices of the items already purchased through the Inventory which is not what I'm looking for:

SkuDetails gasDetails = inventory.getSkuDetails(SKU_FULL);      

            if (gasDetails != null){
                alert("Gas is " + gasDetails.getPrice());}

I have looked a the docs querying items available for purchase but struggling to understand it. I would of thought that the Helper class would have implemented some sort of get prices method.

So, my question: Can anyone point me in the right direction?

like image 802
Jonno Avatar asked May 11 '13 23:05

Jonno


1 Answers

Using the billing api

implementation 'com.android.billingclient:billing:1.1' 

Use this to fetch SKU details

public void getPrices(){


        List<String> skuList = new ArrayList<> ();
        skuList.add("id_one"); //These are the product ids in your google console
        skuList.add("id_two");
        skuList.add("id_three");
        SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
        params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
        mBillingClient.querySkuDetailsAsync(params.build(),
                new SkuDetailsResponseListener() {
                    @Override
                    public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {

                        for (SkuDetails details:
                             skuDetailsList) {

                           String item = details.getSku();
                           String price = details.getPrice();
                           String description = details.getDescription();
                           String currencyCode = details.getPriceCurrencyCode();
                           String title = details.getTitle();

                            Toast.makeText(InAppBillingActivity.this, "Finished", Toast.LENGTH_SHORT).show();

                           Log.d("hererereeer- item     ", item);
                           Log.d("hererereeer- price     ", price);
                           Log.d("hererereeer- descr     ", description);
                           Log.d("hererereeer- code     ", currencyCode);
                           Log.d("hererereeer- title     ", title);

                        }

                    }
                });
    }
like image 52
Martin Mbae Avatar answered Sep 18 '22 16:09

Martin Mbae