Android Question webview limitation

hdmiacc

Member
Licensed User
Longtime User
hi.

can i know the default webview cannot download any type of files such as pdf?

when it load the url into webview. i is okay. but when click the link contain pdf or zip file. the webview not download the file.

can i know if it have any solution?
 

DonManfred

Expert
Licensed User
Longtime User
It is up to you to react in webview overrideurl event and download the pdf with okhttputils
 
Upvote 0

hdmiacc

Member
Licensed User
Longtime User
It is up to you to react in webview overrideurl event and download the pdf with okhttputils

B4X:
#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: True
#End Region

Sub Process_Globals
   
End Sub

Sub Globals
    Private webpage As WebView
    Private WebViewSettings1 As WebViewSettings
    Private WebViewExtras1 As WebViewExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("web")
    websetting
    Dim Url As String
    Url = "https://apdm.moe.gov.my"
    webpage.LoadUrl(Url)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub websetting
    WebViewSettings1.setDefaultZoom(webpage, "FAR")
    WebViewSettings1.setLoadWithOverviewMode(webpage, True)
    WebViewSettings1.setUseWideViewPort(webpage, True)
    WebViewSettings1.setDisplayZoomControls(webpage, False)
    WebViewExtras1.addWebChromeClient(webpage,"B4A")
    webpage.JavaScriptEnabled=True   
End Sub

Sub WebView1_OverrideUrl (Url As String) As Boolean
   If Url.indexof(".pdf")>0 Or Url.IndexOf(".doc")>0 Or Url.IndexOf(".docx")>0 Or Url.IndexOf(".zip")>0 Then
        Dim p As PhoneIntents
        StartActivity(p.OpenBrowser(Url))
        Return True
     Else
        Return False
   End If
End Sub

i using WebView1_OverrideUrl. but still cannot download the pdf or any file
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
does you code match the if? I mean put a log into it. dont DO anything. just LOG to see what happens....

B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
   If Url.indexof(".pdf")>0 Or Url.IndexOf(".doc")>0 Or Url.IndexOf(".docx")>0 Or Url.IndexOf(".zip")>0 Then
        log("Document on "&Url&" found")
        'Dim p As PhoneIntents
        'StartActivity(p.OpenBrowser(Url))
        Return True
     Else
        Return False
   End If
End Sub

Do you get the log-output?
 
Upvote 0

hdmiacc

Member
Licensed User
Longtime User
does you code match the if? I mean put a log into it. dont DO anything. just LOG to see what happens....

B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
   If Url.indexof(".pdf")>0 Or Url.IndexOf(".doc")>0 Or Url.IndexOf(".docx")>0 Or Url.IndexOf(".zip")>0 Then
        log("Document on "&Url&" found")
        'Dim p As PhoneIntents
        'StartActivity(p.OpenBrowser(Url))
        Return True
     Else
        Return False
   End If
End Sub

Do you get the log-output?

B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (apdm) Create, isFirst = true **
** Activity (apdm) Resume **

got nothing. can u guide me?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
and with
B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
   log("Got URL: "&Url)
   If Url.indexof(".pdf")>0 Or Url.IndexOf(".doc")>0 Or Url.IndexOf(".docx")>0 Or Url.IndexOf(".zip")>0 Then
        log("Document on "&Url&" found")
        'Dim p As PhoneIntents
        'StartActivity(p.OpenBrowser(Url))
        Return True
     Else
        Return False
   End If
End Sub
 
Upvote 0

hdmiacc

Member
Licensed User
Longtime User
and with
B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
   log("Got URL: "&Url)
   If Url.indexof(".pdf")>0 Or Url.IndexOf(".doc")>0 Or Url.IndexOf(".docx")>0 Or Url.IndexOf(".zip")>0 Then
        log("Document on "&Url&" found")
        'Dim p As PhoneIntents
        'StartActivity(p.OpenBrowser(Url))
        Return True
     Else
        Return False
   End If
End Sub

nothing happen also.

this my code
 

Attachments

  • webview.zip
    7.5 KB · Views: 185
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
this my code
Your eventname is WRONG!

You set webpage in designer as eventname for the webview. Not Webview1

B4X:
Sub webpage_PageFinished (Url As String)
   Log($"PageFinished(${Url})"$)   
End Sub
Sub webpage_OverrideUrl (Url As String) As Boolean
   Log("Got URL: "&Url)
   Return True
     If Url.indexof(".pdf")>0 Or Url.IndexOf(".doc")>0 Or Url.IndexOf(".docx")>0 Or Url.IndexOf(".zip")>0 Then
        Log("Document on "&Url&" found")
        'Dim p As PhoneIntents
        'StartActivity(p.OpenBrowser(Url))
        Return True
     Else
        Return False
   End If
End Sub
 
Upvote 0

hdmiacc

Member
Licensed User
Longtime User
Your eventname is WRONG!

You set webpage in designer as eventname for the webview. Not Webview1

B4X:
Sub webpage_PageFinished (Url As String)
   Log($"PageFinished(${Url})"$)
End Sub
Sub webpage_OverrideUrl (Url As String) As Boolean
   Log("Got URL: "&Url)
   Return True
     If Url.indexof(".pdf")>0 Or Url.IndexOf(".doc")>0 Or Url.IndexOf(".docx")>0 Or Url.IndexOf(".zip")>0 Then
        Log("Document on "&Url&" found")
        'Dim p As PhoneIntents
        'StartActivity(p.OpenBrowser(Url))
        Return True
     Else
        Return False
   End If
End Sub

Thanks and sorry for the mistake. this my 1st time use webview. after change with your code. my log output show this.
B4X:
** Activity (main) Pause, UserClosed = true **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
PageFinished(https://apdm.moe.gov.my/)
Got URL: https://apdm.moe.gov.my/panduan/dokumen_MBK.zip

but still cannot download any file. (T T)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
So you get the url... But your if does not match as the second log entry is not shown.
Search the error.

To download the zip you need to use httputils and download the zip by yourself and in JobDone you need to save the result to a file giving it the right filename.

https://www.b4x.com/android/forum/threads/okhttp-replaces-the-http-library.54723/

And a tutorial about https://www.b4x.com/android/forum/t...oid-web-services-are-now-simple.9176/#content

Search the forum for more info. there is a lot.
 
Upvote 0

hdmiacc

Member
Licensed User
Longtime User
So you get the url... But your if does not match as the second log entry is not shown.
Search the error.

To download the zip you need to use httputils and download the zip by yourself and in JobDone you need to save the result to a file giving it the right filename.

https://www.b4x.com/android/forum/threads/okhttp-replaces-the-http-library.54723/

And a tutorial about https://www.b4x.com/android/forum/t...oid-web-services-are-now-simple.9176/#content

Search the forum for more info. there is a lot.

thanks a lot @DonManfred for guide me.
 
Upvote 0
Top