Android Question Download document in webView

Alphaw

Member
Licensed User
Longtime User
I and a student and I would like to make an app that link to my college website, I need to login and download or open the materials when I click the items list on the web. I tried the download server or httputils2, however the webview do not have any change.

Question:
1. When I click the item, no reaction. Is it any sub I need to use for the webview? And Can I do the download action when click the items in webview? (The item selected will be doc, docx, ppt, pptx or pdf file.)

2. Can I use the phone's intent downloader to download the file? Since the original download function is enough for us to download the study materials. If yes, how to do so, if no, it will go back to question 1, how to download with the webview.

3. Last question, is it possible to read the document file directly when I click the item, just like showing content inside the webview.

I really need helps, thank you.
 

eurojam

Well-Known Member
Licensed User
Longtime User
1+2:
you can use the OverrideUrl event to decect the extension of the file, something like
B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
   If Url.indexof(".pdf")>0 OR Url.IndexOf(".doc")>0 OR Url.IndexOf(".docx")>0 Then
     ....
then you start to download the file using HttpUtils2
3: I think no, you can't do this.
 
Upvote 0

Alphaw

Member
Licensed User
Longtime User
1+2:
you can use the OverrideUrl event to decect the extension of the file, something like
B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
   If Url.indexof(".pdf")>0 OR Url.IndexOf(".doc")>0 OR Url.IndexOf(".docx")>0 Then
     ....
then you start to download the file using HttpUtils2
3: I think no, you can't do this.

eurojam, can you give me a hint for calling the download service? Here is my code, and I still cannot do downloading. The attached file is whole code, I just use download1, I do not know whether it is correct or anything I missing. Thank you.
B4X:
Sub wv_OverrideUrl (Url As String) As Boolean
    If Url.indexof(".pdf")>0 Or Url.IndexOf(".doc")>0 Or Url.IndexOf(".docx")>0 Or Url.IndexOf(".ppt")>0 Or Url.IndexOf(".pptx")>0 Then
    'Send a GET request
    downloadurl = Url
    End If
    Dim job As HttpJob
    job.Initialize("Job", Me)
    job.Download(downloadurl)
    Return True
End Sub
 

Attachments

  • test.zip
    425 KB · Views: 328
Upvote 0
Top