Current link to IAB for Android

I’ve been struggling with Android IAB v3 for some time now. I am constantly working on my test devices. However, my crash reporting service shows two recurring failures: one for null pointer exception and one for exception due to illegal state. I tried to update the Google sample code with numerous suggestions from Stackoverflow users facing similar issues. I went through the “read crash reports, do research, try to fix the crash, send updates, see the same crash reports”, cycle several times. I think the time has come for a different approach.

If you started with Android IAB today, what would you choose as the most modern, correct resource for code samples, patches, documentation, etc.

This should not be the only resource. Any combination of sample code, corrections from SO posts, blog posts, or even an “update from the Android SDK Manager” will be helpful. Ideally, we can create a resource for people new to the IAB that prevents their headaches and tries to try to integrate the service.


edit 1 : more information about crashes

java.lang.IllegalStateException: Can't start async operation (refresh inventory) because another async operation(launchPurchaseFlow) is in progress. at com.android.vending.billing.IabHelper.flagStartAsync(IabHelper.java:832) at com.android.vending.billing.IabHelper.queryInventoryAsync(IabHelper.java:623) at com.android.vending.billing.IabHelper.queryInventoryAsync(IabHelper.java:651) ... java.lang.NullPointerException at com.android.vending.billing.IabHelper.launchPurchaseFlow(IabHelper.java:398) at com.android.vending.billing.IabHelper.launchPurchaseFlow(IabHelper.java:350) ... 

These are two exceptions. They are not always in the same places on IabHelper. Maybe I could just fix them, but that doesn't seem like the right way to solve this problem. In addition, it does not help anyone.

It’s possible that I am using an outdated sample of Google code. However, I searched quite a bit and could not find anything more recent.

+5
source share
4 answers

Hey, I’ve also been working on InApp Purchase since 10 days, and I have successfully integrated my application and am ready to make it live. Initially, when I started doing this, I downloaded the Google Payment InApp Billing Example called "Trivial Drive" from here .

But this did not help me, since he has a lot of problems and mistakes. So I decided to do it myself, using the new v3 api, which you can find. This tutorial has a clear explanation that will help you, as well as if you have time to see this youtube video, where a Google employee explained how to integrate it.

Also, if you need a quick example, I have an example application that you can download from here . Feel free to ask if you have any questions.

+6
source

The first IllegalStateException occurs because a previously launched operation using the IAB helper is not yet complete.

Likely reasons:

  • Forgot to call mHelper.dispose() in onDestroy() activity.
  • If you start a purchase when you press the button quickly, double-clicking the button on any device will crash.

In your case, you are trying to fulfill an inventory request when the purchase has already started.

Solution: The status of the async operation is reflected in the mAsyncInProgress variable in IabHelper . You will need to change the scope of the variable to public , by default it is a package. You can then take either of two approaches after querying the variable:

Make sure you call mHelper.dispose() in onDestroy() activity.

  • cancel the current operation and start a new operation, ignoring

or

  1. current request if any operation is performed.

An exception is flagStartAsync in flagStartAsync .

To understand the root cause of a NullPointerException , you will need to provide code to run PurchasFlow with line numbers.

Other precautions you should take: To avoid the "IAB Assistant" is not configured. Cannot complete the operation: launchPurchaseFlow, which is called when you call launchPurchaseFlow before the IabHelper installation completes.

You can disable the purchase button by default. Enable the button on the onIabSetupFinished IabHelper callback. Therefore, the button will only work when IabHelper installation is complete.

+2
source

Perhaps you are using asynchronous operations. The current IabHelper is not safe if you use methods ... async. The problem is that at any time you start the asynchronous operation, dispose can be called on the main thread. In this case, you will get NullPointerExceptions and IllegalStateExceptions.

Try this clone studiozanandroid

With Ans link, download here to avoid asynchronous errors.

besides this verification of signature verification issues like paying me lib , try using OpenIAB libs.

+1
source

Whatever you do, DO NOT USE IabHelper. This is left over from earlier versions of application billing. This is not required with version 3, as it introduces a different level and is a bug.

Just do billing, as shown in white papers - implements billing applications .

The V3 API basically contains only three methods and is very easy to implement. If you are serious about billing in the application, you should understand how this process works in any case, no library or assistant will help you with this.

-1
source

Source: https://habr.com/ru/post/1203968/


All Articles