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
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
- oneIn the
shouldOverrideUrlLoadingmethodshouldOverrideUrlLoadingcheck 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
- oneoh, yes, yes, hurry is simple :) - Flippy
- 2don't forget that
shouldOverrideUrlLoading(WebView view, String url)now deprecated at API level 24. Useboolean shouldOverrideUrlLoading (WebView view, WebResourceRequest request)instead. - mit
|