Hi all,
I have a question to any Java professional here.
My IAP module for Android is almost finished but there is a tiny problem. The purchase callback isn't called and the solution is to override the onActivityResult method like it's explained here:
http://stackoverflow.com/questions/14800286/oniabpurchasefinished-never-called?rq=1
@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.");
}
}
So far so good, but my IAPWrapper isn't an activity and using the BBAndroidGame.AndroidGame().GetActivity() call does not make it because it's obviously not "overridden" in the base (super) class called AndroidGame or MonkeyGame.
public void purchase( String itemId, String payload )
{
_isPurchaseFinished = false;
Activity activity = BBAndroidGame.AndroidGame().GetActivity();
_helper.launchPurchaseFlow( activity, itemId, 10001, _purchaseFinishedListener, payload );
}
Using the lines above the purchase itself DOES work but the callback is never called:
// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener _purchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener()
{
public void onIabPurchaseFinished( IabResult result, Purchase purchase )
{
_lastResult = result;
if( result.isSuccess() )
_isPurchaseFinished = true;
else
_isPurchaseFinished = false;
}
};
Of course I could alter the monkeytarget.java file but I don't like that. Another "solution" might be to extend my IAPWrapper class from AndroidGame (or MonkeyGame) BUT that doesn't work either because there is no running instance of my class as still the MonkeyGame instance is running.
All in all I'd like to avoid to change the monkeytarget.java file (which doesn't know anything about my wrapper class)...
Any ideas?
|