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 ?
Answer by daniel glenn
·
Jul 03, 2012 at 02:03 AM
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
thanks but i seem to be getting errors when i try to import java net package ? would you please tell me how to import it into unity ? thanks
import java.net; gives me The type or namespace name `java' could not be found. Are you missing a using directive or an assembly reference?
sorry for my late feedback. I have big account issue with the new UDN community. Use import java[dot]net[dot][star]; to import all package. Probably you need to import java[dot]util[dot][star];
[dot] equal .
[star] equal *
A good link for this:
sorry for this [dot [star]..blabla the url forum parser is a pain in the a**
Answer by daniel glenn
·
Jul 03, 2012 at 03:03 AM
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("\n"+ Formatter.formatIpAddress(wim.getConnectionInfo().getIpAddress()));
Hope it helps, have nice day
What using statements did you add to resolve WifiManager?
Dear Daniel,
I am utterly interested how on earth can you import java.net into Unity 5.2 that I am using. or the WifiManager... I have checked the link you posted above, but still couldnt figure it out, even after a whole day of googling... im sure I am missing a core knowledge. I know that this is pretty much a dead thread, but if you dont mind, could you please let me know how can I get with or without java.net* the IP on an Android through C# unity?
would make my day!! thanks, Korn.
Perform DNS Lookup To Get IP Address
1
Answer
Networking ?
2
Answers
Adding server's ip address to favorites so that I don't have to type it in all the time?
1
Answer
Getting android device's IP
1
Answer
android version of a pc game
1
Answer