Hello,
With OKHttputilis2 I want to download text in a file.txt from a server and put it into a variable.
I Know to download an image and I use this Sub which runs fine
B4X:
Sub DownloadImage(Link As String, iv As ImageView)
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Link)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
iv.Bitmap = j.GetBitmap
End If
j.Release
End Sub
How to modify this sub to download text that is in a file.txt on the server ant put it into a string variable
The sub below does'nt run.
Thank you
B4X:
Sub DownloadString(Link As String, TheString As String )
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Link)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
TheString = j.GetString
Log(j.GetString)
End If
j.Release
End Sub
This is a slightly modified sub based on the code from: [B4X] OkHttpUtils2 with Wait For Call it when you want to download a file and save it. You can wait for it to complete if needed. Sub DownloadAndSave (Url As String, Dir As String, FileName As String) As ResumableSub Dim j As HttpJob...
Sub Activity_Create(FirstTime As Boolean)
Dim URL As String = "https://filesamples.com/samples/document/txt/sample1.txt"
Wait For (DownloadTxt(URL)) Complete (Content As String)
Log(Content)
End Sub
Sub DownloadTxt (Url As String) As ResumableSub
Dim TheString As String
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Url)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
TheString = j.GetString
End If
j.Release
Return TheString
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim URL As String = "https://filesamples.com/samples/document/txt/sample1.txt"
Wait For (DownloadTxt(URL)) Complete (Content As String)
Log(Content)
End Sub
Sub DownloadTxt (Url As String) As ResumableSub
Dim TheString As String
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Url)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
TheString = j.GetString
End If
j.Release
Return TheString
End Sub