Android — Get Public IP Address

Chintan Patel
2 min readDec 3, 2021

--

Public IP Address

To get the public IP address in our android/iOS mobile device, our device must be connected to the internet. Our devices are called front-end/client device and it holds only device/private IP address which we can get by writing a program in our app. When you are connected with a Wi-fi router, it will return a local/private IP address for the connected router only using the written program in our device.

The question is how we can get Public IP address when connected to the internet?

To get the public IP address, it requires server programming and calls to the server function which can return our public IP address to which network we are connected.

Does anyone provide the functionality for a Public IP address?

Yes, Ipify provides an API to get a public IP address with code samples for different languages to use in our project.

Can I get it easier for Android?

Obviously! This library Ipify-Android is specially made for #Android #developers, for you, using Ipify API service.

Curious to know the features of this library!

  1. This library provides both IPv4 and IPv6 IP addresses. You can configure it when you initialize the library.
  2. It provides an observer to get a current IP address. So whenever users switch from mobile data to Wi-fi or vice versa, change the Wi-fi network, or the internet gets off/on, It fetches the latest Public IP address for the currently connected internet network.
  3. When the internet goes off or cellular data/Wi-fi gets turned off, it also stores the public IP address which was available for the last connected network and returns it in lastStoredIpAddress.
  4. Once you initialize the Ipfy library at your application level, you can access the instance from anywhere in your project and observe for public IP address changes.

Want to Implement it in your android project?

Go through the link here and enjoy the library with hassle-free code and the rest will be handled by the library itself.

Don’t forget to 👏 and share if you loved ❤️ this.

Also If you loved this hard work👷, you can Buy me a ☕️

--

--

Chintan Patel

Project Manager | Content Writer | Mentor | Senior Mobile App Developer | Enthusiastic | Energetic | Public Speaker