Issue
I am adding a web view with URL http://www.google.com into a FrameLayout. I am not able to view the web page in the web view and get error message "net::ERR_NAME_NOT_RESOLVED". In other case if I try to access a web page hosted locally http://localhost:9080/mobApp/aboutUs.html
it is giving error message "net::ERR_CONNETION_REFUSED". I am not able to make out what is the error or things I had done wrong. I also added the permission(<uses-permission android:name="android.permission.INTERNET"></uses-permission>
) in AndroidManifest.xml file to provide internet permissions to my app. Code is as follows:
String url = "http://localhost:9080/mobApp/aboutUs.html";
aboutUsWebView.loadUrl(url);
FrameLayout contentLayout = (FrameLayout)findViewById(R.id.container);
if(contentLayout != null)
contentLayout.addView(aboutUsWebView);
I actually want to access web app hosted locally!
Solution
localhost
points to the local environment, if you connect to it from your phone it will attempt to connect to a server running on the phone (same goes for AVD) and if you don't have a web server running on that device listening on the specified port (9080 in your case) it will not be able to connect.
In order to connect to a webserver running on another device you need to configure the webserver to accept connections from other devices (in most cases listening on your ip instead of localhost will enable this) and then load the page <your ip>:9080/mobApp/aboutUs.html
.
You can use your local network ip if both devices are on the same network or your external ip otherwise, but in this case you might have to configure your router to forward the port to the device with the webserver.
You might also have to configure your firewall to allow for inbound connections on that port.
Answered By - Valentin Iorgu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.