Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 792
user2113703 Avatar asked Feb 27 '13 03:02

user2113703


People also ask

How do I access localhost on my phone?

You can access your host machine with the IP address "10.0. 2.2". This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via "http://10.0.2.2:8080".

Can I access localhost from Android emulator?

If you're using Android Studio to run the emulator, then localhost of your host computer will be mapped to the IP address, 10.0. 2.2 , inside the emulator. If you're using other programs to run the emulator, then you may need to consult the documentation associated with those programs.

How do I view web views on android?

Create two Android layout files – “res/layout/main. xml” and “res/layout/webview. xml“. Two activity classes, an activity to display a button, another activity display the WebView with predefined URL.


1 Answers

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

like image 129
JAC Avatar answered Sep 20 '22 13:09

JAC