How to download file from Webview

tcgoh

Active Member
Licensed User
Longtime User
Currency converter doesn't use a WebView to download the resource.

Tks Erel, I'm planning a project to use Webview as the main layout on a site where I can download files.

Curreny converter page on B4a is just a example. I read somewhere, if I click on a download link on webview page, it should open up the default browser, but its not happening on B4a?
 
Upvote 0

tcgoh

Active Member
Licensed User
Longtime User
Basic4android WebView is the regular native WebView. You can use OverrideUrl event to send an intent and launch the default browser when the user presses on a link. You can also download the file yourself with HttpClient.

Can you please give a example on how to use the "OverrideUrl event to sent an intent". Thanks.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Something like:
B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
   'Test whether this Url points to a file.
   'For example:
   If Url.EndsWith(".pdf") Then
      Dim p As PhoneIntents
      Dim i As Intent
      i.Initialize(p.OpenBrowser(Url)
      Return True
   Else
      Return False 'let WebView process the Url
   End If
End Sub
 
Upvote 0

tcgoh

Active Member
Licensed User
Longtime User
Something like:
B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
   'Test whether this Url points to a file.
   'For example:
   If Url.EndsWith(".pdf") Then
      Dim p As PhoneIntents
      Dim i As Intent
      i.Initialize(p.OpenBrowser(Url)
      Return True
   Else
      Return False 'let WebView process the Url
   End If
End Sub

Tks Erel,
I was unale to work on my project for a few days.
But the code you gave is not working: should it be

i.Initialize(p.OpenBrower(Url))
But with the end ) in the code I'm still getting an error of

Parameter name cannot hide global variable name.:sign0104:
 
Upvote 0
Top