B4J Question Compare a text file hosted online with a text file inside the assets folder.

Dominik H

Member
Licensed User
Longtime User
Just as the title says, how would I go about doing this? It would work similar to an update checker.

The main struggle here is that I don't know how I would go about downloading that file to a temporary location so that it can be read and converted into a number and then compared.

Any help is appreciated!

Thank you in advance!
 

eurojam

Well-Known Member
Licensed User
Longtime User
this can be done easy with httputils:
something like this...not tested, but should work in this way...

B4X:
Sub AppStart (Args() As String)
    Dim job1 As HttpJob

    job1.Initialize("Job1", Me)
    job1.Download("http://www.yourdomain.com/youtextfile.txt")
    StartMessageLoop
End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName

            Case "Job1"
'                'do something with the string
                 'compare it with your text or so on...
                Log(Job.GetString)
   

        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
    End If
    Job.Release
End Sub
 
Upvote 0

Dominik H

Member
Licensed User
Longtime User
this can be done easy with httputils:
something like this...not tested, but should work in this way...

B4X:
Sub AppStart (Args() As String)
    Dim job1 As HttpJob

    job1.Initialize("Job1", Me)
    job1.Download("http://www.yourdomain.com/youtextfile.txt")
    StartMessageLoop
End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName

            Case "Job1"
'                'do something with the string
                 'compare it with your text or so on...
                Log(Job.GetString)
  

        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
    End If
    Job.Release
End Sub
This works perfect, thanks a lot sir! By the way, is StartMessageLoop required? Because it doesn't seem like I'd need it.
 
Upvote 0
Top