Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Google's IAB, can I get the product title and price before I call the launchpurchaseflow method?

I have a program that sets an alert dialog that asks "Would you like to purchase "TITLE" for "PRICE""

I know that the Google IAB library has a getSku() call but that's only available after a result from purchasing the item. Is there a way to get these two variables before any purchasing? Thanks.

I might have seen an item that queries a bundle of sku's which lists out all the items, but I may be wrong

like image 597
kevinl Avatar asked Jan 11 '13 00:01

kevinl


2 Answers

use this method in IABHelper:

 List<String> moreSkus = new ArrayList<String>();
  moreSkus.add("sku1");
  moreSkus.add("sku2");              

  mHelper.queryInventoryAsync(true, moreSkus, mGotInventoryListener);

I test it works ok ,you can add inapp or sub type sku to list ,and return all details in invenroty

like image 134
openkava Avatar answered Oct 15 '22 13:10

openkava


found a solution for this. first of all you will need the sku/product id.

public void getProductDetails(String sku) throws RemoteException, JSONException {
    logDebug("getProductDetails - " + sku);

    ArrayList<String>  skuList = new ArrayList<>();
    // Add the specific sku
    skuList.add(sku);

    if (sku != null) {
         Bundle querySkus = new Bundle();
         querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuList);
         Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(),  ITEM_TYPE_INAPP, querySkus);
         ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

         for (String thisResponse : responseList) {
             SkuDetails d = new SkuDetails(thisResponse);
             logDebug("Looking at sku details: " + d);
             purchaseTitle = d.getTitle(); // these are set as variables so you can call them
             purchasePrice = d.getPrice(); // whenever you want
         }
    }
}
like image 1
kevinl Avatar answered Oct 15 '22 12:10

kevinl