Android Example How I update my apps

I have a very specialized POS application running on Android devices that would not qualify to be entered into the Play Store. These apps need to be updated whenever there are new features or bug fixes. I load the .apk on the website and call the following service:

The name of my app is was.apk

The servername is contained in the string variable Main.hostVersion that is in the Main activity

this will download the apk and start the install process

B4X:
Sub Process_Globals
    Dim host As HttpClient
    Dim Request As HttpRequest
    Dim Receive As String
    Dim AppName As String
    Dim hostaddress As String
End Sub

Sub Service_Create
    AppName = "was.apk"

    host.Initialize("host")
End Sub

Sub Service_Start (StartingIntent As Intent)
    File.Delete(File.DirDefaultExternal,AppName)

    Request.InitializeGet(Main.hostVersion & AppName)
    Request.Timeout = 60000
    host.Execute(Request, 1)
End Sub

Sub Service_Destroy

End Sub

Sub host_ResponseSuccess (Response As HttpResponse, TaskId As Int)
    ToastMessageShow("Retrieving Update",True)
    Receive = Response.GetAsynchronously("UpdateIT",File.OpenOutput(File.DirDefaultExternal,AppName,False),True,TaskId)
End Sub

Sub host_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
    ToastMessageShow("Update Not Available At This Time!",True)
End Sub

Sub UpdateIT_StreamFinish(Success As Boolean, TaskId As Int)
    Dim i As Intent

    ToastMessageShow("Installing Update",True)

    i.Initialize(i.ACTION_VIEW, "file://" & File.DirDefaultExternal & "/" & AppName)
    i.SetType("application/vnd.android.package-archive")

    StartActivity(i)
End Sub
 

timwil

Active Member
Licensed User
Longtime User
I started out looking at the HTTPUtils2 but that was general purpose and had more than I needed - plus got a little lost working thru it

I just did this very specific service that serves only one purpose

Just my preference :)
 

Douglas Farias

Expert
Licensed User
Longtime User
but how to how to call this in main?
 

timwil

Active Member
Licensed User
Longtime User
startservice(updater)

this assumes the above code is a service module named updater
 

Douglas Farias

Expert
Licensed User
Longtime User
yes but it show me the toastmsg but dont load my layout o_O

show the toast messages later this my app stay with no layout
 

timwil

Active Member
Licensed User
Longtime User
I don't understand what you are trying to do - this code will download your app (in this case named was.apk) from your website (contained in hostaddress ) and start the installation process. If the file does not exist it will display a message.
 

Douglas Farias

Expert
Licensed User
Longtime User
i need to force the download
if have new update user need upload or app dont run
 

Douglas Farias

Expert
Licensed User
Longtime User
dont exist any way to force updates?

my app is based on mysql server 80% of updates and news i can add on the server
but to fix bugs or add new menus i need update and force =(

because i go sell coins all user go have coins etc
later i go add new itens with images etc

for exemple i add new item

diamon box = cost 50 coins

only with update user can see the image of the diamon box *-*
 

NJDude

Expert
Licensed User
Longtime User
If you are including a database with your app, you better change the way your app works, if you are going to send updates every time you change something on the database will irritate the user and is not practical, personally, and this is of course my opinion, if I get many updates like that I would be uninstalling your app.

You cannot force updates (or installs) because is a security issue.
 

timwil

Active Member
Licensed User
Longtime User
There is a difference between updating the database and the application

updating the database is quite simple and just requires your app to go out to the server and pull the updates

What I have here is to update the entire application
 

GMan

Well-Known Member
Licensed User
Longtime User
In any way it must work 'cause Google Playstore works the same way.
And - if i have set auto update - it will be installed without any confirmation etc.

Maybe Erel can tell us, if this is possible with B4A, too

And where in your code do you check the app for i.e. newer date, other size, other internal version or what ?
 

udg

Expert
Licensed User
Longtime User
Hi all,

collecting info to design my own AppUpdating library I read a lot about "silent" installation pros and cons.
For one, Android's architects discourage any silent operation as a breach in the OS security framework. The problem is not your app but any other code that could make bad use of that breach.
On the other hand, on rooted devices, you can install a "receiving" service (something like the Playstore app and services) in the system reserved area; this service (with super user rights) waits for commands to install an app and could do it silently.

Since my goal was simply to avoid the Playstore, I designed my lib in a way that you publish your updated version on your server along with a text file containing reference to the newer version number (and soon to a change log list); then in your app, by way of library's subs, you code your logic to discover an eventual newer version, download it and ask the user to install it (and if install is successful the app should be restarted in its newer version). A process very similar to @timwil 's one.

@Douglas Farias: to force the user to update to a newer version can't you just put a "minimum version required" value in the DB so to exit the app with a message if current version is lower than that value?

Umberto
 
Top