IabHelper PurchaseFinishedListener

后端 未结 4 1391
小蘑菇
小蘑菇 2020-12-08 10:34

If I send a purchase intent via the standard

String mySku = \"android.test.purchased\";

mHelper.launchPurchaseFlow(this, mySku, 10001, mPurchaseFinishedLis         


        
相关标签:
4条回答
  • 2020-12-08 11:18

    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);
    }
    
    0 讨论(0)
  • 2020-12-08 11:21

    For those of you who had the same issue I was experiencing...

    I just made my member variable IabHelper static, and that fixed the issue.

    I already had added AndroidPenguin's code, and was still getting crashes from a null IabHelper, after I had purchased an item(so onActivityResult never had a chance to call handleActivityResult because mHelper was null).

    0 讨论(0)
  • 2020-12-08 11:24

    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.");
            }
        }
    
    0 讨论(0)
  • 2020-12-08 11:32

    In my case, it is working try like this, wait until that google play dialog close itself.Then, the listener will get called

    0 讨论(0)
提交回复
热议问题