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?
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".
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With