I want to obtain the local IPv4 address of a user on their phone running my application when connected to a wifi network. Using the following code:
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
hostname = ip;
I am able to get something close to the IPv4 address but when compared to the IPv4 address in the command line, it is not exactly the same. Is there a better way to go about this? I know that formatIpAddress is deprecated but until I find a way to get the IPv4 address I'm not too worried about that for now.
EDIT:
I have discovered that the ip address in the phone's wifi settings is what I am getting when using solutions to get the ip address like the suggested solutions. Is there any way to get the ip address in the ip config client side?