I tried this code public class MainActivity extends Activity {
private static final String TAG = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv= (TextView) findViewById(R.id.textView2);
String a=getLocalIpAddress();
tv.setText(a);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
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()) {
String a= inetAddress.getHostAddress();
return a;
}
}
}
} catch (SocketException ex) {
// Log.e(tag, ex.toString());
}
return "";
}
}
this gives me ip address like 00ff:22ff:.... but I want it like 192.168.3.3... format ip address is depreciated is there any other method so that I could get formatted address