Android get public ip address programmatically

Hey, In this tutorial we are getting a android get ip address programmatically while the phone is connected to a Mobile data connection or WiFi connection. This example demonstrates how do I get the IP address of android device programmatically.