Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Play Store Crashes During BillingClient.launchBillingFlow

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.

like image 591
Justin Avatar asked Dec 01 '20 17:12

Justin


1 Answers

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.

like image 184
Justin Avatar answered Oct 15 '22 14:10

Justin