In App Billing getPrice() Android

后端 未结 3 1153
鱼传尺愫
鱼传尺愫 2021-02-13 20:40

I have successfully implemented in app billing into my app which all works fine. I am now trying to retrieve the price of items (set in developer console) so that I can reflect

3条回答
  •  旧巷少年郎
    2021-02-13 21:25

    Ok, I have found the solution. I have deciphered the developer docs and it appears there were errors in it.

    This is my solution created within IabHelper:

    public String getPricesDev(String packageName) throws RemoteException, JSONException{
    
    
            ArrayList skuList = new ArrayList();
            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 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";
    
    
    }
    

提交回复
热议问题