使用Google应用内结算?

时间:2014-02-05 05:41:00

标签: android in-app-purchase in-app-billing

我正在尝试在我的应用中使用Google进行应用结算。我的代码没有在eclipse中出现任何错误,但是当我在手机上运行时它强行关闭!并将cat cat points错误记录到“new Thread”行。问题是什么?如果有人可以提供帮助,我会感激不尽。

这是我的代码:

在捐赠按钮下的onCreate中

@Override
            public void onClick(View v) {

                new Thread(new Runnable() {
                    public void run() {
                        ArrayList<String> skuList = new ArrayList<String>();
                        skuList.add("My Selling Obj ID");
                        Bundle querySkus = new Bundle();
                        querySkus.putStringArrayList("My App’s RSA Key"
                                , 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("My Selling Obj ID"))
                                      pool = price;
                               }
                            }

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




                        Bundle buyIntentBundle;
                        try {
                            buyIntentBundle = mService.getBuyIntent(3, getPackageName(),
                                       "My Selling Obj ID", "inapp", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
                            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 (SendIntentException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }


                    }
                  }).start();
            }
onActivityResult:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
       if (requestCode == 1001) {           
          int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
          String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
          String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");

          if (resultCode == RESULT_OK) {
             try {
                JSONObject jo = new JSONObject(purchaseData);
                String sku = jo.getString("productId");
                Toast.makeText(Main.this, "thanks for Donation!", Toast.LENGTH_SHORT).show();
                Toast.makeText(Main.this, pool, 
                isdonated = 1;
              }
              catch (JSONException e) {
                 //alert("Failed to parse purchase data.");
                 Toast.makeText(Main.this, "Donation Failed!", Toast.LENGTH_LONG).show();
                 e.printStackTrace();
              }
          }
       }
    }

这里是logcat错误: http://upload7.ir/imgs/2014-02/08566691322028747175.jpg

1 个答案:

答案 0 :(得分:0)

您是否已将此权限添加到清单文件中?

<uses-permission android:name="com.android.vending.BILLING"/>