Este es un tip muy útil que permite obtener la dirección IP que tengamos asignada vía una conexión Wireless.
01
02
03
04
05
06
07
08
09
10
11
12
13
|
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) {}
return null ;
}
|
Existen otras maneras de hacerlo, por ejemplo usando las clases WifiManager
y WifiInfo
, pero es mucho más confiable el método anterior. Además, este método funciona no solo en *Android*, sino en cualquier proyecto Java.
Me gusta:
Me gusta Cargando...
You no doubt know thus appreciably with regards to the following subject, made me for my part ponder over it through numerous several perspectives. It’s just like both males and females usually are not captivated except it really is something connected to Kesha! Your individual stuffs spectacular Drivers android. Always handle this!
Me gustaMe gusta