Android Question Can't download pdf file in webview

Baris Karadeniz

Active Member
Licensed User
I Can't download pdf file in webview with the codes below? Is there any idea? I use HttpUtils2 library.

B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
   If Url.EndsWith(".pdf") Then
        Dim j As HttpJob
     j.Initialize("pdf", Me)
     j.Download(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
 

Baris Karadeniz

Active Member
Licensed User
Ok. I did as you said. I use HttpUtils2 library. But I again have same error when trying to open pdf file after download. As you said I asked this question in B4aPdfViewer forum. Someone else had same error also and didn't receive any answer to his question. I want to ask you that; do I try to open pdf file in wrong place? Do I have to change the pdf opening codes somewhere else? Here are the codes;

B4X:
#Region  Project Attributes
    #ApplicationLabel: TAKSİ'M
    #VersionCode: 2
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

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

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
End Sub

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
    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.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
        Dim j As HttpJob
     j.Initialize("pdf", Me)
     j.Download(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 j_progress(count As Long,total As Long )
  
End Sub

Sub JobDone (Job As HttpJob)
    Log("Job completed: " & Job.Success)
    Dim o As OutputStream
    o = File.OpenOutput(File.DirDefaultExternal, "l.bal", False)
    File.Copy2(Job.GetInputStream, o)
    o.Close
    Job.Release
    If Job.Success = True Then
    Activity.LoadLayout("Layout2")
    Dim pdfView As PDFViewer
    pdfView.init
    Activity.AddView(pdfView,0,0,-1,-1)
    pdfView.getpdf(File.DirRootExternal&"/l.bal")
    End If
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
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
My questions are;

1) So, in which way I can open with B4aPdfViewer? I saw these codes in B4aPdfViewer Forum.

2) Where can I find different pdf library? I saw another but it is not free.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top