-1

i really i appreciate the way you support each other in diff projects, have blessed-up... so to day i got question on my project i started and some of part of my project is based on here..... so that why am begging you favour to help me and my question is how can you redirect all unknown URL or keywords with no http://www. .com or http://www. .com ( Ex: user typed Amazon or Ebay or GitHub only in webview) to be found on google instead of showing user Website is not found or errors because am dealing with creating android app browser

2 Answers2

0

You can use these 2 functions to override the url or do something with it:

webview.setWebViewClient(new WebViewClient() {
            @SuppressWarnings("deprecation")
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // Your code
            }

            @TargetApi(Build.VERSION_CODES.N)
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                // Your code
            }
        });

Read more at Link

Once you get the url that the user enters, you can redirect it to https://www.google.com/search?q=query_string (read more at Link)

Liar
  • 1,235
  • 1
  • 9
  • 19
0

Hi Guys after running some experience about this question... Finally i figured_out the way to fix this question. All you need to do, Is to Set Search_Button as follow:

Your_Button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) 
            {
        String url=Your_TextEdit.getText().toString();


        if(!url.contains("http://") && !url.contains("https://"))
        {
            url="http://" + url;
        }

        else
        {
            url ="https://www.google.com/search?q=q" +url;

        }

        WebSettings webSettings = Your_webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        web2.loadUrl(url);
        web2.setWebViewClient(new WebViewClient());
            }