0

I started this android webView project as my first android studio project awhile ago, I was slow with it and kept adding features little by little. Now I want to develop the project into a web browser worthy of play store publication.

I have selected no action bar in my style, I am using an editText to load URL already but when a text is entered which is not an URL, it gives error.

So, I want to solve this by enabling search function when no URL is entered in edit text but regular text i.e presently in editText google.com facebook.com or any URL loads but typing facebook, news etc in edit text shows error "WEB PAGE NOT AVAILABLE the web page https://google/ could not be loaded because net::ERR_NAME_NOT_RESOLVED"

I want to fix this, to enable google search or any other search engine in such case.

I do hope my question is understandable and well detailed?

1 Answers1

1

Welcome in stack

to open URL with web View you must pass a full URL like https://stackoverflow.com and or stackoverflow.com

when you want to make query in some keys like Facebook or news you can use google search as example with this key to get full link of this result

so when user input text you must check if this is url or not

  • So if is URL and will return true just pass it to web View

  • if not will return false,and pass it as query word to google and then show on web view

You can check if string is url or not by this code refer to this

   bool isUrl= URLUtil.isValidUrl(text);

    String url;
    if(isUrl)
      url = text;
    else{
      //this url well open in web view as google search
      url = "https://www.google.com/search?q="+text.replace(" ", "%20");
    }

    //now you have url to open in your web view 

i hope this help

Community
  • 1
  • 1
Mahmoud Abu Alheja
  • 3,343
  • 2
  • 24
  • 41