Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

android - In-app billing-v3 error in activity result

Whenever starting payment service everything is ok but in activity result got Error

on activity result RESULT_OK = 0 and resultCode =-1 as expect in sample example but i don't know where is going to wrong..

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

there is control goes in else statment ..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

check my below code:

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

        }
    }

Hope it will solve your problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...