Sub Globals
Private trialperiod As Int
Private uniqueid As String
Private ctm As CustomTrustManager
end Sub
Sub Activity_Create(FirstTime as Boolean)
uniqueid = GetDeviceId
trialperiod = 30
checktrial
end Sub
Sub GetDeviceId As String
Dim r As Reflector
Dim Api As Int
Dim p As Phone
Dim id As String
Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
If Api < 9 Then
'Old device
id= p.GetSettings("android_id")
Return id
Else
'New device
Return r.GetStaticField("android.os.Build", "SERIAL")
End If
End Sub
Sub checktrial
FTP.Initialize("FTP", ftpsite, 21, un, pw)
ctm.InitializeAcceptAll
FTP.SetCustomSSLTrustManager(ctm)
FTP.PassiveMode = True
FTP.UseSSLexplicit = True
Sleep(1000) 'pause for initialize
FTP.List("/" & "invitetextntally" &"/")
End Sub
Sub FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
'Log(ServerPath)
If Success = False Then
Log(LastException)
Else
Dim foundit As Int = 0
For i = 0 To Files.Length - 1
'Log(Files(i).Name & ", " & Files(i).Size & ", " & DateTime.Date(Files(i).Timestamp))
If Files(i).Name = uniqueid & ".txt" Then
foundit = 1
End If
Next
If foundit = 0 Then
'create a file and upload it
File.WriteString(File.DirInternal, uniqueid & ".txt", DateTime.now)
FTP.UploadFile(File.DirInternal, uniqueid & ".txt", False, "/" & "invitetextntally" &"/" & uniqueid &".txt")
Else
'download the file
FTP.DownloadFile("/" & "invitetextntally" &"/" & uniqueid &".txt", False, File.DirInternal, uniqueid &".txt")
End If
End If
End Sub
Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
Log(ServerPath & ", Success=" & Success)
If Success = False Then
Log(LastException.Message)
Else
ToastMessageShow("30 day trial period begins now",True)
End If
End Sub
Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
Log(ServerPath & ", Success=" & Success)
If Success = False Then
Msgbox("FTP Download error for trial check","")
Log(LastException.Message)
FTP.close
Else
FTP.close
Dim ts As String = File.ReadString(File.DirInternal, uniqueid & ".txt")
Dim per As Period = DateUtils.PeriodBetweenindays(ts, DateTime.Now)
If per.days <= trialperiod Then
Dim daysleft As Int = trialperiod - per.days
ToastMessageShow(daysleft & " days left in trial period",True)
Else
Msgbox("Trial Period over", "")
Activity.finish
End If
End If
End Sub