Android In-App billing item price

2019-02-03 00:00发布

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 only can find out the price for an in-app item in the purchase dialog and i would like to avoid to store the prices in the application for all supported currencies.

3条回答
小情绪 Triste *
2楼-- · 2019-02-03 00:19

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;
        }
    }
}
查看更多
地球回转人心会变
3楼-- · 2019-02-03 00:20
String price = inventory.getSkuDetails("sku_of_your_product").getPrice();
查看更多
迷人小祖宗
4楼-- · 2019-02-03 00:27

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);
查看更多
登录 后发表回答