问题 在App Billing getPrice()Android中


我已成功将应用程序计费实施到我的应用程序中,一切正常。我现在正在尝试检索项目的价格(在开发者控制台中设置),以便我可以在我的应用程序中反映这些价格而无需硬编码值。

这个代码显然只收集通过库存购买的商品的价格,这不是我想要的:

SkuDetails gasDetails = inventory.getSkuDetails(SKU_FULL);      

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

我看了一眼 文档 查询可供购买但可能难以理解的物品。我认为Helper类会实现某种get price方法。

那么,我的问题是:有人能指出我正确的方向吗?


11258
2018-05-11 23:39


起源



答案:


如果您使用Google提供的“TrivialDrive”示例中提供的实现,则可以通过将查询方法中的参数传递给参数“details”和“moreSkus”来检索所有skus的信息(即使它们未被购买)库存

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

9
2017-12-12 12:55





好的,我找到了解决方案。我已经破译了开发人员文档,看起来它有错误。

这是我在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";


}

4
2018-05-11 23:54