Wednesday 15 June 2011

Get local IP address of the PC in Android -


I am running some android code in Android emulator on PC. I want to get the local IP address of the PC in my Android code, it is not sure that this is possible ...

I have checked the following post but it seems that it is only public IP The address of the PC can be given.

Thank you.

Normally an Android device or emulator should be thought of as a separate computer from your development computer Could.

He said that if you want to connect to a local computer with an Android emulator / device, here are 2 options for you.

>

  • Use an internal DNS that indicates a name on your local PC, you can also use it to override the "live" url, if it is the same Which you want.

  • Use the BuildConfig.DEBUG flag or similar mechanisms to switch between live and debug URLs / resources

    For example, when I test, to switch between a live URL for exporting and debugging:

      Public Final Class MyAppConstants {// for all requests of public APIs} Url support; My API public static final string BASE_URL; // Auto-switch between LIVE and debug URLs based on usage STECTIVE {if (buildconfig.deview) {URL_BASE = "http://debug.server.com/"; } And {URL_BASE = "http://live.server.com/"; }}}    

  • No comments:

    Post a Comment