--ADVERTISEMENT--

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.

Related:
How to Get Registered Email Address Programmatically in Android
How to Get Current GPS Location Programmatically in Android
Get Current Time in Android Programmatically

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.

res/layout/android_device_ip_address.xml


Java Activity File


Following is the little bit java code of activity file.

src/GettingAndroidDeviceIPAddress.java


AndroidManifest.xml 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.

AndroidManefest.xml

Strings.xml File


res/values/strings.xml

Android Example: Getting the IP Address of Android Device

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.

Post a Comment

Powered by Blogger.