Reputation: 3585
I have several apps that sell subscriptions but now I'm selling a consumable and it's not quite working right. I sell the consumable and the order does indeed go through but my code to immediately consume and provision is not working. . .
public void btnTranslations_Clicked(View v)
{
String payload = "";
DebugLog.debugLog("Launching translations purchase flow", false);
mHelper.launchPurchaseFlow(this, SKU_TRANSLATIONS, RC_REQUEST,
mPurchaseFinishedListener, payload);
}
// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
DebugLog.debugLog("In Purchase finished: " + result + ", purchase: " + purchase, false);
in the above example the purchase flow is successfully launched but control never returns to the PurchaseFinishedListener CallBack. I know because that debug statement never executes.
Fortunately, when the app is started up again, the following code
mHelper.queryInventoryAsync(mGotInventoryListener);
is working just fine because the callback works and the consumables the user purchased on the last execution gets consumed and provisioned.
So the question is why is the IabHelper.OnIabPLurchaseFinishedListener never getting executed? Thanks, Dean
Upvotes: 1
Views: 133
Reputation: 3585
Well, here I am again answering my own question. I don't know if my questions are getting harder or this forum is becoming less useful than it used to be.
The problem was errors and omissions in Google documentation namely this.
The documentation completely fails to say that the following method is required to make immediate consumption and provisioning work . . .
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
if (mHelper == null) return;
// 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.");
}
}
The call to mHelper.handleActivityResult somehow causes the mPurchaseFinishedListener callback to execute. The TrivialDrive example code has this method - they just didn't see fit to put it in the how-to instructions. There are also other errors such as how to properly include the aidl file.
The harm is that these sloppy docs turn a few-hour task into a few-day task because every one of their omissions/errors takes researching.
Maybe the next victim of these docs will trip across this post and save some time. Dean
Upvotes: 2