Android Question Download multiple files with JSInterface library

AlpVir

Well-Known Member
Licensed User
Longtime User
To download an html file (and then write it) I use JSInterface library of warwound. All right !
I do not quite do the same operation with more files.
To be precise first I have access to "index.html" and then to "pag1.html", "pag2.html", "pag3.html", etc. etc.
Something like that :
B4X:
Sub Globals
   Dim myInterface As JSInterface
   Dim WebView1    As WebView
   Dim P           as int
   Dim W       as int      
End Sub


Sub Activity_Create(FirstTime As Boolean)
   WebView1.Initialize("WebView1")
   Activity.AddView (WebView1,0,0,100%x,100%y)
   W=1
   myInterface.addJSInterface(WebView1, "B4A")
   WebView1.LoadUrl("http://www.site.com/folder/index.html")
End Sub

Sub WebView1_PageFinished (Url As String)
   If W=1 Then
    jsStatement="B4A.CallSub('processIndex', document.documentElement.outerHTML)"
    myInterface.execJS(WebView1, jsStatement)
   Else
    jsStatement="B4A.CallSub('processPag', document.documentElement.outerHTML)"
    myInterface.execJS(WebView1, jsStatement) 
   End If
End Sub

Sub processIndex(html As String)
   '--- save html
   Dim TW As TextWriter
   TW.Initialize(File.Openoutput(File.DirRootExternal,"index.txt",False))
   TW.Write (html)
   TW.Close
   '
   W=2
   dim I    as int
   For I=0 To 10
      WebView1.LoadUrl("http://www.site.com/folder/pag " & P & ".html")
   Next 
End Sub

Sub processPag(html As String)
    '---  save html
    Dim TW As TextWriter
    TW.Initialize(File.Openoutput(File.DirRootExternal,"pag" & P & ".txt",False))
    TW.Write (html)
    TW.Close
End Sub
Where am I wrong?
Where to put the For Next loop?
Thank you in advance
 

DonManfred

Expert
Licensed User
Longtime User
following post #3
You can reference each Post seperately by copying the link from the postcounter... #3

Rightclick on the postlink...

Aufnahme1.png



Copy the url.

Now answer giving a reference to this post (using the url you just copied).
 
Upvote 0
Top