Sub hc_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
' ********** Modified code *************
Dim cs As CountingOutputStream
'THE NEXT LINE FAILS ON ANDROID 5.1 WITH A DIRECTORY NOT FOUND ERROR!
' Temp folder is set to TempFolder = File.DirInternalCache
cs.Initialize(File.OpenOutput(TempFolder, TaskId, False))
Dim j As HttpJob = TaskIdToJob.Get(TaskId)
If j.Tag <> Null And j.Tag Is JobTag Then
Dim jt As JobTag = j.Tag
jt.CountingStream = cs
jt.Total = Response.ContentLength
If jt.Data.url = "" Then
Log("Job cancelled before downloaded started")
cs.Close
End If
Response.GetAsynchronously("response", cs , _
True, TaskId)
'**************************************
Else
' ************* TEST CODE
Dim job As HttpJob = TaskIdToJob.Get(TaskId)
job.Tag = Response.StatusCode
Response.GetAsynchronously("response", File.OpenOutput(TempFolder, TaskId, False), _
True, TaskId)
End If
End Sub