Android Development

Rapid android development from Berlin

Browsing Posts tagged localhost

The obvious way to get the IP-Address of your device simply doesn’t work on Android.

The first thing I tried was using the WifiInfo.

1
2
3
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();

But wait: ipAddress is an integer? Of course not. I also did the math but couldn’t find a way to get the IP out of this integer. So thats not the right way.
continue reading…

  • Share/Bookmark

It might be obvious linux savvy folks, but trying to access localhost or 127.0.0.1 with the android emulator in order to access a local server for testing won’t get you anywhere. That’s because the IP is used internally by the undlying linux as you might have guessed.

Luckily there’s an IP you can use to achieve hitting your local apache/tomcat/whatever : 10.0.2.2

  • Share/Bookmark
Powered by WordPress Web Design by SRS Solutions © 2010 Android Development Design by SRS Solutions