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.
Asked
Active
Viewed 1.5k times
4 Answers
17
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);

Will Kamp
- 171
- 1
- 2
-
5And then in `mGotInventoryListener` get the price by `String price = inventory.getSkuDetails("SKU_ITEMONE").getPrice();` as @Cícero Moura said – adl Aug 03 '15 at 16:01
-
1For IABv3, I needed to use `mHelper.queryInventoryAsync(true, Arrays.asList(moreSkus), null, mGotInventoryListener);` – Spikatrix Sep 04 '18 at 13:23
17
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;
}
}
}

Sergey Glotov
- 20,200
- 11
- 84
- 98
-
@SergeyGlotov no no, it was a response to "Can I have an official confirm about this information?" for VitoShadow question, not to your answer which is 100% correct. Sorry for misunderstanding. – EvilDuck Feb 08 '12 at 08:27
3
String price = inventory.getSkuDetails("sku_of_your_product").getPrice();

Hussein El Feky
- 6,627
- 5
- 44
- 57

Cícero Moura
- 2,027
- 1
- 24
- 36
0
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);
}
}
}
}
});
}

Anas Iqbal
- 206
- 3
- 10
-
Is this price rounded ? If so how? Where can I read about it? – android developer Apr 23 '20 at 13:29