How to get separate price and currency information for an in-app purchase?

后端 未结 8 1506
攒了一身酷
攒了一身酷 2020-12-24 07:02

I am implementing in-app purchases for an app with support for several countries.

The In-App Billing Version 3 API claims that:

No currency co

8条回答
  •  再見小時候
    2020-12-24 07:12

    You can. You need to modify SkuDetails.java like below.

    Steps:

    1. Check their sample app for in-app billing.
    2. Modify the SkuDetails.java file as follows:
    import org.json.JSONException; import org.json.JSONObject;
    
    /**  
     * Represents an in-app product's listing details.  
     */ 
    public class SkuDetails {
        String mItemType;
        String mSku;
        String mType;
        int mPriceAmountMicros;
        String mPriceCurrencyCode;
        String mPrice;
        String mTitle;
        String mDescription;
        String mJson;
    
        public SkuDetails(String jsonSkuDetails) throws JSONException {
            this(IabHelper.ITEM_TYPE_INAPP, jsonSkuDetails);
        }
    
        public SkuDetails(String itemType, String jsonSkuDetails) throws JSONException {
            mItemType = itemType;
            mJson = jsonSkuDetails;
            JSONObject o = new JSONObject(mJson);
            mSku = o.optString("productId");
            mType = o.optString("type");
            mPrice = o.optString("price");
            mPriceAmountMicros = o.optInt("price_amount_micros");
            mPriceCurrencyCode = o.optString("price_currency_code");
            mTitle = o.optString("title");
            mDescription = o.optString("description");
        }
    
        public String getSku() { return mSku; }
        public String getType() { return mType; }
        public String getPrice() { return mPrice; }
        public String getTitle() { return mTitle; }
        public String getDescription() { return mDescription; }
        public int getPriceAmountMicros() { return mPriceAmountMicros; }
        public String getPriceCurrencyCode() { return mPriceCurrencyCode; }
    
        @Override
        public String toString() {
            return "SkuDetails:" + mJson;
        } 
    }
    

提交回复
热议问题