In App Billing getPrice() Android

后端 未结 3 1143
鱼传尺愫
鱼传尺愫 2021-02-13 20:40

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

3条回答
  •  再見小時候
    2021-02-13 21:17

    Using the billing api

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

    Use this to fetch SKU details

    public void getPrices(){
    
    
            List 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 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);
    
                            }
    
                        }
                    });
        }
    

提交回复
热议问题