2

Anybody help me to get IP Address whenever I use mobile data. When I am using wifi then I am getting IP Address, but while using mobile data its not working.

Thanks in advance..

Ajith
  • 169
  • 1
  • 2
  • 12

1 Answers1

0

From here: https://groups.google.com/forum/#!topic/android-developers/a5loFkRuV3w

public String getLocalIpAddress() { 
        try { 
            for (Enumeration<NetworkInterface> en = 
NetworkInterface.getNetworkInterfaces(); en 
                    .hasMoreElements();) { 
                NetworkInterface intf = en.nextElement(); 
                for (Enumeration<InetAddress> enumIpAddr = 
intf.getInetAddresses(); enumIpAddr 
                        .hasMoreElements();) { 
                    InetAddress inetAddress = enumIpAddr.nextElement 
(); 
                    if (!inetAddress.isLoopbackAddress()) { 
                        return inetAddress.getHostAddress().toString 
(); 
                    } 
                } 
            } 
        } catch (SocketException ex) { 
            Log.e(S.TAG, ex.toString()); 
        } 
        return null; 
    } 

Although I havent tried it myself

Vrashabh Irde
  • 14,129
  • 6
  • 51
  • 103