I seem to have a few users where in app billing doesn't work well but for most it is absolutely fine, or maybe they just give up and don't tell me.
Before I get flamed yes I have searched, I have read the tutorial and many many other posts.
Would someone be so kind as to check the attached code and tell me if its okay or if I am doing it wrong.
This is all in my Starter activity which sets variable AppSubscribed to either True or False, then in key places of my app I check Starter.AppSubscribed and either continue if true or take them to a subscription page if false
If there is a better way please educate me.
Before I get flamed yes I have searched, I have read the tutorial and many many other posts.
Would someone be so kind as to check the attached code and tell me if its okay or if I am doing it wrong.
This is all in my Starter activity which sets variable AppSubscribed to either True or False, then in key places of my app I check Starter.AppSubscribed and either continue if true or take them to a subscription page if false
If there is a better way please educate me.
B4X:
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
'Public analytics As FirebaseAnalytics
' Public CL As Crashlytics
Private logs As StringBuilder
Private logcat As LogCat
Dim manager As AHPreferenceManager
Dim Payload As String
Dim Cursor1, CursKeyBlank, CursMake, CursVehicles, CursKeyInfo, CursRemote, CursChips As Cursor
Dim AppSubscription As Boolean : AppSubscription = False
Dim CurrentTool, currentVehicle, currentMake As String
Dim SubManager As BillingManager3
Dim kvs As KeyValueStore
Dim Manufacturers(6), codeSeries, codeTable As String
Dim MyVersion As String
Dim usersPassword, usersName As String 'usersCompany
Dim dataStatus As String :dataStatus = "false"
Dim publicKey As String
' Dim RegistrationMode As String :RegistrationMode = "Login"
' Dim WVS As WebViewSettings
End Sub
Sub Service_Create
logs.Initialize
'analytics.Initialize
Dim context As JavaObject 'depends on JavaObject
context.InitializeContext
' CL.Initialize(context)
#if RELEASE
logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
#end if
publicKey = "MIIBIjANBgkqhkiG9wXXXXXX" ' not real key of course'
kvs.Initialize(File.DirInternal, "datastore")
#If NoSubs
AppSubscription = True
#else
'AppSubscription = False
SubManager.Initialize("SubManager", publicKey)
SubManager.DebugLogging = True
' SubManager.GetOwnedProducts
#End If
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Private Sub logcat_LogCatData (Buffer() As Byte, Length As Int)
logs.Append(BytesToString(Buffer, 0, Length, "utf8"))
If logs.Length > 5000 Then
logs.Remove(0, logs.Length - 4000)
End If
End Sub
Sub SubManager_BillingSupported (Supported As Boolean, Message As String)
If Supported Then
SubManager.GetOwnedProducts
Else
AppSubscription = False
End If
End Sub
Sub SubManager_OwnedProducts (Success As Boolean, purchases As Map)
Log(Success)
If Success Then
'Log(purchases)
#if NoSubs
'test_1 = "DAT33"
AppSubscription = True
#end if
#If Full
If purchases.ContainsKey("laraplus1") Or purchases.ContainsKey("laraplus2018") Or purchases.ContainsKey("laraplus6mth") Then
AppSubscription = True
'test_1 = "DAT33"
Else
AppSubscription = False
'test_1 = "DAT12"
End If
#end if
kvs.PutEncyptedObject("subs",AppSubscription,"ynot")
Else
AppSubscription = kvs.GetEncryptedObject("AppSubscription","ynot")
End If
End Sub
Sub SubManager_PurchaseCompleted (Success As Boolean, Product As Purchase)
If Success Then
SubManager.GetOwnedProducts
End If
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
'wait for 500ms to allow the logs to be updated.
#if Full
Return False
#Else
Dim jo As JavaObject
Dim l As Long = 500
jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))
logcat.LogCatStop
logs.Append(StackTrace)
' logs.Append(Routines.getMail)
Dim email As Email
email.To.Add(emailAddress)
email.Subject = "LARA crash Report"
email.Body = logs
StartActivity(email.GetIntent)
Return True
#end if
End Sub
Sub Service_Destroy
End Sub