Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

inappbilling NOTIFY_EVENT is being called multiple times & making random push notifications

$
0
0

Android - inappbilling mobile 2.2.1 - Titanium Studio, build: 3.2.3.201404181442

I tested this on both an HTC ONE M7 Android 4.4.2 & a Samsung Galaxy S4 Active 4.2.2

I'm having a bit of trouble when using NOTIFY_EVENT. My in-app purchasing is fairly simple - after purchase, the app goes to my remote server and downloads a .JSON file to load into a database. That part all works (I put the code into the if (checkBillingResponse.responseCode == InAppBilling.RESULT_OK){) code and as soon as the Google Play window popped up, the file is downloaded. That was just to test, it's out of there now :)

It seems as though NOTIFY_EVENT is being called multiple times, sometimes 10-12 times. I've read that using NOTIFY_EVENT is the only way to get PURCHASE_STATE_CHANGED_EVENT to fire... Is this correct? I couldn't get it to work until I used NOTIFY_EVENT.

Anyway, here's my code for the in-app purchasing part:

Buybutton.addEventListener('click',function(e)
{ 
 
var synchronousResponse = InAppBilling.requestPurchase({
        productId: storeID,
        productType: InAppBilling.ITEM_TYPE_INAPP,
    });
});
 
InAppBilling.addEventListener(InAppBilling.NOTIFY_EVENT, function(e) {
    var synchronousResponse = InAppBilling.getPurchaseInformation({
        notificationIds: [e.notifyId]
    });
    a=JSON.stringify(e.notifyId);
   alert(a); //THIS makes 10-12 pop up windows with different responses
});
 
InAppBilling.addEventListener(InAppBilling.PURCHASE_STATE_CHANGED_EVENT, function(e){
 
        download(fileName);
        //UPDATE DATABASE CODE IS HERE
        winDialog.show();
        db.close();
 
});
Also I usually get a 'Purchase Failed' Push Notification when this fires (only 1) and it says the purchase failed, BUT it always for a product I DIDN'T purchase at that time. I only ever get 1 of those notifications per button click, but 10-12 of those alerts.

The PURCHASE_STATE_CHANGED_EVENT is being called AND it's working correctly in that aspect, but the app will sometimes freeze with all the alerts going on (even if I comment that line out, the app will hang and crash, but when I open the app again, what I wanted to buy is purchased).

There is only 1 instance of these eventlisteners in my app. I don't have them in any other .JS files.

Let me know if you need to see any other code. Thanks for looking!


Viewing all articles
Browse latest Browse all 8068

Trending Articles