从谷歌播放获取应用内商品价格

时间:2013-03-22 05:46:42

标签: android android-billing

我指的是这个链接

http://developer.android.com/training/in-app-billing/list-iab-products.html

亲爱的, 我必须通过谷歌播放显示我的应用程序的应用程序内产品的价格。 虽然我试图从google play获得价格,如上面的链接所示...

出错
" for (String thisResponse : responseList) { "

告诉

"Type mismatch: cannot convert from element type Object to String".

我该如何解决这个错误? 或者我可以通过哪种方式从Google Play获得应用内商品价格?

这是我的代码。

    ArrayList skuList = new ArrayList();
    skuList.add("000001");
    skuList.add("gas");
    Bundle querySkus = new Bundle();
    querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
    String mPackagePrice;

    try {
        Bundle skuDetails = mService.getSkuDetails(3, 
                   getPackageName(), "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.equals("000001")) mPackagePrice = price;
           }
        }

    } catch (RemoteException e) {
        e.printStackTrace();
    }

2 个答案:

答案 0 :(得分:0)

您不能保留ArrayList通用:

ArrayList<String> skuList = new ArrayList<String>();

ArrayList<String> responseList = ...

答案 1 :(得分:0)

就像“323go”一样,它会解决你的问题,但之后,如果你使用Eclipse,它会要求你用try / catch包围这个部分来处理jsonException:

    } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }

他们你没事。

相关问题