【问题标题】:retrieve price from inApp in Android从 Android 中的 inApp 中检索价格
【发布时间】:2013-08-24 02:43:24
【问题描述】:

拜托,我快疯了。

我可以从我的一位测试员那里购买,但我无法检索我的产品的价格。

看,下面是“连接”的代码:

    //Binding Service
   bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
                    mServiceConn, Context.BIND_AUTO_CREATE);

    String base64EncodedPublicKey;

    base64EncodedPublicKey = getString(R.string.baseEncodedPubKey);

    // compute your public key and store it in base64EncodedPublicKey
    mHelper = new IabHelper(this, base64EncodedPublicKey);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
           public void onIabSetupFinished(IabResult result) {
              if (!result.isSuccess()) {
                 // Oh noes, there was a problem.
                 Log.d("TMA Setup Billing", "Problem setting up In-app Billing: " + result);
              }            
                 // Hooray, IAB is fully set up!  
              else{

                  Log.d("TMA Setup Billing", "Ready to sell! OK!! " + result);

                  //Get the prices of inApps
                  Bundle teste = null;
                  ArrayList<String> teste1 = null;

                  getInAppsInfo(teste,teste1);

              }
           }
        });

从上面的代码中,我得到了 Ok 消息,所以它正在连接...

问题出在下面这段代码:

    //Func syncr to download prices
private synchronized void getInAppsInfo(final Bundle querySkus,final ArrayList<String> skuList) {
    AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {

        @Override
        public String doInBackground(Void... params) {

        ArrayList<String> skuList = new ArrayList<String>(); 
              skuList.add(getString(R.string.prod1_maistempo));  
              Bundle querySkus = new Bundle(); 
              querySkus.putStringArrayList("DETAILS_LIST", skuList);

              String resposta = getString(R.string.naodisp);

              try {
                  Bundle skuDetails = mService.getSkuDetails(3, getPackageName(), "inapp", querySkus);

    int response = skuDetails.getInt("RESPONSE_CODE");
    Log.d("TMA Synch Billing","response = " + response );
    preco = preco + " " + response;
    if (response == 0) {
        Log.d("TMA Synch Billing","response = OK");
        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");
        Log.d("TMA Synch Billing","Sky e Price: " + sku + " " + price);
        if (sku.equals(getString(R.string.prod1_maistempo))) resposta = price;
               }
            }
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            Log.d("TMA Synch Billing","Error Remote: " + e.getMessage());
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Log.d("TMA Synch Billing","Error JSON: " + e.getMessage());
        }


        return resposta;

        }

        @Override
        protected void onPostExecute(String result) {
            preco = preco + " " + result;
        }

    };
    task.execute();
}

这个函数返回 5 > (BILLING_RESPONSE_RESULT_DEVELOPER_ERROR 5
提供给 API 的参数无效。此错误还可能表明应用未正确签名或未正确设置 Google Play 中的应用内结算,或者在其清单中没有必要的权限)

但是,我可以使用相同的设备(并且对我所有的测试者朋友都一样),使用以下代码成功购买 inApp:

    //Yes button clicked, Start buy Activity

                    Bundle buyIntentBundle;
                    try {
                        buyIntentBundle = mService.getBuyIntent(3, getPackageName(),
                               getString(R.string.prod1_maistempo), "inapp", "buyer info");

                        PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

                        startIntentSenderForResult(pendingIntent.getIntentSender(),
                                   1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0),
                               Integer.valueOf(0));

                    } catch (RemoteException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Log.d("TMA billing Buy "," Remote " + e.getMessage());
                    } catch (SendIntentException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Log.d("TMA billing Buy "," SendIntent " + e.getMessage());
                    }

然后,我可以使用来自 google 的示例处理 JSON 字符串。

那么,你能告诉我我在获取价格的函数中做错了什么吗?非常感谢你们。

【问题讨论】:

    标签: android in-app-billing billing


    【解决方案1】:

    您传递给getSkuDetailsBundle 有一个ArrayList&lt;String&gt;,它们的键为ITEM_ID_LIST,而不是您所拥有的DETAILS_LISTDETAILS_LIST 是响应ArrayList&lt;String&gt; 中的Bundle

    【讨论】:

    • 谢谢 ianhanniballake!所以我必须将“DETAIL_LIST”更改为“ITEM_ID_LIST”?
    • 我需要几个小时来测试任何更改,因为谷歌需要太多时间来发布更新,所以请给我一个提示,因为我对这个结构有点迷茫...... tks。
    • @Totalys - 没错 - 只需将 querySkus.putStringArrayList("DETAILS_LIST", skuList); 更改为 querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
    • 嗨,ianhanniballake。有效!完美的。非常感谢!有趣的是,还有另一个线程,他们按照我的方式将 setence 作为解决方案。请查看:stackoverflow.com/questions/5912538/…,您也可以对他们的解决方案进行一些更正...
    • @Totalys - 实际上,该解决方案还有querySkus.putStringArrayList(“ITEM_ID_LIST”, skuList); 行(注意使用ITEM_ID_LIST 作为输入Bundle)。很高兴你让它工作了!如果有帮助,请采纳答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 2021-05-19
    • 2015-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多