Private Sub Button1_Click
'non-https link so we need to add SetApplicationAttribute(android:usesCleartextTraffic, "true") in B4A.
Wait For (DownloadAndTrackProgress("http://mirror.filearena.net/pub/speed/SpeedTest_16MB.dat")) Complete (Success As Boolean)
End Sub
Private Sub DownloadAndTrackProgress (url As String) As ResumableSub
Dim 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
Dim TaskId As Int
Do While TaskId = 0
For Each id As Int In TaskToJob.Keys
If TaskToJob.Get(id) = j Then
TaskId = id
Exit
End If
Next
Sleep(10)
Loop
Dim b() As Boolean = Array As Boolean(False)
TrackProgress(j, b, TaskId)
Wait For (j) JobDone (j As HttpJob)
b(0) = True
j.Release
Log("complete")
Return j.Success
End Sub
Private Sub TrackProgress (j As HttpJob, Stop() As Boolean, TaskId As Int)
Do While Stop(0) = False
If j.Out.IsInitialized Then
Dim TotalLength As Long = j.Response.ContentLength
Dim size As Long = File.Size(HttpUtils2Service.TempFolder, TaskId)
Log(size & ", " & TotalLength)
End If
Sleep(100)
Loop
Log(size & ", " & TotalLength)
End Sub