【问题标题】:In app Billing crash应用内结算崩溃
【发布时间】:2017-10-03 22:42:35
【问题描述】:

我正在将应用内计费集成到我的应用程序中。我使用了从谷歌开发网站获得的以下代码:

    buttonDownload = (Button) findViewById(R.id.download);
    buttonDownload.setOnClickListener(new OnClickListener() {

        // @Override  
          //  public void onClick(View v) {  
            // Intent i = new Intent(Intent.ACTION_VIEW);
            // i.setData(Uri.parse(url2));
            // startActivity(i);
            // link.open();
        @Override
        public void onClick(View v) {
            ArrayList skuList = new ArrayList();
            skuList.add(inappid);
            Bundle querySkus = new Bundle();
            querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
            Bundle skuDetails;
            try {
                skuDetails = mservice.getSkuDetails(3, getPackageName(),
                        "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.equals(inappid)) {
                            System.out.println("price " + price);
                            Bundle buyIntentBundle = mservice
                                    .getBuyIntent(3, getPackageName(), sku,
                                            "inapp",
                                            "bGoa+V7g/WqDXvKRqq+JTFn4uQRbPiQJEipf9RzJ");
                            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();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SendIntentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

我使用 android.test.purchased 来测试应用内计费。当我单击下载按钮时,它会购买没有缺陷的测试对象。但是,一旦我再次尝试购买它,应用程序就会崩溃,人们可以在我的应用程序中购买的商品必须可以多次购买。有人可以告诉我如何解决这个问题吗?

【问题讨论】:

  • 请贴出崩溃的logcat
  • ABActivity.java 的第 156 行正在抛出 NullPointerException
  • 我需要改变什么来解决这个问题?
  • 你需要更改ABActivity.java的第156行...

标签: android in-app-billing


【解决方案1】:

这个问题与 NullPointerException 无关,如果您的库存中已经有一个对象,Google In app billing V3 将不允许您购买一个对象,这就是您需要先消费它的原因。为此,您可以在代码中添加类似这样的内容:

  mservice.consumePurchase(3, getPackageName(), purchaseToken);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多