0

I am trying to get back to the IabHelper.OnIabPurchaseFinishedListener when purchasing is over for my subscription , but the problem is Its not calling when purchase is done .

I had tried with onactivity result but still its not working here Is my code block I'm extending fragments as below

public class ConfirmationScreen extends Fragment {

mHelper = new IabHelper(getActivity(), base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
    public void onIabSetupFinished(IabResult result) {
        Log.d(TAG, "Setup finished.");

        if (!result.isSuccess()) {
           // Oh noes, there was a problem.
           complain("Problem setting up in-app billing: " + result);
           return;
        }

        // Have we been disposed of in the meantime? If so, quit.
        if (mHelper == null) return;

        // IAB is fully set up. Now, let's get an inventory of stuff we own.
        Log.d(TAG, "Setup successful. Querying inventory.");
        //  mHelper.queryInventoryAsync(mGotInventoryListener);
    }
});

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
        Log.d(TAG, "Query inventory finished.");
        // Have we been disposed of in the meantime? If so, quit.
        if (mHelper == null) return;

        // Is it a failure?
        if (result.isFailure()) {
            complain("Failed to query inventory: " + result);
            return;
        }
        Log.d(TAG, "Query inventory was successful.");

        /*
         * Check for items we own. Notice that for each purchase, we check
         * the developer payload to see if it's correct! See
         * verifyDeveloperPayload().
         */

        Purchase gasPurchase = inventory.getPurchase(SKU);
        if (gasPurchase != null && verifyDeveloperPayload(gasPurchase)) {
            Log.d(TAG, "We have gas. Consuming it.");
            mHelper.consumeAsync(inventory.getPurchase(SKU), mConsumeFinishedListener);
            return;
        }
    }
};

//Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
        Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
        // if we were disposed of in the meantime, quit.
        if (mHelper == null) return;
        Log.d(TAG, "Purchase successful.");
        if (purchase.getSku().equals(SKU)) {
            //bought 1/4 tank of gas. So consume it.
            Log.d(TAG, "Purchase is gas. Starting gas consumption.");
        }
    }
};

I have referred to this link

Community
  • 1
  • 1
Kirtikumar A.
  • 4,140
  • 43
  • 43

2 Answers2

4

You need to implement the onActivityResult method on your FragmentActivity

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Pass on the activity result to the helper for handling
    if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
        // not handled, so handle it ourselves (here's where you'd
        // perform any handling of activity results not related to in-app
        // billing...
        super.onActivityResult(requestCode, resultCode, data);
    } else {
        Log.d(TAG, "onActivityResult handled by IABUtil.");
    }
}
alexgophermix
  • 4,189
  • 5
  • 32
  • 59
Dayanand Waghmare
  • 2,979
  • 1
  • 22
  • 27
0

You need to implement the onActivityResult method on your FragmentActivity

This has to be put in activity, which actually runs the:

mHelper.launchPurchaseFlow(...);
AlexV
  • 743
  • 6
  • 9