2013-05-11 77 views
11

我已經成功實現了應用程序結算到我的應用程序,這一切工作正常。我現在試圖檢索項目的價格(在開發者控制檯中設置),以便我可以在不使用硬編碼值的情況下在應用內反映這些價格。在應用程序結算getPrice()Android

此代碼很明顯只收集物品的價格已通過這不是庫存購買什麼我在尋找:

SkuDetails gasDetails = inventory.getSkuDetails(SKU_FULL);  

      if (gasDetails != null){ 
       alert("Gas is " + gasDetails.getPrice());} 

我看過一個在docs可以轉讓,但苦苦查詢項目明白它。我會認爲助手類會實施某種獲取價格的方法。

所以,我的問題:任何人都可以指向正確的方向嗎?

回答

4

好的,我找到了解決方案。我破譯了開發人員文檔,看起來有錯誤。

這是內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"; 


} 
9

如果您使用的是谷歌的「TrivialDrive」樣本中提出的實現,你可以檢索所有SKU的信息(即使他們沒有購買)通過傳遞真實的PARAMATERS「詳細信息」和「moreSkus」在查詢庫存的方法

/** 
* 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 { 
相關問題