在App Billing getPrice()Android中 [英] In App Billing getPrice() Android
问题描述
我已成功在应用计费中实施到我的应用中,一切正常。我现在正在尝试检索项目的价格(在开发者控制台中设置),以便我可以在我的应用程序中反映这些价格,而无需硬编码值。
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 these prices within my app without hard-coding values.
此代码相当显然只收集通过库存购买的商品的价格,这不是我想要的:
This code quite obviously only gathers prices of the items already purchased through the Inventory which is not what I'm looking for:
SkuDetails gasDetails = inventory.getSkuDetails(SKU_FULL);
if (gasDetails != null){
alert("Gas is " + gasDetails.getPrice());}
我看过 docs 查询可供购买的商品,但很难理解。我认为Helper类会实现某种get price方法。
I have looked a the docs querying items available for purchase but struggling to understand it. I would of thought that the Helper class would have implemented some sort of get prices method.
所以,我的问题:有人能指出我正确的方向吗?
So, my question: Can anyone point me in the right direction?
推荐答案
好的,我找到了解决方案。我已经破译了开发人员文档,似乎有错误。
Ok, I have found the solution. I have deciphered the developer docs and it appears there were errors in it.
这是我在IabHelper中创建的解决方案:
This is my solution created within 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";
}
这篇关于在App Billing getPrice()Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!