Android Play Store Crashes During BillingClient.launchBillingFlow
Asked Answered
P

1

7

When attempting to launch billing for an in-app item, I am getting the following error.

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference

The code is simple. The user selects an item. I then pass that item into querySkuDetailsAsync. I get and see the result. For API reasons, I then call...

SkuDetails skuDetails = new SkuDetails(skuDetails.getOriginalJSON());
BillingFlowParams flowParams = BillingFlowParams.newBuilder().setSkuDetails(skuDetails).build();
BillingResult billingResult = client.launchBillingFlow(activity, flowParams);

And then, most of the time, I get the NPE. Things were working fine. I don't know what change caused this issue.

Note that I did try passing the skuDetails directly, in case JSON was the issue. It didn't work.

The billing library isn't open source, so I am at a loss as to how to solve this issue.

Palacios answered 1/12, 2020 at 17:26 Comment(1)
I've never had an issue with this, but I only ever pass SkuDetails instances directly that I got from querySkuDetails. Can you post the complete stack trace?Wellspring
P
15

I found a solution. If I call activity.setIntent(new Intent()) before calling "launchBillingFlow", the error goes away. Seems like a bug in the now closed sourced billing library.

Palacios answered 8/12, 2020 at 16:11 Comment(4)
Thanks! I am having the same issue and will try this with the next app update (adding a null-check on activity.intent though). It looks very plausible, as the launchBillingFlow (you can easily decompile in Android Studio) looks for the intent extra "PROXY_PACKAGE" without null-checking the intent first. Did you report this to Google yet?Phenology
I haven't reported it yet. I've had terrible luck with Google and bug reports. They probably will refuse to acknowledge the issue unless I generate a full bug report, build them a sample app, and fly out to SF to show them how to reproduce it in person.Palacios
I understand! The crash is gone now for my app with your the fix applied. Thanks again!Phenology
It seems that this is still an issue. Your fix helped me thanks! In Kotlin do activity.intent = Intent() before calling launchBillingFlow.Urrutia

© 2022 - 2024 — McMap. All rights reserved.