For various reasons, I have a few apps that aren't distributed via stores. To make life a little easier, I've set up a script on one of my servers that can be queried by an app, to find out the most up to date version, display info about it. This is not the most elegant B4A code - it could use resumable subs now - but it does the job of checking for updates, and then if required, downloading and prompting the user to install.
The script at api.nigelwhitfield.net/appinfo is written in PHP, but could be in anything; it just looks up info in the database and returns a JSON string, the format of which is fairly obvious from the B4A code.
appinfo is an integer that represents the build number of the app and used for comparison, rather than the more user-friendly version number (eg 246, vs 2.4.6). It's a pretty trivial script, but if anyone wants to see the code, I'm happy to share it. The same server provides info for my desktop apps, too. So once I have new versions to deploy, I just upload them to the server, and update the info in the database. Users can either check manually via a menu option, or in some apps, it happens automatically based on time since last check.
The script at api.nigelwhitfield.net/appinfo is written in PHP, but could be in anything; it just looks up info in the database and returns a JSON string, the format of which is fairly obvious from the B4A code.
appinfo is an integer that represents the build number of the app and used for comparison, rather than the more user-friendly version number (eg 246, vs 2.4.6). It's a pretty trivial script, but if anyone wants to see the code, I'm happy to share it. The same server provides info for my desktop apps, too. So once I have new versions to deploy, I just upload them to the server, and update the info in the database. Users can either check manually via a menu option, or in some apps, it happens automatically based on time since last check.
B4X:
Sub updateCheck_click
' check with the app info service for update information
Dim appid As Int = 2
Dim infourl As String = "https://api.nigelwhitfield.net/appinfo/"
Dim check As HttpJob
check.Initialize("appinfo",Me)
check.PostString(infourl,"platform=android&appcode=" & appid)
End Sub
Sub jobDone( job As HttpJob )
If job.Success Then
If job.JobName = "appinfo" Then
' getting the info aboutan app
Dim apiJSON As JSONParser
Dim apiresults As Map
apiJSON.Initialize(job.GetString)
apiresults = apiJSON.NextObject
If ( apiresults.Get("status") = "error" ) Then
Msgbox("Invalid response received from update server","Sorry, there was an error")
Else
Dim appdetails As Map = apiresults.Get("appinfo")
If appdetails.Get("latestbuild") > appinfo Then
Dim newinfo As String
newinfo = "Version " & appdetails.get("latestversion") & " (build " & appdetails.Get("latestbuild") & ")" & CRLF & CRLF & appdetails.Get("notes")
Dim choice As Int
choice = Msgbox2(newinfo,"Update available","Install","","Ignore",Null)
If choice = DialogResponse.POSITIVE Then
newbuild = appdetails.Get("latestbuild")
Dim downloader As HttpJob
downloader.Initialize("update",Me)
downloader.Download(appdetails.get("url"))
End If
Else
Msgbox("Your app is up to date","No update available")
End If
End If
Else
' must be a download and install request
Dim apkFile As OutputStream
apkFile = File.OpenOutput(File.DirDefaultExternal,"estim4android-" & newbuild & ".apk",False)
File.Copy2(job.GetInputStream,apkFile)
apkFile.Close
Dim i As Intent
i.Initialize(i.ACTION_VIEW,"file://" & File.Combine(File.DirDefaultExternal,"estim4android-" & newbuild & ".apk"))
i.SetType("application/vnd.android.package-archive")
StartActivity(i)
End If
Else
Msgbox("Sorry. Please try later","Unable to contact server")
End If
End Sub