其他分享
首页 > 其他分享> > android – 活动结果中的应用内结算-v3错误

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

作者:互联网

每当启动支付服务时一切正常,但在活动结果中得到错误

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

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

否则控制权在其他地方……

解决方法:

检查我的下面的代码:

@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();
            }

        }
    }

希望它能解决你的问题.

标签:android,android-intent,in-app-purchase,in-app-billing
来源: https://codeday.me/bug/20190929/1834053.html