Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onIabPurchaseFinishedListener never gets called

My onIabPurchaseFinishedListener never gets called, even though I click the buy now in the inapp dialog, the logcat doesn't print anything.

public class CreateAlbumActivity extends Activity {
IabHelper mHelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_album);
        mHelper = new IabHelper(this, Global.inapp);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
           public void onIabSetupFinished(IabResult result) {
              if (!result.isSuccess()) {
                 // Oh noes, there was a problem.
                 // AlertDialogHelper.CreateNormalDialog(context, "Failed to set In-App Billing: " +result);
                 Log.d(Global.TAG, "Problem setting up In-app Billing: " + result);
                 return;
              }            
                 // Hooray, IAB is fully set up!  

           }
        });
    }
 public void createAlbumEvent(){

                    mHelper.launchPurchaseFlow(CreateAlbumActivity.this, "android.test.purchased", 10001,   
                           mPurchaseFinishedListener, "bGoa+V7g/yqDXvKRqq");


    }
    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener 
     = new IabHelper.OnIabPurchaseFinishedListener() {
     public void onIabPurchaseFinished(IabResult result, Purchase purchase) 
     {
        if (result.isFailure()) {
           Log.d(Global.TAG, "Error purchasing: " + result);
           return;
        }      
        Log.d(Global.TAG, "SUCCESS PURCHASE!");
     }
     };
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         Log.d(Global.TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + 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(Global.TAG, "onActivityResult handled by IABUtil.");
         }
     }
}
like image 678
idish Avatar asked Aug 18 '13 16:08

idish


3 Answers

Alright, so after spending hours over hours about trying to solve this issue, I came across the following answer : https://stackoverflow.com/a/17411617/1203043

The problem was that my activity has a flag of "NO HISTORY". If I remove this flag off the activity, it works just fine. I really don't have any clue why it happens but here it is.

Hope you guys will never go through the nightmare I have gone through.

like image 61
idish Avatar answered Oct 22 '22 03:10

idish


I found the following link helpful: onIabPurchaseFinished never called.

The problem is that the Activity doesn't handle onActivityResult correctly and there is no mention of it in the In App Purchasing tutorial.

like image 5
running-codebase Avatar answered Oct 22 '22 03:10

running-codebase


The problem I faced was because I used fragments and onActivityResult was not called until I called it manually from the parent activity. I provided an answer here if anyone faces the same issue!

like image 2
Abdelalim Hassouna Avatar answered Oct 22 '22 04:10

Abdelalim Hassouna