活动结果中的应用内结算-v3错误

时间:2013-10-03 06:15:56

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

每当启动付款服务时,一切正常,但在活动结果中出现错误

关于活动结果 RESULT_OK = 0和resultCode = -1如示例中的预期,但我不知道哪里出错...

if (Navigator.REQUEST_PASSPORT_PURCHASE == requestCode) {
        if (RESULT_OK == resultCode) {
            dealWithSuccessfulPurchase();
        } else {
            dealWithFailedPurchase();
        }
    }

控制权在其他情况下进行..

1 个答案:

答案 0 :(得分:1)

检查我的以下代码:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + ","
                + data);

        if (mHelper == null)
            return;

        if (requestCode == 10001) {

            int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
            String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
            Log.d("INAPP_PURCHASE_DATA", ">>>" + purchaseData);
            String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
            Log.d("INAPP_DATA_SIGNATURE", ">>>" + dataSignature);
            String continuationToken = data
                    .getStringExtra("INAPP_CONTINUATION_TOKEN");
            Log.d("INAPP_CONTINUATION_TOKEN", ">>>" + continuationToken);

            if (resultCode == RESULT_OK) {
                try {
                    Log.d("purchaseData", ">>>"+purchaseData);
                    JSONObject jo = new JSONObject(purchaseData);
                    String sku = jo.getString("productId");
                    alert("You have bought the " + sku
                            + ". Excellent choice, adventurer!");
                } catch (JSONException e) {
                    alert("Failed to parse purchase data.");
                    e.printStackTrace();
                }
            } else if (resultCode == RESULT_CANCELED) {

                // } else if (resultCode == RESULT_CANCELED) {

                Toast.makeText(AppMainTest.this,
                        "Sorry, you have canceled purchase Subscription.",
                        Toast.LENGTH_SHORT).show();

            } else if (resultCode == IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                Toast.makeText(AppMainTest.this, "Item already owned",
                        Toast.LENGTH_SHORT).show();
            }

        }
    }

希望它能解决你的问题。