Android billing exception

此生再无相见时 提交于 2019-11-28 21:13:51

The IabHelper will only allow a single asynchronous query to be executed at a time. You need to implement onActivityResult() and pass the parameters into the handleActivityResult() method of the IabHelper.

The in-app billing sample code implements the method like this:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(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(TAG, "onActivityResult handled by IABUtil.");
    }
}

Just in case someone is missing the forest for the trees like I was...

I received a java.lang.IllegalStateException stack trace in the Play Developer Console which didn't provide much more than the error message... so I was stumped.

I couldn't figure out how this was happening at first because I never thought to try tapping the button that triggers IAB twice! (it looks disabled after the first tap due to an overlay that let's taps through, [sometimes]).

So, make sure your users can't tap your button twice.

You are using sample code of google and in IabHelper class line 793 there is this piece of code

 if (mAsyncInProgress) throw new IllegalStateException("Can't start async operation (" +
            operation + ") because another async operation(" + mAsyncOperation + ") is in       progress.");

and when you make a purchase for first time 'mAsyncInProgress' becomes true,and until you haven't consumed your purchase it remains true ,so you need to consume your purchase. I recommend you to read all Classes in util package completely,it will help you.

after any successful purchase you need to consume it

mHelper.consumeAsync(purchase, mConsumeFinishedListener)

but sometimes the consume request fails so you need to handle your purchases every time your activity is created :

mHelper.queryInventoryAsync(mGotInventoryListener);

and try to consume your purchases in mGotInventoryListener callback.

get the latest version of the library here: https://code.google.com/p/marketbilling/source/browse/ where they fixed the problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!