How can I implement the interception of the transition to the example on google.com and open it not in the webview, but transfer the opening of the link to a third-party browser via Intent?

    1 answer 1

    For your "capture" there is a method shouldOverrideUrlLoading

      public boolean shouldOverrideUrlLoading(WebView view, String url) { if(url.equals("google.com")) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } else { view.loadUrl(url); return true; } } 

    For API> = 24, you can get Uri directly from WebResourceRequest

    • I need to intercept the link transition in the webview itself. - FAR747
    • one
      In the shouldOverrideUrlLoading method shouldOverrideUrlLoading check the links. In general, look, I updated the answer - Flippy
    • 'view.loadUrl (url);' I pushed it in elsewhere ; after clicking, the link was still loaded into the webview - FAR747
    • one
      oh, yes, yes, hurry is simple :) - Flippy
    • 2
      don't forget that shouldOverrideUrlLoading(WebView view, String url) now deprecated at API level 24. Use boolean shouldOverrideUrlLoading (WebView view, WebResourceRequest request) instead. - mit