androidif-statementandroid-webviewhttp-redirectandroid-browser

redirect unknown website to google search result in web browser android studio


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


Solution

  • 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());
                }