I'm using B4XPages to develop for Android using B4A. I want to download a SQLite database of just a few MB from a https url and wait for it to finish. I'm using the example code in old thread https://www.b4x.com/android/forum/t...from-server-with-progress.126797/#post-793290 coded in a module called by ShowPage from B4XMainPage.
My code looks exactly the same as the code in that thread (with a few lines added for Log statements etc) but I get a Compiler error of "Unknown member taskidtojob on
line 41 "Dim TaskToJob As Map = HttpUtils2Service.TaskIdToJob" in "Sub DownloadProgress" shown below:
PS I have HU_2 in the Conditional Symbols for Build Configuration and I have library OkHttpUtils2 included.
My code looks exactly the same as the code in that thread (with a few lines added for Log statements etc) but I get a Compiler error of "Unknown member taskidtojob on
line 41 "Dim TaskToJob As Map = HttpUtils2Service.TaskIdToJob" in "Sub DownloadProgress" shown below:
B4X:
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private SDDir As String
Private DBFilename As String = "JewishWorld.db"
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("TestCode")
B4XPages.SetTitle(Me, "TestCode")
SDDir = xui.DefaultFolder
Wait For(DownloadAndTrackProgress("https://app.box.com/s/vk2t0zrqaf0y16fk6evxnxcer13jb3ng")) Complete (Success As Boolean)
If Success = True Then
Private TempFullFilename As String
TempFullFilename=HttpUtils2Service.TempFolder & DBFilename
Log("Downloaded into: " & TempFullFilename)
ToastMessageShow("Downloaded into " & TempFullFilename, True)
Else
Dim dbProblem As String
dbProblem = "Database Not Available from Internet:" & CRLF & _
"Try Again Later."
Wait For (xui.MsgboxAsync(dbProblem, "Database Problem")) Msgbox_Result (Result As Int)
B4XPages.ClosePage(Me)
End If
End Sub
Private Sub DownloadAndTrackProgress (url As String) As ResumableSub
Log("DownloadAndTrackProgress")
Private j As HttpJob
j.Initialize("", Me)
j.Download(url)
Dim TaskToJob As Map = HttpUtils2Service.TaskIdToJob
Do While HttpUtils2Service.TaskIdToJob.IsInitialized = False
Log("Waiting for HttpUtils2Service to be ready.")
Sleep(30)
Loop
Log("Checking Tasks")
Private TaskId As Int
Do While TaskId = 0
For Each id As Int In TaskToJob.Keys
If TaskToJob.Get(id) = j Then
TaskId = id
Log("TaskId="&id)
Exit
End If
Next
Sleep(10)
Loop
Private b() As Boolean = Array As Boolean(False)
TrackProgress(j, b, TaskId)
Wait For (j) JobDone (j As HttpJob)
b(0) = True
j.Release
Log("Database Downloaded")
Return j.Success
End Sub
Private Sub TrackProgress (j As HttpJob, Stop() As Boolean, TaskId As Int)
Log("Track Progress")
Do While Stop(0) = False
If j.Out.IsInitialized Then
Private TotalLength As Long = j.Response.ContentLength
Private size As Long = File.Size(HttpUtils2Service.TempFolder, TaskId)
Log(size & " of " & TotalLength & " downloaded")
pbDownload.Progress=Round((size*100)/TotalLength)
End If
Sleep(100)
Loop
pbDownload.Progress=Round((size*100)/TotalLength)
Log("Database: Downloaded: " & size & " should equal " & TotalLength)
End Sub
PS I have HU_2 in the Conditional Symbols for Build Configuration and I have library OkHttpUtils2 included.