Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android emulator access server in local network

i am having difficulties to have my android app running in the emulator to connect to servers in my local network. i am getting a

java.net.UnknownHostException

but the servers are resolvable fine from the machine where the emulator is run.

thanks for any help on this topic!

like image 252
clamp Avatar asked Aug 26 '10 10:08

clamp


People also ask

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.

Can an emulator access the Internet?

If your emulator must access the internet through a proxy server, you can configure a custom HTTP proxy from the emulator's Extended controls screen. With the emulator open, click More , and then click Settings and Proxy. From here, you can define your own HTTP proxy settings.

Does emulator have IP address?

Web traffic is routed through your development machine, so the emulator's external IP is whatever IP has been assigned to that machine by your provider. The development machine can always be reached from your device at 10.0. 2.2.

How do I change DNS on Android emulator?

Then run one of the available emulators with the command, “emulator -avd DEVICE_NAME”, followed by the argument “-dns-server 8.8. 8.8”. This will launch the emulator and overwrite the default DNS server address, replacing it with the address of the primary DNS server for Google DNS.


2 Answers

You have to use 10.0.2.2 to access local server.

like image 87
Kwasi Owusu Gyasi-Agyei Avatar answered Oct 05 '22 11:10

Kwasi Owusu Gyasi-Agyei


Try adding <uses-permission android:name="android.permission.INTERNET" /> to your manifest. This allows your application network access.

More can be found here.

like image 24
Bradley Stacey Avatar answered Oct 05 '22 13:10

Bradley Stacey