how can i make the user know his own IP address and show it to him in his phone screen in android in order to give it to a friend to connect and play in multiplayer mode ?
IP adress, using the WifiManager from android:
TextView tv = (TextView) findViewById(R.id.tv);
WifiManager wim= (WifiManager) getSystemService(WIFI_SERVICE);
List<WifiConfiguration> l = wim.getConfiguredNetworks();
WifiConfiguration wc = l.get(0);
tv.append("
"+ Formatter.formatIpAddress(wim.getConnectionInfo().getIpAddress()));
Hope it helps, have nice day
you need to import the java net package before you can run this basic example:
try{
InetAddress ownIP=InetAddress.getLocalHost();
System.out.println("IP of my Device := "+ownIP.getHostAddress());
}catch (Exception e){
System.out.println("Exception caught ="+e.getMessage());
}
hope it helps, have a nice day