Issue
I'm creating an app that shows a web view. The web view uses a URL entered by a user. How can I have it so a user only needs to enter the url similar to how they would do it in a chrome browser?
For example
If I put facebook.com
in chrome it will load https://www.facebook.com
.
If I do webView.loadUrl("facebook.com");
it will fail. I would need to specify webView.loadUrl("https://www.facebook.com");
for it to work.
I want to avoid making my users first figure out if the page is http or https and if they need www.
or not.
Solution
There is not method to check if the url will need a www (i.e. if is mypage.com or www.mypage.com), because this a issue of the own webpage. There must to be an redirection or something.
For the HTTP case is easier, you can check if has the http, and if not, add it. Here is the code to do that: https://stackoverflow.com/questions/10650428/add-http-www-in-the-text-if-not-exist.
Almost every page that support https will redirect from a http request.
Answered By - Alex Gama
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.