2013-05-11 15 views
11

Uygulamamda tüm uygulamaların düzgün çalıştığı uygulama faturalandırma uygulamasında başarıyla uyguladım. Şu anda ürünlerimin fiyatını (geliştirici konsolunda belirle) almaya çalışıyorum. Böylece, bu fiyatları uygulamamda sabit kodlama değerleri olmadan yansıtabiliyorum.Uygulamada Faturalandırma getPrice() Android

Bu kod oldukça açıkçası sadece öğelerin fiyatlarına zaten aradığım ne değildir Envanteri yoluyla satın toplar: alım bunlarla mücadele için kullanılabilir

SkuDetails gasDetails = inventory.getSkuDetails(SKU_FULL);  

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

Ben baktım bir docs sorgulama öğeler anla. Helper sınıfının bir çeşit getiri fiyatları yöntemi uygulayacağını düşünürdüm.

Yani, sorum: Birisi bana doğru yönde işaret edebilir mi?

cevap

4

Tamam, ben çözüm bulduk. Geliştirici dokümanları deşifre ettim ve hatalar göründü.

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 tarafından "TrivialDrive" numunede önerilen uygulama kullanıyorsanız, onlar satın olmasa bile (tüm SKU'lara ait bilgi alabilirsiniz:

Bu IabHelper içinde oluşturulan benim çözümdür) envanter sorgular yöntemde İlmek "ayrıntılar" sadık geçen ve "moreSkus" tarafından

/** 
* 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 { 
İlgili konular