I'm using 'Wait For' in a B4XPages project calling the OkhttpUtils2 library to download a 2MB file. I've attached a zip file of the project. The relevant code in B4XHTTPSPage (as B4XMainPage is just code for a button to show B4XHTTPSPage) is:
However, the app hangs after installing it using B4A-Bridge. The log is attached as a screenshot as I was not able to work out how to copy it as a text file.
I can download the file by using the url in Firefox. However, Firefox pops up a window asking me if I want to save the file. Does the OkhttpUtils2 library automatically respond to this window?
PS I want to show the progress of the download in a ProgressBar. But I'll ask that on another thread if Erel says that I should.
B4X:
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private DBFolder As String
Private HTTP1 As HttpJob
Private DBFilename As String = "JewishWorld.db"
Private DBSize As Long
Private DBTotalDownloaded As Long
Private DBTotalOutOf As Long
Private pbDownload As ProgressBar
End Sub
'You can add more parameters here.
Public Sub Initialize As Object
Return Me
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("HTTPS")
B4XPages.SetTitle(Me, "HTTPS")
DBFolder = xui.DefaultFolder
Dim ServerPath As String = "rose.myddns.me/" & DBFilename
HTTP1.Initialize("", Me)
Log("HTTPS.Initialized")
HTTP1.Download(ServerPath)
Log("Started https")
DownloadAndTrackProgress
End Sub
Private Sub DownloadAndTrackProgress
Dim j As HttpJob
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
Log("File was downloaded successfully")
Else
Log(j.GetString)
Log("Error downloading file")
End If
j.Release
DBSize = File.Size(DBFolder, DBFilename)
Log("Database : " & Round(DBSize / 1000) & "KB")
Log("Downloaded: " & Round(DBTotalDownloaded / 1000) & "KB")
Log("Out of : " & Round(DBTotalOutOf / 1000) & "KB")
pbDownload.Progress = Round((DBTotalDownloaded*100)/DBTotalOutOf)
End Sub
However, the app hangs after installing it using B4A-Bridge. The log is attached as a screenshot as I was not able to work out how to copy it as a text file.
I can download the file by using the url in Firefox. However, Firefox pops up a window asking me if I want to save the file. Does the OkhttpUtils2 library automatically respond to this window?
PS I want to show the progress of the download in a ProgressBar. But I'll ask that on another thread if Erel says that I should.
Attachments
Last edited: