Search code examples
androidandroid-activitywebview

Can't Get the url in the Should over overriding webview


I am developing an android app, which has a webview in it..

The URL is https://www.facebook.com/ when the post is clicked in the webview the post URL is not getting in should overidding url but webview is redirecting the facebook to that particular post what is the problem the url should be in the shouldoverriding method of the webviewclient

Here I am Setting the Custom WebView Client 

webView.setWebViewClient(new WebViewController());

public class WebViewController extends WebViewClient {
@Override
        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            Log.e("urltop", str + " ==top");
            String str3 = "youtube";
            if (!str.contains("market://")) {
                if (!str.contains("mailto:") && !str.contains("play.google") && !str.contains("tel:") && !str.contains("intent:") && !str.contains("vid:") && !str.contains(str3) && !str.contains("fb-messenger://")) {
                    if (!str.contains("whatsapp://")) {
                        if (str.contains("m.me")) {
                            Log.e("urlm.me", str);
                            return true;
                        } else if (str.contains("jpg")) {
                            Log.e("urljpg", str);
                            return true;
                        }
                        return true;
                    } else {
                        Log.e("url", str);
                    }
                }
            }
            return true;
        }

Thanks in advance :)


Solution

  • Just using shouldOverrideUrlLoading:

    public class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.equals("YOURLINK")) {
                Intent intent = new Intent(getContext(), YourActivity.class);
                startActivity(intent);
                return true; // Handle By application itself
            } else {
                view.loadUrl(url);
                return true;
            }
        }
    }