Android In-App billing item price

前端 未结 4 2062
情书的邮戳
情书的邮戳 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<String> 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<SkuDetails> 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);
    
                                }
                            }
                        }
    
                    }
                });
    }
    
    0 讨论(0)
  • 2020-12-29 05:03

    If you are using the Trivial Drive example and included IabHelper class you need to pass a list of skus to queryInventoryAsync.

        String[] moreSkus = {"SKU_ITEMONE", "SKU_ITEMTWO"};
        mHelper.queryInventoryAsync(true, Arrays.asList(moreSkus), mGotInventoryListener);
    
    0 讨论(0)
  • 2020-12-29 05:13

    It is possible now with Billing API v3. You can get information with getSkuDetails() method. Example is here.

    ArrayList skuList = new ArrayList();
    skuList.add("premiumUpgrade"); 
    skuList.add("gas");
    Bundle querySkus = new Bundle();
    querySkus.putStringArrayList(“ITEM_ID_LIST”, skuList);
    
    Bundle skuDetails = mService.getSkuDetails(3, getPackageName(), “inapp”, querySkus);
    
    int response = skuDetails.getInt("RESPONSE_CODE");
    if (response == 0) {
        ArrayList responseList = skuDetails.getStringArrayList("DETAILS_LIST");
    
        for (String thisResponse : responseList) {
            JSONObject object = new JSONObject(thisResponse);
            String sku = object.getString("productId");
            String price = object.getString("price");
            if (sku.equals(“premiumUpgrade”)) {
                mPremiumUpgradePrice = price;
            } else if (sku.equals(“gas”)) { 
                mGasPrice = price;
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-29 05:17
    String price = inventory.getSkuDetails("sku_of_your_product").getPrice();
    
    0 讨论(0)
提交回复
热议问题