Oniabpurchasefinished Never Called

onIabPurchaseFinished never called.

Try adding this to the Activity that calls mHelper.launchPurchaseFlow(..):

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

onIabPurchaseFinishedListener never gets called

Alright, so after spending hours over hours about trying to solve this issue, I came across the following answer : https://stackoverflow.com/a/17411617/1203043

The problem was that my activity has a flag of "NO HISTORY". If I remove this flag off the activity, it works just fine. I really don't have any clue why it happens but here it is.

Hope you guys will never go through the nightmare I have gone through.

android in app billing using version 3 - onIabPurchaseFinished never invoked

You are passing the mPurchaseFinishedListener before you have initialized it (which happens right after you call launchPurchaseFlow).

Also, initializing the listener in the onClick is not a very good idea. You will be doing this every time the button is pressed. Take that out from the onClickIap() method.

You can do that statically in your Activity, just like it is done in Google's sample app Trivial Drive:

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase){
Log.d(TAG, "In onIabPurchaseFinished ");
...
...
...
}
};

Initializing the IabHelper is probably best to be done in the onCreate() of the activity:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_subscribe);

mHelper = new IabHelper(this);
}

Then do not forget to dispose of it in onDestory():

 @Override
protected void onDestroy() {
super.onDestroy();
// very important:
if (mHelper != null) {
mHelper.dispose();
mHelper = null;
}
}

Also, there is no need to set up the IabHelper from a background thread. Just call mHelper.startSetup from your UI thread whenever you are ready.

I don't recieve onIabPurchaseFinished when purchase is finished

I've just forgotten to write onActivityResult:

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
if (mHelper == null) return;

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

onBillingSetupFinished never called

There are no errors in your code afaik except the Toast itself. onBillingServiceDisconnected isn't called on the main thread. If you put a try catch around it like so:

try {
Toast.makeText(this@Settings, "NO", Toast.LENGTH_SHORT).show()
} catch (ex: Exception) {
Log.e("MyApp", "Error", ex)
}

It will print an error like this

06-05 00:00:38.713 8595 9215 E MyApp :
java.lang.NullPointerException: Can't toast on a thread that has not
called Looper.prepare()

You can also print the thread the callback is called from:

Log.e("MyApp", "Running on ${Thread.currentThread().name}")

and it will tell you

Running on PlayBillingLibrary-1

So switch back to the main thread for the Toast (there are ways) or use a simple Log statement to verify that the method is called.

IabHelper PurchaseFinishedListener

I found out how to fix it. Implement handleActivityResult in onActivityResult. It's needed to create a bridge between the listener and the launched purchase flow.

Given below is the code I used:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + ","
+ data);

// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
} else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}

Android in app billing (IAB) onIabSetupFinished not being called

After lunch I switched on debug in IanHelper.java and this code appears to be working now.

boolean mDebugLog = true; // Line 75

I cannot see any reason why this wasn't working before. Must be user Error, wrong apk installed or something like that! Now we will never know!



Related Topics



Leave a reply



Submit