IAB V3:获取产品价格

时间:2014-02-13 09:54:32

标签: android google-play

我正在我的Android游戏项目上实施Google In-app Billing。现在,我可以使用mHelper.launchPurchaseFlow()购买产品。但是如何使用v3 API获得产品价格?我在网上找到了一些方法,但它不起作用,价格始终为空。

这是我的代码:

public void IAB_getprice()
{       
    bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
            mServiceConn, Context.BIND_AUTO_CREATE);

    ArrayList<String> skuList = new ArrayList<String> ();
        skuList.add("10001");
        skuList.add("10002");
        skuList.add("10003");
        skuList.add("10004");
        skuList.add("10005");
        skuList.add("10006");

        mHelper.queryInventoryAsync(true, skuList,mQueryFinishedListener);

        Bundle querySkus = new Bundle();
        querySkus.putStringArrayList("ITEM_ID_LIST", skuList);

        try {
            Bundle skuDetails = mService.getSkuDetails(3,
                    this.getPackageName(), "inapp", querySkus);
            ArrayList<String> responseList = skuDetails
                    .getStringArrayList("DETAILS_LIST");

            Log.e("In-app billing","skuDetails");
            if (null != responseList) {
                for (String thisResponse : responseList) {
                    try {

                        SkuDetails d = new SkuDetails(thisResponse);
                        Log.e("In-app billing","thisResponse");

                        for (int i = 0; i < skuList.size(); i++) {
                            if (skuList.get(i).equals(d.getSku())) {
                                //price_list.set(i, d.getPrice());
                                payload[i] = d.getPrice();
                                product_id[i] = d.getSku();                                         
                            }
                        }

                    } catch (JSONException e) {
                        Log.e("In-app billing","JSONException");
                    // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }
            }
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            Log.e("In-app billing","RemoteException");
            e.printStackTrace();
        }

}

0 个答案:

没有答案