1

Is there a way to pass my PCs/Laptops current local IP to my App via command line argument or something else?

I don't want to switch to a static IP or enter it all the time I begin to work on my App that relies on a local server that runs on my laptop. I think the easiest way would be to pass it as a macro from the run configurations. Is there a way to do this or something similar?

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378

1 Answers1

0

There are two main ways to do this.

  1. Write your IP Address to a system property and then read that in your app.
  2. Start your activity with an intent that contains the IP Address as an extra.

Of the two, I'd suggest using an intent. Refer to this other answer for how to use adb to start your app. In your activity code, in onCreate you should call getIntent and then get your extra and parse it.

Community
  • 1
  • 1
justhecuke
  • 765
  • 4
  • 8