-2

How can I get the ip address when the android is in Active data network mode? I searched about How can I get the ip address in android and I found the following answers:

WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());

When I run the code above in my device, I get the ip address only when my device is in WIFI mode. But when my device is in Active data network mode and then I run the above code I see such thing: 0.0.0.0. I want to get any ip address in both situations.Thank you.

SolarBear
  • 4,534
  • 4
  • 37
  • 53
android
  • 91
  • 9
  • There are several similar questions here that can guide you to the answer, please do a search before posting yours. – Sebastian Aug 04 '15 at 11:14

1 Answers1

0

WifiManager

This class provides the primary API for managing all aspects of Wi-Ficonnectivity.

Get an instance of this class by calling Context.getSystemService(Context.WIFI_SERVICE). It deals with several categories of items:

The list of configured networks. The list can be viewed and updated, and attributes of individual entries can be modified.

The currently active Wi-Fi network, if any. Connectivity can be established or torn down, and dynamic information about the state of the network can be queried.

Results of access point scans, containing enough information to make decisions about what access point to connect to.

It defines the names of various Intent actions that are broadcast upon any sort of change in Wi-Fi state.

This is the API to use when performing Wi-Fi specific operations. To perform operations that pertain to network connectivity at an abstract level, use ConnectivityManager.

WifiManager

Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28