Android Question Downloading and updating a new update database

DeclanOK

Member
Licensed User
I have an app - abcmedicalnotes
I want it to check if there is a new online database and if new download it
However I can't seem to work out a good or easy way to do this
I don't want to download it if not new
I need to know the name of the database to download it
Am I missing something. What is the most efficient way to do this
 

drgottjr

Expert
Licensed User
Longtime User
there is no way - efficient or otherwise. doubly so if you
don't know the name of the database. triply so if you
have no way of knowing when the database was created
and which version of the database you have.

if the database is kept in a special location by the server,
and you knew where that special location was, at least
you might have a way of downloading the most recent
version. whether that version were different from the
one you already have is difficult to know. even if you
could load the database directly from abcmedicalnotes.com,
you would need a way of moving it to the proper location
within the app.

are you sure the app doesn't have a way of dealing with
updating the database? every app i have lets me know when
its database needs to be updated. and my own apps do the
same for my users.
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
Does the app and the online database belong to you?

If yes, then you can edit the database to have some form of version number which you can check anytime you launch the application and download the updated version into the users application/device
 
Upvote 0

DeclanOK

Member
Licensed User
Thanks yes it just seems just a bit more complicated than I thought it would be
I do own the site and database. Issue is I don't want to download it to check it....
I also want db name to be constant so will need to be more tricky than I planned
 
Upvote 0

emexes

Expert
Licensed User
I want it to check if there is a new online database and if new download it

If changes have been made to the database, then usually the file/download size will have changed too.

Not guaranteed in all cases, but true for databases where info is only added.

I need to know the name of the database to download it

If the database name is changing, then that's another clue that it's been updated.

Does it change in a predictable(ish) fashion, eg incrementing version number, or some kind of date and/or time?

If you have your own website, then the simplest thing might be that you create a simple webpage that has the database version and a URL for the download. Then your app can check your page, and if the version number is different to the database you have on the device, go the URL and download the updated database.

But download to a temporary file, make sure it's downloaded ok, and *then* replace the old local database with the new downloaded database. That way, if the download doesn't happen, at least your user still has a working app with data that was good enough yesterday. You could warn the user that the old local database is being used and thus some of the results returned might be out of date.
 
Upvote 0

emexes

Expert
Licensed User
I do own the site and database. Issue is I don't want to download it to check it....
I also want db name to be constant so will need to be more tricky than I planned

Why would the db name be changing?

Although it'd be kinda useful if the name incorporated a version number or revision date.

If it's a version number that is incremented by one each time the app is updated, then your program can just check at startup to see if there is an update to the current local database, eg if local database version is 2078, then check URL http:/mywebsite.com/appname/support/updates/alltheinfo2079.db.zip

Although that method falls over if there is a gap in the numbering, or the database hasn't yet been originally downloaded.

How about: have an update webpage which lists the last few updates (in case a user ever needs to go back to an older version of the database?) and then your app just reads that page and chooses the download with the highest version number or date, and downloads it only if it is newer than the database already on the app.

Or the webpage could just point to the latest database download.
 
Upvote 0

DeclanOK

Member
Licensed User
I found this code from Erel which might do it which will enable me to compare when database file made even if same names

Checking file date:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    File.WriteString(File.DirInternal, "test.txt", "111")
    Log($"$DateTime{GetCreationTime(File.DirInternal, "test.txt")}"$)
End Sub

'Android 26+
Sub GetCreationTime (Dir As String, FileName As String) As Long
    Dim Files As JavaObject
    Files.InitializeStatic("java.nio.file.Files")
    Dim FileSystems As JavaObject
    Dim FileSystem As JavaObject = FileSystems.InitializeStatic("java.nio.file.FileSystems").RunMethod("getDefault", Null)
    Dim Path As JavaObject = FileSystem.RunMethod("getPath", Array(File.Combine(Dir, FileName), Array As String()))
    Dim BasicFileAttributes As JavaObject
    BasicFileAttributes.InitializeStatic("java.nio.file.attribute.BasicFileAttributes")
    Dim LinkOptions As JavaObject
    LinkOptions.InitializeArray("java.nio.file.LinkOption", Array())
    Return Files.RunMethodJO("getAttribute", Array(Path, "creationTime", LinkOptions)).RunMethod("toMillis", Null)
End Sub
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
creationtime is not necessarily what you want. lastmodifiedtime is better.
 
Upvote 0

Intelemarketing

Active Member
Licensed User
Longtime User
The simplest method of knowing whether or not to update the client is to have a very small file which contains the date of the new release, up on the website,
along with the new database. You could even have a Version Number in the tiny file.

Your software on the customer's machine would download the small file from the website (using FTP) and check the date against the release date/version on the customer computer.
If different, your system would download the new date/version file and the new database file to the customer's computer.
Messages may need to warn the customer if the database is in use.

Rather simplistic but it will work perfectly.

Also, in this way you just use B4X FTP commands which are very easy to use.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
The simplest method of knowing whether or not to update the client is to have a very small file which contains the date of the new release, up on the website,
along with the new database. You could even have a Version Number in the tiny file.

Your software on the customer's machine would download the small file from the website (using FTP) and check the date against the release date/version on the customer computer.
If different, your system would download the new date/version file and the new database file to the customer's computer.
Messages may need to warn the customer if the database is in use.

Rather simplistic but it will work perfectly.

Also, in this way you just use B4X FTP commands which are very easy to use.
exactly what i've done for the last 10 years
 
Upvote 0

Intelemarketing

Active Member
Licensed User
Longtime User
FTP is the most reliable data transport mechanism I have used over the past 20 years. No need for special permissions, firewall considerations, XML or JSON conversions. Just put a file on a website - Download it from anywhere else. It is "the Hard Disk in the Sky". It was invented and has been in use long, long, long before we heard about "Cloud Computing". Simple to use. Reliable. And can take any number of hits from users sending data to be subsequently picked up by another FTP client AT THEIR LESIURE, and processed AT THEIR LESIURE. I have used this concept for more than 15 years, to pick up sales orders from the sales force in the field, with remarkable accuracy and without the fear of databases collapsing with overload transactions. Also, by identifying transactions that are uploaded via FTP, you can also, re-read them to validate that the transaction was in fact uploaded - NOT? Try again. It is the perfect mechanism when you need to handle high volume or even massive transaction processing. So what if the processing takes an extra second or two - Accuracy is the goal - not lightning speed which often gets tripped up with internet variations. (for Business Transactions). Game technology is another subject of which I have no idea or experience - clearly, lightning speed is essential in this environment. Probably not a good application for FTP.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I absolutely agree with @Intelemarketing about FTP - I also use it all the time. So why not simply do an FTP.List(folderPath) and check the timestamp of the database file on the host to find out if it is newer than the local file? Doesn't everybody do this!
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Upvote 0
Top