Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IabHelper PurchaseFinishedListener

Tags:

If I send a purchase intent via the standard

String mySku = "android.test.purchased";  mHelper.launchPurchaseFlow(this, mySku, 10001, mPurchaseFinishedListener); 

I am able to purchase the item and it will store and I can query the item and that works fine too. The only thing that doesn't work is is the PurchaseFinishedListener. I've got it coded pretty much identical to the sample app however it doesn't seem to get called at all.

12-12 01:40:47.248: D/IabHelper(23502): Calling getPurchases with continuation token: null 12-12 01:40:50.116: D/IabHelper(23502): Starting async operation: launchPurchaseFlow 

These are the last two methods that get called and after that when I finish the purchase it doesn't call the purchasefinishedlistener

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new OnIabPurchaseFinishedListener() {      @Override     public void onIabPurchaseFinished(IabResult result, Purchase purchase) {         Log.d(TAG, "Purchase finished: " + result + ", purchase: "                 + purchase);         if (result.isFailure()) {             complain("Error purchasing: " + result);             // setWaitScreen(false);             return;         }          if (purchase.getSku().equals(mySku)) {             Log.d(TAG, "mySku is being consumed.");             mHelper.consumeAsync(purchase, mConsumeFinishedListener);         }         Log.d(TAG, "Purchase successful.");         new AsyncQuestionsActivity().doInBackground();     } }; 

Nothing from the log to the end works. Is there anything that I'm just somehow missing?

like image 886
AndroidPenguin Avatar asked Dec 12 '12 01:12

AndroidPenguin


2 Answers

I found out how to fix it. Implement handleActivityResult in onActivityResult. It's needed to create a bridge between the listener and the launched purchase flow.

Given below is the code I used:

@Override     protected void onActivityResult(int requestCode, int resultCode, Intent data) {         super.onActivityResult(requestCode, resultCode, data);          Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + ","                 + data);          // Pass on the activity result to the helper for handling         if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {             super.onActivityResult(requestCode, resultCode, data);         } else {             Log.d(TAG, "onActivityResult handled by IABUtil.");         }     } 
like image 149
AndroidPenguin Avatar answered Oct 12 '22 02:10

AndroidPenguin


AndroidPenguin, I'm running into the same issue as you, but I have the activityresult correctly set and yet my purchasefinishedlistener does not execute.

Here is my onActivityResult

@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {      if (SettingsManager.getBooleanSetting(rootId, "inapppurchase", false)){         Log.d(TAG, "take care of activity result with billing helper");         if (!mBillingService.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.");         }     }     else         super.onActivityResult(requestCode, resultCode, data); } 
like image 39
kevinl Avatar answered Oct 12 '22 02:10

kevinl