How to Access Localhost from a Genymotion Android Emulator

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 added
httpAddress = "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 emulator
emulator -avd AVDNAME -partition-size 128

Second remount the AVD to make it writable
adb remount

Third pull the host file from emulator to your local machine
adb pull /etc/hosts

Fourth edit the host file using local editor based on the need
198.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



Leave a reply



Submit