Android Question Links in webview don't work

Baris Karadeniz

Active Member
Licensed User
I am developing webview app for android. Web site is opened by app. But the e-mail, pdf and other web site links are not working. When I push on them, it happens nothing. What should I do?
 

An Schi

Well-Known Member
Licensed User
You should use the overrideurl function of the webview to open email or pdf apps.
Search here on the forum and you will find examples.
"Normal" website links should work....
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
I already used overrideurl for pdf. But it doesn't work. I did same app for ios. ios app works very well. What should I check?

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private WebView1 As WebView
    Private WebView2 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    Dim WebViewSettings1 As WebViewSettings
    WebViewSettings1.setDefaultZoom(WebView1, "FAR")
    WebViewSettings1.setLoadWithOverviewMode(WebView1, True)
    WebViewSettings1.setUseWideViewPort(WebView1, True)
    WebViewSettings1.setAllowFileAccess(WebView1, True)
    WebViewSettings1.setDisplayZoomControls(WebView1, False)
    WebView1.LoadUrl("http://www.taksi-m.com.tr/track")
End Sub

Sub WebView1_OverrideUrl (Url As String) As Boolean
   If Url.StartsWith("https://www.google.com") Or Url.EndsWith(".pdf") Then
        Activity.LoadLayout("Layout2")
     Dim WebViewSettings2 As WebViewSettings
     WebViewSettings2.setDefaultZoom(WebView2, "FAR")
     WebViewSettings2.setLoadWithOverviewMode(WebView2, True)
     WebViewSettings2.setUseWideViewPort(WebView2, True)
     WebViewSettings2.setAllowFileAccess(WebView2, True)
     WebViewSettings2.setDisplayZoomControls(WebView2, False)
     WebView2.LoadUrl(Url)
     Return True
   Else
     Return False
   End If  
End Sub

Sub JobDone (Job As HttpJob)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
I used that library. But pdf files are not opened on the screen. it doesn't work. Codes are given below. What is my fault?

B4X:
ub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private WebView1 As WebView
    Private WebView2 As WebView
    Dim pdfv As PDFViewer
    Dim pc As Int=0
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    Dim WebViewSettings1 As WebViewSettings
    WebViewSettings1.setDefaultZoom(WebView1, "FAR")
    WebViewSettings1.setLoadWithOverviewMode(WebView1, True)
    WebViewSettings1.setUseWideViewPort(WebView1, True)
    WebViewSettings1.setAllowFileAccess(WebView1, True)
    WebViewSettings1.setDisplayZoomControls(WebView1, False)
    WebView1.LoadUrl("http://www.taksi-m.com.tr/track")
End Sub

Sub WebView1_OverrideUrl (Url As String) As Boolean
   If Url.EndsWith(".pdf") Then
        Activity.LoadLayout("Layout2")
     pdfv.init
        Activity.AddView(pdfv,0,0,-1,-1)
        pdfv.getpdf(Url)
        If pdfv.isValid Then
      'Log("pagecount:"&pdfv.PageCount)
      pdfv.scrollToPage(0)
      pc=pdfv.GetPageCount
      pdfv.zoom(3.0)
      Return True
      Else
      Return False
      End If
   Else If Url.StartsWith("https://www.google.com") Then
        Activity.LoadLayout("Layout2")
     Dim WebViewSettings2 As WebViewSettings
     WebViewSettings2.setDefaultZoom(WebView2, "FAR")
     WebViewSettings2.setLoadWithOverviewMode(WebView2, True)
     WebViewSettings2.setUseWideViewPort(WebView2, True)
     WebViewSettings2.setAllowFileAccess(WebView2, True)
     WebViewSettings2.setDisplayZoomControls(WebView2, False)
     WebView2.LoadUrl(Url)
     Return True
   Else If Url.IndexOf("mailto:") > -1 Then 
     Dim Intent1 As Intent
     Intent1.Initialize(Intent1.ACTION_VIEW, Url)
     StartActivity(Intent1)
     Return True
   Else
     Return False
   End If
End Sub

Sub JobDone (Job As HttpJob)
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event

End Sub

Sub CanGoBack (wv As WebView) As Boolean
    Dim r As Reflector
    r.Target = wv
    Return r.RunMethod("CanGoBack")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



I used that library. But pdf is not opened on the screen. it doesn't work. Codes are given below
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Android Webview is not able to show pdf. Download the pdf and show it with a pdf-reader installed on your device
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
In override url event you need to catch the url of the pdf. If the url is a pdf-file then start a download of the given pdf. When download finishes (the sub JobDone is raised) you can save the download to a readable space and open a new activity with the pdf.

MAybe my FileUtils can help to split the url into parts
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
I try to download but I receive an log error given below;

java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/data/app.taksim/files/libpdfview2.so" not found

I added b4aPdfViewer lib. Do I need to install another library too? What is my fault?
 
Upvote 0
Top