Une recherche rapide sur Google m'a envoyé ici: http://www.droidnova.com/get-the-ip-address-of-your-device,304.html
Lire les commentaires sur la façon d'utiliser le premier bloc de code pour obtenir l'adresse IP wifi (sur le réseau local, et non IP publique)
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
Modifier: L'émulateur semble retourner 0 sur wifiInfo.getIpAddress(), mais il fonctionne très bien sur un téléphone. Le code suivant convertit l'entier à une adresse ip:
String ipBinary = Integer.toBinaryString(ipAddress);
//Leading zeroes are removed by toBinaryString, this will add them back.
while(ipBinary.length() < 32) {
ipBinary = "0" + ipBinary;
}
//get the four different parts
String a=ipBinary.substring(0,8);
String b=ipBinary.substring(8,16);
String c=ipBinary.substring(16,24);
String d=ipBinary.substring(24,32);
//Convert to numbers
String actualIpAddress =Integer.parseInt(d,2)+"."+Integer.parseInt(c,2)+"."+Integer.parseInt(b,2)+"."+Integer.parseInt(a,2);
Qu'est-ce que "local-perm"? (non natif) – WarrenFaith
Désolé, je voulais dire: Internal-ip – rayman