Android Question In-App Billing need online connection to keep working?

asales

Expert
Licensed User
Longtime User
I did a app with the In-App Billing (that hide the AdMod) and works ok, but when I restart the phone - in offline mode (without wi-fi or data connection) - in-app billing don't work and show the admob.

I need start the internet connection and restart the app to in-app billing works again.

Is this how it works or I made a mistake in code (I can post the code if necessary)?

Thanks in advance for any tips.
 

asales

Expert
Licensed User
Longtime User
Are you referring to BillingManager.GetOwnedProducts method?
No. I use the same code of tutorial.

The problem is:
when I restart the devide (phone or tablet), without internet connection, the options (in-app billing to remove ads) of full version of my app is disable.

I need turn on the internet connection and restart the app to options of full version works again.

I want to know if this is how in-app billing works?
It needs the internet connection (after restart the device) to check if the user has bought a option to remove the ads)?
 
Upvote 0

asales

Expert
Licensed User
Longtime User
I'll try to explain better my doubts:
1 - I have a app with in-app billing that remove advertisements and enable full options.
2 - The option to purchase works correctly: I select the option, pay and the ads disappear and the full options are enable.
3 - The problem: when I restart the smartphone with the internet connection (wi-fi or 3G) turn off, the full options is disable.
4 - My doubt: this is how In-app Billing works? It loses the purchase information in the application, if the smartphone is restarted and you are without internet?
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Can you post your relevant code?
Hi @JonPM.
This is my code (I removed several parts, but this is related to in-app billing):

B4X:
Sub Process_Globals
    Dim billman3 As BillingManager3   
    Dim Const key As String = "MIIBIjANBgkqhkB..."
    Dim DeveloperPayload As String = "My App"
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        billman3.Initialize("billman3", key)     
        billman3.DebugLogging = False
    End If
...
End Sub

'* * * IN-APP BILLING

Sub billman3_BillingSupported (Supported As Boolean, Message As String)
    If Supported Then
        billman3.GetOwnedProducts
    End If
End Sub

Sub billman3_OwnedProducts (Success As Boolean, purchases As Map)
    Log("Success: " & Success)
    If Success Then
        ' success = true and have purchases
        If purchases.Size > 0 Then
            Log("purchases.Size > 0")
            For Each p As Purchase In purchases.Values
                Log(p.PurchaseState) '0 - purchased, 1 - canceled, 2 - refunded.
                If p.ProductId = "hide_ad" Then
                    If p.PurchaseState = p.STATE_PURCHASED Then
                        Utils.FullVersion = True
                        GetFull
                    End If
                End If
            Next
        Else
            ' success = true and don't have purchases
            Utils.FullVersion = False
            GetFreeVersion   
        End If
    Else
        ' success = false
        Utils.FullVersion = False
        GetFreeVersion
    End If   
End Sub

Sub billman3_PurchaseCompleted(Success As Boolean, Product As Purchase)
    If Success Then
        If Product.Productid = "hide_ad" Then
            Msgbox("Advertisements will not run.","Hide Ads")
            ConfirmPayment
        End If
    End If
End Sub

Sub ConfirmPayment
    Utils.FullVersion = True

    'hide admob
    If AdView1.IsInitialized Then
        AdView1.Visible = False
        AdView1.Enabled = False
    End If

    'reduce advertisements space
    iheight = 5dip

    'adjust main panel
    pContent.Height = Activity.height - (pnlAB.height + iheight)
   
    'adjust grid
    Grid.Height = pContent.Height
End Sub

Sub GetFull
    Utils.FullVersion = True
    iheight = 5dip
   
    'reduce advertisements space
    iheight = 5dip

    'adjust main panel
    pContent.Height = Activity.height - (pnlAB.height + iheight)
End Sub

Sub GetFreeVersion
    Utils.FullVersion = False

    iheight = 50dip

    Activity.AddView(pContent, 0, pnlAB.height, Activity.Width, Activity.height-(pnlAB.height + iheight)) 

    ...

    'show ads
    Activity.AddView(AdView1, 0dip, 100%y - (iheight - 3dip), 100%x, iheight)
    AdView1.LoadAd  'loads an ad   
End Sub

'END IN-APP * * * * * * * * * *

The problem is when I restart the smartphone, with internet connection (wi-fi and 3G) disabled, the application returns to the previous mode, displaying the space for advertisements and set the variable Utils.FullVersion = False.
 
Upvote 0

asales

Expert
Licensed User
Longtime User
You can save the status of the owned products in a file and then check it before you call GetOwnedProducts.
Ok. Thanks.
Then the library doesn't store the products state.
I need the internet connection to check the product purchase every time the app is open, correct?
 
Upvote 0

asales

Expert
Licensed User
Longtime User
You can save the status of the owned products in a file and then check it before you call GetOwnedProducts.

Is the best pratice move the variable FullVersion (module Utils), that checks if app is in free or full version, to the Starter service?
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Ok. Thanks.
Then the library doesn't store the products state.
I need the internet connection to check the product purchase every time the app is open, correct?

In theory it should store the state, but for some reason, on some devices it doesn't. I had the same issue with an app and had to revert to using Erel's method, which is less than ideal.
 
Upvote 0
D

Deleted member 103

Guest
If the library is initialized in the Starter-Service, where all events will take place, Main-Activity or Starter-Service?
  1. manager_BillingSupported
  2. manager_OwnedProducts
  3. manager_ProductConsumed
  4. manager_PurchaseCompleted
 
Upvote 0
Top