Finishing the purchase of an Android application after payment

I applied the app to purchase in my app. I used the “TrivialDrive” example for version 3 of the billing in the application, I tested the application with static answers, everything works as expected.

But when I download the application from the market, upon successful purchase the application crashes,

My successful purchase code

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 a successful purchase message, but I do not see this message (this means that linux is not running it) when I successfully purchased it, after the application crashes, the application crashes.

When you restart the application and try to buy a product, it is already purchased.

I received a crash message from the 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 the 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 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 great on a static response, but crashes when I buy from the market.

+6
source share
5 answers

I fixed this problem simply by creating my IabHelper (mHelper) static member variable

+1
source

I ran into the same problem. Then I realized that all activities are sometimes recreated during the buying process (for no reason). I did not test the Trivia example separately to check if this is happening with this application, but I would expect this because it seems to be related to the billing process (or to the helper methods of this example that I use in my own application too) .

The only difference between the billing part of my own code and the Trivia example was that I created mHelper from a method running on a specific event, while in the Trivia example, an instance was created from onCreate. So I made this change (now I am creating a new mHelper instance from onCreate), and everything started working fine. The fact is that when the activity is recreated, mHelper gets the instance again in onCreate, so in the next call to onActivityResult it cannot be zero.

To be honest, I don't know why an activity is active and why the onActivityResult method is called for a new instance of Activity, but now everything works.

0
source

I had the same problem. I found that when the purchase window in the application is displayed, the onPause method is executed in my application activity, and when the box is closed, the onResume method is executed. This is the code for these methods:

 @Override public void onPause() { mWakeLock.release(); super.onPause(); } @Override public void onResume() { super.onResume(); mWakeLock.acquire(); } 

Finally, I delete the lines in which mWaveLock is executed.

 @Override public void onPause() { super.onPause(); } @Override public void onResume() { super.onResume(); } 

and it works great. I hope this helps someone.

0
source

I know this thread is outdated, but I probably had the same problem. What does your method do

 complain("Error purchasing: " + result); 

make?

I called

 Toast.makeText(getParent(), "Premium purchased successfully", Toast.LENGTH_LONG) .show(); 

in the same place, and this caused the following error for me:

 06-26 14:02:54.229: E/AndroidRuntime(25681): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=10001, result=0, data=Intent { (has extras) }} to activity {sf.com.flightBook/sf.com.flightBook.ui.configuration.ConfigurationMain}: java.lang.NullPointerException 

If this is still relevant for you, you should check your "complaints ()" method.

0
source

When I had this problem, I realized that my public key in my application does not match the license key that Google Play generated for my application.

0
source

All Articles