Android Question How can i make my app Update itself... with a click

Magma

Expert
Licensed User
Longtime User
Hi there,

I am trying to create an app that will have the function to update itself by a click...

ofcourse i will use httpjob - but my problem is how will make it to save the file at sdcard with specific name "blahblah.apk" and then after download progress automatically run this apk.

Tried... but i am stacked... where the sh!@##t (sorry for bad language) saves the file - and how i will run it to update my app ?
 

Magma

Expert
Licensed User
Longtime User
B4X:
Sub JobDone (Job As HttpJob)
  If Job.Success = True Then
      Select Job.JobName
....
        Case "Job2"
            Dim out As OutputStream
            out = File.OpenOutput(File.DirRootExternal,"rt-z.apk",False) 'Don't see that works..
            File.Copy2(Job.GetInputStream,out) 'Don't see that works..
            out.close
            'run apk to install
            Dim iIntent As Intent
            iIntent.Initialize(iIntent.ACTION_VIEW, file:///sdcard/rt-z.apk) 'can't find anyhting because nothing downloaded ?????
            iIntent.SetType("application/vnd.android.package-archive")
            StartActivity(iIntent)
      End Select
  Else
      ToastMessageShow(Job.ErrorMessage, True)
.....
  End If
  Job.Release
End Sub
 
 
Sub Button4_Click
job2.Initialize("Job2", Me)
job2.Download("the domain and the file exactly with http at start") ' can't understand if that works..
End Sub

why i can't do it... where am i wrong....

Please help me - Thanks in advanced
 
Last edited:
Upvote 0

vampirbcn

Active Member
Licensed User
Longtime User
One Example:

B4X:
Sub ActualitzacionAPP
  
    If File.Exists(File.DirDefaultExternal,"result.apk") Then
        File.Delete(File.DirDefaultExternal,"result.apk")
    End If
  
    HttpUtils.CallbackActivity = "Sincronizar"
    HttpUtils.CallbackJobDoneSub = "JobDone"
    HttpUtils.CallbackUrlDoneSub = "UrlDone"
    HttpUtils.CallbackProgressSub="ProgressHTTP"
    url="http://www.mydomain.com/result.apk"
    HttpUtils.Download("downloadFile",url)
  
End Sub


Sub JobDone (Job As String)
    Select Job
        Case "downloadFile"
        If HttpUtils.IsSuccess(url) Then
            HttpUtils.SaveFile(url,File.DirDefaultExternal,"result.apk")
            If File.Exists(File.DirDefaultExternal,"result.apk") Then
                Dim Intent1 As Intent
                Intent1.Initialize(Intent1.ACTION_VIEW, "file://" & File.Combine(File.DirDefaultExternal,"result.apk"))
                Intent1.SetType("application/vnd.android.package-archive")
                StartActivity(Intent1)
            End If
        End If
     End Select
End Sub
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
For the record... the problem was at file... because had a special characte the "-" inside the name of file needed to use download2 or had to rename the file and the directory to work fine with .download !!!

my code was OK from the start--- thank to all the guys reply !
 
Upvote 0
Top