user3782810
user3782810

Reputation: 113

How to load URL in android Web View if HTTP or HTTPS not include in given URL

I have an project where I want to load some url came from webservice into a webView but. for that I am facing the following problem. Please help.

url = "www.facebook.com"
wv.loadUrl(url);

for above code I got an error say unable load webpage.

But if i changed this to

url = "https://www.facebook.com"

its working but I need to load url without having http or https mentioned .

Please help me on this.

Upvotes: 5

Views: 3793

Answers (1)

Abdul Mohsin
Abdul Mohsin

Reputation: 1435

add this by your own code like

    String urlCameFromServer = "www.facebook.com";
    if(!urlCameFromServer.contains("http")) {
         urlCameFromServer = "http://"+urlCameFromServer;
    }
    wv.loadUrl(urlCameFromServer);

Upvotes: 5

Related Questions