Android Question How to redirect links in webview ?

AbdurRahman

Member
Starting by thanking builder from depth of heart. I must say its only fastest way to develop android apps. 😍

What I want to achieve ?
To support webview display PDFs, in customised UI (PDF.js only 2 buttons: print and back button)

What I tried:
B4X:
#Region  Project Attributes
    #ApplicationLabel: WebIntercept
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #FullScreen: True
    #IncludeTitle:False
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Private WebView1 As WebView
    Private WebViewClient As UltimateWebViewClient
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    WebViewClient.Initialize2("WebView1",WebView1)
    WebView1.LoadUrl("https://smartdocument.bpp.it/fipub/bppfipub/index2pub.php")
End Sub

Sub WebView1_ShouldInterceptRequest(Request As WebResourceRequest) As WebResourceResponse
    If Request.Url.Contains("foglio.png") Then
        Dim rp As RuntimePermissions
        Dim Parent="/storage/emulated/0/Pictures"
        Dim filename="favicon.png"
        Log(File.Exists(Parent,filename))
        Dim WebResourceResponse1 As WebResourceResponse
        WebResourceResponse1.Initialize("image/png", Null, File.OpenInput(Parent, filename))
        Return WebResourceResponse1
    End If
    Return Null
End Sub
End Sub

What issue in code:
I copied that example from forum somewhere. It run fine i.e no errors, image exists...
But fails to do any change to link. I see no change in image on display.

Additional info:
On windows, using webview2 (microsoft edge runtime)
and rout its traffic through titanium web proxy
which intercepts and redirect link toward our local hosted PDF.js server

But on android, not sure if my idea make sense and possible ?
 
Top