Hey everyone,
Here I will explain how you can make an evaluation/trial version of your app using an online database.
With this, the user will be able to open up the app x times. When 0 is achieved, it will force close the app.
First you'd need some basic knowledge of HTML, PHP, SQL and ofcourse Basic4Android.
I will not explain on how to setup your directory files, SQL Database, etc.
Here's how it works:
Before the app runs (in globals) I send my IMEI with a POST Method to a php webserver. I do this with one code with a library I have written, instead of using HTTPUtils etc.
The database exists of three columns:
id, IMEI, starts.
The PHP file looks in the database if the IMEI exists, if it exists, it looks for the amount in the third column and substracts 1. If it doesn't exists, a IMEI.txt file is generated. The file contains how much the app can be opened. 30 here.
If 0 is succeeded, the text Expired appears.
In my app, a timer runs during 6 seconds. This is done to process everything server side. When the timer ticks, I perform a http GET to the IMEI.txt (its not IMEI.txt but e.g. 59644885484.txt). If the response string is an amount, then the app runs, otherwise if it's "Expired", then the app is closed.
Some code:
Attached is the PHP file. Upload it and link to that PHP File.
It is commented. Open it and edit where asked.
Here is a maintenance table of how many times StreamNation Studio is downloaded, opened, used,...:
http://www.rootsoftllc.com/streamNation/trialStats.php
XverhelstX
Here I will explain how you can make an evaluation/trial version of your app using an online database.
With this, the user will be able to open up the app x times. When 0 is achieved, it will force close the app.
First you'd need some basic knowledge of HTML, PHP, SQL and ofcourse Basic4Android.
I will not explain on how to setup your directory files, SQL Database, etc.
Here's how it works:
Before the app runs (in globals) I send my IMEI with a POST Method to a php webserver. I do this with one code with a library I have written, instead of using HTTPUtils etc.
The database exists of three columns:
id, IMEI, starts.
The PHP file looks in the database if the IMEI exists, if it exists, it looks for the amount in the third column and substracts 1. If it doesn't exists, a IMEI.txt file is generated. The file contains how much the app can be opened. 30 here.
If 0 is succeeded, the text Expired appears.
In my app, a timer runs during 6 seconds. This is done to process everything server side. When the timer ticks, I perform a http GET to the IMEI.txt (its not IMEI.txt but e.g. 59644885484.txt). If the response string is an amount, then the app runs, otherwise if it's "Expired", then the app is closed.
Some code:
B4X:
Sub Globals
ProgressDialogShow("Trial Activated" & CRLF & "Connecting with webserver for authentication")
Dim p As PhoneId
Dim cantopen As Boolean
cantopen = False
Dim camera1 As AdvancedCamera
Dim strActivationCheck As String
strActivationCheck = "http://www.example.com/" & p.GetDeviceId & ".txt"
'Small password protection, PHP File on webserver, IMEI, Trials
' change the url to the url of your site.
'You should download the latest version of my Advanced Camera Library to use 'AppTrial' because it is a lot easie for me this way instead of working with HTTPutlils.
Camera1.AppTrial("Password","http://www.example.com/trialCheck.php",p.GetDeviceId,30)
tmrEvaluation.Initialize("tmrEvaluation",6000)
tmrEvaluation.Enabled = True
End Sub
Sub tmrEvaluation_tick
ProgressDialogShow("Checking Activation.")
tmrEvaluation.Enabled = False
Dim request1 As HttpRequest
request1.InitializeGet(strActivationCheck)
request1.Timeout=50000
If HttpClient1.Execute(request1, 1) = False Then
Return
End If
End Sub
Sub http_ResponseSuccess (Response As HttpResponse, TaskId As Int)
ProgressDialogHide()
If TaskId = 1 Then
Dim strActivationResponse As String
strActivationResponse = response.GetString("UTF8")
If strActivationResponse = "Expired" Then
cantopen = True
Msgbox("The evaluation version of StreamNation Studio has expired." & CRLF & "You can buy the full version or take the chance of winning the full version by rating the app and giving it a small review!","Evaluation")
ExitApplication
Else
Msgbox("You can run the app " & strActivationResponse & " more times.","Evaluation")
End If
End If
End Sub
Sub Http_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
If TaskId = 1 Then
Msgbox(Reason,"An error occured." & CRLF & "Check your internet connection or try again later.")
ExitApplication
End If
End Sub
Attached is the PHP file. Upload it and link to that PHP File.
It is commented. Open it and edit where asked.
Here is a maintenance table of how many times StreamNation Studio is downloaded, opened, used,...:
http://www.rootsoftllc.com/streamNation/trialStats.php
XverhelstX
Attachments
Last edited: