How to access localhost from a Genymotion android emulator?
Update
After genymotion update to 2.2 you can use 10.0.3.2
, ref
Another approach
To access your localhost through Genymotion is using your PC IP address. to get your IP address go to:
start -> cmd -> ipconfig
then search for IPv4, copy the IP and paste it in your URL. It should looks like the following:
String YourURL = "http://192.168.0.106:8888/your_script_location.php";
Hope this works too for you, give me a feedback.
P.S: if it didn't work, turn off the firewall and any anti-virus application you have in your PC.
Cannot access localhost from Genymotion Free Version
Problem solved!
This is what I did:
First Genymotion Emulator couldn't reach the localhost at all although I was using the correct address (http://192.168.56.1:8080) which is VBox-0 ip address (got that from ipconfig)....Then I went to the Virtual Box -> Settings -> Network -> and switched Adapter-1 to Bridge Adapter and selected my wifi network and then switched back...this must have re-triggered some corrupt process in the Oracle VBox that comes with Genymotion. That fixed problem 1 and now I can reach my Tomcat.
Still Google Endpoints cannot be reached via, Thanks to This Answer my problem was solved. In Module:backend build.gradle I addedhttpAddress = "0.0.0.0"
under appengine, then synced the backend module. And on the Android App where I make the call to the backend endpoints, I changed the url from 10.0.2.2:8080
which is Android Default Emulator into .setRootUrl("http://192.168.56.1:8080/_ah/api/")
That solved problem 2.
Make sure your VBox is set as follows:
Adapter 1: Host-only Adapter - VirtualBox Host-only Ethernet Adapter #2
Adapter 2: Host-only Adapter - VirtualBox Host-only Ethernet Adapter (which was 192.168.56.1)
my phone ip address was also on the same network as Vbox0 i.e. (192.168.56.101)
Accessing Localhost and Virtualhost From Emulator in Android Studio?
You can try editing the hosts file from terminal of the android studio.
First go to terminal and launch the emulatoremulator -avd AVDNAME -partition-size 128
Second remount the AVD to make it writableadb remount
Third pull the host file from emulator to your local machineadb pull /etc/hosts
Fourth edit the host file using local editor based on the need198.0.0.1 localhost
Finally, push the edited file from local machine back to emulator adb push hosts /etc/hosts
Now, type localhost or domain you assigned in the host file.
Hope this is enough!
Access host from Genymotion emulator
try this ip address: 10.0.3.2
It should work
Genymotion localhost access inside a webview
I found a solution, the problem was not in genymotion or in my code but actually in the local server, i had to enable CORS (you can find how to enable cors in wamp here)
I also had this problem with my remote server so i have to enable CORS there also.
Related Topics
Illegalstateexception When Replacing a Fragment
How to Display Border to Imageview
Disable the Touch Events for All the Views
Android Set Button Background Programmatically
Android Studio Build Fails with "Task '' Not Found in Root Project 'Myproject'."
How to Completely Kill/Remove/Delete/Stop an Asynctask
Why Shouldn't I Use System.Out.Println() in Android
How to Add Crosswalk Webview in My Own Android Library Module
How to Make Edittext Not Editable Through Xml in Android
Pass List of Objects from One Activity to Other Activity in Android
Clear Text in Edittext When Entered
How to Open the Options Menu Programmatically
Onclicklistener - X,Y Location of Event
Android.Os.Networkonmainthreadexception with Android 4.2
How to Use a Timertask to Run a Thread
Firebase Realtime Database Connection Killed: Different Region