obtaining local ip adress after CONNECTIVITY_CHANGE Broadcast from Android
<p>I want to know which is my local ip adress after i received a CONNECTIVITY_CHANGE Broadcast from Android:</p>

<pre><code>if(intent.getExtras()!=null) { 
  NetworkInfo ni=(NetworkInfo) intent.getExtras().get(ConnectivityManager.EXTRA_NETWORK_INFO); 
  if(ni!=null &amp;&amp; ni.getState()==NetworkInfo.State.CONNECTED){
    String ip = LocalIPAddress.getLocalIPAddress(); 
  }


public static String getLocalIPAddress() {
try {
   for (Enumeration&lt;NetworkInterface&gt; en = NetworkInterface.getNetworkInterfaces();  en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration&lt;InetAddress&gt; enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    return inetAddress.getHostAddress().toString();
                }
            }
        }
    } catch (SocketException e) {
        Log.i(LogInfo.tag, "Getting the local ip address failed.", e);
    }
    return null;
}
</code></pre>

<p>Most of the time this works fine, but sometimes ip remains empty.</p>

<p>What would be the best way to wait for a valid ip adress?</p>
