Android Question Read data from a url

DonManfred

Expert
Licensed User
Longtime User
How can a textfile be "inside" a url?

What exactly are you trying to archieve?

I guess you should use okhttputils2 and download the file, save it to sdcard and then read the file...
 
Upvote 0

bixmatech

Member
Licensed User
ok,
this is the link, when you access it through browser, it shows "value is 5".
I want to do a request from b4a to this link and get the returned value in a string to use it.
 
Upvote 0

bixmatech

Member
Licensed User
Perfect worked, but it seems that job woek in async mode, how to run it in sync mode?
I mean now when i run the app, the logs are:
Will check internet now
Internet: 0
value is 5

so it is executing the statement {If ConnexioInternet = "value is 5" Then} before that the function {CheckInternet} finished its job. which give swrong results, as the {CheckInternet} should finish to update the ConnexioInternet variable and then do the checking.


B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim ConnexioInternet As String
    Dim no_intenet As String = "<center><h1>No Internet</h1></center>"
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
   
    Dim myw As WebView
    myw.Initialize("myw")
    Activity.AddView(myw, 0, 0, 100%x, 100%y) 'Your options for size here
    Log("Will check internet now")
    CheckInternet
    If ConnexioInternet = "value is 5" Then
        Log("Internet: 1")
        myw.LoadUrl("http://www.stackoverflow.com")
    Else
        Log("Internet: 0")
        myw.LoadUrl($"no_internet"$)
    End If
End Sub

Sub CheckInternet
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("http://bixma.com/test_value.txt")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        ConnexioInternet = j.GetString
        Log(ConnexioInternet)
    End If
    j.Release
End Sub
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
Move the
B4X:
If ConnexioIternet
section to inside the
B4X:
If j.success
so that you don't check it until you've set the value
 
Upvote 0
Top