In App Billing getPrice() Android
Ok, I have found the solution. I have deciphered the developer docs and it appears there were errors in it.
This is my solution created within IabHelper:
public String getPricesDev(String packageName) throws RemoteException, JSONException{
ArrayList<String> skuList = new ArrayList<String>();
skuList.add("full.discount.fetch");
skuList.add("gas");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails = mService.getSkuDetails(3,packageName, "inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> 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.contains("full.discount.fetch")) return price;
}
}
return "Not found";
}
If you are using the implementation proposed in the "TrivialDrive" sample by Google, you can retrieve the info of all skus (even if they are not purchased) by passing true to the paramaters "details" and "moreSkus" in the method that queries the inventory
/** * Queries the inventory. This will query all owned items from the server, as well as * information on additional skus, if specified. This method may block or take long to execute. * Do not call from a UI thread. For that, use the non-blocking version {@link #refreshInventoryAsync}. * * @param querySkuDetails if true, SKU details (price, description, etc) will be queried as well * as purchase information. * @param moreItemSkus additional PRODUCT skus to query information on, regardless of ownership. * Ignored if null or if querySkuDetails is false. * @param moreSubsSkus additional SUBSCRIPTIONS skus to query information on, regardless of ownership. * Ignored if null or if querySkuDetails is false. * @throws IabException if a problem occurs while refreshing the inventory. */ public Inventory queryInventory(boolean querySkuDetails, List<String> moreItemSkus, List<String> moreSubsSkus) throws IabException {
Using the billing api
implementation 'com.android.billingclient:billing:1.1'
Use this to fetch SKU details
public void getPrices(){
List<String> 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<SkuDetails> 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);
}
}
});
}