2013-05-11 16 views
11

Ho implementato con successo nella fatturazione app nella mia app, che funziona perfettamente. Ora sto cercando di recuperare il prezzo degli articoli (impostato nella console di sviluppo) in modo da poter riflettere questi prezzi all'interno della mia app senza valori hard-coding.In App Billing getPrice() Android

Questo codice ovviamente raccoglie solo prezzi degli articoli già acquistati attraverso l'Inventario, che non è quello che sto cercando:

SkuDetails gasDetails = inventory.getSkuDetails(SKU_FULL);  

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

ho guardato una delle voci docs interrogazione disponibili per l'acquisto, ma fatica a capiscilo. Avrei pensato che la classe Helper avrebbe implementato una sorta di metodo per ottenere prezzi.

Quindi, la mia domanda: qualcuno può indicarmi la giusta direzione?

risposta

4

Ok, ho trovato la soluzione. Ho decifrato i documenti dello sviluppatore e sembra che ci fossero degli errori.

Questa è la mia soluzione creata all'interno 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

Se si utilizza l'attuazione proposto nel "TrivialDrive" campione da parte di Google, è possibile recuperare le informazioni di tutti gli SKU (anche se non vengono acquistati) passando fedele ai paramaters "dettagli" e "moreSkus" nel metodo che interroga l'inventario

/** 
* 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 { 
Problemi correlati