While developing application sometimes you may need the IP address of android device on which an application is installed. So in this tutorial, I am going to show how to get the IP address of an android device and display in TextView programmatically.
We can get the IP address of android device on which an app is installed with different ways and here I am going to show the best and easy method to get the IP address of app installed android device. To get IP address of android device (phone, tablet, tv, wear) using this method I have used WifiManager. So in this way you can get the IP address of any app running android device if there is WiFi network connected.
Android Example: Getting the IP Address of Android Device
Following example will give you the IP address of android device on which an app is installed.
XML Layout File
Following is the content of XML layout file where I have added a TextView to display the IP address of android device.
Java Activity File
Following is the little bit java code of activity file.
We are using Wifi Manager to get and display the IP address of android device so, don’t forget to add internet connection and wifi connection permission in your app manifest file.
You have done all things. Now run your How to Get the IP Address of Android Device Programmatically android application, you will see the IP address of your android phone in the screen. Make sure your WiFi connection is ON because we have used WiFiManager.