Someone Somewhere
Someone Somewhere

Reputation: 23787

How is it possible to debug IAP in Android?

What I've done:

How do I debug my app so that I can step through the IAP process and observe the problem ? Is it possible to attach the debugger and step through the IAP process ?


UPDATE

so progress here is ridiculously slow because it takes Google about 2 hours to upload an alpha release - RIDICULOUS!

By doctoring my app with a ton of toast messages (and recording video when I run my app to check all the messages) I've found that IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener isn't called eventhough it is referenced in launchPurchaseWorkflow(), see below:

protected void launchPurchaseWorkflow(Activity activity, String sku)
{
    mHelper.launchPurchaseFlow(
            activity,
            sku,
            Constants.PURCHASE_REQUEST_ID,
            mPurchaseFinishedListener,
            Constants.DEVELOPER_PAYLOAD);
}

As a result, a successful purchase doesn't trigger a callback into the app. So the app isn't updating the UI... After restarting the app, it does do an inventory successfully and then it detects the purchase.

What am I doing wrong ? (What isn't the documentation telling me?)

Upvotes: 1

Views: 308

Answers (1)

Someone Somewhere
Someone Somewhere

Reputation: 23787

Solution:

1) Copy the "util" folder from \sdk\extras\google\play_billing\samples\TrivialDrive\src\com\example\android\trivialdrivesample into your project (First make sure your SDK Manager has updated to the latest "Google Play Billing Library")

2) From \sdk\extras\google\play_billing\samples\TrivialDrive\src\com\example\android\trivialdrivesample\MainActivity.java copy all the important callbacks, such as IabHelper.QueryInventoryFinishedListener mGotInventoryListener, IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener, IabHelper.OnConsumeFinishedListener mConsumeFinishedListener

3) I wrote this utility method, which you could copy into your code also:

// (arbitrary) request code for the purchase flow
public static int PURCHASE_REQUEST_ID = 1234;

protected void launchPurchaseWorkflow(Activity activity, String sku)
{
    mHelper.launchPurchaseFlow(
            activity,
            sku,
            Constants.PURCHASE_REQUEST_ID++,// just needs to be a positive number and unique
            mPurchaseFinishedListener,
            Constants.DEVELOPER_PAYLOAD);
}

So far so good... there is one more thing that you need to make it all work !

4) You would think that since you've passed a reference mPurchaseFinishedListener to mHelper.launchPurchaseFlow() that you're good to go - but you're not !

Copy this code into the same activity that you passed in mHelper.launchPurchaseFlow()

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
    if (ApplicationContext.mHelper == null) return;

    // Pass on the activity result to the helper for handling
    if (!ApplicationContext.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.");
    }
}

NOW IT WILL WORK !!

I spent 5 days on this "problem" - you would think that requiring onActivityResult() would have been better documented within trivialdrivesample. In fact, there's absolutely no method comment for it !

Upvotes: 1

Related Questions