B4A Library AppUpdating - automate apps updating from a webserver

Status
Not open for further replies.
Important note: since all the changes made to the Android OS the original code is to be considered outdated. Thanks to @Yayou49 you may find at post#290 a version of the class usable on Android 6+ versions.

Note: version 1.25 breaks existing code so, please, read changelog in post #60 below.


Hi all,

this is my first contributing lib to this great NG.
How do I dare to publish such a low-grade stuff in an area where generally you may find real masterpieces of programming? Well, to be honest, I hope in your help to upgrade my work to a status of "ready-made solution" for those who prefer to run their own webservers where to publish apps.
Secondly, I was asked (both privately and publicly) to overcome my legitimate embarassment and go on with the publication. So, here we are: AppUpdating 1.18!

Note: any valid code fragment comes from some other thread, while all the bad stuff is entirely mine ;-)

Please find attached both the library as is (yes, it works out of the box) and its source code.

On a following post I'm gonna describe the lib in greater detail and show how to use it.

Umberto

AppUpdating version history

* version 1.30 (read notes on post #228)
  • compiled with okHttp 1.01 and okHttpUtils 2.20
  • removed files for version 1.25

* version 1.26 (read notes on post #84)
  • added property WebChangeLog to read optional app's version changelog data
  • better management of versioning in the info file
  • removed files for version 1.18 to avoid confusion (still available on request)
* version 1.25
* version 1.18
  • initial release
 

Attachments

  • AppUpdating_126_ex.zip
    28.3 KB · Views: 1,090
  • AppUpdating_126.zip
    11.3 KB · Views: 1,113
  • AppUpdating_126_src.zip
    10.8 KB · Views: 878
  • AppUpdating_130.zip
    11.4 KB · Views: 1,116
  • AppUpdating_130_src.zip
    15.7 KB · Views: 1,020
  • AppUpdating_130_ex.zip
    33.4 KB · Views: 1,220
Last edited:

udg

Expert
Licensed User
Longtime User
Hi Steve,

looking at the log you posted above I can see that both package name (b4a.CustomerTablet) and text file should be correct since the lib finds your newer release number (1.01 against its previous 1.00).
What is missing is the newer apk file.
I suspect the problem being the capitalization in CustomerTablet.apk since I had a similar problem time ago.
Please verify whether the name on the webserver is exactly the same as that put in NewVerApk variable.

Regards,

Umberto
 

DonManfred

Expert
Licensed User
Longtime User
Please verify whether the name on the webserver is exactly the same as that put in NewVerApk variable.

As additional info to @Steve Miller :

The urlpath AND apkfilename is CaseSensitive and should exactly mirror the structure and filename on your webserver...
 

Steve Miller

Active Member
Licensed User
Longtime User
Since I can't place the project up here, here are the important parts:

Package Name:
B4X:
b4a.CustomerTablet

Manifest:
B4X:
AddReceiverText(eu.dgconsulting.appupdating.newinst2,
  <intent-filter>
  <action android:name="android.intent.action.PACKAGE_REPLACED" />
    <data android:scheme="package" />
  </intent-filter>)

Versioning in project:
B4X:
#FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: CustomerTablet
    #VersionCode: 1
    #VersionName: 1.00
    #SupportedOrientations: Landscape
    #CanInstallToExternalStorage: True

Subroutine for checking:
B4X:
Sub CheckForUpdates
      apkupdt.Initialize(Me,"UpdateCheck")                
    'this is yor app's package name (see "Project/Package name")
    apkupdt.PackageName = "b4a.CustomerTablet"
    'this is the complete path to the text file holding the newer version number
    apkupdt.NewVerTxt = "http://www.xxxx.us/CustomerTablet/version.txt"
    'this is the complete path to your newer apk
    apkupdt.NewVerApk = "http://www.xxxx.us/CustomerTablet/CustomerTablet.apk"
    'apkupdt.UserName = "CustomerTablet"        'needed since folder p_apk has access restrictions
    'apkupdt.UserPassword = "suncoast"    'as above
    'this function starts checking for any newer version of the current app
    apkupdt.LookForNewVersion                                                    

End Sub
Sub UpdateCheck_UpdateComplete
  Log("Status: "  & apkupdt.Status)
  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

Also, when the package compiles, it is called CustomerTablet.apk.
 

Steve Miller

Active Member
Licensed User
Longtime User
I have the CustomerTablet as a virtual folder on the site and it finds the version file just fine. The apk is in the same folder and named just as it is shown.
 

DonManfred

Expert
Licensed User
Longtime User
Umberto and i are working on a new version of this library (the lib is umbertos part)... He´s actually in holiday but maybe tomorrow he will be back at his pc and have a deeper look into this problem.

There will be a windows-tool available in future (that´s my part) which will upload the right files to the right place on your webserver

snap0005.png
 

udg

Expert
Licensed User
Longtime User
Hi Steve,

unfortunately I'm away from my PC so I can't check the lib code.

I have a second question for you: when you copy the string

http://www.xxxx.us/CustomerTablet/CustomerTablet.apk (xxxx appropriately substituted by its real counterpart)

in your browser url box, does the apk's download start?

If not, does it start when the whole string is lower-cased?

I saw you commented out the credentials so I derive that currently the folder is not protected, right?

Umberto
 

Steve Miller

Active Member
Licensed User
Longtime User
Nice!
I'm looking at the AppUpdating source from the top of this thread, to see if I notice anything that may be interfering with my calls.
 

Steve Miller

Active Member
Licensed User
Longtime User
Interestingly enough, I get a not found from the browser also...Hmmmm. Strange how it finds the version.txt, but not this. Good point!
Something for me to look into further.
 

Steve Miller

Active Member
Licensed User
Longtime User
I got it working. I had to set the mime type for .apk to application/vnd.android.package-archive.
 

Steve Miller

Active Member
Licensed User
Longtime User
No, I had to add it as a mime type in IIS. It was IIS that was causing the not found issue because it didn't recognize the file type.
 

Steve Miller

Active Member
Licensed User
Longtime User
Sorry, I misread your first response. I interpreted it as changing the web.config on the site. :rolleyes:
 

Steve Miller

Active Member
Licensed User
Longtime User
I have a question. My app uses the kiosk mode and the automatic updating. I'm finding that when an update is found, the notification gets pushed to the background behind my app, due to the kiosk mode. It happens so
Fast that I don't see the notification to install the updated app. The kiosk mode doesn't allow me to close the app in order to reply to the install prompt. My app simply opens again, over the install prompt.

Is there any way to have the install go automatically without being prompted or have the prompt be modal over my kiosk app?
 

udg

Expert
Licensed User
Longtime User
Hi Steve,

unfortunately a completely automatic (and silent) install/update is forbidden in Android (as far as I know).
User intervention is always needed.

The good news is that you could insert a few lines of code in function JobDone in order to open a confirmation dialog box just before the sending of the intent. That is between status=5 and status=6.
So, if the user response is negative you just skip the intent stuff otherwise you execute those lines (but this will result in the user prompted again, this time by the OS).

On a second thought, maybe I could release a newer AppUpdating version where a boolean discriminate bewtween going straight to the sending of OS intent and stopping at status=5 (newer apk downloaded), leaving control on how to proceed to your Main.
What do you think?

Umberto
 

Steve Miller

Active Member
Licensed User
Longtime User
Hi Umberto,
I need to somehow get the install prompt to not fall behind the app. When the app is in kiosk mode, it is always in the forefront. And if it is closed, it always restarts and is in forefront again. Taking that all out of kiosk mode if an update is available may work, but I need to be sure that once the install is done or cancelled, my app is started again. I don't know how to code this, or if it is even possible.
 

udg

Expert
Licensed User
Longtime User
Hi Steve,

maybe one way to solve this situation could be to use AppUpdating just to discover an eventual newer apk version and then download it. All this in kiosk mode.
When your app (or a launcher app) is started again, this time NOT in kiosk mode, it will look for the already downloaded update version and send the OS intent. This way if the user accepts the installation you end up with the update app ready to start (now in kiosk mode); otherwise you manage how to proceed (kiosk mode+old version OR message like "service unavailable until you upgrade.." OR anything you think it may fit).

Let me know if this is may fit your needs and I will upgrade AppUpdating accordingly.

Umberto
 

Steve Miller

Active Member
Licensed User
Longtime User
I need to think of how to best handle this. The problem is this app is for a doctors office. Its a registration app that the patients use to sign in or register as a new patient. So, the tablet needs to be locked down at all times, that's the reason for kiosk mode. I can't take the chance of it being out of kiosk mode while in the hand of a patient.
 
Status
Not open for further replies.
Top