Here is a method using FTP to create a trial period for your app. Since there is no local file with trial information, the user cannot defeat it by manipulating stored data. Also, FTP calls are very simple and no database required. Thought I would share this method since I have benefited so much from others in forum.
Process steps:
1. Get a unique id. This will be your file name on FTP site.
2. Do a FTP.list on your site to see if a file is present with that name
3. If it does not exist, create a file with unique id as its name and put timestamp inside file
1 libraries required: DateUtils, Reflection, Phone, Net
2. You could modify the comparison as a countdown rather than days by putting counter in file
3. Each file on your FTP site will represent a user who is trying (or has tried) your program. You can get a count from this information.
here is the code:
Process steps:
1. Get a unique id. This will be your file name on FTP site.
2. Do a FTP.list on your site to see if a file is present with that name
3. If it does not exist, create a file with unique id as its name and put timestamp inside file
- tell the user that the trial period of 30 (you pick) days has begun and continue with program
- Compare current time with timestamp
- if within 30 day, send a message of time remaining and continue on your program
- if outside of 30 days, end program
1 libraries required: DateUtils, Reflection, Phone, Net
2. You could modify the comparison as a countdown rather than days by putting counter in file
3. Each file on your FTP site will represent a user who is trying (or has tried) your program. You can get a count from this information.
here is the code:
B4X:
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
Last edited: