Android Question App Updating problem

Mwinsor

Member
Licensed User
Longtime User
I have used the cl_appupdate code in other projects without a problem but any new projects don't seem to be working. I have narrowed it down to the fact that getting the version number does not fire the jobdone event. I am giving it a path to a txt file and when I type this path directly into the browser I see the version fine. It is in this section in the cl_appupdating code:
B4X:
Public Sub ReadWebVN
    Log("---- AppUpdating.ReadWebVN")
    ' check whether NewVerTxt file was declared
    If sNewVerTxt = "" Then
        sStatusCode = ERR_NOTXT
        If sVerbose Then Log(TAB & "missing txt file full path indication")
        webver = ""
        Finito
        Return
    End If
    Dim job1 As HttpJob
    'Send a GET request
    job1.Initialize("JobWebVNonly", Me)  <----  I never get to the jobdone subroutine. 
    job1.Username = sUserName
    job1.Password = sUPassword
    job1.Download(sNewVerTxt)
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Where is the sub? In a Class? In an Activity? In a Service?
The Jobdone is raised where it get started from. Class/Activity/Service. It does NOT work in Code-Modules for sure.
 
Upvote 0

Mwinsor

Member
Licensed User
Longtime User
Hmm, ok. I had it in a library (the cl_appupdating library posted here), but when I saw a new version posted I put it in a class module. Should I put it in a service?

A relevant point is this is the code in the cl_appupdating library. It is not my code and I have it working in other projects so I'm sure it is something I'm doing differently but I cannot figure why the jobdone doesn't fire.
 
Last edited:
Upvote 0

Mwinsor

Member
Licensed User
Longtime User
Here is a small program that essentially does nothing but call the app update routines.
 

Attachments

  • HubCountTest.zip
    9.3 KB · Views: 227
Upvote 0

Mwinsor

Member
Licensed User
Longtime User
Ok. I had stripped it down because it said it was too big. Here is the Export as zip version

Note: I forgot to change my extension from .htm back to .txt. I was testing with htm but it doesn't work with either.
 

Attachments

  • hubcounttest.zip
    18.6 KB · Views: 205
Last edited:
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
I have checked your code and did not find the error you reported. The JobDone event fires every time.

My server (where the apk's are stored) is configured a little differently. Instead of looking for a text file, I fire a php script that finds the most recent apk (based on time stamp) and returns the file name of that apk (I keep older versions on the site just in case..., they can be downloaded manually if necessary) So it does work very much the same otherwise.
Once these changes were made, pointing your code to my server works fine.
I use a Moto-X (2014) with Android 5.1

There were a number of small buglets, like calling
B4X:
If sVerbose then
instead of
B4X:
If sVerbose = True Then
but that did not prevent the code from running.

I had to make a number of adjustments in order to see what was going on. The biggest: I actually download the apk for another app (I changed the app name pointed to) so that I can keep running the code without actually updating the app I am debugging.

So I am not sure what the problem is. You say the code used to run. Can you load an older version and see if it still works?
What else has changed in the mean time, the phone or tablet, an OS upgrade, a different server?
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Another thing I have found, not sure if it is the expected behavior: once the intent is fired, the app terminates, whether the app that was downloaded is updated or the user Cancels.
I would understand if you are upgrading the app that is running, but in my case, I upgrade another app, so it is not clear why this app terminates.

I have renamed the app AppUpdate here, and the app I am downloading is named
XACT_v1.54.apk

This is what I get when the intent is fired (the intent runs normally, but the app under it crashes)

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
ReleaseTypeIsDebug = false
---- AppUpdating.ReadWebVN
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
cl_AppUpdate.JobDone:
    JobName = JobWebVNonly, Success = true
    JobWebVNonly: XACT_v1.54.apk
    Web version number: 1.54
Status: 2
    -- ApkUpdate
ApkUpdate: Downloading http://www.---.com/---/XACT_v1.54.apk
cl_AppUpdate.JobDone:
    JobName = JobApkUpdate, Success = true
    JobApkUpdate:
    JobApkDownload: new version saved to File.DirDefaultExternal/tmp.apk
    user asked to install new apk
Status: 6
com.edsfl.appupdate
** Activity (main) Pause, UserClosed = false **
main_appupdate_updatecomplete (java line: 389)
anywheresoftware.b4a.B4AUncaughtException
    at anywheresoftware.b4a.Msgbox.msgbox(Msgbox.java:172)
    at anywheresoftware.b4a.keywords.Common.Msgbox2(Common.java:443)
    at anywheresoftware.b4a.keywords.Common.Msgbox(Common.java:422)
    at com.edsfl.appupdate.main._appupdate_updatecomplete(main.java:389)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1058)
    at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:1005)
    at com.edsfl.appupdate.cl_appupdate._finito(cl_appupdate.java:469)
    at com.edsfl.appupdate.cl_appupdate$ResumableSub_JobDone.resume(cl_appupdate.java:907)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1736)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5343)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
 
Last edited:
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Here is my version of your code.
The archive also includes the php script I use to send back the most recent version.

In my case, I code the apk's file name like this, but the file name does not really matter on the server since the script sorts on time stamps:
xxxxx_vY.YY.apk
However, the version number is used in the app to compare to the currently running app, so the code was modified accordingly (the ExtractVN() routine).

I have created a test folder on my server with an apk from one of the examples from the B4A web site, so the project works out the box.
It will be interesting to see if anyone else has issues.

Note: I changed the sdk requirements in the manifest to min 5 and target 27 and that did not affect the app.
 

Attachments

  • AppUpdate.zip
    11.2 KB · Views: 224
Last edited:
Upvote 0
Top