Android: Getting the Wifi Ip Address
Author: The Man
This is how to get the ip address of your Android phone.
View Code JAVA
1 2 3 4 | WifiManager myWifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo myWifiInfo = myWifiManager.getConnectionInfo(); int ipAddress = myWifiInfo.getIpAddress(); System.out.println("WiFi address is " + android.text.format.Formatter.formatIpAddress(ipAddress)); |
Make sure you also add
View Code JAVA
1 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> |
to your Application Manifest.






February 20th, 2012 at 9:15 pm
Thank you for this snippet of code and even more importantly, the ApplicationManifest permission line.
- Xander
April 7th, 2012 at 11:34 am
Hi
The code that you posted is very useful, but i faced a problem when i run the app i got the following error:
app has stopped unexpectedly…
How can i fix this error?
Thank you so much.
April 7th, 2012 at 4:40 pm
You need to learn how to debug, this will get you started http://developer.android.com/guide/developing/debugging/index.html