I have successfully implemented in app billing into my app which all works fine. I am now trying to retrieve the price of items (set in developer console) so that I can reflect these prices within my app without hard-coding values.
This code quite obviously only gathers prices of the items already purchased through the Inventory which is not what I'm looking for:
SkuDetails gasDetails = inventory.getSkuDetails(SKU_FULL);
if (gasDetails != null){
alert("Gas is " + gasDetails.getPrice());}
I have looked a the docs querying items available for purchase but struggling to understand it. I would of thought that the Helper class would have implemented some sort of get prices method.
So, my question: Can anyone point me in the right direction?
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";
}