'Android web browser

please predecessors, Am creating a web browser homepage in android studio and want to be able to input URL from the same editText as that of my search. have been able to take search and load google results, but URL still end up in searched instade of loading the URL website.

this is my codes.

    EditText searchEditText = rootView.findViewById (R.id.searchEditText);
    ImageButton searchBt = rootView.findViewById (R.id.searchBt);

    searchBt.setOnClickListener (new View.OnClickListener ( ) {
        @Override
        public void onClick(View v) {
            String searchQuery = searchBar.getText ().toString ();
            if(URLUtil.isValidUrl (searchQuery)){
                webView.loadUrl (searchQuery);
            }else {
                String searchURL = "https://www.google.com/search?q="+searchQuery;
                webView.loadUrl (searchURL);
            }

        }
    });


Solution 1:[1]

The problem is probably because your URL doesn't have https at the beginning. Try using some other mechanism to determine if the URL is valid.

For example, use WEB_URL pattern in Patterns Class

Patterns.WEB_URL.matcher(potentialUrl).matches()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 XPTO