How to access the local host server with web view in Android

 ̄綄美尐妖づ 提交于 2019-12-23 12:15:38

问题


I have an Android Application and I need to go to my web server and connect my Android Application to another program on the web. my web program is working and when I put its IP address on Android FIrefox or Browser it is working but when I call its IP address with my webview ( webView.loadUrl(my web program IP address) it's not working. Can somebody help me where is my mistake?


回答1:


Make sure you are not using "localhost" from you app (a very common mistake).

If you are accessing your local server from a wifi, you just need to check which IP your server has assigned and use it in the app.

If you are using the emulator, try with 10.0.2.2

See here Accessing localhost:port from Android emulator




回答2:


I too had the same issue. Let's say the IP address is `216.58.216.164. I rectified it using following

webView.loadUrl("http://216.58.216.164/")


来源:https://stackoverflow.com/questions/15103463/how-to-access-the-local-host-server-with-web-view-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!