Android In-App billing item price

前端 未结 4 2082
情书的邮戳
情书的邮戳 2020-12-29 04:21

How can the price of an in-app billing item be retrieved before actually displaying the android market frontend for the in-app purchase? Currently it looks like the user onl

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 05:02

    If you are not following the google trivia example then you can get price by using this code.

    private void getItemsPrice(){
        List skuList = new ArrayList<>();
        skuList.add("example1");
        skuList.add("example2");
        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) {
                        if (responseCode == BillingClient.BillingResponse.OK
                                && skuDetailsList != null) {
                            for (SkuDetails skuDetails : skuDetailsList) {
                                String sku = skuDetails.getSku();
                                String price = skuDetails.getPrice();
                                Log.d("item price",price);
                                if ("example1".equals(sku)) {
                                        tvPlan1.setText(price);
                                }
                                else if ("example2".equals(sku)){
                                        tvPlan2.setText(price);
    
                                }
                            }
                        }
    
                    }
                });
    }
    

提交回复
热议问题