Android Question Intercepting Page Change on Webview

DawningTruth

Active Member
Licensed User
I need to redirect certain App Websites to the main phone browser as webview is incomplete. This would typically be sites like Facebook.com.

These App Websites would be accessed by the user clicking on a link, such as Facebook Share link.

The code below is intended to intercept these clicks.

Unfortunately it both opens the main phone browser and navigates to the App Website url in my webview.

How do I prevent it from navigating in my webview.

B4X:
Sub wbv_WebContent_OverrideUrl (currentUrl As String)

    Private thisWebView As WebView = Sender
    
    If isAppSite(currentUrl) Then
    
        webViewExtras1.Initialize(thisWebView)

       '*** My current unsuccessful attempts to deal with it navigating to the page
        webViewExtras1.StopLoading
        webViewExtras1.Back
        '*** 

        StartActivity(phoneIntent1.OpenBrowser(currentUrl))
        
        Return 'Don't try to navigate to this URL. My attempt to prevent it from navigating to the page
      
    End If

End Sub
 

DawningTruth

Active Member
Licensed User
Thx Don,

When I try change it I get the following error:

OverideError.png


If I make a Resumable sub I get another error:

java.lang.ClassCastException: anywheresoftware.b4a.keywords.Common$ResumableSubWrapper cannot be cast to java.lang.Boolean
at anywheresoftware.b4a.objects.WebViewWrapper$1.shouldOverrideUrlLoading(WebViewWrapper.java:64)
at android.webkit.WebViewClient.shouldOverrideUrlLoading(WebViewClient.java:73)
at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(PG:16)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:379)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:7523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
 

DonManfred

Expert
Licensed User
Private thisWebView As WebView = Sender If isAppSite(currentUrl) Then webViewExtras1.Initialize(thisWebView) '*** My current unsuccessful attempts to deal with it navigating to the page webViewExtras1.StopLoading webViewExtras1.Back
why these lines? Especially WHY you are initialiting the webview extrras AGAIN? You alread did in activity_create (or you should have)


For your NEW issue (which you should have started a new thread for).
Try changing the result from As Boolean to As ResumeableSub
 

DawningTruth

Active Member
Licensed User
Thx Don,

To clarify. The suggested solution does not work as it is a resumable sub. Hence showing you the error. I then proqactively changed it to a resumable sub and got the other error.

In other words the suggested solution is not working. Should I start another thread for this, as the suggested solution is not working?
 

DawningTruth

Active Member
Licensed User
why these lines? Especially WHY you are initialiting the webview extrras AGAIN? You alread did in activity_create (or you should have)
They are an attempt to go back after it has already navigated to the site. In other words a workaround. But they did not work. My architecture is very complicated, so I create a WebView extras every time I need it in a particular sub, rather than in the Activity Create Sub.
 
Top