Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
apkupdt.Initialize(Me,"update") 'initializes the class
apkupdt.Verbose = True 'this one affects the verbosity of the logs
End If
'ALWAYS NEEDED - this is your app's package name (see "Project/BuilConfigurations/Package")
apkupdt.PackageName = "b4a.example.appupdate205"
'ALWAYS NEEDED - this is the complete path to the info text file holding the newer version number
apkupdt.NewVerTxt = "http://www.dgconsulting.eu/free_apk/AppUpdateExample2.inf"
'ALWAYS NEEDED - this is the complete path to your newer apk
apkupdt.NewVerApk = "http://www.dgconsulting.eu/free_apk/AppUpdateExample2.apk"
'OPTIONAL - Set credentials to access a protected folder. Not needed for this example
apkupdt.setCredentials("test","test")
'STEP 1: which is apk's current version number?
apkupdt.ReadCurVN 'send out command; async result in update_UpdateComplete
'STEP 2: just curious about eventual availability of a newer apk version, so we simply check for it
apkupdt.ReadWebVN 'send out command; async result in update_UpdateComplete
'STEP 3: compares current version number to the one reported by the webserver
If apkupdt.CurVN < apkupdt.WebVN Then
Activity.LoadLayout("lytUpdate")
'STEP 4: let's download the apk published on the webserver. No check on its version; just download it
apkupdt.DownloadApk 'send out command; async result in update_UpdateComplete
else
Activity.LoadLayout("lytMain")
end if
end sub
'This subs gets called after each command is executed
Sub update_UpdateComplete
LogColor($"UpdateComplete - time: ${DateTime.Time(DateTime.Now)}"$, 0xFF556B2F)
apkupdt.StopSplashScreen
'too lazy to manage error conditions..check apkupdt.ERR_xxx codes if you like
Select apkupdt.Status
Case apkupdt.OK_CURVER
EditText1.Text=$"${EditText1.Text}Running apk version: ${apkupdt.CurVN}${CRLF}"$
Case apkupdt.OK_WEBVER
EditText1.Text=$"${EditText1.Text}Webserver apk version: ${apkupdt.WebVN}${CRLF}"$
EditText1.Text=$"${EditText1.Text}Optional Change Log data: ${apkupdt.WebChangeLog}${CRLF}"$
EditText1.Text=$"${EditText1.Text}Optional FileSize Log data: ${apkupdt.WebFileSize}${CRLF}"$
Case apkupdt.OK_NEWERAPK
EditText1.Text=$"${EditText1.Text}Newer version available${CRLF}"$
Case apkupdt.NO_NEWERAPK
EditText1.Text=$"${EditText1.Text}No newer version available${CRLF}"$
Case apkupdt.OK_DOWNLOAD
EditText1.Text=$"${EditText1.Text}Newer version downloaded${CRLF}"$
Case apkupdt.OK_INSTALL
EditText1.Text=$"${EditText1.Text}User asked to install newer version${CRLF}"$
Case apkupdt.ERR_NOPERM
Log("No permission to install")
EditText1.Text=$"${EditText1.Text}User gave no permission to install${CRLF}"$
Case Else
EditText1.Text=$"${EditText1.Text}Status: ${apkupdt.Status}${CRLF}"$
End Select
End Sub