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,190
  • AppUpdating_126.zip
    11.3 KB · Views: 1,254
  • AppUpdating_126_src.zip
    10.8 KB · Views: 1,011
  • AppUpdating_130.zip
    11.4 KB · Views: 1,224
  • AppUpdating_130_src.zip
    15.7 KB · Views: 1,137
  • AppUpdating_130_ex.zip
    33.4 KB · Views: 1,347
Last edited:

Don Roberts

Member
Licensed User
Hi,
Not sure what happened but the backup no longer works. It was running perfect and then I started
Adding additional Libs to my project and now it just sits on the splash screen and you have to close
the program down.
I declare in the activity create and just use the all in one button.
I also attached an image of the current libs I am using in case anything sticks out as a conflict.
I would really like to get this working again, any help would be appreciated.

B4X:
'Activity create first time
apkupdt.Initialize(Me,"apkupdt") 
apkupdt.setCredentials("bb4asystem","KHJHF^&*$RVF^TBY(")
'ALWAYS NEEDED - this is yor app's package name (see "Project/Package name")
apkupdt.PackageName = "PN"
'ALWAYS NEEDED - this is the complete path to the text file holding the newer version number  
apkupdt.NewVerTxt = "http://site/bb4a/prot/bb4aupdate.info" 
'ALWAYS NEEDED - this is the complete path to your newer apk
apkupdt.NewVerApk = "http://site/bb4a/prot/Ballistic_Basics.apk"   

'check button
apkupdt.SetAndStartSplashScreen(Activity,LoadBitmap(File.DirAssets, "update.jpg"))
apkupdt.setCredentials("bb4asys","KHJHF^&*$RVF^TBY(")apkupdt.UpdateApk
 

Attachments

  • Image2.png
    Image2.png
    32.8 KB · Views: 263

Harris

Expert
Licensed User
Longtime User
Hi,
Not sure what happened but the backup no longer works. It was running perfect and then I started
Adding additional Libs to my project and now it just sits on the splash screen and you have to close
the program down.
I declare in the activity create and just use the all in one button.
I also attached an image of the current libs I am using in case anything sticks out as a conflict.
I would really like to get this working again, any help would be appreciated.

B4X:
'Activity create first time
apkupdt.Initialize(Me,"apkupdt")
apkupdt.setCredentials("bb4asystem","KHJHF^&*$RVF^TBY(")
'ALWAYS NEEDED - this is yor app's package name (see "Project/Package name")
apkupdt.PackageName = "PN"
'ALWAYS NEEDED - this is the complete path to the text file holding the newer version number 
apkupdt.NewVerTxt = "http://site/bb4a/prot/bb4aupdate.info"
'ALWAYS NEEDED - this is the complete path to your newer apk
apkupdt.NewVerApk = "http://site/bb4a/prot/Ballistic_Basics.apk"  

'check button
apkupdt.SetAndStartSplashScreen(Activity,LoadBitmap(File.DirAssets, "update.jpg"))
apkupdt.setCredentials("bb4asys","KHJHF^&*$RVF^TBY(")apkupdt.UpdateApk


Http2utils.... Unless you are using the code module rather than the lib.

https://www.b4x.com/android/forum/t...ing-from-a-webserver.37783/page-8#post-368032

See link above...
 

Harris

Expert
Licensed User
Longtime User
https://www.b4x.com/android/forum/t...-updating-from-a-webserver.37783/#post-225221

Post 7 of this thread... Start from there and read on...
I use the code module (source), not the compiled lib of this AppUpdater - since the compiled lib contains other modules that I have modified for my purposes (namely the lib HttpUtils2 which is called HttpUtils2Service module) .
Yes, a wee bit confusing but manageable when you discover your conflict.

For a test, uncheck the lib HttpUtls2 (and comment any code that needs it) and try AppUpdater again to see if it works...
 

Yayou49

Active Member
Licensed User
Hi everyone,

I have a question about the apk file location.
I'm working with a SQL database and my apk is stored in one table.

So in my case, it's easy for me to download the apk from my data base and then to store it in a Stream in my project.

In that case, what do become the line :
B4X:
apkupdt.NewVerApk = "http://umbetest.web44.net/free_apk/AppUpdateExample.apk"

Is it possible to assign a Stream ?

Many thanks in advance

PS: if it's possible just tell me the good way and also if some other lines must be changed.
 

Harris

Expert
Licensed User
Longtime User
The easiest way out would be to write the apk in blob to a disk file, at path defined.
However, they will be a timing issue since the text file which defines a New Version expects the apk file to be there so upload to device can begin immediately.

Look at the source code for this project to discover what might be accomplished.
 

udg

Expert
Licensed User
Longtime User
Hi Yayou49,
as @Harris correctly replied your best approach would be to use partially the lib's code. Since whithin the lib the downoad is made by HttpUtils and you seems to prefer the DB-related approach, I would suggest to use those functions intended for discovery and installation, while leaving the ndownload step to your code.

udg
 

Yayou49

Active Member
Licensed User
Hi,

While using apkupdt.DownloadApk, I've got this error message:
java.io.FileNotFoundException: /sdcard/Android/data/yaya.yaya/files/tmp.apk: open failed: ENOENT (No such file or directory)

I don't have a sdcard strorage on my device.
How it's possible to set the path with the real app path on the device ?

Thanks
 

udg

Expert
Licensed User
Longtime User
Hi,
if you're downloading direct from your DB you shouldn't use DownloadApk at all.
What i suggested above is to use your own functions to read the newer apk from your DB table and put it in DirDefaultExternal, then call InstallApk to start the installation step.

Anyway a working example of a download path could be:
jobapk.Download("http://umbetest.web44.net/p_apk/myapp.apk")

udg
 

Yayou49

Active Member
Licensed User
Hi,
if you're downloading direct from your DB you shouldn't use DownloadApk at all.
What i suggested above is to use your own functions to read the newer apk from your DB table and put it in DirDefaultExternal, then call InstallApk to start the installation step.

Anyway a working example of a download path could be:
jobapk.Download("http://umbetest.web44.net/p_apk/myapp.apk")

udg

Thanks udg for your prompt answer ! ;)
Anyway, my error seems to be due to the fact that i'm running it in B4A environment.
Indeed, after a try on my phone, it seems to work fine.

About my files, I'm now using my IIS directory to store the version and the apk file. Then I can fully use your WONDERFUL Library !!!!

So, many thanks for your work and your participation to the community.
 
  • Like
Reactions: udg

Yayou49

Active Member
Licensed User
Still me .... o_O

On my project, i've set version as:
B4X:
    #VersionCode: 1
    #VersionName: 1.00

In my file "AppUpdateExample.info", version is set as:
ver:1.00

Anyway when I run apkupdt.DownloadApk, app response is always "Newer version downloaded" ...
Why not "No newer version available" ?
 

udg

Expert
Licensed User
Longtime User
Hi,
test in code row 319 reads "If curver < webver Then.." so it should signal a newer version only when the reading from the webserver shows a number greater than the one in the current apk.
One thing to note is that the webserver check expects the version number in the format version=release while in your post above I read version:release.
The equal sign is needed.
Anyway, looking at my code, the missing equal sign should lead to an error indicating a missing webserver version number..maybe you found a bug..eheh
 
D

Deleted member 103

Guest
Hi udg,

first of all thank you for this library.

It works actually everything except the last Step (installation) I get this error message, what can that mean?

AppUpdateExample.png
 

Harris

Expert
Licensed User
Longtime User
Hi udg,

first of all thank you for this library.

It works actually everything except the last Step (installation) I get this error message, what can that mean?

View attachment 40735

Likely the APK is corrupt. The download missed some bytes or wrote it incorrectly.
I have seen this when I emailed an app to my device (gmail) and tried to install it.
I sent a second copy and it worked well.
 

udg

Expert
Licensed User
Longtime User
Hi Filippo,
I agree with @Harris , it should be a problem with the downloaded apk. The dialog is not from the library; presumably it's caused by the intent executed to install the newer apk.
Looking at your screenshot, are you using a modified version of the Demo? Did you add any code that could be useful to others too?

udg
 
D

Deleted member 103

Guest
Hi udg and Harris,

Thanks for the answer.

@udg
I use your example of the first page without changing. :(
I tested with my tablet and my phone.
 

Yayou49

Active Member
Licensed User
Hi,

I'm facing a new problem with the Library.

While trying to start the service, I get this error:

B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
---- AppUpdating.ReadWebVN
---- AppUpdating.ReadCurVN
    Current Version: 1.20
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
---- AppUpdating.JobDone --
    JobName = JobWebVNonly, Success = false
    Error: java.net.UnknownHostException: Unable to resolve host "MySite.com": No address associated with hostname
    error in httputils2

At the same time, I ran the same request in a VB.net project and I have no problem with this URL.

What can be the problem in this Library ?

Thanks in advance.

PS: this error occurs some times and not always ....
 

udg

Expert
Licensed User
Longtime User
Reading the error, it gets returned by HttpUtils2 when trying to read from site "mysite.com" .I read it as an error from a DNS server, unable to return the IP associated to that domain. If you can confirm that is an error occuring only at times, one thing to try is to set your DNS to google's (8.8.8.8) or try with your browser at the same time the error occurs and see what happens.
Anyway, I doesn't seem to be related to the library.

udg
 

Yayou49

Active Member
Licensed User
As I said in my message, I've tried with another application at the same time and then no problem to contact this URL....
I've tried also with IE and once again, no problem to contact this URL....
Only B4A call failed.
So I'm still looking for a solution or a way to understand what's going on.
While writting this message, I've made a new try and, without change on my computer and B4A code, it works !!!.....:eek:
Nothing to understand :confused:
 
Status
Not open for further replies.
Top