Android Question In-App billing fails occassionally

Inman

Well-Known Member
Licensed User
Longtime User
I am using InAppBilling3 (1.31) in an app of mine. I have about 14000 active users, out of which I have received emails from maybe 40-50 users saying they can't upgrade. Apparently when they click upgrade button, the popup from Play Store won't appear. Here is the code for upgrade button.
B4X:
If BillingSupported Then
   manager.RequestPayment(ProductID,"inapp","upgrade")
End If

Now regarding the variable BillingSupported, manager.Initialize("manager", key) is called in Activity_Create. And then this happens.
B4X:
Sub manager_BillingSupported (Supported As Boolean, Message As String)
    BillingSupported=Supported   
    If Supported Then manager.GetOwnedProducts Else ProgressDialogHide
End Sub

Since the user is complaining that he doesn't see the in-app upgrade pop-up from Play Store, it could mean either BillingSupported=False or manager.RequestPayment(ProductID,"inapp","upgrade") is not working. Some of the users who complained later informed me that in-app purchase worked after restarting the app a few times.

The same issue is happening with some users who are trying to restore their previous purchases. As you can see I am calling manager.GetOwnedProducts if BillingSupported=True. Here also it has worked for users after 3-4 attempts.

In both cases the common factor is the check for BillingSupported=True. I am wondering if it returns False sometimes. Personally I couldn't recreate this on any of my test devices.

Is the B4A version of the library on a par with Google's latest release?
 

Inman

Well-Known Member
Licensed User
Longtime User
You are probably doing something wrong.

Where is the code that initializes BillingManager? Where is BillingSupported declared?

BillingManager is initialized in Activity_Create with manager.Initialize("manager", key), where manager is a Process_Globals variable. BillingSupport is declared in Globals.

You should show a message if BillingSupported is False.
That's a good idea. I will add it to the next update.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
Ok I watched the video again. I will try moving BillingSupported to Process_Globals and see if it makes a difference.

But I still have a doubt. BillingSupported is used only in one activity, which is the Main activity. User runs the app, manager checks for BillingSupported, displays the result, all happening in sequence within the same activity. In this case, will it make a difference if BillingSupported is in Process_Globals, as opposed to Globals?
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
No, I will do that now. Will it make a difference when the process is a straightforward Install-Run-Check Billing Supported-False?

EDIT:

Actually I do have it inside If FirstTime=True check.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
This means that if the activity was destroyed and recreated then BillingSupported will be False. This happens because it was a Global variable instead of a Process_Global variable.

Even though the chance of activity getting destroyed is pretty low when the user experiences this in the very first run of the app (while activity is still in foreground), I guess it is worth a try. Thanks Erel.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
If orientation is not locked then it will happen very quickly. It can also happen in other cases (user clicks on the back key and then returns to your app as well as other cases).

I have orientation locked to portrait mode but you are right about the back key issue, which is probably why only a small subset of users are experiencing this. I will definitely move the variable to Process_Globals and see.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I released an update yesterday with the changes mentioned above and I am still getting error reports on latest version. Now that there is a popup for BillingSupported, it is returning false for some users.

To recap, here is the in-app billing implementation in my app
  • Dim manager As BillingManager3, BillingSupported As Boolean inside Process_Globals of Main activity
  • If FirstTime=True, then manager.Initialize("manager", key)
B4X:
Sub manager_BillingSupported (Supported As Boolean, Message As String)
    BillingSupported=Supported   
    If Supported Then manager.GetOwnedProducts Else ProgressDialogHide
End Sub
When user clicks upgrade/restore button
B4X:
If BillingSupported Then
   manager.RequestPayment(ProductID,"inapp","upgrade")
Else
   Msgbox("Play Store billing is not working on your device","Error")
End If
 
Upvote 0

npsonic

Active Member
Licensed User
I released an update yesterday with the changes mentioned above and I am still getting error reports on latest version. Now that there is a popup for BillingSupported, it is returning false for some users.

To recap, here is the in-app billing implementation in my app
  • Dim manager As BillingManager3, BillingSupported As Boolean inside Process_Globals of Main activity
  • If FirstTime=True, then manager.Initialize("manager", key)
B4X:
Sub manager_BillingSupported (Supported As Boolean, Message As String)
    BillingSupported=Supported 
    If Supported Then manager.GetOwnedProducts Else ProgressDialogHide
End Sub
When user clicks upgrade/restore button
B4X:
If BillingSupported Then
   manager.RequestPayment(ProductID,"inapp","upgrade")
Else
   Msgbox("Play Store billing is not working on your device","Error")
End If
This is just a guess, but have you think about possibility that these users may have flashed devices, so there might be some Google components missing.
You usually decide your self what Google services to install when flashing device with new os.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
This is just a guess, but have you think about possibility that these users may have flashed devices, so there might be some Google components missing.
You usually decide your self what Google services to install when flashing device with new os.

I actually asked these users that and every one of them seem to have no issues purchasing other apps.

Are they able to make a purchase if they kill the app and start it again?

They didn't say "kill" specifically. But apparently, multiple closing and opening attempts seem to work for many users.

I am thinking maybe when BillingSupported=False, I should tell the user to restart the app and call ExitApplication myself. That is equivalent to killing the app, right?

Also is it possible to restart the app via code? I think I have seen some apps do it.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
FWIW - I use InAppBilling3 in several apps & haven't had this issue. I put the initialization & BillingSupported & OwnedProducts callbacks into my Starter service & everything else in a separate "Purchase" activity. Because I also use Firebase Analytics I also do an IsGooglePlayServicesAvailable check before I initialize my billing manager.

I do occasionally see IAP related crashes in Crashlytics, however these are always related to devices that have been rooted.

- Colin.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
If you can, try to debug it. Add some log messages and try to understand what happens. Many developers use this feature and I don't remember seeing other similar reports.

Ok. What about calling ExitApplication or a way to restart the app via code?
FWIW - I use InAppBilling3 in several apps & haven't had this issue. I put the initialization & BillingSupported & OwnedProducts callbacks into my Starter service & everything else in a separate "Purchase" activity. Because I also use Firebase Analytics I also do an IsGooglePlayServicesAvailable check before I initialize my billing manager.

I do occasionally see IAP related crashes in Crashlytics, however these are always related to devices that have been rooted.

- Colin.

Never tried moving the code to Starter service. Will do that next.

What was the reason you put in Starter service?
 
Upvote 0

asales

Expert
Licensed User
Longtime User
FWIW - I use InAppBilling3 in several apps & haven't had this issue. I put the initialization & BillingSupported & OwnedProducts callbacks into my Starter service & everything else in a separate "Purchase" activity. Because I also use Firebase Analytics I also do an IsGooglePlayServicesAvailable check before I initialize my billing manager.

I do occasionally see IAP related crashes in Crashlytics, however these are always related to devices that have been rooted.

- Colin.
Very nice.
Can you put an example of the subs in Starter service and in the separate activities?
Thanks.
 
Upvote 0
Top