Edit: please refer to post #62 for instructions updated to version 1.25 and up.
AppUpdating - how to use it
As usual with any contributed library, download its zip (AppUpdating_118.zip, you need just this one), unzip it and place both files (.xml and .jar) in your additional libraries path (see menu option "Tools/Configure paths" in your B4A installation).
Now, for any app that you'd like to use this lib with, go to its Manifest editor ("Project/Manifest Editor") and add the following code:
AddReceiverText(eu.dgconsulting.appupdating.newinst2,
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>)
In your app's Main you have to:
0. Put a version number in "#VersionName:" key in Module Attributes. As an example: #VersionName:1.14
1. dim a variable to access the lib's class; do this in Sub Globals
Sub Globals
... 'your code here
Dim apkupdt As cl_appupdate
End Sub
2. Add code to Activity_Create to access any desired function in the lib
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
... 'any specific code for your app initialization
End If
Activity.LoadLayout("Main")
.... 'more stuff
If FirstTime Then
apkupdt.Initialize(Me,"tab1") 'tab1 has no meaning; use any name you like
'this is yor app's package name (see "Project/Package name")
apkupdt.PackageName = "eu.dgconsulting.tmb"
'this is the complete path to the text file holding the newer version number
apkupdt.NewVerTxt = "http://umbetest.web44.net/p_apk/tmb.txt"
'this is the complete path to your newer apk
apkupdt.NewVerApk = "http://umbetest.web44.net/p_apk/tmb.apk"
apkupdt.UserName = "test" 'needed since folder p_apk has access restrictions
apkupdt.UserPassword = "test" 'as above
'not needed- just to show use of function GetCurVN
Log("I am version: " & apkupdt.GetCurVN)
'use only if you like to show a splash screen while update checking goes on
apkupdt.SetAndStartSplashScreen(Activity,LoadBitmap(File.DirAssets, "tmb0.png"))
'this function starts checking for any newer version of the current app
apkupdt.LookForNewVersion
End If
End Sub
3. Receive feedback from the lib
Sub tab1_UpdateComplete
If apkupdt.IsDone Then
Log("New Ver available: " & apkupdt.NewVerAvailable)
Log("Status: " & apkupdt.Status)
apkupdt.StopSplashScreen
If apkupdt.Status = 6 Then
Log(apkupdt.PackageName)
End If
End If
End Sub
Note: sub name above is made up by a first part ("tab1") choosen by you (see apkupdt.Initialize in Activity_Create) and a second mandatory substring ("_UpdateComplete") as coded in the class part of the lib.
That's all for blindingly using the lib as is (well, that's all for the coding aspect of it..)!
AppUpdating - set the webserver
This one is easy.
On a webserver (even any free shared service would be ok), create a folder (in the example above, I created folder p_apk on webserver umbetest.web44.net) and eventually restrict access to it (I used the .htaccess method).
Prepare a text file named after your apk (in the example above, you may find tmb.apk and tmb.txt) having one single line of text as follows:
ver=x.yz
where x.yz is the newer apk version. Due to my laziness, currently the lib takes for granted that the version number starts on the 5th char..
Then, using any FTP client, copy both your newer apk's version and its corresponding text file in the folder set before.
That's all.
What the lib does is simply to check whether the version written in the text file is greater then the one showed in the running copy of your app.
If it finds indication of a newer version, it downloads it, then ask the user to install it.
Since we can't know if the user agrees to update the app, we simply go on with our app, knowing that a service burned in the lib will fire when the OS signals that the user accepted to install the newly downloaded copy of the app. In this latter case, the same service will reload the app when ready.
Umberto