2013-05-11 3 views
11

私は正常にすべての正常に動作する私のアプリにアプリの請求で実装されています。私は今、ハードコーディング値なしで私のアプリ内でこれらの価格を反映できるように、開発者用コンソールに設定されたアイテムの価格を取得しようとしています。AppBilling getPrice()Android

このコードはかなり明らかにのみ、すでに私が探しているものではありませんインベントリを通じて購入したアイテムの価格を収集します

SkuDetails gasDetails = inventory.getSkuDetails(SKU_FULL);  

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

私が購入可能docs照会の項目を見てそれに苦労してきましたそれを理解します。私は、Helperクラスがある種のget pricesメソッドを実装していると思います。

私の質問:誰かが正しい方向に私を指摘できますか?

答えて

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

は、Googleで「TrivialDrive」サンプルで提案された実装を使用している場合、あなたはすべてのSKUの情報を取得することができます(それらが購入されていない場合でも、 )

/** 
* 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 { 
インベントリを照会方法でPARAMATERS「詳細」および「moreSkus」にtrueを渡すことにより
関連する問題