Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android in-app purchase crashing after payment

I have implemented in app purchase in my app I have used "TrivialDrive" example for version 3 of in-app billing, I have tested app by using static responses all works as expected.

But when I download app from market, application crashes on successful purchase,

My code is of successful purchase

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {

    Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
    if (result.isFailure()) {
    complain("Error purchasing: " + result);
    }

    if (purchase != null) {
    if (purchase.getSku().equals(Constants.IN_APP_PURCHASE_PRODUCT_ID)) {
        // bought the premium upgrade!
        String message = getResources().getString(R.string.app_purchase_successful_msg);
        mIsPremium = true;
        updateUi(mIsPremium);
        successAlert(message);
    }
    }
}
};

I have setting up message on successful purchase but i cant see this message, (means those linse are not executing) when I successfully purchased from it, application crashes after successful payment.

When relaunch app and try to buy item it says already purchased.

I got crash report from developer console.

02-09 02:01:13.181: E/AndroidRuntime(11530): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=10001, result=-1, data=Intent { (has extras) }} to activity {com.eknathkadam.grammaruplite/com.webrich.base.ui.GoogleInAppPurchaseActivity}: java.lang.NullPointerException
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3141)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3184)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread.access$1100(ActivityThread.java:130)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.os.Looper.loop(Looper.java:137)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread.main(ActivityThread.java:4745)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at java.lang.reflect.Method.invokeNative(Native Method)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at java.lang.reflect.Method.invoke(Method.java:511)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at dalvik.system.NativeStart.main(Native Method)
**02-09 02:01:13.181: E/AndroidRuntime(11530): Caused by: java.lang.NullPointerException
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.google.billing.Base64.decode(Base64.java:434)**
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.google.billing.Security.generatePublicKey(Security.java:87)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.google.billing.Security.verifyPurchase(Security.java:66)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.google.billing.IabHelper.handleActivityResult(IabHelper.java:437)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.webrich.base.ui.GoogleInAppPurchaseActivity.onActivityResult(GoogleInAppPurchaseActivity.java:238)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.Activity.dispatchActivityResult(Activity.java:5192)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3137)
02-09 02:01:13.181: E/AndroidRuntime(11530):    ... 11 more
02-09 02:02:20.610: E/JavaBinder(250): !!! FAILED BINDER TRANSACTION !!!
02-09 02:02:20.638: E/MountService(250): Listener dead
02-09 02:02:20.638: E/MountService(250): Listener dead
02-09 02:02:22.028: E/InputDispatcher(250): channel '41f313f0 com.android.vending/com.android.vending.AssetBrowserActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
02-09 02:03:59.884: E/PowerManagerService(250): Excessive delay setting brightness: 198ms, mask=2 

Its throwing Null Pointer Exceptions in onActivityResult() method on this line

if (!mHelper.handleActivityResult(requestCode, resultCode, data))

Method is 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.");
}
}

It works perfectly fine on static response but crashes on when I purchase from market.

like image 343
Mac Avatar asked Feb 09 '13 04:02

Mac


People also ask

Why does my in app purchase fail?

- Make sure your card information is up to date in Google Payments. Expired credit cards or old billing addresses are a common reason for payments not to work properly. - Try a different payment method.

Are in app purchases a rip off?

In-app purchase fraud disrupts the economics of a game and allows some players to gain an unfair advantage. This can destroy not only the game economy, but also the strong gaming community, which many games rely on for the longevity of the game.


1 Answers

I fixed this issue by simply making my IabHelper member variable(mHelper) static

like image 82
wizurd Avatar answered Sep 28 '22 11:09

wizurd