Android Question downloading pdf file from webiew

tcgoh

Active Member
Licensed User
Longtime User
Hi,

I have download a pdf file from the webview module, its working but how do I code a "download completed" with a callsubdelay?
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    webview1.SetLayout(0,0,100%x,90%y)
    webview1.LoadUrl("https://www.cs.kent.ac.uk/events/2015/AISB2015/templates/AISB08.pdf")

   job1.Initialize("Job1", Me)
   'Send a GET request
'  job1.Download2("http://www.b4x.com/print.php", _
  '    Array As String("first key", "first value :)", "second key", "value 2"))
   'Send a POST request
  ' job2.Initialize("Job2", Me)
  ' job2.PostString("http://www.b4x.com/print.php", "first key=first value&key2=value2")

   'Send a GET request
   job3.Initialize("Job3", Me)
   job3.Download("https://www.cs.kent.ac.uk/events/2015/AISB2015/templates/AISB08.pdf")
End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      Select Job.JobName
         Case "Job1", "Job2"
            'print the result to the logs
'           Log(Job.GetString)
         Case "Job3"
        Job.Download("https://www.cs.kent.ac.uk/events/2015/AISB2015/templates/AISB08.pdf")
           Dim out As  OutputStream
          out = File.OpenOutput(File.DirRootExternal,"tcctest.pdf",False)
           File.Copy2(Job.GetInputStream,out)
           out.Close
      End Select
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub

The log shows about 20 x
"JobName = Job3, Success = true"
"sending message to waiting queue (CallSubDelayed - JobDone)"
before the pdf is completed and saved.

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top